Merge pull request #49 from ssiloti/plugin-exported-api

Only use exported types in the plugin api
This commit is contained in:
Arvid Norberg 2015-07-25 15:53:22 -07:00
commit 742548b69c
21 changed files with 91 additions and 65 deletions

View File

@ -44,8 +44,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
class torrent_info; class torrent_info;
class torrent;
struct torrent_plugin; struct torrent_plugin;
struct torrent_handle;
// The add_torrent_params is a parameter pack for adding torrents to a // The add_torrent_params is a parameter pack for adding torrents to a
// session. The key fields when adding a torrent are: // session. The key fields when adding a torrent are:
@ -331,7 +331,7 @@ namespace libtorrent
// to avoid race conditions. For instance it may be important to have the // to avoid race conditions. For instance it may be important to have the
// plugin catch events that happen very early on after the torrent is // plugin catch events that happen very early on after the torrent is
// created. // created.
std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> > std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> >
extensions; extensions;
// the default tracker id to be used when announcing to trackers. By // the default tracker id to be used when announcing to trackers. By

View File

@ -62,7 +62,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/session.hpp" // for user_load_function_t #include "libtorrent/session.hpp" // for user_load_function_t
#include "libtorrent/ip_voter.hpp" #include "libtorrent/ip_voter.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/peer_id.hpp" #include "libtorrent/peer_id.hpp"
@ -111,6 +110,7 @@ namespace libtorrent
class torrent; class torrent;
class alert; class alert;
struct cache_info; struct cache_info;
struct torrent_handle;
namespace dht namespace dht
{ {
@ -193,7 +193,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>( void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(
torrent*, void*)> ext); torrent_handle const&, void*)> ext);
void add_ses_extension(boost::shared_ptr<plugin> ext); void add_ses_extension(boost::shared_ptr<plugin> ext);
#endif #endif
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS

View File

@ -96,10 +96,9 @@ POSSIBILITY OF SUCH DAMAGE.
// //
// The signature of the function is:: // The signature of the function is::
// //
// boost::shared_ptr<torrent_plugin> (*)(torrent*, void*); // boost::shared_ptr<torrent_plugin> (*)(torrent_handle const&, void*);
// //
// The first argument is the internal torrent object, the second argument // The second argument is the userdata passed to ``session::add_torrent()`` or
// is the userdata passed to ``session::add_torrent()`` or
// ``torrent_handle::add_extension()``. // ``torrent_handle::add_extension()``.
// //
// The function should return a ``boost::shared_ptr<torrent_plugin>`` which // The function should return a ``boost::shared_ptr<torrent_plugin>`` which
@ -177,12 +176,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/sha1_hash.hpp" // for sha1_hash #include "libtorrent/sha1_hash.hpp" // for sha1_hash
#include "libtorrent/error_code.hpp" #include "libtorrent/error_code.hpp"
#include "libtorrent/peer_connection_handle.hpp" #include "libtorrent/session_handle.hpp"
namespace libtorrent namespace libtorrent
{ {
namespace aux { struct session_impl; }
struct peer_plugin; struct peer_plugin;
struct peer_request; struct peer_request;
class entry; class entry;
@ -191,9 +188,9 @@ namespace libtorrent
struct bitfield; struct bitfield;
class alert; class alert;
struct torrent_plugin; struct torrent_plugin;
class torrent;
struct torrent_peer;
struct add_torrent_params; struct add_torrent_params;
struct peer_connection_handle;
struct torrent_handle;
// this is the base class for a session plugin. One primary feature // this is the base class for a session plugin. One primary feature
// is that it is notified of all torrents that are added to the session, // is that it is notified of all torrents that are added to the session,
@ -211,18 +208,18 @@ namespace libtorrent
// If the plugin returns a torrent_plugin instance, it will be added // If the plugin returns a torrent_plugin instance, it will be added
// to the new torrent. Otherwise, return an empty shared_ptr to a // to the new torrent. Otherwise, return an empty shared_ptr to a
// torrent_plugin (the default). // torrent_plugin (the default).
virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent*, void*) virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent_handle const&, void*)
{ return boost::shared_ptr<torrent_plugin>(); } { return boost::shared_ptr<torrent_plugin>(); }
// called when plugin is added to a session // called when plugin is added to a session
virtual void added(aux::session_impl*) {} virtual void added(session_handle) {}
// called when an alert is posted alerts that are filtered are not posted // called when an alert is posted alerts that are filtered are not posted
virtual void on_alert(alert const*) {} virtual void on_alert(alert const*) {}
// return true if the add_torrent_params should be added // return true if the add_torrent_params should be added
virtual bool on_unknown_torrent(sha1_hash const& /* info_hash */ virtual bool on_unknown_torrent(sha1_hash const& /* info_hash */
, peer_connection_handle /* pc */, add_torrent_params& /* p */) , peer_connection_handle const& /* pc */, add_torrent_params& /* p */)
{ return false; } { return false; }
// called once per second // called once per second
@ -234,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
@ -267,7 +264,7 @@ namespace libtorrent
// to it, use ``weak_ptr``. // to it, use ``weak_ptr``.
// //
// If this function throws an exception, the connection will be closed. // If this function throws an exception, the connection will be closed.
virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection_handle) virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection_handle const&)
{ return boost::shared_ptr<peer_plugin>(); } { return boost::shared_ptr<peer_plugin>(); }
// These hooks are called when a piece passes the hash check or fails the hash // These hooks are called when a piece passes the hash check or fails the hash

