fixed piece picker problem when a downloading piece could not be picked with the right speed category

This commit is contained in:
Arvid Norberg 2007-09-10 08:07:18 +00:00
parent 0db64cba2c
commit 80aee32972
6 changed files with 30 additions and 9 deletions

View File

@ -303,7 +303,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info
void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const& peers)
{
using namespace libtorrent;
out << " down (total) up (total) que req flags source fail hshf sndb inactive wait disk block-progress "
out << " down (total) up (total) sent-req recv flags source fail hshf sndb inactive wait disk block-progress "
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
"country "
#endif
@ -321,7 +321,8 @@ void print_peer_info(std::ostream& out, std::vector<libtorrent::peer_info> const
<< "(" << add_suffix(i->total_download) << ") " << esc("0")
<< esc("31") << (i->up_speed > 0 ? add_suffix(i->up_speed) + "/s ": " ")
<< "(" << add_suffix(i->total_upload) << ") " << esc("0")
<< to_string(i->download_queue_length, 3) << " "
<< to_string(i->download_queue_length, 3) << " ("
<< to_string(i->target_dl_queue_length, 3) << ") "
<< to_string(i->upload_queue_length, 3) << " "
<< ((i->flags & peer_info::interesting)?'I':'.')
<< ((i->flags & peer_info::choked)?'C':'.')

View File

@ -155,8 +155,7 @@ namespace libtorrent
int prefer_whole_pieces() const
{
if (m_prefer_whole_pieces == 0)
return peer_info_struct() && peer_info_struct()->on_parole ? 1 : 0;
if (on_parole()) return 1;
return m_prefer_whole_pieces;
}

View File

@ -117,6 +117,11 @@ namespace libtorrent
// for yet
int download_queue_length;
// the number of requests that is
// tried to be maintained (this is
// typically a function of download speed)
int target_dl_queue_length;
// this is the number of requests
// the peer has sent to us
// that we haven't sent yet

View File

@ -2019,8 +2019,9 @@ namespace libtorrent
p.load_balancing = total_free_upload();
p.download_queue_length = (int)download_queue().size();
p.upload_queue_length = (int)upload_queue().size();
p.download_queue_length = int(download_queue().size() + m_request_queue.size());
p.target_dl_queue_length = int(desired_queue_size());
p.upload_queue_length = int(upload_queue().size());
if (boost::optional<piece_block_progress> ret = downloading_piece_progress())
{

View File

@ -1125,7 +1125,7 @@ namespace libtorrent
, interesting_blocks, backup_blocks, num_blocks
, prefer_whole_pieces, peer, speed, on_parole);
if (num_blocks == 0) return;
if (num_blocks <= 0) return;
if (rarest_first)
{
@ -1364,6 +1364,13 @@ namespace libtorrent
if (prefer_whole_pieces > 0 && !exclusive_active) continue;
// don't pick too many back-up blocks
if (i->state != none
&& i->state != speed
&& !exclusive_active
&& int(backup_blocks.size()) >= num_blocks)
continue;
for (int j = 0; j < num_blocks_in_piece; ++j)
{
// ignore completed blocks and already requested blocks
@ -1412,9 +1419,15 @@ namespace libtorrent
if (num_blocks <= 0) return 0;
if (on_parole) return num_blocks;
int to_copy;
if (prefer_whole_pieces == 0)
to_copy = (std::min)(int(backup_blocks.size()), num_blocks);
else
to_copy = int(backup_blocks.size());
interesting_blocks.insert(interesting_blocks.end()
, backup_blocks.begin(), backup_blocks.end());
num_blocks -= int(backup_blocks.size());
, backup_blocks.begin(), backup_blocks.begin() + to_copy);
num_blocks -= to_copy;
backup_blocks.clear();
if (num_blocks <= 0) return 0;

View File

@ -284,6 +284,8 @@ namespace libtorrent
for (std::vector<piece_block>::iterator i = interesting_pieces.begin();
i != interesting_pieces.end(); ++i)
{
if (prefer_whole_pieces == 0 && num_requests <= 0) break;
if (p.is_requested(*i))
{
if (num_requests <= 0) break;