From c4761e39224e35537eee41c17cf2b9a1229e40a7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 28 Apr 2011 07:32:42 +0000 Subject: [PATCH] proper seed mode fix --- src/policy.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/policy.cpp b/src/policy.cpp index 90d5a1f00..1e2ee41a7 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -357,20 +357,32 @@ namespace libtorrent continue; } + if (ses.m_alerts.should_post()) + ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), (*i)->address())); + + int current = i - m_peers.begin(); + TORRENT_ASSERT(current >= 0); + TORRENT_ASSERT(m_peers.size() > 0); + TORRENT_ASSERT(i != m_peers.end()); + if ((*i)->connection) { - (*i)->connection->disconnect(errors::banned_by_ip_filter); - if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), (*i)->address())); + // disconnecting the peer here may also delete the + // peer_info_struct. If that is the case, just continue + int count = m_peers.size(); + peer_connection* p = (*i)->connection; + + p->disconnect(errors::banned_by_ip_filter); + // what *i refers to has changed, i.e. cur was deleted + if (m_peers.size() < count) + { + i = m_peers.begin() + current; + continue; + } TORRENT_ASSERT((*i)->connection == 0 || (*i)->connection->peer_info_struct() == 0); } - else - { - if (ses.m_alerts.should_post()) - ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), (*i)->address())); - } - int current = i - m_peers.begin(); + erase_peer(i); i = m_peers.begin() + current; }