polish peer-ranking feature

This commit is contained in:
Arvid Norberg 2013-01-28 02:13:25 +00:00
parent bca1d62bbe
commit 5b3a075387
1 changed files with 8 additions and 4 deletions

View File

@ -1502,10 +1502,14 @@ namespace libtorrent
peer_connection* torrent::find_lowest_ranking_peer() const peer_connection* torrent::find_lowest_ranking_peer() const
{ {
// TODO: 3 filter out peers that are disconnecting const_peer_iterator lowest_rank = end();
const_peer_iterator lowest_rank = std::min_element(begin(), end() for (const_peer_iterator i = begin(); i != end(); ++i)
, boost::bind(&peer_connection::peer_rank, _1) {
< boost::bind(&peer_connection::peer_rank, _2)); // disconnecting peers don't count
if ((*i)->is_disconnecting()) continue;
if (lowest_rank == end() || (*lowest_rank)->peer_rank() > (*i)->peer_rank())
lowest_rank = i;
}
if (lowest_rank == end()) return NULL; if (lowest_rank == end()) return NULL;
return *lowest_rank; return *lowest_rank;