From b3372dced659cbb64a6031cdff53f05091bf0adc Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 28 Aug 2009 07:48:31 +0000 Subject: [PATCH] fixed rare request queuing issue for peers in parole mode --- src/peer_connection.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 8c4b26369..8790c24c8 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1863,21 +1863,34 @@ namespace libtorrent in_req_queue = true; break; } + // if this is not in the request queue, we have to // assume our outstanding bytes includes this piece too if (!in_req_queue) { - if (t->alerts().should_post()) + for (std::vector::iterator i = m_request_queue.begin() + , end(m_request_queue.end()); i != end; ++i) { - t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote - , m_peer_id, b.block_index, b.piece_index)); + if (*i != b) continue; + in_req_queue = true; + m_request_queue.erase(i); + break; } + + if (!in_req_queue) + { + if (t->alerts().should_post()) + { + t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote + , m_peer_id, b.block_index, b.piece_index)); + } #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - (*m_logger) << " *** The block we just got was not in the " - "request queue ***\n"; + (*m_logger) << " *** The block we just got was not in the " + "request queue ***\n"; #endif + } m_download_queue.insert(m_download_queue.begin(), b); - m_download_queue.front().not_wanted = true; + if (!in_req_queue) m_download_queue.front().not_wanted = true; m_outstanding_bytes += r.length; } }