From 1c2b7471cb325c5eceab78ae814ce913ca30fd9e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 2 Jul 2012 03:27:32 +0000 Subject: [PATCH] fix one more issue with end-game mode when some pieces that are no longer selected for download have been downloaded --- include/libtorrent/piece_picker.hpp | 3 +++ src/policy.cpp | 9 +-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 7271ad708..515813d9b 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -341,6 +341,9 @@ namespace libtorrent int num_have() const { return m_num_have; } + // the number of pieces we want and don't have + int num_want_left() const { return num_pieces() - m_num_have - m_num_filtered; } + #ifdef TORRENT_DEBUG // used in debug mode void verify_priority(int start, int end, int prio) const; diff --git a/src/policy.cpp b/src/policy.cpp index e79c5295f..a9b822635 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -236,15 +236,8 @@ 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 - && num_have + p.num_downloading_pieces() < num_want) + && p.num_downloading_pieces() < p.num_want_left()) || dq.size() + rq.size() > 0; // this is filled with an interesting piece