From c15880be91e2890728659b7b88d64cfea4bb02bb Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 27 Feb 2011 17:26:57 +0000 Subject: [PATCH] support having torrents that the IP filter doesn't apply to --- docs/manual.rst | 16 ++++++++++++++++ include/libtorrent/add_torrent_params.hpp | 2 ++ include/libtorrent/torrent.hpp | 7 +++++++ include/libtorrent/torrent_handle.hpp | 7 +++++++ src/policy.cpp | 1 + src/torrent.cpp | 21 +++++++++++++++++---- src/torrent_handle.cpp | 6 ++++++ 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 43f737239..b276fcd1a 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2194,6 +2194,8 @@ Its declaration looks like this:: void set_upload_mode(bool m) const; void set_share_mode(bool m) const; + void apply_ip_filter(bool b) const; + void flush_cache() const; void resolve_countries(bool r); @@ -2705,6 +2707,16 @@ not necessarily be downloaded, especially not the whole of it. Only parts that a to be distributed to more than 2 other peers are downloaded, and only if the previous prediction was correct. +apply_ip_filter() +----------------- + +:: + + void apply_ip_filter(bool b) const; + +Set to true to apply the session global IP filter to this torrent (which is the +default). Set to false to make this torrent ignore the IP filter. + resolve_countries() ------------------- @@ -3304,6 +3316,7 @@ It contains the following fields:: int queue_position; bool need_save_resume; + bool ip_filter_applies; }; ``handle`` is a handle to the torrent whose status the object represents. @@ -3574,6 +3587,9 @@ queue. If the torrent is a seed or finished, this is -1. to its download state and statistics since the last resume data was saved. +``ip_filter_applies`` is true if the session global IP filter applies +to this torrent. This defaults to true. + peer_info ========= diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index cc63722c0..bb12d9432 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -63,6 +63,7 @@ namespace libtorrent , upload_mode(false) , file_priorities(0) , share_mode(false) + , apply_ip_filter(true) {} // libtorrent version. Used for forward binary compatibility @@ -88,6 +89,7 @@ namespace libtorrent std::string url; std::string uuid; std::string source_feed_url; + bool apply_ip_filter; }; } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index e758d82ac..76c12787b 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -823,6 +823,9 @@ namespace libtorrent void update_last_upload() { m_last_upload = 0; } + void set_apply_ip_filter(bool b); + bool apply_ip_filter() const { return m_apply_ip_filter; } + private: void on_files_deleted(int ret, disk_io_job const& j); @@ -1300,6 +1303,10 @@ namespace libtorrent // by default for such torrents. It does not necessarily // have to be a magnet link. bool m_magnet_link:1; + + // set to true if the session IP filter applies to this + // torrent or not. Defaults to true. + bool m_apply_ip_filter:1; }; } diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 018e286a8..6288c4471 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -228,6 +228,8 @@ namespace libtorrent void set_share_mode(bool b) const; void flush_cache() const; + void apply_ip_filter(bool b) const; + void force_recheck() const; enum save_resume_flags_t { flush_disk_cache = 1, save_info_dict = 2 }; @@ -475,6 +477,7 @@ namespace libtorrent , time_since_download(0) , queue_position(0) , need_save_resume(false) + , ip_filter_applies(true) {} // handle to the torrent @@ -683,6 +686,10 @@ namespace libtorrent // true if this torrent has had changes since the last // time resume data was saved bool need_save_resume; + + // defaults to true. Determines whether the session + // IP filter applies to this torrent or not + bool ip_filter_applies; }; } diff --git a/src/policy.cpp b/src/policy.cpp index ae2d302f8..b4fd59d52 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -347,6 +347,7 @@ namespace libtorrent INVARIANT_CHECK; aux::session_impl& ses = m_torrent->session(); + if (!m_torrent->apply_ip_filter()) return; for (iterator i = m_peers.begin(); i != m_peers.end();) { diff --git a/src/torrent.cpp b/src/torrent.cpp index d855f17ed..eeb86f965 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -406,6 +406,7 @@ namespace libtorrent , m_need_connect_boost(true) , m_lsd_seq(0) , m_magnet_link(false) + , m_apply_ip_filter(p.apply_ip_filter) { if (!p.ti || !p.ti->is_valid()) { @@ -786,6 +787,13 @@ namespace libtorrent set_state(torrent_status::downloading_metadata); } + void torrent::set_apply_ip_filter(bool b) + { + if (b == m_apply_ip_filter) return; + m_apply_ip_filter = b; + m_policy.ip_filter_updated(); + } + #ifndef TORRENT_DISABLE_DHT bool torrent::should_announce_dht() const { @@ -2293,7 +2301,8 @@ namespace libtorrent if (e || host == tcp::resolver::iterator() || m_ses.is_aborted()) return; - if (m_ses.m_ip_filter.access(host->endpoint().address()) & ip_filter::blocked) + if (m_apply_ip_filter + && m_ses.m_ip_filter.access(host->endpoint().address()) & ip_filter::blocked) { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING error_code ec; @@ -3937,7 +3946,8 @@ namespace libtorrent return; } - if (m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) + if (m_apply_ip_filter + && m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) { if (m_ses.m_alerts.should_post()) m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), a.address())); @@ -3986,7 +3996,8 @@ namespace libtorrent void torrent::connect_web_seed(std::list::iterator web, tcp::endpoint a) { TORRENT_ASSERT(m_ses.is_network_thread()); - if (m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) + if (m_apply_ip_filter + && m_ses.m_ip_filter.access(a.address()) & ip_filter::blocked) { if (m_ses.m_alerts.should_post()) m_ses.m_alerts.post_alert(peer_blocked_alert(get_handle(), a.address())); @@ -4822,7 +4833,8 @@ namespace libtorrent TORRENT_ASSERT(m_ses.num_connections() < m_ses.settings().connections_limit || ignore_limit); tcp::endpoint a(peerinfo->ip()); - TORRENT_ASSERT((m_ses.m_ip_filter.access(peerinfo->address()) & ip_filter::blocked) == 0); + TORRENT_ASSERT(!m_apply_ip_filter + || (m_ses.m_ip_filter.access(peerinfo->address()) & ip_filter::blocked) == 0); boost::shared_ptr s(new socket_type(m_ses.m_io_service)); @@ -7310,6 +7322,7 @@ namespace libtorrent st->queue_position = queue_position(); st->need_save_resume = need_save_resume_data(); + st->ip_filter_applies = m_apply_ip_filter; st->state = (torrent_status::state_t)m_state; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index c7d7e53a2..c1b50a747 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -351,6 +351,12 @@ namespace libtorrent TORRENT_ASYNC_CALL1(pause, bool(flags & graceful_pause)); } + void torrent_handle::apply_ip_filter(bool b) const + { + INVARIANT_CHECK; + TORRENT_ASYNC_CALL1(set_apply_ip_filter, b); + } + void torrent_handle::set_share_mode(bool b) const { INVARIANT_CHECK;