View File

@ -35,22 +35,23 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; struct torrent_handle;
// constructor function for the trackers exchange extension. This can // constructor function for the trackers exchange extension. This can
// either be passed in the add_torrent_params::extensions field, or // either be passed in the add_torrent_params::extensions field, or
// via torrent_handle::add_extension(). // via torrent_handle::add_extension().
boost::shared_ptr<torrent_plugin> TORRENT_EXPORT create_lt_trackers_plugin(torrent*, void*); boost::shared_ptr<torrent_plugin> TORRENT_EXPORT create_lt_trackers_plugin(torrent_handle const&, void*);
} }
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -48,7 +48,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; struct torrent_handle;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// constructor function for the metadata transfer extension. This // constructor function for the metadata transfer extension. This
@ -58,7 +58,7 @@ namespace libtorrent
// via torrent_handle::add_extension(). // via torrent_handle::add_extension().
TORRENT_DEPRECATED TORRENT_DEPRECATED
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> TORRENT_EXPORT boost::shared_ptr<torrent_plugin>
create_metadata_plugin(torrent*, void*); create_metadata_plugin(torrent_handle const&, void*);
#endif #endif
} }
#endif #endif

View File

@ -45,7 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; struct torrent_handle;
// constructor function for the smart ban extension. The extension keeps // constructor function for the smart ban extension. The extension keeps
// track of the data peers have sent us for failing pieces and once the // track of the data peers have sent us for failing pieces and once the
@ -53,7 +53,7 @@ namespace libtorrent
// out to have sent corrupt data. // out to have sent corrupt data.
// This function can either be passed in the add_torrent_params::extensions // This function can either be passed in the add_torrent_params::extensions
// field, or via torrent_handle::add_extension(). // field, or via torrent_handle::add_extension().
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_smart_ban_plugin(torrent*, void*); TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_smart_ban_plugin(torrent_handle const&, void*);
} }
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -35,17 +35,18 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
class torrent; struct torrent_handle;
// constructor function for the ut_metadata extension. The ut_metadata // constructor function for the ut_metadata extension. The ut_metadata
// extension allows peers to request the .torrent file (or more // extension allows peers to request the .torrent file (or more
@ -56,7 +57,7 @@ namespace libtorrent
// //
// This can either be passed in the add_torrent_params::extensions field, or // This can either be passed in the add_torrent_params::extensions field, or
// via torrent_handle::add_extension(). // via torrent_handle::add_extension().
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin(torrent*, void*); TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin(torrent_handle const&, void*);
} }
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -49,7 +49,7 @@ namespace libtorrent
{ {
struct torrent_plugin; struct torrent_plugin;
struct peer_plugin; struct peer_plugin;
class torrent; struct torrent_handle;
// constructor function for the ut_pex extension. The ut_pex // constructor function for the ut_pex extension. The ut_pex
// extension allows peers to gossip about their connections, allowing // extension allows peers to gossip about their connections, allowing
@ -59,7 +59,7 @@ namespace libtorrent
// //
// This can either be passed in the add_torrent_params::extensions field, or // This can either be passed in the add_torrent_params::extensions field, or
// via torrent_handle::add_extension(). // via torrent_handle::add_extension().
TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent*, void*); TORRENT_EXPORT boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent_handle const&, void*);
bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep); bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep);
} }

