From 22da6b5901454a8ca33a3b0754c2c9dec8e939da Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 9 Jul 2008 17:45:37 +0000 Subject: [PATCH] fixed bug where FAST pieces were cancelled when choking --- ChangeLog | 1 + src/peer_connection.cpp | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d7487fa9..8e2610a5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * Fix bug where FAST pieces were cancelled on choke * Fixed problems with restoring piece states when hash failed. * Minimum peer reconnect time fix. Peers with no failures would reconnect immediately. diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 60335090e..80b6ed7d9 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2038,22 +2038,28 @@ namespace libtorrent m_num_invalid_requests = 0; // reject the requests we have in the queue - std::for_each(m_requests.begin(), m_requests.end() - , bind(&peer_connection::write_reject_request, this, _1)); + // except the allowed fast pieces + for (std::deque::iterator i = m_requests.begin(); + i != m_requests.end();) + { + if (m_accept_fast.count(i->piece)) + { + ++i; + continue; + } + + peer_request const& r = *i; + write_reject_request(r); #ifdef TORRENT_VERBOSE_LOGGING - for (std::deque::iterator i = m_requests.begin() - , end(m_requests.end()); i != end; ++i) - { - peer_request const& r = *i; (*m_logger) << time_now_string() << " ==> REJECT_PIECE [ " "piece: " << r.piece << " | " "s: " << r.start << " | " "l: " << r.length << " ]\n"; - } #endif - m_requests.clear(); + i = m_requests.erase(i); + } } void peer_connection::send_unchoke()