mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-06 10:12:30 +00:00
Merge branch 'master' into xirvik
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
\section(IP filtering}
|
||||
|
||||
\subsection{Introduction}
|
||||
|
||||
\subsection{Make a new ip table}
|
||||
|
||||
\begin{verbatim}
|
||||
ip_tables.insert_table = <table_name>
|
||||
\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 = <table_name>, 10.0.0.0/8, <value>
|
||||
\end{verbatim}
|
||||
|
||||
Set <value> for all addresses in the address block, overwriting prior
|
||||
values.
|
||||
|
||||
|
||||
\subsection{Add a new address block}
|
||||
|
||||
\begin{verbatim}
|
||||
ip_tables.load = <table_name>, ~/foo.txt, <value>
|
||||
\end{verbatim}
|
||||
|
||||
Set <value> 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 = <table_name>, 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 = <table_name>
|
||||
\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.
|
||||
+14
-14
@@ -3,10 +3,10 @@
|
||||
AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((constructor))],
|
||||
[cc_cv_attribute_constructor],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void ctor() __attribute__((constructor));
|
||||
void ctor() { };
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_constructor=yes],
|
||||
[cc_cv_attribute_constructor=no])
|
||||
])
|
||||
@@ -23,9 +23,9 @@ AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
|
||||
AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((format(printf, n, n)))],
|
||||
[cc_cv_attribute_format],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { }
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_format=yes],
|
||||
[cc_cv_attribute_format=no])
|
||||
])
|
||||
@@ -42,9 +42,9 @@ AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
|
||||
AC_DEFUN([CC_ATTRIBUTE_INTERNAL], [
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((visibility("internal")))],
|
||||
[cc_cv_attribute_internal],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void __attribute__((visibility("internal"))) internal_function() { }
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_internal=yes],
|
||||
[cc_cv_attribute_internal=no])
|
||||
])
|
||||
@@ -66,9 +66,9 @@ AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
|
||||
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((visibility("default")))],
|
||||
[cc_cv_attribute_visibility],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void __attribute__((visibility("default"))) visibility_function() { }
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_visibility=yes],
|
||||
[cc_cv_attribute_visibility=no])
|
||||
])
|
||||
@@ -90,10 +90,10 @@ AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
|
||||
AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((nonnull()))],
|
||||
[cc_cv_attribute_nonnull],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void some_function(void *foo, void *bar) __attribute__((nonnull()));
|
||||
void some_function(void *foo, void *bar) { }
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_nonnull=yes],
|
||||
[cc_cv_attribute_nonnull=no])
|
||||
])
|
||||
@@ -110,9 +110,9 @@ AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
|
||||
AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
|
||||
AC_CACHE_CHECK([if compiler supports __attribute__((unused))],
|
||||
[cc_cv_attribute_unused],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void some_function(void *foo, __attribute__((unused)) void *bar);
|
||||
],
|
||||
])],
|
||||
[cc_cv_attribute_unused=yes],
|
||||
[cc_cv_attribute_unused=no])
|
||||
])
|
||||
@@ -129,13 +129,13 @@ AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
|
||||
AC_DEFUN([CC_FUNC_EXPECT], [
|
||||
AC_CACHE_CHECK([if compiler has __builtin_expect function],
|
||||
[cc_cv_func_expect],
|
||||
[AC_COMPILE_IFELSE([
|
||||
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
int some_function()
|
||||
{
|
||||
int a = 3;
|
||||
return (int)__builtin_expect(a, 3);
|
||||
}
|
||||
],
|
||||
])],
|
||||
[cc_cv_func_expect=yes],
|
||||
[cc_cv_func_expect=no])
|
||||
])
|
||||
|
||||
+18
-18
@@ -1,15 +1,15 @@
|
||||
AC_DEFUN([TORRENT_CHECK_XFS], [
|
||||
AC_MSG_CHECKING(for XFS support)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <xfs/libxfs.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <xfs/libxfs.h>
|
||||
#include <sys/ioctl.h>
|
||||
int main() {
|
||||
struct xfs_flock64 l;
|
||||
ioctl(0, XFS_IOC_RESVSP64, &l);
|
||||
return 0;
|
||||
}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_DEFINE(USE_XFS, 1, Use XFS filesystem stuff.)
|
||||
AC_MSG_RESULT(yes)
|
||||
@@ -46,13 +46,13 @@ AC_DEFUN([TORRENT_WITH_XFS], [
|
||||
AC_DEFUN([TORRENT_CHECK_EPOLL], [
|
||||
AC_MSG_CHECKING(for epoll support)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <sys/epoll.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/epoll.h>
|
||||
int main() {
|
||||
int fd = epoll_create(100);
|
||||
return 0;
|
||||
}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_DEFINE(USE_EPOLL, 1, Use epoll.)
|
||||
AC_MSG_RESULT(yes)
|
||||
@@ -77,14 +77,14 @@ AC_DEFUN([TORRENT_WITHOUT_EPOLL], [
|
||||
AC_DEFUN([TORRENT_CHECK_KQUEUE], [
|
||||
AC_MSG_CHECKING(for kqueue support)
|
||||
|
||||
AC_LINK_IFELSE(
|
||||
[[#include <sys/time.h> /* Because OpenBSD's sys/event.h fails to compile otherwise. Yeah... */
|
||||
AC_LINK_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/time.h> /* Because OpenBSD's sys/event.h fails to compile otherwise. Yeah... */
|
||||
#include <sys/event.h>
|
||||
int main() {
|
||||
int fd = kqueue();
|
||||
return 0;
|
||||
}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_DEFINE(USE_KQUEUE, 1, Use kqueue.)
|
||||
AC_MSG_RESULT(yes)
|
||||
@@ -96,8 +96,8 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE], [
|
||||
AC_DEFUN([TORRENT_CHECK_KQUEUE_SOCKET_ONLY], [
|
||||
AC_MSG_CHECKING(whether kqueue supports pipes and ptys)
|
||||
|
||||
AC_RUN_IFELSE(
|
||||
[[#include <fcntl.h>
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/event.h>
|
||||
@@ -122,7 +122,7 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE_SOCKET_ONLY], [
|
||||
if ((n = kevent(kfd, NULL, 0, ev_out, 2, &ts)) < 1) return 9;
|
||||
return 0;
|
||||
}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
@@ -364,11 +364,11 @@ AC_DEFUN([TORRENT_CHECK_TR1], [
|
||||
AC_LANG_PUSH(C++)
|
||||
AC_MSG_CHECKING(for TR1 support)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <tr1/unordered_map>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <tr1/unordered_map>
|
||||
class Foo;
|
||||
typedef std::tr1::unordered_map<Foo*, int> Bar;
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_TR1, 1, Define to 1 if your C++ library supports the extensions from Technical Report 1)
|
||||
@@ -385,14 +385,14 @@ AC_DEFUN([TORRENT_CHECK_CXX11], [
|
||||
AC_LANG_PUSH(C++)
|
||||
AC_MSG_CHECKING(for C++11 support)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <functional>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
class Foo;
|
||||
typedef std::unordered_map<Foo*, int> Bar;
|
||||
|
||||
union test { Bar b1; };
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_CXX11, 1, Define to 1 if your C++ compiler has support for C++11.)
|
||||
|
||||
+23
-24
@@ -99,11 +99,11 @@ AC_DEFUN([TORRENT_OTFD], [
|
||||
AC_LANG_PUSH(C++)
|
||||
AC_MSG_CHECKING(for proper overloaded template function disambiguation)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[template <typename T> void f(T&) {}
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
template <typename T> void f(T&) {}
|
||||
template <typename T> void f(T*) {}
|
||||
int main() { int *i = 0; f(*i); f(i); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
@@ -119,24 +119,24 @@ AC_DEFUN([TORRENT_MINCORE_SIGNEDNESS], [
|
||||
AC_LANG_PUSH(C++)
|
||||
AC_MSG_CHECKING(signedness of mincore parameter)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <sys/types.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
void f() { mincore((char*)0, 0, (unsigned char*)0); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_DEFINE(USE_MINCORE, 1, Use mincore)
|
||||
AC_DEFINE(USE_MINCORE_UNSIGNED, 1, use unsigned char* in mincore)
|
||||
AC_MSG_RESULT(unsigned)
|
||||
],
|
||||
[
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <sys/types.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
void f() { mincore((char*)0, 0, (char*)0); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_DEFINE(USE_MINCORE, 1, Use mincore)
|
||||
AC_DEFINE(USE_MINCORE_UNSIGNED, 0, use char* in mincore)
|
||||
@@ -168,11 +168,11 @@ AC_DEFUN([TORRENT_MINCORE], [
|
||||
AC_DEFUN([TORRENT_CHECK_MADVISE], [
|
||||
AC_MSG_CHECKING(for madvise)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <sys/types.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
void f() { static char test[1024]; madvise((void *)test, sizeof(test), MADV_NORMAL); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(USE_MADVISE, 1, Use madvise)
|
||||
@@ -184,10 +184,9 @@ AC_DEFUN([TORRENT_CHECK_MADVISE], [
|
||||
AC_DEFUN([TORRENT_CHECK_POPCOUNT], [
|
||||
AC_MSG_CHECKING(for __builtin_popcount)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
void f() { __builtin_popcount(0); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(USE_BUILTIN_POPCOUNT, 1, Use __builtin_popcount.)
|
||||
@@ -199,12 +198,12 @@ AC_DEFUN([TORRENT_CHECK_POPCOUNT], [
|
||||
AC_DEFUN([TORRENT_CHECK_CACHELINE], [
|
||||
AC_MSG_CHECKING(for cacheline)
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[[#include <stdlib.h>
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <stdlib.h>
|
||||
#include <linux/cache.h>
|
||||
void* vptr __cacheline_aligned;
|
||||
void f() { posix_memalign(&vptr, SMP_CACHE_BYTES, 42); }
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(found builtin)
|
||||
dnl AC_DEFINE(LT_SMP_CACHE_BYTES, SMP_CACHE_BYTES, Largest L1 cache size we know of, should work on all archs.)
|
||||
@@ -224,10 +223,10 @@ dnl Need to fix this so that it uses the stuff defined by the system.
|
||||
AC_DEFUN([TORRENT_CHECK_EXECINFO], [
|
||||
AC_MSG_CHECKING(for execinfo.h)
|
||||
|
||||
AC_RUN_IFELSE(
|
||||
[[#include <execinfo.h>
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([
|
||||
#include <execinfo.h>
|
||||
int main() { backtrace((void**)0, 0); backtrace_symbols((char**)0, 0); return 0;}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(USE_EXECINFO, 1, Use execinfo.h)
|
||||
@@ -239,8 +238,8 @@ AC_DEFUN([TORRENT_CHECK_EXECINFO], [
|
||||
AC_DEFUN([TORRENT_CHECK_ALIGNED], [
|
||||
AC_MSG_CHECKING(the byte alignment)
|
||||
|
||||
AC_RUN_IFELSE(
|
||||
[[#include <inttypes.h>
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([
|
||||
#include <inttypes.h>
|
||||
int main() {
|
||||
char buf[8] = { 0, 0, 0, 0, 1, 0, 0, 0 };
|
||||
int i;
|
||||
@@ -248,7 +247,7 @@ AC_DEFUN([TORRENT_CHECK_ALIGNED], [
|
||||
if (*(uint32_t*)(buf + i) == 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
]],
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(none needed)
|
||||
], [
|
||||
|
||||
@@ -34,8 +34,6 @@ libsub_root_a_SOURCES = \
|
||||
signal_handler.h \
|
||||
thread_base.cc \
|
||||
thread_base.h \
|
||||
thread_main.cc \
|
||||
thread_main.h \
|
||||
thread_worker.cc \
|
||||
thread_worker.h
|
||||
|
||||
|
||||
+26
-10
@@ -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)
|
||||
@@ -187,12 +197,14 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) {
|
||||
if (args.size() != 2)
|
||||
throw torrent::input_error("Incorrect number of arguments.");
|
||||
|
||||
std::fstream file(rak::path_expand(args.front().as_string()).c_str(), std::ios::in);
|
||||
std::string filename = args.front().as_string();
|
||||
std::string value_name = args.back().as_string();
|
||||
int value = torrent::option_find_string(torrent::OPTION_IP_FILTER, value_name.c_str());
|
||||
|
||||
std::fstream file(rak::path_expand(filename).c_str(), std::ios::in);
|
||||
|
||||
if (!file.is_open())
|
||||
throw torrent::input_error("Could not open ip filter file: " + args.front().as_string());
|
||||
|
||||
int value = torrent::option_find_string(torrent::OPTION_IP_FILTER, args.back().as_string().c_str());
|
||||
throw torrent::input_error("Could not open ip filter file: " + filename);
|
||||
|
||||
char buffer[4096];
|
||||
unsigned int lineNumber = 0;
|
||||
@@ -218,25 +230,29 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) {
|
||||
}
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
snprintf(buffer, 2048, "Error in ip filter file: %s:%u: %s", args.front().as_string().c_str(), lineNumber, e.what());
|
||||
snprintf(buffer, 2048, "Error in ip filter file: %s:%u: %s", filename.c_str(), lineNumber, e.what());
|
||||
|
||||
throw torrent::input_error(buffer);
|
||||
}
|
||||
|
||||
lt_log_print(torrent::LOG_CONNECTION_INFO, "Loaded %u %s address blocks (%u kb in-memory) from '%s'.",
|
||||
lineNumber,
|
||||
args.back().as_string().c_str(),
|
||||
value_name.c_str(),
|
||||
torrent::PeerList::ipv4_filter()->sizeof_data() / 1024,
|
||||
args.front().as_string().c_str());
|
||||
filename.c_str());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
void
|
||||
initialize_command_ip() {
|
||||
CMD2_ANY_STRING ("ip_tables.insert_table", std::bind(&apply_ip_tables_insert_table, 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));
|
||||
CMD2_ANY ("strings.ip_filter", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_FILTER));
|
||||
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));
|
||||
|
||||
CMD2_ANY ("ipv4_filter.size_data", std::bind(&apply_ipv4_filter_size_data));
|
||||
CMD2_ANY_STRING ("ipv4_filter.get", std::bind(&apply_ipv4_filter_get, std::placeholders::_2));
|
||||
|
||||
@@ -238,8 +238,6 @@ initialize_command_network() {
|
||||
|
||||
CMD2_ANY ("strings.connection_type", std::bind(&torrent::option_list_strings, torrent::OPTION_CONNECTION_TYPE));
|
||||
CMD2_ANY ("strings.encryption", std::bind(&torrent::option_list_strings, torrent::OPTION_ENCRYPTION));
|
||||
CMD2_ANY ("strings.ip_filter", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_FILTER));
|
||||
CMD2_ANY ("strings.ip_tos", std::bind(&torrent::option_list_strings, torrent::OPTION_IP_TOS));
|
||||
|
||||
CMD2_VAR_BOOL ("log.handshake", false);
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ Control::initialize() {
|
||||
|
||||
m_ui->init(this);
|
||||
|
||||
m_inputStdin->insert(main_thread->poll());
|
||||
m_inputStdin->insert(torrent::main_thread()->poll());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -124,7 +124,7 @@ Control::cleanup() {
|
||||
|
||||
priority_queue_erase(&taskScheduler, &m_taskShutdown);
|
||||
|
||||
m_inputStdin->remove(main_thread->poll());
|
||||
m_inputStdin->remove(torrent::main_thread()->poll());
|
||||
|
||||
m_core->download_store()->disable();
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <torrent/poll.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/utils/thread_base.h>
|
||||
|
||||
#include "control.h"
|
||||
|
||||
@@ -69,22 +70,22 @@ CurlSocket::receive_socket(void* easy_handle, curl_socket_t fd, int what, void*
|
||||
|
||||
if (socket == NULL) {
|
||||
socket = stack->new_socket(fd);
|
||||
main_thread->poll()->open(socket);
|
||||
torrent::main_thread()->poll()->open(socket);
|
||||
|
||||
// No interface for libcurl to signal when it's interested in error events.
|
||||
// Assume that hence it must always be interested in them.
|
||||
main_thread->poll()->insert_error(socket);
|
||||
torrent::main_thread()->poll()->insert_error(socket);
|
||||
}
|
||||
|
||||
if (what == CURL_POLL_NONE || what == CURL_POLL_OUT)
|
||||
main_thread->poll()->remove_read(socket);
|
||||
torrent::main_thread()->poll()->remove_read(socket);
|
||||
else
|
||||
main_thread->poll()->insert_read(socket);
|
||||
torrent::main_thread()->poll()->insert_read(socket);
|
||||
|
||||
if (what == CURL_POLL_NONE || what == CURL_POLL_IN)
|
||||
main_thread->poll()->remove_write(socket);
|
||||
torrent::main_thread()->poll()->remove_write(socket);
|
||||
else
|
||||
main_thread->poll()->insert_write(socket);
|
||||
torrent::main_thread()->poll()->insert_write(socket);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -99,7 +100,7 @@ CurlSocket::close() {
|
||||
if (m_fileDesc == -1)
|
||||
throw torrent::internal_error("CurlSocket::close() m_fileDesc == -1.");
|
||||
|
||||
main_thread->poll()->closed(this);
|
||||
torrent::main_thread()->poll()->closed(this);
|
||||
m_fileDesc = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,7 +429,7 @@ void
|
||||
DownloadList::pause(Download* download, int flags) {
|
||||
check_contains(download);
|
||||
|
||||
lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "->download_list: Pausing download: flags%0x.", flags);
|
||||
lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "->download_list: Pausing download: flags:%0x.", flags);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
@@ -43,6 +43,4 @@ rak::timer cachedTime;
|
||||
rpc::ip_table_list ip_tables;
|
||||
|
||||
Control* control = NULL;
|
||||
//__thread ThreadBase* main_thread = NULL;
|
||||
ThreadMain* main_thread = NULL;
|
||||
ThreadWorker* worker_thread = NULL;
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
#include <rak/priority_queue_default.h>
|
||||
|
||||
#include "thread_base.h"
|
||||
#include "thread_main.h"
|
||||
#include "thread_worker.h"
|
||||
#include "rpc/ip_table_list.h"
|
||||
|
||||
@@ -57,8 +56,6 @@ 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.
|
||||
extern ThreadMain* main_thread;
|
||||
extern ThreadWorker* worker_thread;
|
||||
|
||||
#endif
|
||||
|
||||
+24
-21
@@ -77,7 +77,6 @@
|
||||
#include "signal_handler.h"
|
||||
#include "option_parser.h"
|
||||
|
||||
#include "thread_main.h"
|
||||
#include "thread_worker.h"
|
||||
|
||||
void handle_sigbus(int signum, siginfo_t* sa, void* ptr);
|
||||
@@ -150,14 +149,29 @@ load_arg_torrents(Control* c, char** first, char** last) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline rak::timer
|
||||
static uint64_t
|
||||
client_next_timeout(Control* c) {
|
||||
if (taskScheduler.empty())
|
||||
return c->is_shutdown_started() ? rak::timer::from_milliseconds(100) : rak::timer::from_seconds(60);
|
||||
return (c->is_shutdown_started() ? rak::timer::from_milliseconds(100) : rak::timer::from_seconds(60)).usec();
|
||||
else if (taskScheduler.top()->time() <= cachedTime)
|
||||
return 0;
|
||||
else
|
||||
return taskScheduler.top()->time() - cachedTime;
|
||||
return (taskScheduler.top()->time() - cachedTime).usec();
|
||||
}
|
||||
|
||||
static void
|
||||
client_perform() {
|
||||
// Use throw exclusively.
|
||||
if (control->is_shutdown_completed())
|
||||
throw torrent::shutdown_exception();
|
||||
|
||||
if (control->is_shutdown_received())
|
||||
control->handle_shutdown();
|
||||
|
||||
control->inc_tick();
|
||||
|
||||
cachedTime = rak::timer::current();
|
||||
rak::priority_queue_perform(&taskScheduler, cachedTime);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -171,9 +185,6 @@ main(int argc, char** argv) {
|
||||
|
||||
control = new Control;
|
||||
|
||||
main_thread = new ThreadMain();
|
||||
main_thread->init_thread();
|
||||
|
||||
worker_thread = new ThreadWorker();
|
||||
worker_thread->init_thread();
|
||||
|
||||
@@ -195,7 +206,11 @@ main(int argc, char** argv) {
|
||||
SignalHandler::set_handler(SIGUSR1, sigc::ptr_fun(&do_nothing));
|
||||
|
||||
torrent::Poll::slot_create_poll() = std::tr1::bind(&core::create_poll);
|
||||
torrent::initialize(main_thread->poll());
|
||||
torrent::initialize();
|
||||
|
||||
torrent::main_thread()->init_thread();
|
||||
torrent::main_thread()->slot_do_work() = tr1::bind(&client_perform);
|
||||
torrent::main_thread()->slot_next_timeout() = tr1::bind(&client_next_timeout, control);
|
||||
|
||||
// Initialize option handlers after libtorrent to ensure
|
||||
// torrent::ConnectionManager* are valid etc.
|
||||
@@ -856,18 +871,7 @@ main(int argc, char** argv) {
|
||||
|
||||
worker_thread->start_thread();
|
||||
|
||||
while (!control->is_shutdown_completed()) {
|
||||
if (control->is_shutdown_received())
|
||||
control->handle_shutdown();
|
||||
|
||||
control->inc_tick();
|
||||
|
||||
cachedTime = rak::timer::current();
|
||||
rak::priority_queue_perform(&taskScheduler, cachedTime);
|
||||
|
||||
// Do shutdown check before poll, not after.
|
||||
main_thread->poll()->do_poll(client_next_timeout(control).usec());
|
||||
}
|
||||
torrent::thread_base::event_loop(torrent::main_thread());
|
||||
|
||||
control->core()->download_list()->session_save();
|
||||
control->cleanup();
|
||||
@@ -883,7 +887,6 @@ main(int argc, char** argv) {
|
||||
|
||||
delete control;
|
||||
delete worker_thread;
|
||||
delete main_thread;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+2
-1
@@ -46,6 +46,7 @@
|
||||
#include <unistd.h>
|
||||
#include <rak/error_number.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
#include "globals.h"
|
||||
@@ -167,7 +168,7 @@ ThreadBase::interrupt_main_polling() {
|
||||
int sleep_length = 0;
|
||||
|
||||
while (ThreadBase::is_main_polling()) {
|
||||
pthread_kill(main_thread->m_thread, SIGUSR1);
|
||||
pthread_kill(torrent::main_thread()->pthread(), SIGUSR1);
|
||||
|
||||
if (!ThreadBase::is_main_polling())
|
||||
return;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// rTorrent - BitTorrent library
|
||||
// Copyright (C) 2005-2011, 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
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "thread_main.h"
|
||||
#include "globals.h"
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/poll.h>
|
||||
|
||||
ThreadMain::~ThreadMain() {
|
||||
}
|
||||
|
||||
void
|
||||
ThreadMain::init_thread() {
|
||||
// The main thread always holds the lock while running.
|
||||
acquire_global_lock();
|
||||
|
||||
m_poll = core::create_poll();
|
||||
m_poll->set_flags(torrent::Poll::flag_waive_global_lock);
|
||||
|
||||
m_state = STATE_INITIALIZED;
|
||||
m_thread = pthread_self();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// rTorrent - BitTorrent library
|
||||
// Copyright (C) 2005-2011, 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_THREAD_MAIN_H
|
||||
#define RTORRENT_THREAD_MAIN_H
|
||||
|
||||
#include "thread_base.h"
|
||||
|
||||
// Check if cacheline aligned with inheritance ends up taking two
|
||||
// cachelines.
|
||||
|
||||
class lt_cacheline_aligned ThreadMain : public ThreadBase {
|
||||
public:
|
||||
ThreadMain() {}
|
||||
~ThreadMain();
|
||||
|
||||
virtual void init_thread();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
ThreadWorker();
|
||||
~ThreadWorker();
|
||||
|
||||
const char* name() const { return "worker_rtorrent"; }
|
||||
|
||||
virtual void init_thread();
|
||||
|
||||
rpc::SCgi* scgi() { return m_safe.scgi; }
|
||||
|
||||
Reference in New Issue
Block a user