~ubuntu-branches/ubuntu/lucid/rtorrent/lucid

« back to all changes in this revision

Viewing changes to src/command_peer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-12-16 19:48:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20071216194829-uq7srtp6qgq2o5vf
Tags: 0.7.9-1
* debian/control:
 + Specified minimum libxmlrpc-c3 version to >=1.06. (Closes: #449271)
 + Build-depends on libtorrent updated to 0.11.9.
* debian/rules:
 + Added `-fno-strict-aliasing`. (Closes: #453100)
* debian/control:
 + Updated to Standards-Version 3.7.3, no modifications needed.
* New rtorrent.rc shipped is up-to-date. (Closes: #448998)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#include <rak/error_number.h>
40
40
#include <rak/path.h>
 
41
#include <rak/socket_address.h>
 
42
#include <rak/string_manip.h>
 
43
#include <torrent/bitfield.h>
 
44
#include <torrent/rate.h>
41
45
#include <torrent/peer/peer.h>
 
46
#include <torrent/peer/peer_info.h>
42
47
 
43
48
#include "core/manager.h"
 
49
#include "display/utils.h"
44
50
 
45
51
#include "globals.h"
46
52
#include "control.h"
47
53
#include "command_helpers.h"
48
54
 
49
 
// void
50
 
// apply_f_set_priority(torrent::File* file, uint32_t value) {
51
 
//   if (value > torrent::PRIORITY_HIGH)
52
 
//     throw torrent::input_error("Invalid value.");
53
 
 
54
 
//   file->set_priority((torrent::priority_t)value);
55
 
// }
56
 
 
57
 
// torrent::Object
58
 
// apply_f_path(torrent::File* file) {
59
 
//   if (file->path()->empty())
60
 
//     return std::string();
61
 
 
62
 
//   torrent::Object resultRaw(*file->path()->begin());
63
 
//   torrent::Object::string_type& result = resultRaw.as_string();
64
 
 
65
 
//   for (torrent::Path::const_iterator itr = ++file->path()->begin(), last = file->path()->end(); itr != last; itr++)
66
 
//     result += '/' + *itr;
67
 
 
68
 
//   return resultRaw;
69
 
// }
70
 
 
71
 
// torrent::Object
72
 
// apply_f_path_components(torrent::File* file) {
73
 
//   torrent::Object resultRaw(torrent::Object::TYPE_LIST);
74
 
//   torrent::Object::list_type& result = resultRaw.as_list();
75
 
 
76
 
//   for (torrent::Path::const_iterator itr = file->path()->begin(), last = file->path()->end(); itr != last; itr++)
77
 
//     result.push_back(*itr);
78
 
 
79
 
//   return resultRaw;
80
 
// }
81
 
 
82
 
// torrent::Object
83
 
// apply_f_path_depth(torrent::File* file) {
84
 
//   return (int64_t)file->path()->size();
85
 
// }
 
55
torrent::Object
 
56
retrieve_p_id(torrent::Peer* peer) {
 
57
  const torrent::HashString* hashString = &peer->id();
 
58
 
 
59
  return rak::transform_hex(hashString->begin(), hashString->end());
 
60
}
 
61
 
 
62
torrent::Object
 
63
retrieve_p_id_html(torrent::Peer* peer) {
 
64
  const torrent::HashString* hashString = &peer->id();
 
65
 
 
66
  return rak::copy_escape_html(hashString->begin(), hashString->end());
 
67
}
 
68
 
 
69
torrent::Object
 
70
retrieve_p_address(torrent::Peer* peer) {
 
71
  return rak::socket_address::cast_from(peer->info()->socket_address())->address_str();
 
72
}
 
73
 
 
74
torrent::Object
 
75
retrieve_p_port(torrent::Peer* peer) {
 
76
  return rak::socket_address::cast_from(peer->info()->socket_address())->port();
 
77
}
 
78
 
 
79
torrent::Object
 
80
retrieve_p_client_version(torrent::Peer* peer) {
 
81
  char buf[128];
 
82
  display::print_client_version(buf, buf + 128, peer->info()->client_info());
 
83
 
 
84
  return std::string(buf);
 
85
}
 
86
 
 
87
torrent::Object
 
88
retrieve_p_options_str(torrent::Peer* peer) {
 
89
  return rak::transform_hex(peer->info()->options(), peer->info()->options() + 8);
 
90
}
 
91
 
 
92
torrent::Object
 
93
retrieve_p_completed_percent(torrent::Peer* peer) {
 
94
  return (100 * peer->bitfield()->size_set()) / peer->bitfield()->size_bits();
 
95
}
86
96
 
87
97
#define ADD_CP_SLOT(key, function, slot, parm, doc)    \
88
98
  commandPeerSlotsItr->set_slot(slot); \
95
105
#define ADD_CP_VOID(key, slot) \
96
106
  ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_fn(slot), "i:", "")
97
107
 
 
108
#define ADD_CP_VALUE(key, get) \
 
109
  ADD_CP_SLOT_PUBLIC("p." key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "i:", "")
 
110
 
98
111
#define ADD_CP_VALUE_UNI(key, get) \
99
112
  ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "i:", "")
100
113
 
102
115
  ADD_CP_SLOT_PUBLIC("p.set_" key, call_value, rpc::object_value_fn<torrent::Peer*>(set), "i:i", "") \
103
116
  ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "i:", "")
