updated python bindings

This commit is contained in:
Arvid Norberg 2008-03-27 18:14:52 +00:00
parent a53cd86cae
commit bfa7dd7b75
2 changed files with 51 additions and 3 deletions

View File

@ -4,15 +4,33 @@
#include <libtorrent/peer_info.hpp>
#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
using namespace boost::python;
using namespace libtorrent;
tuple get_ip(peer_info const& pi)
{
return make_tuple(boost::lexical_cast<std::string>(pi.ip.address()), pi.ip.port());
}
list get_pieces(peer_info const& pi)
{
list ret;
for (std::vector<bool>::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>("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)

View File

@ -4,6 +4,7 @@
#include <libtorrent/torrent_handle.hpp>
#include <boost/python.hpp>
#include <boost/lexical_cast.hpp>
#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<std::string>(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<std::string>(t[0])), extract<int>(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>("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))