diff --git a/docs/manual.rst b/docs/manual.rst index 0526fb252..6898bd291 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -4346,6 +4346,7 @@ session_settings int max_metadata_size; bool smooth_connects; bool always_send_user_agent; + bool apply_ip_filter_to_trackers; }; ``version`` is automatically set to the libtorrent version you're using @@ -5191,6 +5192,11 @@ instead of attempting to connectin in batches, and timing them out in batches. will include a user-agent with every request, as opposed to just the first request in a connection. +``apply_ip_filter_to_trackers`` defaults to true. It determines whether the +IP filter applies to trackers as well as peers. If this is set to false, +trackers are exempt from the IP filter (if there is one). If no IP filter +is set, this setting is irrelevant. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index f73888a04..06f6ae3b1 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -265,6 +265,7 @@ namespace libtorrent , max_metadata_size(1024*1024) , smooth_connects(true) , always_send_user_agent(false) + , apply_ip_filter_to_trackers(true) {} // libtorrent version. Used for forward binary compatibility @@ -1055,6 +1056,10 @@ namespace libtorrent // always send user-agent bool always_send_user_agent; + + // if true, trackers will also be filtered by the IP + // filter, otherwise they are exempt + bool apply_ip_filter_to_trackers; }; #ifndef TORRENT_DISABLE_DHT diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index ffb43edb5..3a0621fe4 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -89,6 +89,7 @@ namespace libtorrent , key(0) , num_want(0) , send_stats(true) + , apply_ip_filter(true) {} enum @@ -123,6 +124,7 @@ namespace libtorrent std::string ipv4; address bind_ip; bool send_stats; + bool apply_ip_filter; }; struct TORRENT_EXPORT request_callback diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index c2065aef8..59cadc53d 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -255,6 +255,8 @@ namespace libtorrent void http_tracker_connection::on_filter(http_connection& c, std::list& endpoints) { + if (tracker_req().apply_ip_filter == false) return; + // remove endpoints that are filtered by the IP filter for (std::list::iterator i = endpoints.begin(); i != endpoints.end();) diff --git a/src/torrent.cpp b/src/torrent.cpp index a837f7133..2e18c8786 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1868,6 +1868,7 @@ namespace libtorrent e = tracker_request::paused; tracker_request req; + req.apply_ip_filter = m_apply_ip_filter && m_ses.m_settings.apply_ip_filter_to_trackers; req.info_hash = m_torrent_file->info_hash(); req.pid = m_ses.get_peer_id(); req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes; @@ -2027,6 +2028,7 @@ namespace libtorrent if (i == -1) i = 0; tracker_request req; + req.apply_ip_filter = m_apply_ip_filter && m_ses.m_settings.apply_ip_filter_to_trackers; req.info_hash = m_torrent_file->info_hash(); req.kind = tracker_request::scrape_request; req.url = m_trackers[i].url; diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index d04d9e2d2..f76d91ad4 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -163,21 +163,25 @@ namespace libtorrent std::transform(i, tcp::resolver::iterator(), std::back_inserter(m_endpoints) , boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1)); - // remove endpoints that are filtered by the IP filter - for (std::list::iterator k = m_endpoints.begin(); - k != m_endpoints.end();) + if (tracker_req().apply_ip_filter) { - if (m_ses.m_ip_filter.access(k->address()) == ip_filter::blocked) + // remove endpoints that are filtered by the IP filter + for (std::list::iterator k = m_endpoints.begin(); + k != m_endpoints.end();) { + if (m_ses.m_ip_filter.access(k->address()) == ip_filter::blocked) + { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING - if (cb) cb->debug_log("*** UDP_TRACKER [ IP blocked by filter: " + print_address(k->address()) + " ]"); + if (cb) cb->debug_log("*** UDP_TRACKER [ IP blocked by filter: " + print_address(k->address()) + " ]"); #endif - k = m_endpoints.erase(k); + k = m_endpoints.erase(k); + } + else + ++k; } - else - ++k; } + // if all endpoints were filtered by the IP filter, we can't connect if (m_endpoints.empty()) { fail(error_code(errors::banned_by_ip_filter));