diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 0b36de0c2..bff9363fb 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1143,9 +1143,9 @@ namespace libtorrent int diff = share_diff(); - enum { blockLimit=2 }; // how many blocks difference is considered unfair + enum { block_limit=2 }; // how many blocks difference is considered unfair - if (diff > blockLimit*m_torrent->block_size() || m_torrent->is_seed()) + if (diff > block_limit*m_torrent->block_size() || m_torrent->is_seed()) { // if we have downloaded more than one piece more // than we have uploaded OR if we are a seed @@ -1160,7 +1160,7 @@ namespace libtorrent // if we have uploaded too much, send with a rate of // 10 kB/s less than we receive int bias = 0; - if (diff > -blockLimit*m_torrent->block_size()) + if (diff > -block_limit*m_torrent->block_size()) { bias = static_cast(m_statistics.download_rate() * ratio) / 2; if (bias < 10*1024) bias = 10*1024; diff --git a/src/policy.cpp b/src/policy.cpp index f31daf530..35d1ce4ce 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -210,7 +210,7 @@ namespace // (and we should consider it free). If the share diff is // negative, there's no free download to get from this peer. int diff = i->second->share_diff(); - if (i->second->is_peer_interested() || diff <= 0) + if (i->second->is_peer_interested() || diff <= 0 || diff==std::numeric_limits::max()) continue; assert(diff > 0); @@ -233,10 +233,13 @@ 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) { - total_diff += i->second->share_diff(); - if (!i->second->is_peer_interested() || i->second->share_diff() >= 0) continue; + int diff=i->second->share_diff(); + if(diff==std::numeric_limits::max()) continue; + total_diff += diff; + if (!i->second->is_peer_interested() || diff >= 0) continue; ++num_peers; } @@ -305,6 +308,8 @@ namespace libtorrent // int diff = i->total_download() // - i->total_upload(); int diff = c->share_diff(); + if(diff==std::numeric_limits::max()) + diff=0; int weight = static_cast(c->statistics().download_rate() * 10.f) + diff @@ -450,6 +455,7 @@ namespace libtorrent if (c == 0) continue; int diff=c->share_diff(); + // no problem if diff returns std::numeric_limits::max() if (diff <= -free_upload_amount && !c->is_choked())