compare peer updates

This commit is contained in:
Arvid Norberg 2008-04-24 16:34:43 +00:00
parent 33ed6f4720
commit 854affdd92
1 changed files with 8 additions and 10 deletions

View File

@ -1330,26 +1330,24 @@ namespace libtorrent
, address const& external_ip) const , address const& external_ip) const
{ {
// prefer peers with lower failcount // prefer peers with lower failcount
if (lhs.failcount < rhs.failcount) return true; if (lhs.failcount != rhs.failcount)
if (lhs.failcount > rhs.failcount) return false; return lhs.failcount < rhs.failcount;
// Local peers should always be tried first // Local peers should always be tried first
bool lhs_local = is_local(lhs.ip.address()); bool lhs_local = is_local(lhs.ip.address());
bool rhs_local = is_local(rhs.ip.address()); bool rhs_local = is_local(rhs.ip.address());
if (lhs_local && !rhs_local) return true; if (lhs_local != rhs_local) return lhs_local > rhs_local;
if (!lhs_local && rhs_local) return false;
if (lhs.connected < rhs.connected) return true; if (lhs.connected != rhs.connected)
if (lhs.connected > rhs.connected) return false; return lhs.connected < rhs.connected;
#ifndef TORRENT_DISABLE_GEO_IP #ifndef TORRENT_DISABLE_GEO_IP
// don't bias fast peers when seeding // don't bias fast peers when seeding
if (!m_torrent->is_finished() && m_torrent->session().has_asnum_db()) if (!m_torrent->is_finished() && m_torrent->session().has_asnum_db())
{ {
std::pair<const int, int>* lhs_as = lhs.inet_as; int lhs_as = lhs.inet_as ? lhs.inet_as->second : 0;
std::pair<const int, int>* rhs_as = rhs.inet_as; int rhs_as = rhs.inet_as ? rhs.inet_as->second : 0;
if (lhs_as ? lhs_as->second : 0 > rhs_as ? rhs_as->second : 0) return true; if (lhs_as != rhs_as) return lhs_as > rhs_as;
if (lhs_as ? lhs_as->second : 0 < rhs_as ? rhs_as->second : 0) return false;
} }
#endif #endif
int lhs_distance = cidr_distance(external_ip, lhs.ip.address()); int lhs_distance = cidr_distance(external_ip, lhs.ip.address());