00001
00002
00003
00004
00005
00006
00007
00008 #include <libtorrent/extensions.hpp>
00009 #include <libtorrent/entry.hpp>
00010 #include <libtorrent/peer_request.hpp>
00011 #include <boost/python.hpp>
00012
00013 using namespace boost::python;
00014 using namespace libtorrent;
00015
00016 namespace
00017 {
00018 struct peer_plugin_wrap : peer_plugin, wrapper<peer_plugin>
00019 {
00020 void add_handshake(entry& e)
00021 {
00022 if (override f = this->get_override("add_handshake"))
00023 e = call<entry>(f.ptr(), e);
00024 else
00025 peer_plugin::add_handshake(e);
00026 }
00027
00028 void default_add_handshake(entry& e)
00029 {
00030 this->peer_plugin::add_handshake(e);
00031 }
00032
00033 bool on_handshake()
00034 {
00035 if (override f = this->get_override("on_handshake"))
00036 return f();
00037 else
00038 return peer_plugin::on_handshake();
00039 }
00040
00041 bool default_on_handshake()
00042 {
00043 return this->peer_plugin::on_handshake();
00044 }
00045
00046 bool on_extension_handshake(entry const& e)
00047 {
00048 if (override f = this->get_override("on_extension_handshake"))
00049 return f(e);
00050 else
00051 return peer_plugin::on_extension_handshake(e);
00052 }
00053
00054 bool default_on_extension_handshake(entry const& e)
00055 {
00056 return this->peer_plugin::on_extension_handshake(e);
00057 }
00058
00059 bool on_choke()
00060 {
00061 if (override f = this->get_override("on_choke"))
00062 return f();
00063 else
00064 return peer_plugin::on_choke();
00065 }
00066
00067 bool default_on_choke()
00068 {
00069 return this->peer_plugin::on_choke();
00070 }
00071
00072 bool on_unchoke()
00073 {
00074 if (override f = this->get_override("on_unchoke"))
00075 return f();
00076 else
00077 return peer_plugin::on_unchoke();
00078 }
00079
00080 bool default_on_unchoke()
00081 {
00082 return this->peer_plugin::on_unchoke();
00083 }
00084
00085 bool on_interested()
00086 {
00087 if (override f = this->get_override("on_interested"))
00088 return f();
00089 else
00090 return peer_plugin::on_interested();
00091 }
00092
00093 bool default_on_interested()
00094 {
00095 return this->peer_plugin::on_interested();
00096 }
00097
00098 bool on_not_interested()
00099 {
00100 if (override f = this->get_override("on_not_interested"))
00101 return f();
00102 else
00103 return peer_plugin::on_not_interested();
00104 }
00105
00106 bool default_on_not_interested()
00107 {
00108 return this->peer_plugin::on_not_interested();
00109 }
00110
00111 bool on_have(int index)
00112 {
00113 if (override f = this->get_override("on_have"))
00114 return f(index);
00115 else
00116 return peer_plugin::on_have(index);
00117 }
00118
00119 bool default_on_have(int index)
00120 {
00121 return this->peer_plugin::on_have(index);
00122 }
00123
00124 bool on_bitfield(std::vector<bool> const& bitfield)
00125 {
00126 if (override f = this->get_override("on_bitfield"))
00127 return f(bitfield);
00128 else
00129 return peer_plugin::on_bitfield(bitfield);
00130 }
00131
00132 bool default_on_bitfield(std::vector<bool> const& bitfield)
00133 {
00134 return this->peer_plugin::on_bitfield(bitfield);
00135 }
00136
00137 bool on_request(peer_request const& req)
00138 {
00139 if (override f = this->get_override("on_request"))
00140 return f(req);
00141 else
00142 return peer_plugin::on_request(req);
00143 }
00144
00145 bool default_on_request(peer_request const& req)
00146 {
00147 return this->peer_plugin::on_request(req);
00148 }
00149
00150 bool on_piece(peer_request const& piece, char const* data)
00151 {
00152 if (override f = this->get_override("on_piece"))
00153 return f(piece, data);
00154 else
00155 return peer_plugin::on_piece(piece, data);
00156 }
00157
00158 bool default_on_piece(peer_request const& piece, char const* data)
00159 {
00160 return this->peer_plugin::on_piece(piece, data);
00161 }
00162
00163 bool on_cancel(peer_request const& req)
00164 {
00165 if (override f = this->get_override("on_cancel"))
00166 return f(req);
00167 else
00168 return peer_plugin::on_cancel(req);
00169 }
00170
00171 bool default_on_cancel(peer_request const& req)
00172 {
00173 return this->peer_plugin::on_cancel(req);
00174 }
00175
00176 bool on_extended(int length, int msg, buffer::const_interval body)
00177 {
00178 if (override f = this->get_override("on_extended"))
00179 return f(length, msg, body);
00180 else
00181 return peer_plugin::on_extended(length, msg, body);
00182 }
00183
00184 bool default_on_extended(int length, int msg, buffer::const_interval body)
00185 {
00186 return this->peer_plugin::on_extended(length, msg, body);
00187 }
00188
00189 bool on_unknown_message(int length, int msg, buffer::const_interval body)
00190 {
00191 if (override f = this->get_override("on_unknown_message"))
00192 return f(length, msg, body);
00193 else
00194 return peer_plugin::on_unknown_message(length, msg, body);
00195 }
00196
00197 bool default_on_unknown_message(int length, int msg, buffer::const_interval body)
00198 {
00199 return this->peer_plugin::on_unknown_message(length, msg, body);
00200 }
00201
00202 void on_piece_pass(int index)
00203 {
00204 if (override f = this->get_override("on_piece_pass"))
00205 f(index);
00206 else
00207 peer_plugin::on_piece_pass(index);
00208 }
00209
00210 void default_on_piece_pass(int index)
00211 {
00212 this->peer_plugin::on_piece_pass(index);
00213 }
00214
00215 void on_piece_failed(int index)
00216 {
00217 if (override f = this->get_override("on_piece_failed"))
00218 f(index);
00219 else
00220 peer_plugin::on_piece_failed(index);
00221 }
00222
00223 void default_on_piece_failed(int index)
00224 {
00225 this->peer_plugin::on_piece_failed(index);
00226 }
00227
00228 void tick()
00229 {
00230 if (override f = this->get_override("tick"))
00231 f();
00232 else
00233 peer_plugin::tick();
00234 }
00235
00236 void default_tick()
00237 {
00238 this->peer_plugin::tick();
00239 }
00240
00241 bool write_request(peer_request const& req)
00242 {
00243 if (override f = this->get_override("write_request"))
00244 return f(req);
00245 else
00246 return peer_plugin::write_request(req);
00247 }
00248
00249 bool default_write_request(peer_request const& req)
00250 {
00251 return this->peer_plugin::write_request(req);
00252 }
00253 };
00254
00255 object get_buffer()
00256 {
00257 static char const data[] = "foobar";
00258 return object(handle<>(PyBuffer_FromMemory((void*)data, 6)));
00259 }
00260
00261 }
00262
00263 void bind_peer_plugin()
00264 {
00265 class_<
00266 peer_plugin_wrap, boost::shared_ptr<peer_plugin_wrap>, boost::noncopyable
00267 >("peer_plugin")
00268 .def(
00269 "add_handshake"
00270 , &peer_plugin::add_handshake, &peer_plugin_wrap::default_add_handshake
00271 )
00272 .def(
00273 "on_handshake"
00274 , &peer_plugin::on_handshake, &peer_plugin_wrap::default_on_handshake
00275 )
00276 .def(
00277 "on_extension_handshake"
00278 , &peer_plugin::on_extension_handshake
00279 , &peer_plugin_wrap::default_on_extension_handshake
00280 )
00281 .def(
00282 "on_choke"
00283 , &peer_plugin::on_choke, &peer_plugin_wrap::default_on_choke
00284 )
00285 .def(
00286 "on_unchoke"
00287 , &peer_plugin::on_unchoke, &peer_plugin_wrap::default_on_unchoke
00288 )
00289 .def(
00290 "on_interested"
00291 , &peer_plugin::on_interested, &peer_plugin_wrap::default_on_interested
00292 )
00293 .def(
00294 "on_not_interested"
00295 , &peer_plugin::on_not_interested, &peer_plugin_wrap::default_on_not_interested
00296 )
00297 .def(
00298 "on_have"
00299 , &peer_plugin::on_have, &peer_plugin_wrap::default_on_have
00300 )
00301 .def(
00302 "on_bitfield"
00303 , &peer_plugin::on_bitfield, &peer_plugin_wrap::default_on_bitfield
00304 )
00305 .def(
00306 "on_request"
00307 , &peer_plugin::on_request, &peer_plugin_wrap::default_on_request
00308 )
00309 .def(
00310 "on_piece"
00311 , &peer_plugin::on_piece, &peer_plugin_wrap::default_on_piece
00312 )
00313 .def(
00314 "on_cancel"
00315 , &peer_plugin::on_cancel, &peer_plugin_wrap::default_on_cancel
00316 )
00317 .def(
00318 "on_piece_pass"
00319 , &peer_plugin::on_piece_pass, &peer_plugin_wrap::default_on_piece_pass
00320 )
00321 .def(
00322 "on_piece_failed"
00323 , &peer_plugin::on_piece_failed, &peer_plugin_wrap::default_on_piece_failed
00324 )
00325 .def(
00326 "tick"
00327 , &peer_plugin::tick, &peer_plugin_wrap::default_tick
00328 )
00329 .def(
00330 "write_request"
00331 , &peer_plugin::write_request, &peer_plugin_wrap::default_write_request
00332 )
00333
00334
00335
00336 ;
00337
00338 def("get_buffer", &get_buffer);
00339 }
00340