fix to IP filter exemptions

This commit is contained in:
Arvid Norberg 2011-03-02 17:37:10 +00:00
parent 209bee16bf
commit 0aff6803fb
4 changed files with 23 additions and 2 deletions

View File

@ -980,6 +980,10 @@ namespace libtorrent
std::vector<boost::shared_ptr<feed> > m_feeds;
// the number of torrents that have apply_ip_filter
// set to false. This is typically 0
int m_non_filtered_torrents;
// the main working thread
boost::scoped_ptr<thread> m_thread;

View File

@ -1197,7 +1197,8 @@ namespace libtorrent
}
// if the IP is blocked, don't add it
if (ses.m_ip_filter.access(remote.address()) & ip_filter::blocked)
if (m_torrent->apply_ip_filter()
&& (ses.m_ip_filter.access(remote.address()) & ip_filter::blocked))
{
if (ses.m_alerts.should_post<peer_blocked_alert>())
ses.m_alerts.post_alert(peer_blocked_alert(m_torrent->get_handle(), remote.address()));

View File

@ -536,6 +536,7 @@ namespace aux {
#endif
, m_total_failed_bytes(0)
, m_total_redundant_bytes(0)
, m_non_filtered_torrents(0)
#if defined TORRENT_DEBUG && defined BOOST_HAS_PTHREADS
, m_network_thread(0)
#endif
@ -2178,7 +2179,11 @@ namespace aux {
if (!is_local(endp.address()))
m_incoming_connection = true;
if (m_ip_filter.access(endp.address()) & ip_filter::blocked)
// this filter is ignored if a single torrent
// is set to ignore the filter, since this peer might be
// for that torrent
if (m_non_filtered_torrents > 0
&& (m_ip_filter.access(endp.address()) & ip_filter::blocked))
{
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_logger) << "filtered blocked ip\n";

View File

@ -408,6 +408,8 @@ namespace libtorrent
, m_magnet_link(false)
, m_apply_ip_filter(p.apply_ip_filter)
{
if (!m_apply_ip_filter) ++m_ses.m_non_filtered_torrents;
if (!p.ti || !p.ti->is_valid())
{
// we don't have metadata for this torrent. We'll download
@ -790,6 +792,15 @@ namespace libtorrent
void torrent::set_apply_ip_filter(bool b)
{
if (b == m_apply_ip_filter) return;
if (b)
{
TORRENT_ASSERT(m_ses.m_non_filtered_torrents > 0);
--m_ses.m_non_filtered_torrents;
}
else
{
++m_ses.m_non_filtered_torrents;
}
m_apply_ip_filter = b;
m_policy.ip_filter_updated();
}