View File

@ -437,7 +437,7 @@ namespace libtorrent
#endif #endif
// This function adds an extension to this session. The argument is a // This function adds an extension to this session. The argument is a
// function object that is called with a ``torrent*`` and which should // function object that is called with a ``torrent_handle`` and which should
// return a ``boost::shared_ptr<torrent_plugin>``. To write custom // return a ``boost::shared_ptr<torrent_plugin>``. To write custom
// plugins, see `libtorrent plugins`_. For the typical bittorrent client // plugins, see `libtorrent plugins`_. For the typical bittorrent client
// all of these extensions should be added. The main plugins implemented // all of these extensions should be added. The main plugins implemented
@ -482,7 +482,7 @@ namespace libtorrent
// //
// .. _`libtorrent plugins`: libtorrent_plugins.html // .. _`libtorrent plugins`: libtorrent_plugins.html
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>( void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(
torrent*, void*)> ext); torrent_handle const&, void*)> ext);
void add_extension(boost::shared_ptr<plugin> ext); void add_extension(boost::shared_ptr<plugin> ext);
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE

View File

@ -301,7 +301,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::shared_ptr<torrent_plugin>); void add_extension(boost::shared_ptr<torrent_plugin>);
void remove_extension(boost::shared_ptr<torrent_plugin>); void remove_extension(boost::shared_ptr<torrent_plugin>);
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata); , void* userdata);
void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags); void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags);
#endif #endif

View File

@ -501,7 +501,7 @@ namespace libtorrent
// pointer. The function is expected to return a shared pointer to // pointer. The function is expected to return a shared pointer to
// a torrent_plugin instance. // a torrent_plugin instance.
void add_extension( void add_extension(
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata = 0); , void* userdata = 0);
// ``set_metadata`` expects the *info* section of metadata. i.e. The // ``set_metadata`` expects the *info* section of metadata. i.e. The

View File

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/bencode.hpp" #include "libtorrent/bencode.hpp"
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
@ -54,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
#include "libtorrent/io.hpp" #include "libtorrent/io.hpp"
#include "libtorrent/parse_url.hpp" #include "libtorrent/parse_url.hpp"
#include "libtorrent/torrent_handle.hpp"
namespace libtorrent { namespace namespace libtorrent { namespace
{ {
@ -79,7 +81,7 @@ namespace libtorrent { namespace
} }
virtual boost::shared_ptr<peer_plugin> new_connection( virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle pc); peer_connection_handle const& pc);
virtual void tick() virtual void tick()
{ {
@ -360,7 +362,7 @@ namespace libtorrent { namespace
}; };
boost::shared_ptr<peer_plugin> lt_tracker_plugin::new_connection( boost::shared_ptr<peer_plugin> lt_tracker_plugin::new_connection(
peer_connection_handle pc) peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>(); return boost::shared_ptr<peer_plugin>();
@ -377,8 +379,9 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> TORRENT_EXPORT create_lt_trackers_plugin(torrent* t, void*) boost::shared_ptr<torrent_plugin> TORRENT_EXPORT create_lt_trackers_plugin(torrent_handle const& th, void*)
{ {
torrent* t = th.native_handle().get();
if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>(); if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>();
return boost::shared_ptr<torrent_plugin>(new lt_tracker_plugin(*t)); return boost::shared_ptr<torrent_plugin>(new lt_tracker_plugin(*t));
} }

View File

@ -47,9 +47,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/bencode.hpp" #include "libtorrent/bencode.hpp"
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/extensions/metadata_transfer.hpp" #include "libtorrent/extensions/metadata_transfer.hpp"
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
@ -128,7 +130,7 @@ namespace libtorrent { namespace
} }
virtual boost::shared_ptr<peer_plugin> new_connection( virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle pc); peer_connection_handle const& pc);
buffer::const_interval metadata() const buffer::const_interval metadata() const
{ {
@ -543,7 +545,7 @@ namespace libtorrent { namespace
}; };
boost::shared_ptr<peer_plugin> metadata_plugin::new_connection( boost::shared_ptr<peer_plugin> metadata_plugin::new_connection(
peer_connection_handle pc) peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>(); return boost::shared_ptr<peer_plugin>();
@ -590,8 +592,9 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent* t, void*) boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent_handle const& th, void*)
{ {
torrent* t = th.native_handle().get();
// don't add this extension if the torrent is private // don't add this extension if the torrent is private
if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>(); if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>();
return boost::shared_ptr<torrent_plugin>(new metadata_plugin(*t)); return boost::shared_ptr<torrent_plugin>(new metadata_plugin(*t));

View File

@ -414,7 +414,7 @@ namespace libtorrent
} }
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE
void session_handle::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext) void session_handle::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> ext)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
TORRENT_ASYNC_CALL1(add_extension, ext); TORRENT_ASYNC_CALL1(add_extension, ext);

