forked from premiere/premiere-libtorrent
introduced failcounter for peers, increased timeout for peer info (such as being banned). Peers that fails 4 times are removed from the peer-list
This commit is contained in:
parent
e8eb1ca96c
commit
f2778d52d1
|
@ -148,6 +148,9 @@ namespace libtorrent
|
||||||
tcp::endpoint ip;
|
tcp::endpoint ip;
|
||||||
connection_type type;
|
connection_type type;
|
||||||
|
|
||||||
|
// the number of failed connection attempts this peer has
|
||||||
|
int failcount;
|
||||||
|
|
||||||
// this is true if the peer is a seed
|
// this is true if the peer is a seed
|
||||||
bool seed;
|
bool seed;
|
||||||
|
|
||||||
|
@ -226,7 +229,7 @@ namespace libtorrent
|
||||||
// this timeout has to be customizable!
|
// this timeout has to be customizable!
|
||||||
return p.connection == 0
|
return p.connection == 0
|
||||||
&& p.connected != not_tried_yet
|
&& p.connected != not_tried_yet
|
||||||
&& second_clock::universal_time() - p.connected > minutes(30);
|
&& second_clock::universal_time() - p.connected > minutes(120);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -505,9 +505,9 @@ namespace libtorrent
|
||||||
|
|
||||||
policy::peer *policy::find_connect_candidate()
|
policy::peer *policy::find_connect_candidate()
|
||||||
{
|
{
|
||||||
boost::posix_time::ptime local_time=second_clock::universal_time();
|
boost::posix_time::ptime local_time = second_clock::universal_time();
|
||||||
boost::posix_time::ptime ptime(local_time);
|
boost::posix_time::ptime ptime(local_time);
|
||||||
policy::peer* candidate =0;
|
policy::peer* candidate = 0;
|
||||||
|
|
||||||
for (std::vector<peer>::iterator i = m_peers.begin();
|
for (std::vector<peer>::iterator i = m_peers.begin();
|
||||||
i != m_peers.end(); ++i)
|
i != m_peers.end(); ++i)
|
||||||
|
@ -683,7 +683,8 @@ namespace libtorrent
|
||||||
// every minute, disconnect the worst peer in hope of finding a better peer
|
// every minute, disconnect the worst peer in hope of finding a better peer
|
||||||
|
|
||||||
boost::posix_time::ptime local_time = second_clock::universal_time();
|
boost::posix_time::ptime local_time = second_clock::universal_time();
|
||||||
if (m_last_optimistic_disconnect + boost::posix_time::seconds(120) <= local_time)
|
if (m_last_optimistic_disconnect + boost::posix_time::seconds(120) <= local_time
|
||||||
|
&& find_connect_candidate())
|
||||||
{
|
{
|
||||||
m_last_optimistic_disconnect = local_time;
|
m_last_optimistic_disconnect = local_time;
|
||||||
--max_connections; // this will have the effect of disconnecting the worst peer
|
--max_connections; // this will have the effect of disconnecting the worst peer
|
||||||
|
@ -1275,6 +1276,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// assert(c.is_disconnecting());
|
// assert(c.is_disconnecting());
|
||||||
bool unchoked = false;
|
bool unchoked = false;
|
||||||
|
bool erase = false;
|
||||||
|
|
||||||
std::vector<peer>::iterator i = std::find_if(
|
std::vector<peer>::iterator i = std::find_if(
|
||||||
m_peers.begin()
|
m_peers.begin()
|
||||||
|
@ -1293,8 +1295,8 @@ namespace libtorrent
|
||||||
|
|
||||||
if (c.failed())
|
if (c.failed())
|
||||||
{
|
{
|
||||||
i->type = peer::not_connectable;
|
if (++i->failcount > 3) erase = true;
|
||||||
i->ip.port(0);
|
i->connected = second_clock::universal_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the share ratio is 0 (infinite), the
|
// if the share ratio is 0 (infinite), the
|
||||||
|
@ -1310,6 +1312,9 @@ namespace libtorrent
|
||||||
i->prev_amount_upload += c.statistics().total_payload_upload();
|
i->prev_amount_upload += c.statistics().total_payload_upload();
|
||||||
i->connection = 0;
|
i->connection = 0;
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -1405,9 +1410,10 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
policy::peer::peer(const tcp::endpoint& ip_, peer::connection_type t)
|
policy::peer::peer(const tcp::endpoint& ip_, peer::connection_type t)
|
||||||
: seed(false)
|
: ip(ip_)
|
||||||
, ip(ip_)
|
|
||||||
, type(t)
|
, type(t)
|
||||||
|
, failcount(0)
|
||||||
|
, seed(false)
|
||||||
, last_optimistically_unchoked(
|
, last_optimistically_unchoked(
|
||||||
boost::gregorian::date(1970,boost::gregorian::Jan,1))
|
boost::gregorian::date(1970,boost::gregorian::Jan,1))
|
||||||
, connected(boost::gregorian::date(1970,boost::gregorian::Jan,1))
|
, connected(boost::gregorian::date(1970,boost::gregorian::Jan,1))
|
||||||
|
|
Loading…
Reference in New Issue