* Fixed some missing headers.

* Added ip table framework.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1193 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2011-03-27 10:23:16 +00:00
parent 5debd6f1be
commit 6e9df49912
7 changed files with 179 additions and 2 deletions
+76
View File
@@ -411,6 +411,78 @@ apply_xmlrpc_dialect(const std::string& arg) {
return torrent::Object();
}
torrent::Object
apply_ip_tables_insert_table(const std::string& args) {
if (ip_tables.find(args) != ip_tables.end())
throw torrent::input_error("IP table already exists.");
ip_tables.insert(args);
return torrent::Object();
}
torrent::Object
apply_ip_tables_get(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& name = (args_itr++)->as_string();
const std::string& address = (args_itr++)->as_string();
// Move to a helper function, add support for addresses.
uint32_t ip_values[4];
if (sscanf(address.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.");
rpc::ip_table_list::iterator table_itr = ip_tables.find(name);
if (table_itr == ip_tables.end())
throw torrent::input_error("Could not find ip table.");
return table_itr->table.at((ip_values[0] << 24) + (ip_values[1] << 16) + (ip_values[2] << 8) + ip_values[3]);
}
torrent::Object
apply_ip_tables_add_address(const torrent::Object::list_type& args) {
if (args.size() != 3)
throw torrent::input_error("Incorrect number of arguments.");
torrent::Object::list_const_iterator args_itr = args.begin();
const std::string& name = (args_itr++)->as_string();
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 == "block")
value = 1;
else
throw torrent::input_error("Invalid value.");
rpc::ip_table_list::iterator table_itr = ip_tables.find(name);
if (table_itr == ip_tables.end())
throw torrent::input_error("Could not find ip table.");
table_itr->table.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();
@@ -519,6 +591,10 @@ initialize_command_network() {
CMD2_VAR_VALUE ("trackers.numwant", -1);
CMD2_VAR_BOOL ("trackers.use_udp", true);
CMD2_ANY_STRING ("ip_tables.insert_table", std::tr1::bind(&apply_ip_tables_insert_table, std::tr1::placeholders::_2));
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_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));
+1
View File
@@ -40,6 +40,7 @@
rak::priority_queue_default taskScheduler;
rak::timer cachedTime;
rpc::ip_table_list ip_tables;
Control* control = NULL;
//__thread ThreadBase* main_thread = NULL;
+2
View File
@@ -43,6 +43,7 @@
#include "thread_base.h"
#include "thread_main.h"
#include "thread_worker.h"
#include "rpc/ip_table_list.h"
class Control;
@@ -53,6 +54,7 @@ class Control;
extern rak::priority_queue_default taskScheduler;
extern rak::timer cachedTime;
extern rpc::ip_table_list ip_tables;
extern Control* control;
// extern __thread ThreadBase* main_thread; // Only use for worker threads for now.
+7 -1
View File
@@ -297,12 +297,18 @@ main(int argc, char** argv) {
// "view.sort_new = hashing,less=d.state_changed=\n"
// "view.sort_current = hashing,less=d.state_changed=\n"
"view.add = seeding\n"
"view.add = seeding\n"
"view.filter = seeding,\"and=d.state=,d.complete=\"\n"
"view.filter_on = seeding,event.download.resumed,event.download.paused,event.download.finished\n"
"view.sort_new = seeding,less=d.state_changed=\n"
"view.sort_current = seeding,less=d.state_changed=\n"
"view.add = leeching\n"
"view.filter = leeching,\"and=d.state=,not=$d.complete=\"\n"
"view.filter_on = leeching,event.download.resumed,event.download.paused,event.download.finished\n"
"view.sort_new = leeching,less=d.state_changed=\n"
"view.sort_current = leeching,less=d.state_changed=\n"
"schedule2 = view.main,10,10,((view.sort,main,20))\n"
"schedule2 = view.name,10,10,((view.sort,name,20))\n"
+1
View File
@@ -13,6 +13,7 @@ libsub_rpc_a_SOURCES = \
exec_file.cc \
exec_file.h \
fixed_key.h \
ip_table_list.h \
object_storage.cc \
object_storage.h \
parse.cc \
+90
View File
@@ -0,0 +1,90 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2007, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_RPC_IP_TABLE_LISTS_H
#define RTORRENT_RPC_IP_TABLE_LISTS_H
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <torrent/utils/extents.h>
namespace rpc {
typedef torrent::extents<uint32_t, int, 32, 256, 8> ipv4_table;
struct ip_table_node {
std::string name;
ipv4_table table;
bool equal_name(const std::string& str) const { return str == name; }
};
class ip_table_list : private std::vector<ip_table_node> {
public:
typedef std::vector<ip_table_node> base_type;
using base_type::iterator;
using base_type::const_iterator;
using base_type::value_type;
using base_type::begin;
using base_type::end;
iterator insert(const std::string& name);
iterator find(const std::string& name);
};
inline ip_table_list::iterator
ip_table_list::insert(const std::string& name) {
ip_table_node tmp = { name };
return base_type::insert(end(), tmp);
}
inline ip_table_list::iterator
ip_table_list::find(const std::string& name) {
for (iterator itr = begin(), last = end(); itr != last; itr++)
if (itr->equal_name(name))
return itr;
return end();
}
}
#endif
+2 -1
View File
@@ -93,7 +93,8 @@ ElementDownloadList::ElementDownloadList() :
m_bindings['6'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "incomplete");
m_bindings['7'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "hashing");
m_bindings['8'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "seeding");
m_bindings['9'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "active");
m_bindings['9'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "leeching");
m_bindings['0'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "active");
m_bindings[KEY_UP] = m_bindings['P' - '@'] = sigc::mem_fun(*this, &ElementDownloadList::receive_prev);
m_bindings[KEY_DOWN] = m_bindings['N' - '@'] = sigc::mem_fun(*this, &ElementDownloadList::receive_next);