fix ip filter exemption for trackers. also add a global setting to always exempt trackers
This commit is contained in:
parent
cefc97597d
commit
9d0b99480b
|
@ -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
|
||||
===========
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -255,6 +255,8 @@ namespace libtorrent
|
|||
|
||||
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
|
||||
for (std::list<tcp::endpoint>::iterator i = endpoints.begin();
|
||||
i != endpoints.end();)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<tcp::endpoint>::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<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 (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));
|
||||
|
|
Loading…
Reference in New Issue