From e18366bb6b577df27149b3e87d352130491154a1 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 11 Jan 2020 02:01:07 +0100 Subject: [PATCH] make sure &key= stays consistent between different source IPs (as mandated by BEP7) --- ChangeLog | 1 + include/libtorrent/aux_/session_impl.hpp | 6 ------ simulation/test_tracker.cpp | 4 ++-- src/session_impl.cpp | 27 ------------------------ 4 files changed, 3 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1f6a749a..8a8a8adc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * make sure &key= stays consistent between different source IPs (as mandated by BEP7) * fix binding sockets to outgoing interface * add new socks5_alert to trouble shoot SOCKS5 proxies diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index e248d695b..5c5dddbbb 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -221,10 +221,6 @@ namespace aux { std::shared_ptr natpmp_mapper; - // the key is an id that is used to identify the - // client with the tracker only. - std::uint32_t tracker_key = 0; - // set to true when we receive an incoming connection from this listen // socket bool incoming_connection = false; @@ -630,8 +626,6 @@ namespace aux { // or zero if no matching listen socket is found int listen_port(transport ssl, address const& local_addr) override; - std::uint32_t get_tracker_key(address const& iface) const; - void for_each_listen_socket(std::function f) override { for (auto& s : m_listen_sockets) diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index 517f2b855..ed296c15e 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -1108,8 +1108,8 @@ TORRENT_TEST(tracker_key_argument) , [](torrent_handle h) {} , [](torrent_handle h) {}); - // make sure we got two separate keys, one for each listen socket interface - TEST_EQUAL(keys.size(), 2); + // make sure we got the same key for all listen socket interface + TEST_EQUAL(keys.size(), 1); } // make sure we do _not_ send our IPv6 address to trackers for non-private diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 10f757b83..1773a96ff 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1067,8 +1067,6 @@ namespace aux { { auto ls = req.outgoing_socket.get(); - req.key ^= ls->tracker_key; - req.listen_port = #ifdef TORRENT_USE_OPENSSL // SSL torrents use the SSL listen port @@ -1092,9 +1090,6 @@ namespace aux { #endif listen_port(ls.get()); - // we combine the per-torrent key with the per-interface key to make - // them consistent and unique per torrent and interface - socket_req.key ^= ls->tracker_key; socket_req.outgoing_socket = ls; m_tracker_manager.queue_request(get_io_service(), std::move(socket_req), c); } @@ -1315,27 +1310,6 @@ namespace aux { reopen_outgoing_sockets(); } - std::uint32_t session_impl::get_tracker_key(address const& iface) const - { - auto const ses = reinterpret_cast(this); - hasher h(reinterpret_cast(&ses), sizeof(ses)); - if (iface.is_v4()) - { - auto const b = iface.to_v4().to_bytes(); - h.update({reinterpret_cast(b.data()) - , std::ptrdiff_t(b.size())}); - } - else - { - auto const b = iface.to_v6().to_bytes(); - h.update({reinterpret_cast(b.data()) - , std::ptrdiff_t(b.size())}); - } - sha1_hash const hash = h.final(); - unsigned char const* ptr = &hash[0]; - return detail::read_uint32(ptr); - } - std::shared_ptr session_impl::setup_listener( listen_endpoint_t const& lep, error_code& ec) { @@ -1653,7 +1627,6 @@ namespace aux { ret->local_endpoint = tcp::endpoint(udp_ep.address(), udp_ep.port()); } - ret->tracker_key = get_tracker_key(ret->local_endpoint.address()); ret->device = lep.device; error_code err;