From a4d4b362e6ae3bca62f2391715470fa0b53510e2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 15 Aug 2013 05:29:05 +0000 Subject: [PATCH] fix bug in duplicate-peer resolution. just take the port into account, not the whole IP, because the different ends may have different ideas of what their IP is --- src/peer_connection.cpp | 4 ++-- src/policy.cpp | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a85bff4d9..ac17996db 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -5256,8 +5256,8 @@ namespace libtorrent INVARIANT_CHECK; #ifdef TORRENT_VERBOSE_LOGGING - peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" - , bytes_transferred, error.message().c_str()); + peer_log("<<< ON_RECEIVE_DATA [ bytes: %d error: %s ]" + , bytes_transferred, error.message().c_str()); #endif #if defined TORRENT_ASIO_DEBUGGING complete_async("peer_connection::on_receive_data"); diff --git a/src/policy.cpp b/src/policy.cpp index 449f8ab5f..eb73fd8ec 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -913,7 +913,13 @@ namespace libtorrent i = *iter; TORRENT_ASSERT(i->in_use); TORRENT_ASSERT(i->connection != &c); + TORRENT_ASSERT(i->address() == c.remote().address()); +#ifdef TORRENT_VERBOSE_LOGGING + c.peer_log("*** DUPLICATE PEER [ this: \"%s\" that: \"%s\" ]" + , print_address(c.remote().address()).c_str() + , print_address(i->address()).c_str()); +#endif if (i->banned) { c.disconnect(errors::peer_banned); @@ -982,16 +988,14 @@ namespace libtorrent // to be careful to only look at the target end of a // connection for the endpoint. - tcp::endpoint our_ep = outgoing1 ? other_socket->local_endpoint(ec1) : this_socket->local_endpoint(ec1); - tcp::endpoint other_ep = outgoing1 ? this_socket->remote_endpoint(ec1) : other_socket->remote_endpoint(ec1); + int our_port = outgoing1 ? other_socket->local_endpoint(ec1).port() : this_socket->local_endpoint(ec1).port(); + int other_port = outgoing1 ? this_socket->remote_endpoint(ec1).port() : other_socket->remote_endpoint(ec1).port(); - if (our_ep < other_ep) + if (our_port < other_port) { #ifdef TORRENT_VERBOSE_LOGGING - c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%s\" < \"%s\" ]" - , print_endpoint(our_ep).c_str(), print_endpoint(other_ep).c_str()); - i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%s\" < \"%s\" ]" - , print_endpoint(our_ep).c_str(), print_endpoint(other_ep).c_str()); + c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" < \"%d\" ]", our_port, other_port); + i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" < \"%d\" ]", our_port, other_port); #endif // we should keep our outgoing connection @@ -1008,10 +1012,8 @@ namespace libtorrent else { #ifdef TORRENT_VERBOSE_LOGGING - c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%s\" >= \"%s\" ]" - , print_endpoint(our_ep).c_str(), print_endpoint(other_ep).c_str()); - i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%s\" >= \"%s\" ]" - , print_endpoint(our_ep).c_str(), print_endpoint(other_ep).c_str()); + c.peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" >= \"%d\" ]", our_port, other_port); + i->connection->peer_log("*** DUPLICATE PEER RESOLUTION [ \"%d\" >= \"%d\" ]", our_port, other_port); #endif // they should keep their outgoing connection if (outgoing1)