forked from premiere/premiere-libtorrent
refactor find_disconnect_candidate_torrent to match libtorrent_aio
This commit is contained in:
parent
c37420f82d
commit
970ddba29b
|
@ -283,6 +283,7 @@ namespace libtorrent
|
|||
|
||||
boost::weak_ptr<torrent> find_torrent(sha1_hash const& info_hash);
|
||||
boost::weak_ptr<torrent> find_torrent(std::string const& uuid);
|
||||
boost::weak_ptr<torrent> find_disconnect_candidate_torrent();
|
||||
|
||||
peer_id const& get_peer_id() const { return m_peer_id; }
|
||||
|
||||
|
|
|
@ -1079,20 +1079,26 @@ namespace libtorrent
|
|||
{
|
||||
// find a peer in some torrent (presumably the one with most peers)
|
||||
// and disconnect the lowest ranking peer
|
||||
aux::session_impl::torrent_map::iterator i = std::max_element(m_ses.m_torrents.begin(), m_ses.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)));
|
||||
boost::weak_ptr<torrent> torr = m_ses.find_disconnect_candidate_torrent();
|
||||
boost::shared_ptr<torrent> other_t = torr.lock();
|
||||
|
||||
TORRENT_ASSERT(i != m_ses.m_torrents.end());
|
||||
if (i->second->num_peers() <= t->num_peers())
|
||||
if (other_t)
|
||||
{
|
||||
if (other_t->num_peers() <= t->num_peers())
|
||||
{
|
||||
disconnect(errors::too_many_connections);
|
||||
return;
|
||||
}
|
||||
// find the lowest ranking peer and disconnect that
|
||||
peer_connection* p = other_t->find_lowest_ranking_peer();
|
||||
p->disconnect(errors::too_many_connections);
|
||||
peer_disconnected_other();
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(errors::too_many_connections);
|
||||
return;
|
||||
}
|
||||
// find the lowest ranking peer and disconnect that
|
||||
peer_connection* p = i->second->find_lowest_ranking_peer();
|
||||
p->disconnect(errors::too_many_connections);
|
||||
peer_disconnected_other();
|
||||
}
|
||||
|
||||
TORRENT_ASSERT(!m_torrent.expired());
|
||||
|
|
|
@ -4830,6 +4830,18 @@ retry:
|
|||
return boost::weak_ptr<torrent>();
|
||||
}
|
||||
|
||||
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)));
|
||||
|
||||
TORRENT_ASSERT(i != m_torrents.end());
|
||||
if (i == m_torrents.end()) return boost::shared_ptr<torrent>();
|
||||
|
||||
return i->second;
|
||||
}
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
boost::shared_ptr<logger> session_impl::create_log(std::string const& name
|
||||
, int instance, bool append)
|
||||
|
|
Loading…
Reference in New Issue