diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 515813d9b..bb13a6bb4 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -215,6 +215,15 @@ namespace libtorrent return m_piece_map[index].index == piece_pos::we_have_index; } + bool is_downloading(int index) const + { + TORRENT_ASSERT(index >= 0); + TORRENT_ASSERT(index < int(m_piece_map.size())); + + piece_pos const& p = m_piece_map[index]; + return p.downloading; + } + // sets the priority of a piece. // returns true if the priority was changed from 0 to non-0 // or vice versa diff --git a/src/torrent.cpp b/src/torrent.cpp index b489591af..6722d236a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6485,7 +6485,12 @@ namespace libtorrent piece_block b = i->first; int count = i->second; int picker_count = m_picker->num_peers(b); - if (!m_picker->is_downloaded(b)) + // if we're no longer downloading the piece + // (for instance, it may be fully downloaded and waiting + // for the hash check to return), the piece picker always + // returns 0 requests, regardless of how many peers may still + // have the block in their queue + if (!m_picker->is_downloaded(b) && m_picker->is_downloading(b.piece_index)) TORRENT_ASSERT(picker_count == count); } TORRENT_ASSERT(num_have() >= m_picker->num_have_filtered());