fix bug in disconnect candidate torrent function

This commit is contained in:
Arvid Norberg
2013-01-02 08:09:21 +00:00
parent 5afa8c88b9
commit cd4b38cfc3
2 changed files with 11 additions and 11 deletions

View File

@@ -281,9 +281,9 @@ namespace libtorrent
void remove_feed(feed_handle h); void remove_feed(feed_handle h);
void get_feeds(std::vector<feed_handle>* f) const; void get_feeds(std::vector<feed_handle>* f) const;
boost::weak_ptr<torrent> find_torrent(sha1_hash const& info_hash); boost::weak_ptr<torrent> find_torrent(sha1_hash const& info_hash) const;
boost::weak_ptr<torrent> find_torrent(std::string const& uuid); boost::weak_ptr<torrent> find_torrent(std::string const& uuid) const;
boost::weak_ptr<torrent> find_disconnect_candidate_torrent(); boost::weak_ptr<torrent> find_disconnect_candidate_torrent() const;
peer_id const& get_peer_id() const { return m_peer_id; } peer_id const& get_peer_id() const { return m_peer_id; }

View File

@@ -4803,13 +4803,13 @@ retry:
// the return value from this function is valid only as long as the // the return value from this function is valid only as long as the
// session is locked! // session is locked!
boost::weak_ptr<torrent> session_impl::find_torrent(sha1_hash const& info_hash) boost::weak_ptr<torrent> session_impl::find_torrent(sha1_hash const& info_hash) const
{ {
TORRENT_ASSERT(is_network_thread()); TORRENT_ASSERT(is_network_thread());
torrent_map::iterator i = m_torrents.find(info_hash); torrent_map::const_iterator i = m_torrents.find(info_hash);
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
for (torrent_map::iterator j for (torrent_map::const_iterator j
= m_torrents.begin(); j != m_torrents.end(); ++j) = m_torrents.begin(); j != m_torrents.end(); ++j)
{ {
torrent* p = boost::get_pointer(j->second); torrent* p = boost::get_pointer(j->second);
@@ -4820,11 +4820,11 @@ retry:
return boost::weak_ptr<torrent>(); return boost::weak_ptr<torrent>();
} }
boost::weak_ptr<torrent> session_impl::find_torrent(std::string const& uuid) boost::weak_ptr<torrent> session_impl::find_torrent(std::string const& uuid) const
{ {
TORRENT_ASSERT(is_network_thread()); TORRENT_ASSERT(is_network_thread());
std::map<std::string, boost::shared_ptr<torrent> >::iterator i std::map<std::string, boost::shared_ptr<torrent> >::const_iterator i
= m_uuids.find(uuid); = m_uuids.find(uuid);
if (i != m_uuids.end()) return i->second; if (i != m_uuids.end()) return i->second;
return boost::weak_ptr<torrent>(); return boost::weak_ptr<torrent>();
@@ -4836,7 +4836,7 @@ retry:
{ {
// a torrent with 0 peers is never a good disconnect candidate // a torrent with 0 peers is never a good disconnect candidate
// since there's nothing to disconnect // since there's nothing to disconnect
if ((lhs.second->num_peers() == 0) != (lhs.second->num_peers() == 0)) if ((lhs.second->num_peers() == 0) != (rhs.second->num_peers() == 0))
return lhs.second->num_peers() != 0; return lhs.second->num_peers() != 0;
// other than that, always prefer to disconnect peers from seeding torrents // other than that, always prefer to disconnect peers from seeding torrents
@@ -4847,9 +4847,9 @@ retry:
return lhs.second->num_peers() > rhs.second->num_peers(); return lhs.second->num_peers() > rhs.second->num_peers();
} }
boost::weak_ptr<torrent> session_impl::find_disconnect_candidate_torrent() boost::weak_ptr<torrent> session_impl::find_disconnect_candidate_torrent() const
{ {
aux::session_impl::torrent_map::iterator i = std::min_element(m_torrents.begin(), m_torrents.end() aux::session_impl::torrent_map::const_iterator i = std::min_element(m_torrents.begin(), m_torrents.end()
, boost::bind(&compare_disconnect_torrent, _1, _2)); , boost::bind(&compare_disconnect_torrent, _1, _2));
TORRENT_ASSERT(i != m_torrents.end()); TORRENT_ASSERT(i != m_torrents.end());