From 7af8beff021dd51c6f5b67a2579f8a57e69d3495 Mon Sep 17 00:00:00 2001 From: Magnus Jonsson Date: Wed, 25 Feb 2004 13:18:41 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/policy.hpp | 3 +++ src/allocate_resources.cpp | 6 +++--- src/peer_connection.cpp | 11 +++++------ src/policy.cpp | 21 +++++++++++++-------- src/torrent_handle.cpp | 2 -- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 3bf55ddd8..5dab457ec 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -170,6 +170,9 @@ namespace libtorrent peer* find_unchoke_candidate(); + void connect_peer(peer *); + + bool connect_one_peer(); bool disconnect_one_peer(); peer* find_disconnect_candidate(); diff --git a/src/allocate_resources.cpp b/src/allocate_resources.cpp index 53259aef2..01123f319 100644 --- a/src/allocate_resources.cpp +++ b/src/allocate_resources.cpp @@ -208,7 +208,7 @@ namespace libtorrent int toGive = 1+std::min(max_give-1,r->used); resources_to_distribute-=give(r,toGive); } -#elif 1 +#elif 0 size_type total_used=0; size_type max_used=0; for(int i = 0;i < (int)requests.size();++i) @@ -288,13 +288,13 @@ namespace libtorrent kNumer=1; kDenom=max_used; } - +/* if(kNumer > kDenom) { kNumer=1; kDenom=1; } - +*/ for(int i = 0;i < (int)requests.size() && resources_to_distribute;++i) { resource_request *r=requests[i]; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 29200fb1c..ef1ce1f3c 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1232,7 +1232,7 @@ namespace libtorrent // client has sent us. This is the mean to // maintain the share ratio given by m_ratio // with all peers. - +/* if (m_torrent->is_seed() || is_choked() || m_torrent->ratio()==0.0f) { // if we have downloaded more than one piece more @@ -1241,19 +1241,19 @@ namespace libtorrent if(!m_send_buffer.empty() || (!m_requests.empty() && !is_choked())) upload_bandwidth.wanted = std::numeric_limits::max(); else - upload_bandwidth.wanted = 0; + upload_bandwidth.wanted = 1; } else { double bias = 0x20000 + m_free_upload; - double break_even_time = 10; + double break_even_time = 5; double have_uploaded = (double)m_statistics.total_payload_upload(); double have_downloaded = (double)m_statistics.total_payload_download(); double download_speed = m_statistics.download_rate(); double soon_downloaded = - have_downloaded+download_speed * 2 * break_even_time; + have_downloaded+download_speed * 1.5 * break_even_time; double upload_speed_limit = (soon_downloaded*m_torrent->ratio() - have_uploaded + bias) / break_even_time; @@ -1263,8 +1263,8 @@ namespace libtorrent upload_bandwidth.wanted = (int) upload_speed_limit; } +*/ -/* size_type diff = share_diff(); enum { block_limit = 2 }; // how many blocks difference is considered unfair @@ -1300,7 +1300,6 @@ namespace libtorrent // the maximum send_quota given our download rate from this peer if (upload_bandwidth.wanted < 256) upload_bandwidth.wanted = 256; } -*/ } // -------------------------- diff --git a/src/policy.cpp b/src/policy.cpp index 29126784d..d75409ee4 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -779,9 +779,7 @@ namespace libtorrent if(m_torrent->num_peers() < m_max_connections) { - i->connection = &m_torrent->connect_to_peer(remote); - i->connected = boost::posix_time::second_clock::local_time(); - m_last_optimistic_disconnect=boost::posix_time::second_clock::local_time(); + connect_peer(&*i); } return; } @@ -910,13 +908,20 @@ namespace libtorrent assert(!p->banned); assert(!p->connection); assert(p->type==peer::connectable); - + + connect_peer(p); + return true; + } + + void policy::connect_peer(peer *p) + { p->connection = &m_torrent->connect_to_peer(p->id); p->connection->add_stat(p->prev_amount_download, p->prev_amount_upload); p->prev_amount_download = 0; p->prev_amount_upload = 0; - p->connected = boost::posix_time::second_clock::local_time(); - return true; + p->connected = + m_last_optimistic_disconnect = + boost::posix_time::second_clock::local_time(); } bool policy::disconnect_one_peer() @@ -940,8 +945,6 @@ namespace libtorrent assert(i->connection == &c); i->connected = boost::posix_time::second_clock::local_time(); - i->prev_amount_download += c.statistics().total_payload_download(); - i->prev_amount_upload += c.statistics().total_payload_upload(); if (!i->connection->is_choked() && !m_torrent->is_aborted()) { --m_num_unchoked; @@ -956,6 +959,8 @@ namespace libtorrent assert(i->connection->share_diff() < std::numeric_limits::max()); m_available_free_upload += i->connection->share_diff(); } + i->prev_amount_download += c.statistics().total_payload_download(); + i->prev_amount_upload += c.statistics().total_payload_upload(); i->connection = 0; } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 29c528ee6..af1d3d754 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -454,8 +454,6 @@ namespace libtorrent p.id = peer->get_peer_id(); p.ip = peer->get_socket()->sender(); - // TODO: add the prev_amount_downloaded and prev_amount_uploaded - // from the peer list in the policy p.total_download = statistics.total_payload_download(); p.total_upload = statistics.total_payload_upload();