From 9a5c7faf696fad6b66699a78c22a42bbd3f2fc15 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 15 Dec 2003 03:14:01 +0000 Subject: [PATCH] *** empty log message *** --- src/policy.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/policy.cpp b/src/policy.cpp index 24c0fce95..f6283d33d 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -210,18 +210,29 @@ namespace { if (free_upload == 0) return free_upload; int num_peers = 0; + int total_diff = 0; for (torrent::peer_iterator i = start; i != end; ++i) { - if ((*i)->is_interesting() || !(*i)->is_peer_interested()) continue; + total_diff += (*i)->share_diff(); + if (!(*i)->is_peer_interested() || (*i)->share_diff() >= 0) continue; ++num_peers; } if (num_peers == 0) return free_upload; - int upload_share = free_upload / num_peers; + int upload_share; + if (total_diff >= 0) + { + upload_share = std::min(free_upload, total_diff) / num_peers; + } + else + { + upload_share = (free_upload + total_diff) / num_peers; + } + if (upload_share < 0) return free_upload; for (torrent::peer_iterator i = start; i != end; ++i) { - if ((*i)->is_interesting() || !(*i)->is_peer_interested()) continue; + if (!(*i)->is_peer_interested() || (*i)->share_diff() >= 0) continue; (*i)->add_free_upload(upload_share); free_upload -= upload_share; }