View File

@ -75,6 +75,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
#include "libtorrent/file.hpp" #include "libtorrent/file.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/ip_filter.hpp" #include "libtorrent/ip_filter.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
@ -95,6 +96,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/magnet_uri.hpp" #include "libtorrent/magnet_uri.hpp"
#include "libtorrent/aux_/session_settings.hpp" #include "libtorrent/aux_/session_settings.hpp"
#include "libtorrent/torrent_peer.hpp" #include "libtorrent/torrent_peer.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/choker.hpp" #include "libtorrent/choker.hpp"
#include "libtorrent/error.hpp" #include "libtorrent/error.hpp"
@ -867,13 +869,13 @@ namespace aux {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
typedef boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> ext_function_t; typedef boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> ext_function_t;
struct session_plugin_wrapper : plugin struct session_plugin_wrapper : plugin
{ {
session_plugin_wrapper(ext_function_t const& f) : m_f(f) {} session_plugin_wrapper(ext_function_t const& f) : m_f(f) {}
virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent* t, void* user) virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent_handle const& t, void* user)
{ return m_f(t, user); } { return m_f(t, user); }
ext_function_t m_f; ext_function_t m_f;
}; };
@ -895,7 +897,7 @@ namespace aux {
m_ses_extensions.push_back(ext); m_ses_extensions.push_back(ext);
m_alerts.add_extension(ext); m_alerts.add_extension(ext);
ext->added(this); ext->added(session_handle(this));
} }
#endif // TORRENT_DISABLE_EXTENSIONS #endif // TORRENT_DISABLE_EXTENSIONS
@ -3638,12 +3640,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 +3674,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 +3685,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 +3697,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 +3714,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;
@ -4433,7 +4445,7 @@ retry:
for (ses_extension_list_t::iterator i = m_ses_extensions.begin() for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, end(m_ses_extensions.end()); i != end; ++i) , end(m_ses_extensions.end()); i != end; ++i)
{ {
boost::shared_ptr<torrent_plugin> tp((*i)->new_torrent(torrent_ptr.get(), userdata)); boost::shared_ptr<torrent_plugin> tp((*i)->new_torrent(torrent_ptr->get_handle(), userdata));
if (tp) torrent_ptr->add_extension(tp); if (tp) torrent_ptr->add_extension(tp);
} }
} }
@ -4623,13 +4635,13 @@ retry:
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::vector<boost::function< typedef std::vector<boost::function<
boost::shared_ptr<torrent_plugin>(torrent*, void*)> > boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> >
torrent_plugins_t; torrent_plugins_t;
for (torrent_plugins_t::const_iterator i = params.extensions.begin() for (torrent_plugins_t::const_iterator i = params.extensions.begin()
, end(params.extensions.end()); i != end; ++i) , end(params.extensions.end()); i != end; ++i)
{ {
torrent_ptr->add_extension((*i)(torrent_ptr.get(), torrent_ptr->add_extension((*i)(torrent_ptr->get_handle(),
params.userdata)); params.userdata));
} }

View File

@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/extensions/smart_ban.hpp" #include "libtorrent/extensions/smart_ban.hpp"
#include "libtorrent/disk_io_thread.hpp" #include "libtorrent/disk_io_thread.hpp"
@ -389,8 +390,9 @@ namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_smart_ban_plugin(torrent* t, void*) boost::shared_ptr<torrent_plugin> create_smart_ban_plugin(torrent_handle const& th, void*)
{ {
torrent* t = th.native_handle().get();
return boost::shared_ptr<torrent_plugin>(new smart_ban_plugin(*t)); return boost::shared_ptr<torrent_plugin>(new smart_ban_plugin(*t));
} }

