diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index e23335600..a1de3755b 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -549,14 +549,14 @@ TORRENT_TEST(announce_no_listen) { // if we don't listen on any sockets at all (but only make outgoing peer // connections) we still need to make sure we announce to trackers - test_ipv6_support("", 2, 2); + test_ipv6_support("", num_interfaces * 2, num_interfaces * 2); } TORRENT_TEST(announce_udp_no_listen) { // since there's no actual udp tracker in this test, we will only try to // announce once, and fail. We won't announce the event=stopped - test_udpv6_support("", 1, 1); + test_udpv6_support("", num_interfaces * 1, num_interfaces * 1); } TORRENT_TEST(ipv6_support_bind_v4_v6_any) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 8e1a980e5..35ed6dffa 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1097,6 +1097,7 @@ namespace aux { void session_impl::queue_tracker_request(tracker_request&& req , std::weak_ptr c) { + req.listen_port = 0; #if TORRENT_USE_I2P if (!m_settings.get_str(settings_pack::i2p_hostname).empty()) { @@ -1125,6 +1126,7 @@ namespace aux { { for (auto& ls : m_listen_sockets) { + if (!(ls->flags & listen_socket_t::accept_incoming)) continue; #ifdef TORRENT_USE_OPENSSL if ((ls->ssl == transport::ssl) != use_ssl) continue; #endif @@ -1833,14 +1835,6 @@ namespace aux { interface_to_endpoints(device, port, ssl, flags, eps); } - std::vector const ifs = enum_net_interfaces(m_io_service, ec); - if (!ec) - { - expand_unspecified_address(ifs, eps); - auto const routes = enum_routes(m_io_service, ec); - if (!ec) expand_devices(ifs, routes, eps); - } - // if no listen interfaces are specified, create sockets to use // any interface if (eps.empty()) @@ -1851,6 +1845,14 @@ namespace aux { , listen_socket_flags_t{}); } + std::vector const ifs = enum_net_interfaces(m_io_service, ec); + if (!ec) + { + expand_unspecified_address(ifs, eps); + auto const routes = enum_routes(m_io_service, ec); + if (!ec) expand_devices(ifs, routes, eps); + } + auto remove_iter = partition_listen_sockets(eps, m_listen_sockets); while (remove_iter != m_listen_sockets.end()) @@ -5341,6 +5343,7 @@ namespace aux { if (m_listen_sockets.empty()) return 0; if (sock) { + if (!(sock->flags & listen_socket_t::accept_incoming)) return 0; // if we're using a proxy, we won't be able to accept any TCP // connections. We may be able to accept uTP connections though, so // announce the UDP port instead @@ -5353,6 +5356,7 @@ namespace aux { #ifdef TORRENT_USE_OPENSSL for (auto const& s : m_listen_sockets) { + if (!(s->flags & listen_socket_t::accept_incoming)) continue; if (s->ssl == transport::plaintext) { if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none) @@ -5363,7 +5367,9 @@ namespace aux { } return 0; #else - return std::uint16_t(m_listen_sockets.front()->tcp_external_port()); + sock = m_listen_sockets.front().get(); + if (!(sock->flags & listen_socket_t::accept_incoming)) return 0; + return std::uint16_t(sock->tcp_external_port()); #endif } @@ -5377,9 +5383,10 @@ namespace aux { std::uint16_t session_impl::ssl_listen_port(listen_socket_t* sock) const { #ifdef TORRENT_USE_OPENSSL - if (sock) { + if (!(sock->flags & listen_socket_t::accept_incoming)) return 0; + // if we're using a proxy, we won't be able to accept any TCP // connections. We may be able to accept uTP connections though, so // announce the UDP port instead @@ -5394,6 +5401,7 @@ namespace aux { for (auto const& s : m_listen_sockets) { + if (!(s->flags & listen_socket_t::accept_incoming)) continue; if (s->ssl == transport::ssl) { if (m_settings.get_int(settings_pack::proxy_type) != settings_pack::none) @@ -5431,6 +5439,7 @@ namespace aux { auto socket = std::find_if(m_listen_sockets.begin(), m_listen_sockets.end() , [&](std::shared_ptr const& e) { + if (!(e->flags & listen_socket_t::accept_incoming)) return false; auto const& listen_addr = e->external_address.external_address(); return e->ssl == ssl && (listen_addr == local_addr