From 27b25017f2c5b349237f64441d5d1a5c4a88851d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 28 Nov 2011 09:55:00 +0000 Subject: [PATCH] fix bug in policy::erase_peers and simplified the logic some --- src/policy.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/policy.cpp b/src/policy.cpp index 6b6c95f32..d850d6098 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -507,31 +507,29 @@ namespace libtorrent peer& pe = *m_peers[round_robin]; int current = round_robin; + if (is_erase_candidate(pe, m_finished) + && (erase_candidate == -1 + || !compare_peer_erase(*m_peers[erase_candidate], pe))) { - if (is_erase_candidate(pe, m_finished) - && (erase_candidate == -1 - || !compare_peer_erase(*m_peers[erase_candidate], pe))) + if (should_erase_immediately(pe)) { - if (should_erase_immediately(pe)) - { - if (erase_candidate > current) --erase_candidate; - if (force_erase_candidate > current) --force_erase_candidate; - TORRENT_ASSERT(current >= 0 && current < int(m_peers.size())); - --round_robin; - erase_peer(m_peers.begin() + current); - } - else - { - erase_candidate = current; - } + if (erase_candidate > current) --erase_candidate; + if (force_erase_candidate > current) --force_erase_candidate; + TORRENT_ASSERT(current >= 0 && current < int(m_peers.size())); + erase_peer(m_peers.begin() + current); + continue; } - if (is_force_erase_candidate(pe) - && (force_erase_candidate == -1 - || !compare_peer_erase(*m_peers[force_erase_candidate], pe))) + else { - force_erase_candidate = current; + erase_candidate = current; } } + if (is_force_erase_candidate(pe) + && (force_erase_candidate == -1 + || !compare_peer_erase(*m_peers[force_erase_candidate], pe))) + { + force_erase_candidate = current; + } ++round_robin; }