fix issues introduced with connection ordering

This commit is contained in:
Arvid Norberg
2013-01-02 07:48:09 +00:00
parent 970ddba29b
commit 5afa8c88b9
3 changed files with 55 additions and 20 deletions

View File

@@ -4830,11 +4830,27 @@ retry:
return boost::weak_ptr<torrent>();
}
// returns true if lhs is a better disconnect candidate than rhs
bool compare_disconnect_torrent(session_impl::torrent_map::value_type const& lhs
, session_impl::torrent_map::value_type const& rhs)
{
// a torrent with 0 peers is never a good disconnect candidate
// since there's nothing to disconnect
if ((lhs.second->num_peers() == 0) != (lhs.second->num_peers() == 0))
return lhs.second->num_peers() != 0;
// other than that, always prefer to disconnect peers from seeding torrents
// in order to not harm downloading ones
if (lhs.second->is_seed() != rhs.second->is_seed())
return lhs.second->is_seed();
return lhs.second->num_peers() > rhs.second->num_peers();
}
boost::weak_ptr<torrent> session_impl::find_disconnect_candidate_torrent()
{
aux::session_impl::torrent_map::iterator i = std::max_element(m_torrents.begin(), m_torrents.end()
, boost::bind(&torrent::num_peers, boost::bind(&session_impl::torrent_map::value_type::second, _1))
< boost::bind(&torrent::num_peers, boost::bind(&session_impl::torrent_map::value_type::second, _2)));
aux::session_impl::torrent_map::iterator i = std::min_element(m_torrents.begin(), m_torrents.end()
, boost::bind(&compare_disconnect_torrent, _1, _2));
TORRENT_ASSERT(i != m_torrents.end());
if (i == m_torrents.end()) return boost::shared_ptr<torrent>();