fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / bindings / python / src / peer_info.cpp
blob9ceeead7a1bcbd1927d140a0a3d50445a06e4ee4
1 // Copyright Daniel Wallin 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/peer_info.hpp>
6 #include <libtorrent/bitfield.hpp>
7 #include <boost/python.hpp>
8 #include <boost/python/iterator.hpp>
10 using namespace boost::python;
11 using namespace libtorrent;
13 int get_last_active(peer_info const& pi)
15 return total_seconds(pi.last_active);
18 int get_last_request(peer_info const& pi)
20 return total_seconds(pi.last_request);
23 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
24 str get_country(peer_info const& pi)
26 return str(pi.country, 2);
28 #endif
30 tuple get_ip(peer_info const& pi)
32 return make_tuple(boost::lexical_cast<std::string>(pi.ip.address()), pi.ip.port());
35 list get_pieces(peer_info const& pi)
37 list ret;
39 for (bitfield::const_iterator i = pi.pieces.begin()
40 , end(pi.pieces.end()); i != end; ++i)
42 ret.append(*i);
44 return ret;
47 void bind_peer_info()
49 scope pi = class_<peer_info>("peer_info")
50 .def_readonly("flags", &peer_info::flags)
51 .def_readonly("source", &peer_info::source)
52 .def_readonly("read_state", &peer_info::read_state)
53 .def_readonly("write_state", &peer_info::write_state)
54 .add_property("ip", get_ip)
55 .def_readonly("up_speed", &peer_info::up_speed)
56 .def_readonly("down_speed", &peer_info::down_speed)
57 .def_readonly("payload_up_speed", &peer_info::payload_up_speed)
58 .def_readonly("payload_down_speed", &peer_info::payload_down_speed)
59 .def_readonly("total_download", &peer_info::total_download)
60 .def_readonly("total_upload", &peer_info::total_upload)
61 .def_readonly("pid", &peer_info::pid)
62 .add_property("pieces", get_pieces)
63 .def_readonly("upload_limit", &peer_info::upload_limit)
64 .def_readonly("download_limit", &peer_info::download_limit)
65 .add_property("last_request", get_last_request)
66 .add_property("last_active", get_last_active)
67 .def_readonly("send_buffer_size", &peer_info::send_buffer_size)
68 .def_readonly("used_send_buffer", &peer_info::used_send_buffer)
69 .def_readonly("num_hashfails", &peer_info::num_hashfails)
70 #ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
71 .add_property("country", get_country)
72 #endif
73 #ifndef TORRENT_DISABLE_GEO_IP
74 .def_readonly("inet_as_name", &peer_info::inet_as_name)
75 .def_readonly("inet_as", &peer_info::inet_as)
76 #endif
77 .def_readonly("load_balancing", &peer_info::load_balancing)
78 .def_readonly("download_queue_length", &peer_info::download_queue_length)
79 .def_readonly("upload_queue_length", &peer_info::upload_queue_length)
80 .def_readonly("failcount", &peer_info::failcount)
81 .def_readonly("downloading_piece_index", &peer_info::downloading_piece_index)
82 .def_readonly("downloading_block_index", &peer_info::downloading_block_index)
83 .def_readonly("downloading_progress", &peer_info::downloading_progress)
84 .def_readonly("downloading_total", &peer_info::downloading_total)
85 .def_readonly("client", &peer_info::client)
86 .def_readonly("connection_type", &peer_info::connection_type)
87 .def_readonly("remote_dl_rate", &peer_info::remote_dl_rate)
88 .def_readonly("pending_disk_bytes", &peer_info::pending_disk_bytes)
89 .def_readonly("send_quota", &peer_info::send_quota)
90 .def_readonly("receive_quota", &peer_info::receive_quota)
91 .def_readonly("rtt", &peer_info::rtt)
94 // flags
95 pi.attr("interesting") = (int)peer_info::interesting;
96 pi.attr("choked") = (int)peer_info::choked;
97 pi.attr("remote_interested") = (int)peer_info::remote_interested;
98 pi.attr("remote_choked") = (int)peer_info::remote_choked;
99 pi.attr("supports_extensions") = (int)peer_info::supports_extensions;
100 pi.attr("local_connection") = (int)peer_info::local_connection;
101 pi.attr("handshake") = (int)peer_info::handshake;
102 pi.attr("connecting") = (int)peer_info::connecting;
103 pi.attr("queued") = (int)peer_info::queued;
104 pi.attr("on_parole") = (int)peer_info::on_parole;
105 pi.attr("seed") = (int)peer_info::seed;
106 #ifndef TORRENT_DISABLE_ENCRYPTION
107 pi.attr("rc4_encrypted") = (int)peer_info::rc4_encrypted;
108 pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted;
109 #endif
111 // connection_type
112 pi.attr("standard_bittorrent") = (int)peer_info::standard_bittorrent;
113 pi.attr("web_seed") = (int)peer_info::web_seed;
115 // source
116 pi.attr("tracker") = (int)peer_info::tracker;
117 pi.attr("dht") = (int)peer_info::dht;
118 pi.attr("pex") = (int)peer_info::pex;
119 pi.attr("lsd") = (int)peer_info::lsd;
120 pi.attr("resume_data") = (int)peer_info::resume_data;
122 // read/write state
123 pi.attr("bw_idle") = (int)peer_info::bw_idle;
124 pi.attr("bw_torrent") = (int)peer_info::bw_torrent;
125 pi.attr("bw_global") = (int)peer_info::bw_global;
126 pi.attr("bw_network") = (int)peer_info::bw_network;