From bfa7dd7b75357da25085f7230ff93a4c90eda0a5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 27 Mar 2008 18:14:52 +0000 Subject: [PATCH] updated python bindings --- bindings/python/src/peer_info.cpp | 22 ++++++++++++++++-- bindings/python/src/torrent_handle.cpp | 32 +++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/bindings/python/src/peer_info.cpp b/bindings/python/src/peer_info.cpp index 49570b795..917e8ef90 100755 --- a/bindings/python/src/peer_info.cpp +++ b/bindings/python/src/peer_info.cpp @@ -4,15 +4,33 @@ #include #include +#include using namespace boost::python; using namespace libtorrent; +tuple get_ip(peer_info const& pi) +{ + return make_tuple(boost::lexical_cast(pi.ip.address()), pi.ip.port()); +} + +list get_pieces(peer_info const& pi) +{ + list ret; + + for (std::vector::const_iterator i = pi.pieces.begin() + , end(pi.pieces.end()); i != end; ++i) + { + ret.append(*i); + } + return ret; +} + void bind_peer_info() { scope pi = class_("peer_info") .def_readonly("flags", &peer_info::flags) - .def_readonly("ip", &peer_info::ip) + .add_property("ip", get_ip) .def_readonly("up_speed", &peer_info::up_speed) .def_readonly("down_speed", &peer_info::down_speed) .def_readonly("payload_up_speed", &peer_info::payload_up_speed) @@ -20,7 +38,7 @@ void bind_peer_info() .def_readonly("total_download", &peer_info::total_download) .def_readonly("total_upload", &peer_info::total_upload) .def_readonly("pid", &peer_info::pid) - .def_readonly("pieces", &peer_info::pieces) + .add_property("pieces", get_pieces) .def_readonly("upload_limit", &peer_info::upload_limit) .def_readonly("download_limit", &peer_info::download_limit) .def_readonly("load_balancing", &peer_info::load_balancing) diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index ab251d2ef..ec4990672 100755 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "gil.hpp" using namespace boost::python; @@ -133,7 +134,8 @@ list get_download_queue(torrent_handle& handle) block_info["num_peers"] = i->blocks[k].num_peers; block_info["bytes_progress"] = i->blocks[k].bytes_progress; block_info["block_size"] = i->blocks[k].block_size; -// block_info["peer"] = i->info[k].peer; + block_info["peer"] = std::make_pair( + boost::lexical_cast(i->blocks[k].peer.address()), i->blocks[k].peer.port()); block_list.append(block_info); } partial_piece["blocks"] = block_list; @@ -144,6 +146,29 @@ list get_download_queue(torrent_handle& handle) return ret; } +namespace +{ + tcp::endpoint tuple_to_endpoint(tuple const& t) + { + return tcp::endpoint(address::from_string(extract(t[0])), extract(t[1])); + } +} + +void connect_peer(torrent_handle& th, tuple ip, int source) +{ + th.connect_peer(tuple_to_endpoint(ip), source); +} + +void set_peer_upload_limit(torrent_handle& th, tuple const& ip, int limit) +{ + th.set_peer_upload_limit(tuple_to_endpoint(ip), limit); +} + +void set_peer_download_limit(torrent_handle& th, tuple const& ip, int limit) +{ + th.set_peer_download_limit(tuple_to_endpoint(ip), limit); +} + void bind_torrent_handle() { void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce; @@ -158,6 +183,7 @@ void bind_torrent_handle() #define _ allow_threads class_("torrent_handle") + .def("connect_peer", connect_peer) .def("status", _(&torrent_handle::status)) .def("torrent_info", _(&torrent_handle::get_torrent_info), return_internal_reference<>()) .def("is_valid", _(&torrent_handle::is_valid)) @@ -168,9 +194,13 @@ void bind_torrent_handle() .def("add_url_seed", _(&torrent_handle::add_url_seed)) .def("set_ratio", _(&torrent_handle::set_ratio)) .def("set_max_uploads", _(&torrent_handle::set_max_uploads)) + .def("set_peer_upload_limit", set_peer_upload_limit) + .def("set_peer_download_limit", set_peer_download_limit) .def("set_max_connections", _(&torrent_handle::set_max_connections)) .def("set_upload_limit", _(&torrent_handle::set_upload_limit)) .def("set_download_limit", _(&torrent_handle::set_download_limit)) + .def("upload_limit", _(&torrent_handle::upload_limit)) + .def("download_limit", _(&torrent_handle::download_limit)) .def("set_sequential_download", _(&torrent_handle::set_sequential_download)) .def("pause", _(&torrent_handle::pause)) .def("resume", _(&torrent_handle::resume))