View File

@ -70,6 +70,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/web_peer_connection.hpp" #include "libtorrent/web_peer_connection.hpp"
#include "libtorrent/http_seed_connection.hpp" #include "libtorrent/http_seed_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/peer_id.hpp" #include "libtorrent/peer_id.hpp"
#include "libtorrent/identify_client.hpp" #include "libtorrent/identify_client.hpp"
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
@ -1497,10 +1498,10 @@ namespace libtorrent
m_extensions.erase(i); m_extensions.erase(i);
} }
void torrent::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext void torrent::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata) , void* userdata)
{ {
boost::shared_ptr<torrent_plugin> tp(ext(this, userdata)); boost::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata));
if (!tp) return; if (!tp) return;
add_extension(tp); add_extension(tp);

View File

@ -296,7 +296,7 @@ namespace libtorrent
} }
void torrent_handle::add_extension( void torrent_handle::add_extension(
boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> const& ext boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata) , void* userdata)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS

View File

@ -46,9 +46,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/bencode.hpp" #include "libtorrent/bencode.hpp"
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/extensions/ut_metadata.hpp" #include "libtorrent/extensions/ut_metadata.hpp"
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
@ -124,7 +126,7 @@ namespace libtorrent { namespace
} }
virtual boost::shared_ptr<peer_plugin> new_connection( virtual boost::shared_ptr<peer_plugin> new_connection(
peer_connection_handle pc); peer_connection_handle const& pc);
int get_metadata_size() const int get_metadata_size() const
{ {
@ -500,7 +502,7 @@ namespace libtorrent { namespace
}; };
boost::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection( boost::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection(
peer_connection_handle pc) peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>(); return boost::shared_ptr<peer_plugin>();
@ -655,8 +657,9 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin(torrent* t, void*) boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin(torrent_handle const& th, void*)
{ {
torrent* t = th.native_handle().get();
// don't add this extension if the torrent is private // don't add this extension if the torrent is private
if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>(); if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>();
return boost::shared_ptr<torrent_plugin>(new ut_metadata_plugin(*t)); return boost::shared_ptr<torrent_plugin>(new ut_metadata_plugin(*t));

View File

@ -33,8 +33,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
#include "libtorrent/peer_connection_handle.hpp"
#include "libtorrent/bencode.hpp" #include "libtorrent/bencode.hpp"
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/broadcast_socket.hpp" #include "libtorrent/broadcast_socket.hpp"
#include "libtorrent/socket_io.hpp" #include "libtorrent/socket_io.hpp"
@ -90,7 +92,7 @@ namespace libtorrent { namespace
, m_last_msg(min_time()) , m_last_msg(min_time())
, m_peers_in_message(0) {} , m_peers_in_message(0) {}
virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection_handle pc); virtual boost::shared_ptr<peer_plugin> new_connection(peer_connection_handle const& pc);
std::vector<char>& get_ut_pex_msg() std::vector<char>& get_ut_pex_msg()
{ {
@ -646,7 +648,7 @@ namespace libtorrent { namespace
bool m_first_time; bool m_first_time;
}; };
boost::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection_handle pc) boost::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>(); return boost::shared_ptr<peer_plugin>();
@ -658,8 +660,9 @@ namespace libtorrent { namespace
namespace libtorrent namespace libtorrent
{ {
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent* t, void*) boost::shared_ptr<torrent_plugin> create_ut_pex_plugin(torrent_handle const& th, void*)
{ {
torrent* t = th.native_handle().get();
if (t->torrent_file().priv() || (t->torrent_file().is_i2p() if (t->torrent_file().priv() || (t->torrent_file().is_i2p()
&& !t->settings().get_bool(settings_pack::allow_i2p_mixed))) && !t->settings().get_bool(settings_pack::allow_i2p_mixed)))
{ {

View File

@ -69,7 +69,7 @@ enum flags_t
}; };
void test_transfer(int flags void test_transfer(int flags
, boost::shared_ptr<libtorrent::torrent_plugin> (*constructor)(libtorrent::torrent*, void*) , boost::shared_ptr<libtorrent::torrent_plugin> (*constructor)(libtorrent::torrent_handle const&, void*)
, int timeout) , int timeout)
{ {
using namespace libtorrent; using namespace libtorrent;