diff --git a/examples/client_test.cpp b/examples/client_test.cpp index a01dded64..f03c618c1 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -219,8 +219,8 @@ int main(int argc, char* argv[]) std::vector handles; session ses(6881); - // limit global upload rate to 30 kB/s - ses.set_upload_rate_limit(30 * 1024); +// // limit global upload rate to 30 kB/s +// ses.set_upload_rate_limit(30 * 1024); ses.set_http_settings(settings); ses.set_severity_level(alert::debug); @@ -249,8 +249,8 @@ int main(int argc, char* argv[]) {} handles.push_back(ses.add_torrent(t, save_path, resume_data)); - handles.back().set_max_uploads(7); - handles.back().set_ratio(1); + handles.back().set_max_uploads(-1); + handles.back().set_ratio(1.02); } catch (std::exception& e) { @@ -357,8 +357,11 @@ int main(int argc, char* argv[]) << "(" << add_suffix(i->total_download) << ") " << "u: " << add_suffix(i->up_speed) << "/s " << "(" << add_suffix(i->total_upload) << ") " + << "ul:" << add_suffix(i->upload_limit) << "/s " +// << "uc:" << add_suffix(i->upload_ceiling) << "/s " // << "df: " << ratio(i->total_download, i->total_upload) << " " - << "q: " << i->download_queue_length << " " +// << "q: " << i->download_queue_length << " " + << "r: " << i->upload_queue_length << " " << "f: " << static_cast((i->flags & peer_info::interesting)?"I":"_") << static_cast((i->flags & peer_info::choked)?"C":"_") @@ -367,7 +370,7 @@ int main(int argc, char* argv[]) << static_cast((i->flags & peer_info::supports_extensions)?"e":"_") << static_cast((i->flags & peer_info::local_connection)?"l":"r") << "\n"; - +/* if (i->downloading_piece_index >= 0) { out << i->downloading_piece_index << ";" @@ -383,8 +386,9 @@ int main(int argc, char* argv[]) } out << "\n"; } +*/ } - +/* out << "___________________________________\n"; i->get_download_queue(queue); @@ -405,19 +409,20 @@ int main(int argc, char* argv[]) } out << "___________________________________\n"; - +*/ } - +/* for (std::deque::iterator i = events.begin(); i != events.end(); ++i) { out << *i << "\n"; } - +*/ clear(); set_cursor(0, 0); std::cout << out.str(); + std::cout.flush(); } } catch (std::exception& e) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 92cc3401d..8ba26be76 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -244,6 +244,8 @@ namespace libtorrent const std::deque& download_queue() const { return m_download_queue; } + const std::deque& upload_queue() const + { return m_requests; } // returns the block currently being // downloaded. And the progress of that diff --git a/include/libtorrent/peer_info.hpp b/include/libtorrent/peer_info.hpp index f380baf14..2ee91732d 100755 --- a/include/libtorrent/peer_info.hpp +++ b/include/libtorrent/peer_info.hpp @@ -69,6 +69,11 @@ namespace libtorrent // for yet int download_queue_length; + // this is the number of requests + // the peer has sent to us + // that we haven't sent yet + int upload_queue_length; + // the currently downloading piece // if piece index is -1 all associated // members are just set to 0 diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a6ae36f02..0b36de0c2 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1143,7 +1143,9 @@ namespace libtorrent int diff = share_diff(); - if (diff > 2*m_torrent->block_size() || m_torrent->is_seed()) + enum { blockLimit=2 }; // how many blocks difference is considered unfair + + if (diff > blockLimit*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 @@ -1158,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 > -2*m_torrent->block_size()) + if (diff > -blockLimit*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 845223b7f..f31daf530 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -302,8 +302,9 @@ namespace libtorrent if (!c->is_peer_interested()) return &(*i); - int diff = i->total_download() - - i->total_upload(); +// int diff = i->total_download() +// - i->total_upload(); + int diff = c->share_diff(); int weight = static_cast(c->statistics().download_rate() * 10.f) + diff @@ -448,18 +449,17 @@ namespace libtorrent peer_connection* c = i->connection; if (c == 0) continue; - int downloaded = i->total_download(); - int uploaded = i->total_upload(); + int diff=c->share_diff(); - if (downloaded - uploaded < -free_upload_amount + if (diff <= -free_upload_amount && !c->is_choked()) { // if we have uploaded more than a piece for free, choke peer and // wait until we catch up with our download. c->send_choke(); } - else if (downloaded - uploaded > -free_upload_amount - && c->is_choked() && c->is_peer_interested()) + else if (diff > -free_upload_amount + && c->is_choked() /* && c->is_peer_interested()*/) { // we have catched up. We have now shared the same amount // to eachother. Unchoke this peer. diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 4809bdd58..9012927a4 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -390,6 +390,7 @@ namespace libtorrent p.load_balancing = peer->total_free_upload(); p.download_queue_length = peer->download_queue().size(); + p.upload_queue_length = peer->upload_queue().size(); boost::optional ret = peer->downloading_piece(); if (ret)