~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to bindings/python/src/peer_info.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
4
 
 
5
#include <libtorrent/peer_info.hpp>
 
6
#include <boost/python.hpp>
 
7
#include <boost/python/iterator.hpp>
 
8
 
 
9
using namespace boost::python;
 
10
using namespace libtorrent;
 
11
 
 
12
int get_last_active(peer_info const& pi)
 
13
{
 
14
    return total_seconds(pi.last_active);
 
15
}
 
16
 
 
17
int get_last_request(peer_info const& pi)
 
18
{
 
19
    return total_seconds(pi.last_request);
 
20
}
 
21
 
 
22
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
 
23
str get_country(peer_info const& pi)
 
24
{
 
25
    return str(pi.country, 2);
 
26
}
 
27
#endif
 
28
 
 
29
tuple get_ip(peer_info const& pi)
 
30
{
 
31
    return make_tuple(boost::lexical_cast<std::string>(pi.ip.address()), pi.ip.port());
 
32
}
 
33
 
 
34
list get_pieces(peer_info const& pi)
 
35
{
 
36
    list ret;
 
37
 
 
38
    for (std::vector<bool>::const_iterator i = pi.pieces.begin()
 
39
        , end(pi.pieces.end()); i != end; ++i)
 
40
    {
 
41
        ret.append(*i);
 
42
    }
 
43
    return ret;
 
44
}
 
45
 
 
46
void bind_peer_info()
 
47
{
 
48
    scope pi = class_<peer_info>("peer_info")
 
49
        .def_readonly("flags", &peer_info::flags)
 
50
        .def_readonly("source", &peer_info::source)
 
51
        .add_property("ip", get_ip)
 
52
        .def_readonly("up_speed", &peer_info::up_speed)
 
53
        .def_readonly("down_speed", &peer_info::down_speed)
 
54
        .def_readonly("payload_up_speed", &peer_info::payload_up_speed)
 
55
        .def_readonly("payload_down_speed", &peer_info::payload_down_speed)
 
56
        .def_readonly("total_download", &peer_info::total_download)
 
57
        .def_readonly("total_upload", &peer_info::total_upload)
 
58
        .def_readonly("pid", &peer_info::pid)
 
59
        .add_property("pieces", get_pieces)
 
60
        .def_readonly("upload_limit", &peer_info::upload_limit)
 
61
        .def_readonly("download_limit", &peer_info::download_limit)
 
62
        .add_property("last_request", get_last_request)
 
63
        .add_property("last_active", get_last_active)
 
64
        .def_readonly("send_buffer_size", &peer_info::send_buffer_size)
 
65
        .def_readonly("used_send_buffer", &peer_info::used_send_buffer)
 
66
        .def_readonly("num_hashfails", &peer_info::num_hashfails)
 
67
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
 
68
        .add_property("country", get_country)
 
69
#endif
 
70
        .def_readonly("load_balancing", &peer_info::load_balancing)
 
71
        .def_readonly("download_queue_length", &peer_info::download_queue_length)
 
72
        .def_readonly("upload_queue_length", &peer_info::upload_queue_length)
 
73
        .def_readonly("failcount", &peer_info::failcount)
 
74
        .def_readonly("downloading_piece_index", &peer_info::downloading_piece_index)
 
75
        .def_readonly("downloading_block_index", &peer_info::downloading_block_index)
 
76
        .def_readonly("downloading_progress", &peer_info::downloading_progress)
 
77
        .def_readonly("downloading_total", &peer_info::downloading_total)
 
78
        .def_readonly("client", &peer_info::client)
 
79
        .def_readonly("connection_type", &peer_info::connection_type)
 
80
        .def_readonly("remote_dl_rate", &peer_info::remote_dl_rate)
 
81
        .def_readonly("pending_disk_bytes", &peer_info::pending_disk_bytes)
 
82
        ;
 
83
 
 
84
    // flags
 
85
    pi.attr("interesting") = (int)peer_info::interesting;
 
86
    pi.attr("choked") = (int)peer_info::choked;
 
87
    pi.attr("remote_interested") = (int)peer_info::remote_interested;
 
88
    pi.attr("remote_choked") = (int)peer_info::remote_choked;
 
89
    pi.attr("supports_extensions") = (int)peer_info::supports_extensions;
 
90
    pi.attr("local_connection") = (int)peer_info::local_connection;
 
91
    pi.attr("handshake") = (int)peer_info::handshake;
 
92
    pi.attr("connecting") = (int)peer_info::connecting;
 
93
    pi.attr("queued") = (int)peer_info::queued;
 
94
    pi.attr("on_parole") = (int)peer_info::on_parole;
 
95
    pi.attr("seed") = (int)peer_info::seed;
 
96
#ifndef TORRENT_DISABLE_ENCRYPTION
 
97
    pi.attr("rc4_encrypted") = (int)peer_info::rc4_encrypted;
 
98
    pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted;
 
99
#endif
 
100
 
 
101
    // connection_type
 
102
    pi.attr("standard_bittorrent") = (int)peer_info::standard_bittorrent;
 
103
    pi.attr("web_seed") = (int)peer_info::web_seed;
 
104
 
 
105
    // source
 
106
    pi.attr("tracker") = (int)peer_info::tracker;
 
107
    pi.attr("dht") = (int)peer_info::dht;
 
108
    pi.attr("pex") = (int)peer_info::pex;
 
109
    pi.attr("lsd") = (int)peer_info::lsd;
 
110
    pi.attr("resume_data") = (int)peer_info::resume_data;
 
111
}
 
112