extensions
@@ -1655,6 +1656,15 @@ public:
ip_filter();
void add_rule(address first, address last, int flags);
int access(address const& addr) const;
+
+ struct ip_range
+ {
+ address first;
+ address last;
+ int flags;
+ };
+
+ std::vector<ip_range> export_filter() const;
};
@@ -1697,6 +1707,18 @@ can currently be 0 or ip_filter::
is O(log n), where n is the minimum number of non-overlapping ranges to describe
the current filter.
+
+
+
+
+std::vector<ip_range> export_filter() const;
+
+
+
This function will return the current state of the filter in the minimum number of
+ranges possible. They are sorted from ranges in low addresses to high addresses. Each
+entry in the returned vector is a range with the access control specified in its
+flags field.
+
diff --git a/docs/manual.rst b/docs/manual.rst
index 5ef67e478..dba1e2c36 100755
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -1636,6 +1636,15 @@ a single rule that allowes all addresses (0.0.0.0 - 255.255.255.255).
ip_filter();
void add_rule(address first, address last, int flags);
int access(address const& addr) const;
+
+ struct ip_range
+ {
+ address first;
+ address last;
+ int flags;
+ };
+
+ std::vector
export_filter() const;
};
@@ -1684,6 +1693,19 @@ is O(``log`` n), where n is the minimum number of non-overlapping ranges to desc
the current filter.
+export_filter()
+---------------
+
+ ::
+
+ std::vector export_filter() const;
+
+This function will return the current state of the filter in the minimum number of
+ranges possible. They are sorted from ranges in low addresses to high addresses. Each
+entry in the returned vector is a range with the access control specified in its
+``flags`` field.
+
+
big_number
==========
diff --git a/examples/client_test.cpp b/examples/client_test.cpp
index 36110be55..4fd00bab3 100755
--- a/examples/client_test.cpp
+++ b/examples/client_test.cpp
@@ -372,7 +372,7 @@ int main(int argc, char* argv[])
catch (invalid_encoding&) {}
catch (boost::filesystem::filesystem_error&) {}
- handles.push_back(ses.add_torrent(e, save_path, resume_data, true, 128 * 1024));
+ handles.push_back(ses.add_torrent(e, save_path, resume_data, true, 64 * 1024));
handles.back().set_max_connections(100);
handles.back().set_max_uploads(-1);
handles.back().set_ratio(1.02f);
diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp
index 99e0d2989..e68299976 100644
--- a/include/libtorrent/ip_filter.hpp
+++ b/include/libtorrent/ip_filter.hpp
@@ -1,6 +1,6 @@
/*
-Copyright (c) 2003, Arvid Norberg
+Copyright (c) 2005, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,17 @@ public:
ip_filter();
void add_rule(address first, address last, int flags);
int access(address const& addr) const;
- void print() const;
+
+ struct ip_range
+ {
+ address first;
+ address last;
+ int flags;
+ };
+
+ std::vector export_filter() const;
+
+// void print() const;
private:
struct range
diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp
index 65ab7baa4..df8b44422 100644
--- a/src/ip_filter.cpp
+++ b/src/ip_filter.cpp
@@ -1,6 +1,6 @@
/*
-Copyright (c) 2003, Arvid Norberg
+Copyright (c) 2005, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -59,14 +59,14 @@ namespace libtorrent
assert(j != i);
int first_access = i->access;
-
+/*
std::cout << "flags: " << flags << "\n";
std::cout << "first_access: " << first_access << "\n";
std::cout << "i->start: " << i->start.as_string() << "\n";
std::cout << "first: " << first.as_string() << "\n";
-
+*/
int last_access = last_access = prior(j)->access;
- std::cout << "last_access: " << last_access << "\n";
+// std::cout << "last_access: " << last_access << "\n";
if (i->start != first && first_access != flags)
{
@@ -77,20 +77,20 @@ namespace libtorrent
--i;
first_access = i->access;
}
-
+/*
std::cout << "distance(i, j): " << std::distance(i, j) << "\n";
std::cout << "size(): " << m_access_list.size() << "\n";
-
+*/
assert(!m_access_list.empty());
assert(i != m_access_list.end());
if (i != j)
m_access_list.erase(next(i), j);
-
+/*
std::cout << "size(): " << m_access_list.size() << "\n";
std::cout << "last: " << last.as_string() << "\n";
std::cout << "last.ip(): " << last.ip() << " " << 0xffffffff << "\n";
-
+*/
if (i->start == first)
{
// we can do this const-cast because we know that the new
@@ -107,7 +107,7 @@ namespace libtorrent
|| (j == m_access_list.end() && last.ip() != 0xffffffff))
{
assert(j == m_access_list.end() || last.ip() < j->start.ip() - 1);
- std::cout << " -- last_access: " << last_access << "\n";
+// std::cout << " -- last_access: " << last_access << "\n";
if (last_access != flags)
j = m_access_list.insert(j, range(address(last.ip() + 1, 0), last_access));
}
@@ -127,6 +127,32 @@ namespace libtorrent
return i->access;
}
+
+ std::vector ip_filter::export_filter() const
+ {
+ std::vector ret;
+ ret.reserve(m_access_list.size());
+
+ for (range_t::const_iterator i = m_access_list.begin()
+ , end(m_access_list.end()); i != end;)
+ {
+ ip_range r;
+ r.first = i->start;
+ assert(r.first.port == 0);
+ r.flags = i->access;
+
+ ++i;
+ if (i == end)
+ r.last = address(0xffffffff, 0);
+ else
+ r.last = address(i->start.ip() - 1, 0);
+
+ ret.push_back(r);
+ }
+ return ret;
+ }
+
+/*
void ip_filter::print() const
{
for (range_t::iterator i = m_access_list.begin(); i != m_access_list.end(); ++i)
@@ -134,6 +160,6 @@ namespace libtorrent
std::cout << i->start.as_string() << " " << i->access << "\n";
}
}
-
+*/
}
diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp
index 053018b3c..7298fbea2 100755
--- a/src/peer_connection.cpp
+++ b/src/peer_connection.cpp
@@ -926,8 +926,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time;
for (std::deque::iterator i = m_download_queue.begin();
- i != m_download_queue.end();
- ++i)
+ i != m_download_queue.end(); ++i)
{
if (i->piece_index == p.piece
&& i->block_index == p.start / m_torrent->block_size())
diff --git a/src/session.cpp b/src/session.cpp
index e8d2b4a2f..5f682e4eb 100755
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -600,8 +600,7 @@ namespace libtorrent { namespace detail
// disconnect the one we couldn't connect to
for (std::vector >::iterator i = error_clients.begin();
- i != error_clients.end();
- ++i)
+ i != error_clients.end(); ++i)
{
connection_map::iterator p = m_connections.find(*i);
if (p != m_connections.end())
@@ -909,6 +908,19 @@ namespace libtorrent
{
boost::mutex::scoped_lock l(m_impl.m_mutex);
m_impl.m_ip_filter = f;
+
+ // Close connections whose endpoint is filtered
+ // by the new ip-filter
+ for (detail::session_impl::connection_map::iterator i
+ = m_impl.m_connections.begin(); i != m_impl.m_connections.end();)
+ {
+ if (m_impl.m_ip_filter.access(i->first->sender())
+ & ip_filter::blocked)
+ {
+ m_impl.m_connections.erase(i++);
+ }
+ else ++i;
+ }
}
void session::set_peer_id(peer_id const& id)
diff --git a/src/torrent.cpp b/src/torrent.cpp
index 1ee7ae636..320fd20d1 100755
--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -677,7 +677,7 @@ namespace libtorrent
// the bitmask need to have exactly one bit for every file
// in the torrent
- assert(bitmask.size() == m_torrent_file.num_files());
+ assert((int)bitmask.size() == m_torrent_file.num_files());
size_type position = 0;