mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 07:09:21 +00:00
* More work on ip filter framework. Note some critical parts are not at this moment available to the public.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1194 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/data/file_manager.h>
|
||||
#include <torrent/peer/peer_list.h>
|
||||
|
||||
#include "core/dht_manager.h"
|
||||
#include "core/download.h"
|
||||
@@ -483,6 +484,55 @@ apply_ip_tables_add_address(const torrent::Object::list_type& args) {
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
torrent::Object
|
||||
apply_ipv4_filter_get(const std::string& args) {
|
||||
// Move to a helper function, add support for addresses.
|
||||
uint32_t ip_values[4];
|
||||
|
||||
if (sscanf(args.c_str(), "%u.%u.%u.%u",
|
||||
ip_values + 0, ip_values + 1, ip_values + 2, ip_values + 3) != 4)
|
||||
throw torrent::input_error("Invalid address format.");
|
||||
|
||||
return torrent::PeerList::ipv4_filter()->at((ip_values[0] << 24) + (ip_values[1] << 16) + (ip_values[2] << 8) + ip_values[3]);
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_ipv4_filter_add_address(const torrent::Object::list_type& args) {
|
||||
if (args.size() != 2)
|
||||
throw torrent::input_error("Incorrect number of arguments.");
|
||||
|
||||
torrent::Object::list_const_iterator args_itr = args.begin();
|
||||
|
||||
const std::string& address = (args_itr++)->as_string();
|
||||
const std::string& value_str = (args_itr++)->as_string();
|
||||
|
||||
// Move to a helper function, add support for addresses.
|
||||
uint32_t ip_values[4];
|
||||
unsigned int block = rpc::ipv4_table::mask_bits;
|
||||
|
||||
if (sscanf(address.c_str(), "%u.%u.%u.%u/%u",
|
||||
ip_values + 0, ip_values + 1, ip_values + 2, ip_values + 3, &block) < 4 ||
|
||||
block > rpc::ipv4_table::mask_bits)
|
||||
throw torrent::input_error("Invalid address format.");
|
||||
|
||||
int value;
|
||||
|
||||
if (value_str == "unwanted")
|
||||
value = torrent::PeerInfo::flag_unwanted;
|
||||
else if (value_str == "preferred")
|
||||
value = torrent::PeerInfo::flag_preferred;
|
||||
else
|
||||
throw torrent::input_error("Invalid value.");
|
||||
|
||||
torrent::PeerList::ipv4_filter()->insert((ip_values[0] << 24) + (ip_values[1] << 16) + (ip_values[2] << 8) + ip_values[3],
|
||||
rpc::ipv4_table::mask_bits - block, value);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_command_network() {
|
||||
torrent::ConnectionManager* cm = torrent::connection_manager();
|
||||
@@ -595,6 +645,9 @@ initialize_command_network() {
|
||||
CMD2_ANY_LIST ("ip_tables.get", std::tr1::bind(&apply_ip_tables_get, std::tr1::placeholders::_2));
|
||||
CMD2_ANY_LIST ("ip_tables.add_address", std::tr1::bind(&apply_ip_tables_add_address, std::tr1::placeholders::_2));
|
||||
|
||||
CMD2_ANY_STRING ("ipv4_filter.get", std::tr1::bind(&apply_ipv4_filter_get, std::tr1::placeholders::_2));
|
||||
CMD2_ANY_LIST ("ipv4_filter.add_address", std::tr1::bind(&apply_ipv4_filter_add_address, std::tr1::placeholders::_2));
|
||||
|
||||
// CMD2_ANY_V ("dht.enable", std::tr1::bind(&core::DhtManager::set_start, control->dht_manager()));
|
||||
// CMD2_ANY_V ("dht.disable", std::tr1::bind(&core::DhtManager::set_stop, control->dht_manager()));
|
||||
CMD2_ANY_STRING_V("dht.mode.set", std::tr1::bind(&core::DhtManager::set_mode, control->dht_manager(), std::tr1::placeholders::_2));
|
||||
|
||||
@@ -41,11 +41,11 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <rak/path.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/object_stream.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/data/file_utils.h>
|
||||
|
||||
#include "rpc/parse_commands.h"
|
||||
|
||||
@@ -43,12 +43,12 @@
|
||||
#include <rak/functional.h>
|
||||
#include <rak/string_manip.h>
|
||||
#include <torrent/data/file.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/hash_string.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/object_stream.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "rpc/parse_commands.h"
|
||||
|
||||
@@ -44,11 +44,11 @@
|
||||
#include <rak/error_number.h>
|
||||
#include <rak/path.h>
|
||||
#include <rak/string_manip.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/object_stream.h>
|
||||
|
||||
#include "utils/directory.h"
|
||||
|
||||
+1
-1
@@ -49,12 +49,12 @@
|
||||
#include <rak/string_manip.h>
|
||||
#include <sigc++/adaptors/bind.h>
|
||||
#include <sigc++/adaptors/hide.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/error.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object_stream.h>
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/throttle.h>
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ WindowPeerList::redraw() {
|
||||
m_canvas->print(x, y, "UP"); x += 7;
|
||||
m_canvas->print(x, y, "DOWN"); x += 7;
|
||||
m_canvas->print(x, y, "PEER"); x += 7;
|
||||
m_canvas->print(x, y, "C/RE/LO"); x += 9;
|
||||
m_canvas->print(x, y, "CT/RE/LO"); x += 10;
|
||||
m_canvas->print(x, y, "QS"); x += 6;
|
||||
m_canvas->print(x, y, "DONE"); x += 6;
|
||||
m_canvas->print(x, y, "REQ"); x += 6;
|
||||
@@ -109,6 +109,7 @@ WindowPeerList::redraw() {
|
||||
m_canvas->print(x, y, "%.1f", (double)p->peer_rate()->rate() / 1024); x += 7;
|
||||
|
||||
char remoteChoked;
|
||||
char peerType;
|
||||
|
||||
if (!p->is_down_choked_limited())
|
||||
remoteChoked = 'U';
|
||||
@@ -117,14 +118,22 @@ WindowPeerList::redraw() {
|
||||
else
|
||||
remoteChoked = 'C';
|
||||
|
||||
m_canvas->print(x, y, "%c/%c%c/%c%c",
|
||||
if (p->peer_info()->is_blocked())
|
||||
peerType = 'u';
|
||||
else if (p->peer_info()->is_preferred())
|
||||
peerType = 'p';
|
||||
else
|
||||
peerType = ' ';
|
||||
|
||||
m_canvas->print(x, y, "%c%c/%c%c/%c%c",
|
||||
p->is_encrypted() ? (p->is_incoming() ? 'R' : 'L') : (p->is_incoming() ? 'r' : 'l'),
|
||||
peerType,
|
||||
p->is_down_choked() ? std::tolower(remoteChoked) : remoteChoked,
|
||||
|
||||
p->is_down_interested() ? 'i' : 'n',
|
||||
p->is_up_choked() ? 'c' : 'u',
|
||||
p->is_up_interested() ? 'i' : 'n');
|
||||
x += 9;
|
||||
x += 10;
|
||||
|
||||
m_canvas->print(x, y, "%i/%i", p->outgoing_queue_size(), p->incoming_queue_size());
|
||||
x += 6;
|
||||
|
||||
Reference in New Issue
Block a user