introduced failcount and retry time settings for peers

This commit is contained in:
Arvid Norberg 2007-04-14 21:47:07 +00:00
parent f16e419abd
commit fceaa8f79e
2 changed files with 24 additions and 12 deletions

View File

@ -58,6 +58,8 @@ namespace libtorrent
, urlseed_pipeline_size(5) , urlseed_pipeline_size(5)
, file_pool_size(40) , file_pool_size(40)
, allow_multiple_connections_per_ip(false) , allow_multiple_connections_per_ip(false)
, max_failcount(3)
, min_reconnect_time(60)
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
, use_dht_as_fallback(true) , use_dht_as_fallback(true)
#endif #endif
@ -154,6 +156,14 @@ namespace libtorrent
// IP address. true will allow it. // IP address. true will allow it.
bool allow_multiple_connections_per_ip; bool allow_multiple_connections_per_ip;
// the number of times we can fail to connect to a peer
// before we stop retrying it.
int max_failcount;
// the number of seconds to wait to reconnect to a peer.
// this time is multiplied with the failcount.
int min_reconnect_time;
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
// while this is true, the dht will note be used unless the // while this is true, the dht will note be used unless the
// tracker is online // tracker is online

View File

@ -514,8 +514,8 @@ namespace libtorrent
ptime ptime(now); ptime ptime(now);
iterator candidate = m_peers.end(); iterator candidate = m_peers.end();
// TODO: take failcount into account int max_failcount = m_torrent->settings().max_failcount;
// TODO: have a minimum time before retrying int min_reconnect_time = m_torrent->settings().min_reconnect_time;
for (iterator i = m_peers.begin(); for (iterator i = m_peers.begin();
i != m_peers.end(); ++i) i != m_peers.end(); ++i)
@ -524,6 +524,9 @@ namespace libtorrent
if (i->banned) continue; if (i->banned) continue;
if (i->type == peer::not_connectable) continue; if (i->type == peer::not_connectable) continue;
if (i->seed && m_torrent->is_seed()) continue; if (i->seed && m_torrent->is_seed()) continue;
if (i->failcount >= max_failcount) continue;
if (now - i->connected < seconds(i->failcount * min_reconnect_time))
continue;
assert(i->connected <= now); assert(i->connected <= now);
@ -1006,6 +1009,13 @@ namespace libtorrent
i->ip = remote; i->ip = remote;
i->source |= src; i->source |= src;
// if this peer has failed before, decrease the
// counter to allow it another try, since somebody
// else is appearantly able to connect to it
// if it comes from the DHT it might be stale though
if (i->failcount > 0 && src != peer_info::dht)
--i->failcount;
if (flags & 0x02) i->seed = true; if (flags & 0x02) i->seed = true;
if (i->connection) if (i->connection)
@ -1214,9 +1224,6 @@ namespace libtorrent
catch (std::exception& e) catch (std::exception& e)
{ {
++p->failcount; ++p->failcount;
// TODO: make this costumizable
if (p->failcount > 3)
m_peers.erase(p);
} }
return false; return false;
} }
@ -1241,7 +1248,6 @@ namespace libtorrent
// assert(c.is_disconnecting()); // assert(c.is_disconnecting());
bool unchoked = false; bool unchoked = false;
bool erase = false;
iterator i = std::find_if( iterator i = std::find_if(
m_peers.begin() m_peers.begin()
@ -1261,8 +1267,7 @@ namespace libtorrent
if (c.failed()) if (c.failed())
{ {
// TODO: make 3 customizable ++i->failcount;
if (++i->failcount > 3) erase = true;
i->connected = time_now(); i->connected = time_now();
} }
@ -1278,9 +1283,6 @@ namespace libtorrent
i->prev_amount_download += c.statistics().total_payload_download(); i->prev_amount_download += c.statistics().total_payload_download();
i->prev_amount_upload += c.statistics().total_payload_upload(); i->prev_amount_upload += c.statistics().total_payload_upload();
if (erase)
m_peers.erase(i);
if (unchoked) if (unchoked)
{ {
// if the peer that is diconnecting is unchoked // if the peer that is diconnecting is unchoked