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

This commit is contained in:
Arvid Norberg 2013-08-15 05:29:05 +00:00
parent 6228ef2e85
commit a4d4b362e6
2 changed files with 15 additions and 13 deletions

View File

@ -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");

View File

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