fixed rare bug where we might erase an entry from the policy peer list when we shouldn't

This commit is contained in:
Arvid Norberg 2010-03-08 08:03:53 +00:00
parent b80664bbaa
commit 5247db7f90
2 changed files with 12 additions and 6 deletions

View File

@ -2220,7 +2220,7 @@ namespace libtorrent
if (t->alerts().should_post<unwanted_block_alert>()) if (t->alerts().should_post<unwanted_block_alert>())
{ {
t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote
, m_peer_id, block_finished.block_index, block_finished.piece_index)); , m_peer_id, block_finished.block_index, block_finished.piece_index));
} }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << " *** The block we just got was not in the " (*m_logger) << " *** The block we just got was not in the "

View File

@ -731,6 +731,7 @@ namespace libtorrent
{ {
c.disconnect(errors::self_connection, 1); c.disconnect(errors::self_connection, 1);
i->connection->disconnect(errors::self_connection, 1); i->connection->disconnect(errors::self_connection, 1);
TORRENT_ASSERT(i->connection == 0);
return false; return false;
} }
@ -740,6 +741,7 @@ namespace libtorrent
if (ec2) if (ec2)
{ {
i->connection->disconnect(ec2); i->connection->disconnect(ec2);
TORRENT_ASSERT(i->connection == 0);
} }
else if (!i->connection->is_connecting() || c.is_local()) else if (!i->connection->is_connecting() || c.is_local())
{ {
@ -754,6 +756,7 @@ namespace libtorrent
"connection in favour of this one"); "connection in favour of this one");
#endif #endif
i->connection->disconnect(errors::duplicate_peer_id); i->connection->disconnect(errors::duplicate_peer_id);
TORRENT_ASSERT(i->connection == 0);
} }
} }
@ -835,6 +838,7 @@ namespace libtorrent
// this cannot be a connect candidate anymore, since i->connection is set // this cannot be a connect candidate anymore, since i->connection is set
TORRENT_ASSERT(!is_connect_candidate(*i, m_finished)); TORRENT_ASSERT(!is_connect_candidate(*i, m_finished));
TORRENT_ASSERT(has_connection(&c));
return true; return true;
} }
@ -1263,11 +1267,13 @@ namespace libtorrent
// if we're not a seed, but we have too many peers // if we're not a seed, but we have too many peers
// start weeding the ones we only know from resume // start weeding the ones we only know from resume
// data first // data first
if (m_torrent->is_seed() || m_peers.size() >= m_torrent->settings().max_peerlist_size * 0.9) // at this point it may be tempting to erase peers
{ // from the peer list, but keep in mind that we might
if (p->source == peer_info::resume_data) // have gotten to this point through new_connection, just
erase_peer(p); // disconnecting an old peer, relying on this policy::peer
} // to still exist when we get back there, to assign the new
// peer connection pointer to it. The peer list must
// be left intact.
} }
void policy::peer_is_interesting(peer_connection& c) void policy::peer_is_interesting(peer_connection& c)