From ddd116829606e96afbf33b49f595489f47137ef4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 10 May 2018 18:58:29 +0200 Subject: [PATCH] don't attempt to make uTP connections if we don't have any outgoing UDP sockets --- include/libtorrent/aux_/session_impl.hpp | 1 + include/libtorrent/aux_/session_interface.hpp | 1 + src/session_impl.cpp | 5 +++++ src/torrent.cpp | 5 ++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 50cac2702..a369d64cc 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -691,6 +691,7 @@ namespace aux { mutable std::condition_variable cond; // implements session_interface + bool has_udp_outgoing_sockets() const override; tcp::endpoint bind_outgoing_socket(socket_type& s, address const& remote_address, error_code& ec) const override; bool verify_incoming_interface(address const& addr); diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index f39275f48..b84880dae 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -211,6 +211,7 @@ namespace aux { virtual void for_each_listen_socket(std::function f) = 0; // ask for which interface and port to bind outgoing peer connections on + virtual bool has_udp_outgoing_sockets() const = 0; virtual tcp::endpoint bind_outgoing_socket(socket_type& s, address const& remote_address, error_code& ec) const = 0; virtual bool verify_bound_address(address const& addr, bool utp diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f85087bca..356e989fd 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4964,6 +4964,11 @@ namespace aux { #endif } + bool session_impl::has_udp_outgoing_sockets() const + { + return !m_outgoing_sockets.sockets.empty(); + } + tcp::endpoint session_impl::bind_outgoing_socket(socket_type& s, address const& remote_address, error_code& ec) const { diff --git a/src/torrent.cpp b/src/torrent.cpp index 47dc1a709..556e433e0 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6563,8 +6563,11 @@ bool is_downloading_state(int const st) if (settings().get_bool(settings_pack::enable_outgoing_utp) && (!settings().get_bool(settings_pack::enable_outgoing_tcp) || peerinfo->supports_utp - || peerinfo->confirmed_supports_utp)) + || peerinfo->confirmed_supports_utp) + && m_ses.has_udp_outgoing_sockets()) + { sm = m_ses.utp_socket_manager(); + } // don't make a TCP connection if it's disabled if (sm == nullptr && !settings().get_bool(settings_pack::enable_outgoing_tcp))