self connection fixes

This commit is contained in:
Arvid Norberg 2008-06-16 13:54:14 +00:00
parent 41f241b476
commit 9a8fc4f713
2 changed files with 39 additions and 0 deletions

View File

@ -3270,11 +3270,21 @@ namespace libtorrent
// this means the connection just succeeded
TORRENT_ASSERT(m_socket);
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
(*m_ses.m_logger) << time_now_string() << " COMPLETED: " << m_remote.address().to_string()
<< " rtt = " << m_rtt << "\n";
#endif
error_code ec;
if (m_remote == m_socket->local_endpoint(ec))
{
// if the remote endpoint is the same as the local endpoint, we're connected
// to ourselves
disconnect("connected to ourselves", 1);
return;
}
if (m_remote.address().is_v4())
{
error_code ec;

View File

@ -618,6 +618,35 @@ namespace libtorrent
if (i->second.connection != 0)
{
boost::shared_ptr<socket_type> other_socket
= i->second.connection->get_socket();
boost::shared_ptr<socket_type> this_socket
= c.get_socket();
error_code ec1;
error_code ec2;
bool self_connection =
other_socket->remote_endpoint(ec2) == this_socket->local_endpoint(ec1)
|| other_socket->local_endpoint(ec2) == this_socket->remote_endpoint(ec1);
if (ec1)
{
c.disconnect(ec1.message().c_str());
return false;
}
if (ec2)
{
i->second.connection->disconnect(ec2.message().c_str());
}
if (self_connection)
{
c.disconnect("connected to ourselves", 1);
i->second.connection->disconnect("connected to ourselves", 1);
return false;
}
TORRENT_ASSERT(i->second.connection != &c);
// the new connection is a local (outgoing) connection
// or the current one is already connected