fixed unchoke bug. made the automatic unchoke strategy the default

This commit is contained in:
Arvid Norberg 2009-05-02 03:15:52 +00:00
parent e929c58e9f
commit 06b609aa1f
5 changed files with 29 additions and 7 deletions

View File

@ -1,3 +1,5 @@
* added support for fully automatic unchoker (no need to specify
number of upload slots). This is on by default
* added support for changing socket buffer sizes through * added support for changing socket buffer sizes through
session_settings session_settings
* added support for merkle hash tree torrents (.merkle.torrent) * added support for merkle hash tree torrents (.merkle.torrent)

View File

@ -121,7 +121,7 @@ namespace libtorrent
, upnp_ignore_nonrouters(false) , upnp_ignore_nonrouters(false)
, send_buffer_watermark(80 * 1024) , send_buffer_watermark(80 * 1024)
, auto_upload_slots(true) , auto_upload_slots(true)
, auto_upload_slots_rate_based(false) , auto_upload_slots_rate_based(true)
, use_parole_mode(true) , use_parole_mode(true)
, cache_size(1024) , cache_size(1024)
, cache_expiry(60) , cache_expiry(60)

View File

@ -354,6 +354,7 @@ namespace libtorrent
void peer_connection::reset_choke_counters() void peer_connection::reset_choke_counters()
{ {
m_downloaded_at_last_unchoke = m_statistics.total_payload_download(); m_downloaded_at_last_unchoke = m_statistics.total_payload_download();
m_uploaded_at_last_unchoke = m_statistics.total_payload_upload();
} }
void peer_connection::start() void peer_connection::start()
@ -2529,8 +2530,6 @@ namespace libtorrent
write_unchoke(); write_unchoke();
m_choked = false; m_choked = false;
m_uploaded_at_last_unchoke = m_statistics.total_payload_upload();
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " ==> UNCHOKE\n"; (*m_logger) << time_now_string() << " ==> UNCHOKE\n";
#endif #endif

View File

@ -1787,6 +1787,7 @@ namespace aux {
m_optimistic_unchoke_time_scaler = 0; m_optimistic_unchoke_time_scaler = 0;
} }
t->choke_peer(*p); t->choke_peer(*p);
continue;
} }
peers.push_back(p.get()); peers.push_back(p.get());
} }
@ -1800,6 +1801,21 @@ namespace aux {
std::sort(peers.begin(), peers.end() std::sort(peers.begin(), peers.end()
, bind(&peer_connection::upload_rate_compare, _1, _2)); , bind(&peer_connection::upload_rate_compare, _1, _2));
#ifdef TORRENT_DEBUG
for (std::vector<peer_connection*>::const_iterator i = peers.begin()
, end(peers.end()), prev(peers.end()); i != end; ++i)
{
if (prev != end)
{
TORRENT_ASSERT((*prev)->uploaded_since_unchoke() * 1000
/ total_milliseconds(unchoke_interval)
>= (*i)->uploaded_since_unchoke() * 1000
/ total_milliseconds(unchoke_interval));
}
prev = i;
}
#endif
// TODO: make configurable // TODO: make configurable
int rate_threshold = 1024; int rate_threshold = 1024;
@ -1809,7 +1825,9 @@ namespace aux {
peer_connection const& p = **i; peer_connection const& p = **i;
int rate = p.uploaded_since_unchoke() int rate = p.uploaded_since_unchoke()
* 1000 / total_milliseconds(unchoke_interval); * 1000 / total_milliseconds(unchoke_interval);
if (rate > rate_threshold) ++m_allowed_upload_slots;
if (rate < rate_threshold) break;
++m_allowed_upload_slots;
// TODO: make configurable // TODO: make configurable
rate_threshold += 1024; rate_threshold += 1024;
@ -1825,9 +1843,6 @@ namespace aux {
std::sort(peers.begin(), peers.end() std::sort(peers.begin(), peers.end()
, bind(&peer_connection::unchoke_compare, _1, _2)); , bind(&peer_connection::unchoke_compare, _1, _2));
std::for_each(m_connections.begin(), m_connections.end()
, bind(&peer_connection::reset_choke_counters, _1));
// auto unchoke // auto unchoke
int upload_limit = m_bandwidth_channel[peer_connection::upload_channel]->throttle(); int upload_limit = m_bandwidth_channel[peer_connection::upload_channel]->throttle();
if (!m_settings.auto_upload_slots_rate_based if (!m_settings.auto_upload_slots_rate_based
@ -1864,6 +1879,10 @@ namespace aux {
peer_connection* p = *i; peer_connection* p = *i;
TORRENT_ASSERT(p); TORRENT_ASSERT(p);
TORRENT_ASSERT(!p->ignore_unchoke_slots()); TORRENT_ASSERT(!p->ignore_unchoke_slots());
// this will update the m_uploaded_at_last_unchoke
p->reset_choke_counters();
torrent* t = p->associated_torrent().lock().get(); torrent* t = p->associated_torrent().lock().get();
TORRENT_ASSERT(t); TORRENT_ASSERT(t);
if (unchoke_set_size > 0) if (unchoke_set_size > 0)

View File

@ -38,6 +38,8 @@ void test_swarm()
session_settings settings; session_settings settings;
settings.allow_multiple_connections_per_ip = true; settings.allow_multiple_connections_per_ip = true;
settings.ignore_limits_on_local_network = false; settings.ignore_limits_on_local_network = false;
settings.auto_upload_slots = true;
settings.auto_upload_slots_rate_based = false;
ses1.set_settings(settings); ses1.set_settings(settings);
ses2.set_settings(settings); ses2.set_settings(settings);
ses3.set_settings(settings); ses3.set_settings(settings);