From 142786d6ed21031ae6d0869940e2f318f75f5679 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 24 Jun 2012 20:57:31 +0000 Subject: [PATCH] fix end-game mode when filtering pieces (i.e. deselecting files for download) --- include/libtorrent/piece_picker.hpp | 2 ++ src/policy.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 877964e51..7271ad708 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -329,6 +329,8 @@ namespace libtorrent std::vector const& get_download_queue() const { return m_downloads; } + int num_downloading_pieces() const { return int(m_downloads.size()); } + void* get_downloader(piece_block block) const; // the number of filtered pieces we don't have diff --git a/src/policy.cpp b/src/policy.cpp index c0873422a..e79c5295f 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -236,9 +236,15 @@ namespace libtorrent // and we're not strictly speaking in end-game mode yet // also, if we already have at least one outstanding // request, we shouldn't pick any busy pieces either + + // the number of pieces we want (i.e. not including the filtered pieces) + int num_want = t.torrent_file().num_pieces() - p.num_filtered(); + // the number of pieces we already have (not counting pieces that are filtered + // that we might have still for some reason) + int num_have = p.num_have() - p.num_have_filtered(); + bool dont_pick_busy_blocks = (ses.m_settings.strict_end_game_mode - && p.num_have() + int(p.get_download_queue().size()) - < t.torrent_file().num_pieces()) + && num_have + p.num_downloading_pieces() < num_want) || dq.size() + rq.size() > 0; // this is filled with an interesting piece