From e44225cb57f3f787e3981408b7df6fcfd57c375d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 5 Oct 2012 03:20:40 +0000 Subject: [PATCH] merged uTP fix from RC_0_16 --- ChangeLog | 1 + include/libtorrent/socket_type.hpp | 3 +++ src/bt_peer_connection.cpp | 2 +- src/peer_connection.cpp | 13 +++++-------- src/session_impl.cpp | 5 ++++- src/socket_type.cpp | 9 +++++++++ src/ut_pex.cpp | 4 ++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 764f056be..2612bf0cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix some issues with SSL over uTP connections * fix UDP trackers trying all endpoints behind the hostname 0.16.4 release diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 4758f3b7e..602b26e29 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -306,6 +306,9 @@ namespace libtorrent // returns true if this socket is an SSL socket bool is_ssl(socket_type const& s); + // returns true if this is a uTP socket + bool is_utp(socket_type const& s); + // assuming the socket_type s is an ssl socket, make sure it // verifies the hostname in its SSL handshake void setup_ssl_hostname(socket_type& s, std::string const& hostname, error_code& ec); diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 0089f15fe..2954ad117 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -367,7 +367,7 @@ namespace libtorrent if (is_queued()) p.flags |= peer_info::queued; p.client = m_client_version; - p.connection_type = get_socket()->get() + p.connection_type = is_utp(*get_socket()) ? peer_info::bittorrent_utp : peer_info::standard_bittorrent; } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index eee2879c8..77b3d0545 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -3291,7 +3291,7 @@ namespace libtorrent // a connection attempt using uTP just failed // mark this peer as not supporting uTP // we'll never try it again (unless we're trying holepunch) - if (m_socket->get() + if (is_utp(*m_socket) && m_peer_info && m_peer_info->supports_utp && !m_holepunch_mode) @@ -3310,7 +3310,8 @@ namespace libtorrent fast_reconnect(true); #ifndef TORRENT_DISABLE_EXTENSIONS - if ((!m_socket->get() || !m_ses.m_settings.enable_outgoing_tcp) + if ((!is_utp(*m_socket) + || !m_ses.m_settings.enable_outgoing_tcp) && m_peer_info && m_peer_info->supports_holepunch && !m_holepunch_mode) @@ -3400,7 +3401,7 @@ namespace libtorrent if (ec == error_code(errors::timed_out_no_handshake)) ++m_ses.m_connect_timeouts; - if (m_socket->get()) ++m_ses.m_error_utp_peers; + if (is_utp(*m_socket)) ++m_ses.m_error_utp_peers; else ++m_ses.m_error_tcp_peers; if (m_outgoing) ++m_ses.m_error_outgoing_peers; @@ -5384,11 +5385,7 @@ namespace libtorrent if (m_disconnecting) return; m_last_receive = time_now(); - if ((m_socket->get() -#ifdef TORRENT_USE_OPENSSL - || m_socket->get >() -#endif - ) && m_peer_info) + if (is_utp(*m_socket) && m_peer_info) { m_peer_info->confirmed_supports_utp = true; m_peer_info->supports_utp = false; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 304474722..4bdc908ef 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3111,7 +3111,7 @@ namespace aux { peer_connection& p = *(*i); if (p.in_handshake()) continue; int protocol = 0; - if (p.get_socket()->get()) protocol = 1; + if (is_utp(*p.get_socket())) protocol = 1; if (p.download_queue().size() + p.request_queue().size() > 0) ++num_peers[protocol][peer_connection::download_channel]; @@ -3666,6 +3666,9 @@ namespace aux { ++peers_up_send_buffer; utp_stream* utp_socket = p->get_socket()->get(); +#ifdef TORRENT_USE_OPENSSL + if (!utp_socket) utp_socket = p->get_socket()->get >(); +#endif if (utp_socket) { utp_up_rate += ul_rate; diff --git a/src/socket_type.cpp b/src/socket_type.cpp index 17e1d2f66..abd061d87 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -63,6 +63,15 @@ namespace libtorrent #endif } + bool is_utp(socket_type const& s) + { + return s.get() +#ifdef TORRENT_USE_OPENSSL + || s.get >() +#endif + ; + } + void setup_ssl_hostname(socket_type& s, std::string const& hostname, error_code& ec) { #if defined TORRENT_USE_OPENSSL && BOOST_VERSION >= 104700 diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 436c5dd09..cd563d7dc 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -173,7 +173,7 @@ namespace libtorrent { namespace #ifndef TORRENT_DISABLE_ENCRYPTION flags |= p->supports_encryption() ? 1 : 0; #endif - flags |= p->get_socket()->get() ? 4 : 0; + flags |= is_utp(*p->get_socket()) ? 4 : 0; flags |= p->supports_holepunch() ? 8 : 0; // i->first was added since the last time @@ -521,7 +521,7 @@ namespace libtorrent { namespace #ifndef TORRENT_DISABLE_ENCRYPTION flags |= p->supports_encryption() ? 1 : 0; #endif - flags |= p->get_socket()->get() ? 4 : 0; + flags |= is_utp(*p->get_socket()) ? 4 : 0; flags |= p->supports_holepunch() ? 8 : 0; tcp::endpoint remote = peer->remote();