make sure &key= stays consistent between different source IPs (as mandated by BEP7)

This commit is contained in:
arvidn 2020-01-11 02:01:07 +01:00 committed by Arvid Norberg
parent 7320568c3c
commit e18366bb6b
4 changed files with 3 additions and 35 deletions

View File

@ -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

View File

@ -221,10 +221,6 @@ namespace aux {
std::shared_ptr<natpmp> 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<void(aux::listen_socket_handle const&)> f) override
{
for (auto& s : m_listen_sockets)

View File

@ -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

View File

@ -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<uintptr_t>(this);
hasher h(reinterpret_cast<char const*>(&ses), sizeof(ses));
if (iface.is_v4())
{
auto const b = iface.to_v4().to_bytes();
h.update({reinterpret_cast<char const*>(b.data())
, std::ptrdiff_t(b.size())});
}
else
{
auto const b = iface.to_v6().to_bytes();
h.update({reinterpret_cast<char const*>(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<listen_socket_t> 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;