forked from premiere/premiere-libtorrent
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:
parent
2c1f24c036
commit
e0e06bc87a
|
@ -190,7 +190,6 @@ namespace libtorrent
|
||||||
struct bitfield;
|
struct bitfield;
|
||||||
class alert;
|
class alert;
|
||||||
struct torrent_plugin;
|
struct torrent_plugin;
|
||||||
struct torrent_peer;
|
|
||||||
struct add_torrent_params;
|
struct add_torrent_params;
|
||||||
|
|
||||||
// this is the base class for a session plugin. One primary feature
|
// this is the base class for a session plugin. One primary feature
|
||||||
|
@ -232,7 +231,7 @@ namespace libtorrent
|
||||||
// optimistically unchoked.
|
// optimistically unchoked.
|
||||||
// if the plugin returns true then the ordering provided will be
|
// if the plugin returns true then the ordering provided will be
|
||||||
// used and no other plugin will be allowed to change it.
|
// 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; }
|
{ return false; }
|
||||||
|
|
||||||
// called when saving settings state
|
// called when saving settings state
|
||||||
|
|
|
@ -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()
|
void session_impl::recalculate_optimistic_unchoke_slots()
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
if (m_stats_counters[counters::num_unchoke_slots] == 0) return;
|
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()
|
for (connection_map::iterator i = m_connections.begin()
|
||||||
, end(m_connections.end()); i != end; ++i)
|
, end(m_connections.end()); i != end; ++i)
|
||||||
|
@ -3660,7 +3672,7 @@ retry:
|
||||||
if (pi->optimistically_unchoked)
|
if (pi->optimistically_unchoked)
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(!p->is_choked());
|
TORRENT_ASSERT(!p->is_choked());
|
||||||
opt_unchoke.push_back(pi);
|
opt_unchoke.push_back(peer_connection_handle(*i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p->is_connecting()
|
if (!p->is_connecting()
|
||||||
|
@ -3671,7 +3683,7 @@ retry:
|
||||||
&& !p->ignore_unchoke_slots()
|
&& !p->ignore_unchoke_slots()
|
||||||
&& t->valid_metadata())
|
&& 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
|
// sort all candidates based on when they were last optimistically
|
||||||
// unchoked.
|
// unchoked.
|
||||||
std::sort(opt_unchoke.begin(), opt_unchoke.end()
|
std::sort(opt_unchoke.begin(), opt_unchoke.end(), last_optimistic_unchoke_cmp());
|
||||||
, boost::bind(&torrent_peer::last_optimistically_unchoked, _1)
|
|
||||||
< boost::bind(&torrent_peer::last_optimistically_unchoked, _2));
|
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
|
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
|
// unchoke the first num_opt_unchoke peers in the candidate set
|
||||||
// and make sure that the others are choked
|
// 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)
|
, 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)
|
if (num_opt_unchoke > 0)
|
||||||
{
|
{
|
||||||
--num_opt_unchoke;
|
--num_opt_unchoke;
|
||||||
|
|
Loading…
Reference in New Issue