From 81cf247cdafceb8d139630ec7b56e89fd8da6f58 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 24 Dec 2007 21:49:46 +0000 Subject: [PATCH] attempt to fix #212. Store 4 bytes and 16 bytes arrays instead of in_addr in ip-filter --- include/libtorrent/ip_filter.hpp | 37 ++++++++++++++++---------------- src/ip_filter.cpp | 12 +++++------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/libtorrent/ip_filter.hpp b/include/libtorrent/ip_filter.hpp index eee76cdc4..1adb14551 100644 --- a/include/libtorrent/ip_filter.hpp +++ b/include/libtorrent/ip_filter.hpp @@ -76,9 +76,9 @@ namespace detail template Addr zero() { - typename Addr::bytes_type zero; + Addr zero; std::fill(zero.begin(), zero.end(), 0); - return Addr(zero); + return zero; } template<> @@ -87,8 +87,8 @@ namespace detail template Addr plus_one(Addr const& a) { - typename Addr::bytes_type tmp(a.to_bytes()); - typedef typename Addr::bytes_type::reverse_iterator iter; + Addr tmp(a); + typedef typename Addr::reverse_iterator iter; for (iter i = tmp.rbegin() , end(tmp.rend()); i != end; ++i) { @@ -99,7 +99,7 @@ namespace detail } *i = 0; } - return Addr(tmp); + return tmp; } inline boost::uint16_t plus_one(boost::uint16_t val) { return val + 1; } @@ -107,8 +107,8 @@ namespace detail template Addr minus_one(Addr const& a) { - typename Addr::bytes_type tmp(a.to_bytes()); - typedef typename Addr::bytes_type::reverse_iterator iter; + Addr tmp(a); + typedef typename Addr::reverse_iterator iter; for (iter i = tmp.rbegin() , end(tmp.rend()); i != end; ++i) { @@ -119,7 +119,7 @@ namespace detail } *i = (std::numeric_limits::max)(); } - return Addr(tmp); + return tmp; } inline boost::uint16_t minus_one(boost::uint16_t val) { return val - 1; } @@ -127,9 +127,9 @@ namespace detail template Addr max_addr() { - typename Addr::bytes_type tmp; + Addr tmp; std::fill(tmp.begin(), tmp.end() - , (std::numeric_limits::max)()); + , (std::numeric_limits::max)()); return Addr(tmp); } @@ -220,23 +220,24 @@ namespace detail return i->access; } - std::vector > export_filter() const + template + std::vector > export_filter() const { - std::vector > ret; + std::vector > ret; ret.reserve(m_access_list.size()); for (typename range_t::const_iterator i = m_access_list.begin() , end(m_access_list.end()); i != end;) { - ip_range r; - r.first = i->start; + ip_range r; + r.first = ExternalAddressType(i->start); r.flags = i->access; ++i; if (i == end) - r.last = max_addr(); + r.last = ExternalAddressType(max_addr()); else - r.last = minus_one(i->start); + r.last = ExternalAddressType(minus_one(i->start)); ret.push_back(r); } @@ -288,8 +289,8 @@ public: private: - detail::filter_impl m_filter4; - detail::filter_impl m_filter6; + detail::filter_impl m_filter4; + detail::filter_impl m_filter6; }; class TORRENT_EXPORT port_filter diff --git a/src/ip_filter.cpp b/src/ip_filter.cpp index 05334e578..eb91de0d0 100644 --- a/src/ip_filter.cpp +++ b/src/ip_filter.cpp @@ -44,12 +44,12 @@ namespace libtorrent if (first.is_v4()) { TORRENT_ASSERT(last.is_v4()); - m_filter4.add_rule(first.to_v4(), last.to_v4(), flags); + m_filter4.add_rule(first.to_v4().to_bytes(), last.to_v4().to_bytes(), flags); } else if (first.is_v6()) { TORRENT_ASSERT(last.is_v6()); - m_filter6.add_rule(first.to_v6(), last.to_v6(), flags); + m_filter6.add_rule(first.to_v6().to_bytes(), last.to_v6().to_bytes(), flags); } else TORRENT_ASSERT(false); @@ -58,15 +58,15 @@ namespace libtorrent int ip_filter::access(address const& addr) const { if (addr.is_v4()) - return m_filter4.access(addr.to_v4()); + return m_filter4.access(addr.to_v4().to_bytes()); TORRENT_ASSERT(addr.is_v6()); - return m_filter6.access(addr.to_v6()); + return m_filter6.access(addr.to_v6().to_bytes()); } ip_filter::filter_tuple_t ip_filter::export_filter() const { - return boost::make_tuple(m_filter4.export_filter() - , m_filter6.export_filter()); + return boost::make_tuple(m_filter4.export_filter() + , m_filter6.export_filter()); } void port_filter::add_rule(boost::uint16_t first, boost::uint16_t last, int flags)