1
// Copyright Daniel Wallin, Arvid Norberg 2007. Use, modification and distribution is
2
// subject to the Boost Software License, Version 1.0. (See accompanying
3
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
#include <libtorrent/extensions.hpp>
6
#include <libtorrent/entry.hpp>
7
#include <libtorrent/peer_request.hpp>
8
#include <libtorrent/peer_connection.hpp>
9
#include <libtorrent/extensions/ut_pex.hpp>
10
#include <libtorrent/extensions/metadata_transfer.hpp>
11
#include <libtorrent/extensions/ut_metadata.hpp>
12
#include <libtorrent/extensions/smart_ban.hpp>
13
#include <boost/python.hpp>
16
using namespace boost::python;
17
using namespace libtorrent;
22
struct torrent_plugin_wrap : torrent_plugin, wrapper<torrent_plugin>
24
boost::shared_ptr<peer_plugin> new_connection(peer_connection* p)
28
if (override f = this->get_override("new_connection"))
30
return torrent_plugin::new_connection(p);
33
boost::shared_ptr<peer_plugin> default_new_connection(peer_connection* p)
35
return this->torrent_plugin::new_connection(p);
38
void on_piece_pass(int index)
42
if (override f = this->get_override("on_piece_pass"))
45
torrent_plugin::on_piece_pass(index);
48
void default_on_piece_pass(int index)
50
this->torrent_plugin::on_piece_pass(index);
53
void on_piece_failed(int index)
57
if (override f = this->get_override("on_piece_failed"))
60
torrent_plugin::on_piece_failed(index);
63
void default_on_piece_failed(int index)
65
return this->torrent_plugin::on_piece_failed(index);
72
if (override f = this->get_override("tick"))
75
torrent_plugin::tick();
80
return this->torrent_plugin::tick();
87
if (override f = this->get_override("on_pause"))
89
return torrent_plugin::on_pause();
92
bool default_on_pause()
94
return this->torrent_plugin::on_pause();
101
if (override f = this->get_override("on_resume"))
103
return torrent_plugin::on_resume();
106
bool default_on_resume()
108
return this->torrent_plugin::on_resume();
112
} // namespace unnamed
115
boost::shared_ptr<torrent_plugin> create_metadata_plugin_wrapper(torrent* t) {
116
return create_metadata_plugin(t, NULL);
119
boost::shared_ptr<torrent_plugin> create_ut_metadata_plugin_wrapper(torrent *t) {
120
return create_ut_metadata_plugin(t, NULL);
123
boost::shared_ptr<torrent_plugin> create_ut_pex_plugin_wrapper(torrent* t) {
124
return create_ut_pex_plugin(t, NULL);
127
boost::shared_ptr<torrent_plugin> create_smart_ban_plugin_wrapper(torrent* t) {
128
return create_smart_ban_plugin(t, NULL);
131
void bind_extensions()
134
torrent_plugin_wrap, boost::shared_ptr<torrent_plugin_wrap>, boost::noncopyable
138
, &torrent_plugin::new_connection, &torrent_plugin_wrap::default_new_connection
142
, &torrent_plugin::on_piece_pass, &torrent_plugin_wrap::default_on_piece_pass
146
, &torrent_plugin::on_piece_failed, &torrent_plugin_wrap::default_on_piece_failed
150
, &torrent_plugin::tick, &torrent_plugin_wrap::default_tick
154
, &torrent_plugin::on_pause, &torrent_plugin_wrap::default_on_pause
158
, &torrent_plugin::on_resume, &torrent_plugin_wrap::default_on_resume
161
// TODO move to it's own file
162
class_<peer_connection, boost::noncopyable>("peer_connection", no_init);
164
class_<torrent_plugin, boost::shared_ptr<torrent_plugin> >("torrent_plugin", no_init);
165
def("create_ut_pex_plugin", create_ut_pex_plugin_wrapper);
166
def("create_metadata_plugin", create_metadata_plugin_wrapper);
167
def("create_ut_metadata_plugin", create_ut_metadata_plugin_wrapper);
168
def("create_smart_ban_plugin", create_smart_ban_plugin_wrapper);