switch to torrent_handle in plugin api

This commit is contained in:
Steven Siloti 2015-07-21 19:11:41 -07:00
parent a1b73317ce
commit fbc67b4e21
21 changed files with 46 additions and 35 deletions

View File

@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/storage_defs.hpp"
#include "libtorrent/peer_id.hpp" // sha1_hash
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/version.hpp"
namespace libtorrent
@ -331,7 +332,7 @@ namespace libtorrent
// 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
// created.
std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent*, void*)> >
std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle, void*)> >
extensions;
// the default tracker id to be used when announcing to trackers. By

View File

@ -193,7 +193,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(
torrent*, void*)> ext);
torrent_handle, void*)> ext);
void add_ses_extension(boost::shared_ptr<plugin> ext);
#endif
#if TORRENT_USE_ASSERTS

View File

@ -96,10 +96,9 @@ POSSIBILITY OF SUCH DAMAGE.
//
// The signature of the function is::
//
// boost::shared_ptr<torrent_plugin> (*)(torrent*, void*);
// boost::shared_ptr<torrent_plugin> (*)(torrent_handle, void*);
//
// The first argument is the internal torrent object, the second argument
// is the userdata passed to ``session::add_torrent()`` or
// The second argument is the userdata passed to ``session::add_torrent()`` or
// ``torrent_handle::add_extension()``.
//
// The function should return a ``boost::shared_ptr<torrent_plugin>`` which
@ -177,6 +176,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket.hpp"
#include "libtorrent/sha1_hash.hpp" // for sha1_hash
#include "libtorrent/error_code.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/peer_connection_handle.hpp"
namespace libtorrent
@ -191,7 +191,6 @@ namespace libtorrent
struct bitfield;
class alert;
struct torrent_plugin;
class torrent;
struct torrent_peer;
struct add_torrent_params;
@ -211,7 +210,7 @@ namespace libtorrent
// If the plugin returns a torrent_plugin instance, it will be added
// to the new torrent. Otherwise, return an empty shared_ptr to a
// torrent_plugin (the default).
virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent*, void*)
virtual boost::shared_ptr<torrent_plugin> new_torrent(torrent_handle, void*)
{ return boost::shared_ptr<torrent_plugin>(); }
// called when plugin is added to a session

View File

@ -35,10 +35,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/config.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -50,7 +52,7 @@ namespace libtorrent
// constructor function for the trackers exchange extension. This can
// either be passed in the add_torrent_params::extensions field, or
// 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, void*);
}
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/config.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
@ -58,7 +59,7 @@ namespace libtorrent
// via torrent_handle::add_extension().
TORRENT_DEPRECATED
TORRENT_EXPORT boost::shared_ptr<torrent_plugin>
create_metadata_plugin(torrent*, void*);
create_metadata_plugin(torrent_handle, void*);
#endif
}
#endif

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
@ -45,7 +47,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct torrent_plugin;
class torrent;
// constructor function for the smart ban extension. The extension keeps
// track of the data peers have sent us for failing pieces and once the
@ -53,7 +54,7 @@ namespace libtorrent
// out to have sent corrupt data.
// This function can either be passed in the add_torrent_params::extensions
// 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, void*);
}
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -35,10 +35,12 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/config.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include "libtorrent/config.hpp"
#include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -56,7 +58,7 @@ namespace libtorrent
//
// This can either be passed in the add_torrent_params::extensions field, or
// 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, void*);
}
#endif // TORRENT_DISABLE_EXTENSIONS

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_DISABLE_EXTENSIONS
#include "libtorrent/socket.hpp" // for endpoint
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
@ -49,7 +50,6 @@ namespace libtorrent
{
struct torrent_plugin;
struct peer_plugin;
class torrent;
// constructor function for the ut_pex extension. The ut_pex
// 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
// 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, void*);
bool was_introduced_by(peer_plugin const* pp, tcp::endpoint const& ep);
}

View File

@ -437,7 +437,7 @@ namespace libtorrent
#endif
// 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
// plugins, see `libtorrent plugins`_. For the typical bittorrent client
// all of these extensions should be added. The main plugins implemented
@ -482,7 +482,7 @@ namespace libtorrent
//
// .. _`libtorrent plugins`: libtorrent_plugins.html
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(
torrent*, void*)> ext);
torrent_handle, void*)> ext);
void add_extension(boost::shared_ptr<plugin> ext);
#ifndef TORRENT_NO_DEPRECATE

View File

@ -301,7 +301,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_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, void*)> const& ext
, void* userdata);
void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags);
#endif

View File

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

View File

@ -377,8 +377,9 @@ namespace libtorrent { namespace
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 th, void*)
{
torrent* t = th.native_handle().get();
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));
}

View File

@ -590,8 +590,9 @@ namespace libtorrent { namespace
namespace libtorrent
{
boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent* t, void*)
boost::shared_ptr<torrent_plugin> create_metadata_plugin(torrent_handle th, void*)
{
torrent* t = th.native_handle().get();
// don't add this extension if the torrent is private
if (t->valid_metadata() && t->torrent_file().priv()) return boost::shared_ptr<torrent_plugin>();
return boost::shared_ptr<torrent_plugin>(new metadata_plugin(*t));

View File

@ -414,7 +414,7 @@ namespace libtorrent
}
#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, void*)> ext)
{
#ifndef TORRENT_DISABLE_EXTENSIONS
TORRENT_ASYNC_CALL1(add_extension, ext);

View File

@ -867,13 +867,13 @@ namespace aux {
#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, void*)> ext_function_t;
struct session_plugin_wrapper : plugin
{
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 t, void* user)
{ return m_f(t, user); }
ext_function_t m_f;
};
@ -4433,7 +4433,7 @@ retry:
for (ses_extension_list_t::iterator i = m_ses_extensions.begin()
, 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);
}
}
@ -4623,13 +4623,13 @@ retry:
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::vector<boost::function<
boost::shared_ptr<torrent_plugin>(torrent*, void*)> >
boost::shared_ptr<torrent_plugin>(torrent_handle, void*)> >
torrent_plugins_t;
for (torrent_plugins_t::const_iterator i = params.extensions.begin()
, 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));
}

View File

@ -389,8 +389,9 @@ namespace
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 th, void*)
{
torrent* t = th.native_handle().get();
return boost::shared_ptr<torrent_plugin>(new smart_ban_plugin(*t));
}

View File

@ -1498,10 +1498,10 @@ namespace libtorrent
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, void*)> const& ext
, void* userdata)
{
boost::shared_ptr<torrent_plugin> tp(ext(this, userdata));
boost::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata));
if (!tp) return;
add_extension(tp);

View File

@ -296,7 +296,7 @@ namespace libtorrent
}
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, void*)> const& ext
, void* userdata)
{
#ifndef TORRENT_DISABLE_EXTENSIONS

View File

@ -655,8 +655,9 @@ namespace libtorrent { namespace
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 th, void*)
{
torrent* t = th.native_handle().get();
// don't add this extension if the torrent is private
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));

View File

@ -658,8 +658,9 @@ namespace libtorrent { namespace
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 th, void*)
{
torrent* t = th.native_handle().get();
if (t->torrent_file().priv() || (t->torrent_file().is_i2p()
&& !t->settings().get_bool(settings_pack::allow_i2p_mixed)))
{

View File

@ -69,7 +69,7 @@ enum flags_t
};
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, void*)
, int timeout)
{
using namespace libtorrent;