switch to peer_connection_handle for optimistic unchoking

This is necessary to enable external plugins since the vector is passed to
plugins via on_optimistic_unchoke.
This commit is contained in:
Steven Siloti 2015-07-23 20:48:35 -07:00
parent 2c1f24c036
commit e0e06bc87a
2 changed files with 19 additions and 10 deletions

View File

@ -190,7 +190,6 @@ namespace libtorrent
struct bitfield;
class alert;
struct torrent_plugin;
struct torrent_peer;
struct add_torrent_params;
// this is the base class for a session plugin. One primary feature
@ -232,7 +231,7 @@ namespace libtorrent
// optimistically unchoked.
// if the plugin returns true then the ordering provided will be
// used and no other plugin will be allowed to change it.
virtual bool on_optimistic_unchoke(std::vector<torrent_peer*>& /* peers */)
virtual bool on_optimistic_unchoke(std::vector<peer_connection_handle>& /* peers */)
{ return false; }
// called when saving settings state

View File

@ -3638,12 +3638,24 @@ retry:
}
}
namespace {
struct last_optimistic_unchoke_cmp
{
bool operator()(peer_connection_handle const& l
, peer_connection_handle const& r)
{
return l.native_handle()->peer_info_struct()->last_optimistically_unchoked
< r.native_handle()->peer_info_struct()->last_optimistically_unchoked;
}
};
}
void session_impl::recalculate_optimistic_unchoke_slots()
{
TORRENT_ASSERT(is_single_thread());
if (m_stats_counters[counters::num_unchoke_slots] == 0) return;
std::vector<torrent_peer*> opt_unchoke;
std::vector<peer_connection_handle> opt_unchoke;
for (connection_map::iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
@ -3660,7 +3672,7 @@ retry:
if (pi->optimistically_unchoked)
{
TORRENT_ASSERT(!p->is_choked());
opt_unchoke.push_back(pi);
opt_unchoke.push_back(peer_connection_handle(*i));
}
if (!p->is_connecting()
@ -3671,7 +3683,7 @@ retry:
&& !p->ignore_unchoke_slots()
&& t->valid_metadata())
{
opt_unchoke.push_back(pi);
opt_unchoke.push_back(peer_connection_handle(*i));
}
}
@ -3683,9 +3695,7 @@ retry:
// sort all candidates based on when they were last optimistically
// unchoked.
std::sort(opt_unchoke.begin(), opt_unchoke.end()
, boost::bind(&torrent_peer::last_optimistically_unchoked, _1)
< boost::bind(&torrent_peer::last_optimistically_unchoked, _2));
std::sort(opt_unchoke.begin(), opt_unchoke.end(), last_optimistic_unchoke_cmp());
#ifndef TORRENT_DISABLE_EXTENSIONS
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
@ -3702,10 +3712,10 @@ retry:
// unchoke the first num_opt_unchoke peers in the candidate set
// and make sure that the others are choked
for (std::vector<torrent_peer*>::iterator i = opt_unchoke.begin()
for (std::vector<peer_connection_handle>::iterator i = opt_unchoke.begin()
, end(opt_unchoke.end()); i != end; ++i)
{
torrent_peer* pi = *i;
torrent_peer* pi = i->native_handle()->peer_info_struct();
if (num_opt_unchoke > 0)
{
--num_opt_unchoke;