From 46320533012f6db6ec03555702d798a0d737c44b Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 11 Feb 2012 18:52:46 +0900 Subject: [PATCH] Added 'ip_tables.size_data'. --- doc/manual/ip_filtering.tex | 85 +++++++++++++++++++++++++++++++++++++ src/command_ip.cc | 11 +++++ 2 files changed, 96 insertions(+) create mode 100644 doc/manual/ip_filtering.tex diff --git a/doc/manual/ip_filtering.tex b/doc/manual/ip_filtering.tex new file mode 100644 index 00000000..976b31d2 --- /dev/null +++ b/doc/manual/ip_filtering.tex @@ -0,0 +1,85 @@ +\section(IP filtering} + +\subsection{Introduction} + +\subsection{Make a new ip table} + +\begin{verbatim} +ip_tables.insert_table = +\end{verbatim} + +Create a new empty table with the name 'table\_name', with the default +value returned being $0$. + +There is currently no use of the generic ip tables commands. + + +\subsection{Add a new address block} + +\begin{verbatim} +ip_tables.add_address = , 10.0.0.0/8, +\end{verbatim} + +Set for all addresses in the address block, overwriting prior +values. + + +\subsection{Add a new address block} + +\begin{verbatim} +ip_tables.load = , ~/foo.txt, +\end{verbatim} + +Set for all addresses in the file 'foo.txt' separated by +newline, similar to 'add\_address'. + + +\subsection{Get value for address} + +\begin{verbatim} +ip_tables.get = , 10.10.10.10 +\end{verbatim} + +Returns the value set for an address, or the address block it belongs +to. The default is $0$. + + +\subsection{Size of data structures} + +\begin{verbatim} +ip_tables.size_data = +\end{verbatim} + +Returns the size in bytes of all data structures for this table, +excluding the root class object itself. Note that the in-memory table +is dynamically consolidated, as such memory use will always be based +on actual fragmentation. + +The table is a b-tree with 1024 nodes per branch. + + +\subsection{IPv4 filtering table} + +\begin{verbatim} +ipv4_filter.add_address = 10.0.0.0/8, unwanted +ipv4_filter.add_address = 11.0.0.0/8, preferred +ipv4_filter.load = ~/filters.txt, unwanted +ipv4_filter.get = 10.10.10.10 +ipv4_filter.size_data = +\end{verbatim} + +The main ip filter, currently supporting 'unwanted' (do not allow +connections) and 'preferred' (currently used only in private code). + + + +\subsection{Constants} + +\begin{verbatim} +strings.ip_filter = +=> +{ "unwanted", PeerInfo::flag_unwanted }, +{ "preferred", PeerInfo::flag_preferred }, +\end{verbatim} + +Constants used by ipv4_filter values. diff --git a/src/command_ip.cc b/src/command_ip.cc index 55d065fc..3b066e08 100644 --- a/src/command_ip.cc +++ b/src/command_ip.cc @@ -88,6 +88,16 @@ apply_ip_tables_insert_table(const std::string& args) { return torrent::Object(); } +torrent::Object +apply_ip_tables_size_data(const std::string& args) { + rpc::ip_table_list::const_iterator itr = ip_tables.find(args); + + if (itr != ip_tables.end()) + throw torrent::input_error("IP table does not exist."); + + return itr->table.sizeof_data(); +} + torrent::Object apply_ip_tables_get(const torrent::Object::list_type& args) { if (args.size() != 2) @@ -238,6 +248,7 @@ initialize_command_ip() { CMD2_ANY ("strings.ip_tos", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_TOS)); CMD2_ANY_STRING ("ip_tables.insert_table", std::bind(&apply_ip_tables_insert_table, std::placeholders::_2)); + CMD2_ANY_STRING ("ip_tables.size_data", std::bind(&apply_ip_tables_size_data, std::placeholders::_2)); CMD2_ANY_LIST ("ip_tables.get", std::bind(&apply_ip_tables_get, std::placeholders::_2)); CMD2_ANY_LIST ("ip_tables.add_address", std::bind(&apply_ip_tables_add_address, std::placeholders::_2));