updated on Tue Jan 17 00:10:10 UTC 2012
[aur-mirror.git] / rtorrent-extended / ex_friend.patch
blobceeb8a1afcb307053a63693681a4a62c15c57025
1 diff --git a/src/command_network.cc b/src/command_network.cc
2 index 15a14a3..68f9395 100644
3 --- a/src/command_network.cc
4 +++ b/src/command_network.cc
5 @@ -266,7 +266,17 @@ apply_ip_filter(const torrent::Object& rawArgs) {
6 std::cout.flush();
7 control->core()->set_ip_filter( f );
9 + return torrent::Object();
12 +torrent::Object
13 +apply_friend(const torrent::Object& rawArgs) {
14 + const torrent::Object::list_type& args = rawArgs.as_list();
15 + if (args.empty() || args.size() > 2)
16 + throw torrent::input_error("Incorrect number of arguments.");
18 + std::pair<uint32_t, uint32_t> range = parse_address_range(args, args.begin());
19 + control->core()->set_peer_filter(range.first, range.second, torrent::ConnectionManager::filter_friend);
20 return torrent::Object();
23 @@ -517,6 +527,8 @@ initialize_command_network() {
25 ADD_COMMAND_LIST("encryption", rak::ptr_fn(&apply_encryption));
27 + ADD_COMMAND_LIST("friend", rak::ptr_fn(&apply_friend));
29 ADD_COMMAND_STRING("tos", rak::ptr_fn(&apply_tos));
31 ADD_COMMAND_STRING_TRI("bind", rak::make_mem_fun(control->core(), &core::Manager::set_bind_address), rak::make_mem_fun(control->core(), &core::Manager::bind_address));
32 diff --git a/src/command_peer.cc b/src/command_peer.cc
33 index 0aae8e0..c17bed2 100644
34 --- a/src/command_peer.cc
35 +++ b/src/command_peer.cc
36 @@ -139,6 +139,7 @@ initialize_command_peer() {
37 ADD_CP_VALUE("is_incoming", std::mem_fun(&torrent::Peer::is_incoming));
38 ADD_CP_VALUE("is_obfuscated", std::mem_fun(&torrent::Peer::is_obfuscated));
39 ADD_CP_VALUE("is_snubbed", std::mem_fun(&torrent::Peer::is_snubbed));
40 + ADD_CP_VALUE("is_friend", std::mem_fun(&torrent::Peer::is_friend));
42 ADD_CP_STRING_UNI("address", std::ptr_fun(&retrieve_p_address));
43 ADD_CP_VALUE_UNI("port", std::ptr_fun(&retrieve_p_port));
44 diff --git a/src/core/manager.cc b/src/core/manager.cc
45 index 9c1d004..31d4fff 100644
46 --- a/src/core/manager.cc
47 +++ b/src/core/manager.cc
48 @@ -238,6 +238,17 @@ Manager::get_address_throttle(const sockaddr* addr) {
49 return m_addressThrottles.get(rak::socket_address::cast_from(addr)->sa_inet()->address_h(), torrent::ThrottlePair(NULL, NULL));
52 +void
53 +Manager::set_peer_filter(uint32_t begin, uint32_t end, uint32_t filter) {
54 + m_addressFilters.set_merge(begin, end, filter);
55 + torrent::connection_manager()->set_filter(sigc::mem_fun(control->core(), &core::Manager::get_peer_filter));
58 +uint32_t
59 +Manager::get_peer_filter(const sockaddr* addr) {
60 + return m_addressFilters.get(rak::socket_address::cast_from(addr)->sa_inet()->address_h(), torrent::ConnectionManager::filter_permitted);
63 // Most of this should be possible to move out.
64 void
65 Manager::initialize_second() {
66 diff --git a/src/core/manager.h b/src/core/manager.h
67 index ac01981..1f03cea 100644
68 --- a/src/core/manager.h
69 +++ b/src/core/manager.h
70 @@ -97,6 +97,9 @@ public:
71 void set_address_throttle(uint32_t begin, uint32_t end, torrent::ThrottlePair throttles);
72 torrent::ThrottlePair get_address_throttle(const sockaddr* addr);
74 + void set_peer_filter(uint32_t begin, uint32_t end, uint32_t flags);
75 + uint32_t get_peer_filter(const sockaddr* addr);
77 // Really should find a more descriptive name.
78 void initialize_second();
79 void cleanup();
80 @@ -143,6 +146,7 @@ public:
82 private:
83 typedef RangeMap<uint32_t, torrent::ThrottlePair> AddressThrottleMap;
84 + typedef RangeMap<uint32_t, uint32_t> AddressFilterMap;
86 void create_http(const std::string& uri);
87 void create_final(std::istream* s);
88 @@ -162,6 +166,7 @@ private:
90 ThrottleMap m_throttles;
91 AddressThrottleMap m_addressThrottles;
92 + AddressFilterMap m_addressFilters;
94 Log m_logImportant;
95 Log m_logComplete;
96 diff --git a/src/ui/element_peer_list.cc b/src/ui/element_peer_list.cc
97 index be0e0b4..c5ad738 100644
98 --- a/src/ui/element_peer_list.cc
99 +++ b/src/ui/element_peer_list.cc
100 @@ -112,6 +112,7 @@ ElementPeerList::create_info() {
102 element->push_back("");
103 element->push_column("Snubbed:", te_command("if=$p.is_snubbed=,yes,no"));
104 + element->push_column("Friend:", te_command("if=$p.is_friend=,yes,no"));
105 element->push_column("Done:", te_command("p.get_completed_percent="));
106 element->push_column("Rate:", te_command("cat=$to_kb=$p.get_up_rate=,\\ KB\\ ,$to_kb=$p.get_down_rate=,\\ KB"));
107 element->push_column("Total:", te_command("cat=$to_kb=$p.get_up_total=,\\ KB\\ ,$to_kb=$p.get_down_total=,\\ KB"));