fix ip filter exemption for trackers. also add a global setting to always exempt trackers

This commit is contained in:
Arvid Norberg 2011-03-04 06:55:39 +00:00
parent cefc97597d
commit 9d0b99480b
6 changed files with 29 additions and 8 deletions

View File

@ -4346,6 +4346,7 @@ session_settings
int max_metadata_size; int max_metadata_size;
bool smooth_connects; bool smooth_connects;
bool always_send_user_agent; bool always_send_user_agent;
bool apply_ip_filter_to_trackers;
}; };
``version`` is automatically set to the libtorrent version you're using ``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 will include a user-agent with every request, as opposed to just the first
request in a connection. 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 pe_settings
=========== ===========

View File

@ -265,6 +265,7 @@ namespace libtorrent
, max_metadata_size(1024*1024) , max_metadata_size(1024*1024)
, smooth_connects(true) , smooth_connects(true)
, always_send_user_agent(false) , always_send_user_agent(false)
, apply_ip_filter_to_trackers(true)
{} {}
// libtorrent version. Used for forward binary compatibility // libtorrent version. Used for forward binary compatibility
@ -1055,6 +1056,10 @@ namespace libtorrent
// always send user-agent // always send user-agent
bool 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 #ifndef TORRENT_DISABLE_DHT

View File

@ -89,6 +89,7 @@ namespace libtorrent
, key(0) , key(0)
, num_want(0) , num_want(0)
, send_stats(true) , send_stats(true)
, apply_ip_filter(true)
{} {}
enum enum
@ -123,6 +124,7 @@ namespace libtorrent
std::string ipv4; std::string ipv4;
address bind_ip; address bind_ip;
bool send_stats; bool send_stats;
bool apply_ip_filter;
}; };
struct TORRENT_EXPORT request_callback struct TORRENT_EXPORT request_callback

View File

@ -255,6 +255,8 @@ namespace libtorrent
void http_tracker_connection::on_filter(http_connection& c, std::list<tcp::endpoint>& endpoints) void http_tracker_connection::on_filter(http_connection& c, std::list<tcp::endpoint>& endpoints)
{ {
if (tracker_req().apply_ip_filter == false) return;
// remove endpoints that are filtered by the IP filter // remove endpoints that are filtered by the IP filter
for (std::list<tcp::endpoint>::iterator i = endpoints.begin(); for (std::list<tcp::endpoint>::iterator i = endpoints.begin();
i != endpoints.end();) i != endpoints.end();)

View File

@ -1868,6 +1868,7 @@ namespace libtorrent
e = tracker_request::paused; e = tracker_request::paused;
tracker_request req; 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.info_hash = m_torrent_file->info_hash();
req.pid = m_ses.get_peer_id(); req.pid = m_ses.get_peer_id();
req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes; req.downloaded = m_stat.total_payload_download() - m_total_failed_bytes;
@ -2027,6 +2028,7 @@ namespace libtorrent
if (i == -1) i = 0; if (i == -1) i = 0;
tracker_request req; 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.info_hash = m_torrent_file->info_hash();
req.kind = tracker_request::scrape_request; req.kind = tracker_request::scrape_request;
req.url = m_trackers[i].url; req.url = m_trackers[i].url;

View File

@ -163,21 +163,25 @@ namespace libtorrent
std::transform(i, tcp::resolver::iterator(), std::back_inserter(m_endpoints) std::transform(i, tcp::resolver::iterator(), std::back_inserter(m_endpoints)
, boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1)); , boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1));
// remove endpoints that are filtered by the IP filter if (tracker_req().apply_ip_filter)
for (std::list<tcp::endpoint>::iterator k = m_endpoints.begin();
k != m_endpoints.end();)
{ {
if (m_ses.m_ip_filter.access(k->address()) == ip_filter::blocked) // remove endpoints that are filtered by the IP filter
for (std::list<tcp::endpoint>::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 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 #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()) if (m_endpoints.empty())
{ {
fail(error_code(errors::banned_by_ip_filter)); fail(error_code(errors::banned_by_ip_filter));