104
117
 
 
118
#define ADD_CP_VALUE_MEM_UNI(key, target, get) \
 
119
  ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(rak::on(std::mem_fun(target), std::mem_fun(get))), "i:", "");
 
120
 
105
121
#define ADD_CP_STRING_UNI(key, get) \
106
122
  ADD_CP_SLOT_PUBLIC("p.get_" key, call_unknown, rpc::object_void_fn<torrent::Peer*>(get), "s:", "")
107
123
 
108
124
void
109
125
initialize_command_peer() {
110
 
//   ADD_CP_VALUE_UNI("is_created",       std::mem_fun(&torrent::Peer::is_created));
111
 
//   ADD_CP_VALUE_UNI("is_open",          std::mem_fun(&torrent::Peer::is_open));
112
 
 
113
 
//   ADD_CP_VALUE_UNI("size_bytes",       std::mem_fun(&torrent::Peer::size_bytes));
114
 
//   ADD_CP_VALUE_UNI("size_chunks",      std::mem_fun(&torrent::Peer::size_chunks));
115
 
//   ADD_CP_VALUE_UNI("completed_chunks", std::mem_fun(&torrent::Peer::completed_chunks));
116
 
 
117
 
//   ADD_CP_VALUE_UNI("offset",           std::mem_fun(&torrent::Peer::offset));
118
 
//   ADD_CP_VALUE_UNI("range_first",      std::mem_fun(&torrent::Peer::range_first));
119
 
//   ADD_CP_VALUE_UNI("range_second",     std::mem_fun(&torrent::Peer::range_second));
120
 
 
121
 
//   ADD_CP_VALUE_BI("priority",          std::ptr_fun(&apply_f_set_priority), std::mem_fun(&torrent::Peer::priority));
122
 
 
123
 
//   ADD_CP_STRING_UNI("path",            std::ptr_fun(&apply_f_path));
124
 
//   ADD_CP_STRING_UNI("path_components", std::ptr_fun(&apply_f_path_components));
125
 
//   ADD_CP_STRING_UNI("path_depth",      std::ptr_fun(&apply_f_path_depth));
126
 
//   ADD_CP_STRING_UNI("frozen_path",     std::mem_fun(&torrent::Peer::frozen_path));
127
 
 
128
 
//   ADD_CP_VALUE_UNI("match_depth_prev", std::mem_fun(&torrent::Peer::match_depth_prev));
129
 
//   ADD_CP_VALUE_UNI("match_depth_next", std::mem_fun(&torrent::Peer::match_depth_next));
130
 
 
131
 
//   ADD_CP_VALUE_UNI("last_touched",     std::mem_fun(&torrent::Peer::last_touched));
 
126
  ADD_CP_STRING_UNI("id",                 std::ptr_fun(&retrieve_p_id));
 
127
  ADD_CP_STRING_UNI("id_html",            std::ptr_fun(&retrieve_p_id_html));
 
128
  ADD_CP_STRING_UNI("client_version",     std::ptr_fun(&retrieve_p_client_version));
 
129
 
 
130
  ADD_CP_STRING_UNI("options_str",        std::ptr_fun(&retrieve_p_options_str));
 
131
 
 
132
  ADD_CP_VALUE("is_encrypted",            std::mem_fun(&torrent::Peer::is_encrypted));
 
133
  ADD_CP_VALUE("is_incoming",             std::mem_fun(&torrent::Peer::is_incoming));
 
134
  ADD_CP_VALUE("is_obfuscated",           std::mem_fun(&torrent::Peer::is_obfuscated));
 
135
  ADD_CP_VALUE("is_snubbed",              std::mem_fun(&torrent::Peer::is_snubbed));
 
136
 
 
137
  ADD_CP_STRING_UNI("address",            std::ptr_fun(&retrieve_p_address));
 
138
  ADD_CP_VALUE_UNI("port",                std::ptr_fun(&retrieve_p_port));
 
139
 
 
140
  ADD_CP_VALUE_UNI("completed_percent",   std::ptr_fun(&retrieve_p_completed_percent));
 
141
 
 
142
  ADD_CP_VALUE_MEM_UNI("up_rate",         &torrent::Peer::up_rate, &torrent::Rate::rate);
 
143
  ADD_CP_VALUE_MEM_UNI("up_total",        &torrent::Peer::up_rate, &torrent::Rate::total);
 
144
  ADD_CP_VALUE_MEM_UNI("down_rate",       &torrent::Peer::down_rate, &torrent::Rate::rate);
 
145
  ADD_CP_VALUE_MEM_UNI("down_total",      &torrent::Peer::down_rate, &torrent::Rate::total);
 
146
  ADD_CP_VALUE_MEM_UNI("peer_rate",       &torrent::Peer::peer_rate, &torrent::Rate::rate);
 
147
  ADD_CP_VALUE_MEM_UNI("peer_total",      &torrent::Peer::peer_rate, &torrent::Rate::total);
132
148
}