merger RC_1_1 into master

This commit is contained in:
arvidn 2017-12-23 17:42:01 +01:00
commit 753826cbb8
10 changed files with 78 additions and 7 deletions

View File

@ -82,6 +82,7 @@
* resume data no longer has timestamps of files * resume data no longer has timestamps of files
* require C++11 to build libtorrent * require C++11 to build libtorrent
* add getters for peer_class_filter and peer_class_type_filter
* make torrent_handler::set_priority() to use peer_classes * make torrent_handler::set_priority() to use peer_classes
* fix support for boost-1.66 (requires C++11) * fix support for boost-1.66 (requires C++11)
* fix i2p support * fix i2p support

View File

@ -60,6 +60,12 @@ struct ip_range
Addr first; Addr first;
Addr last; Addr last;
std::uint32_t flags; std::uint32_t flags;
friend bool operator==(ip_range const& lhs, ip_range const& rhs)
{
return lhs.first == rhs.first
&& lhs.last == rhs.last
&& lhs.flags == rhs.flags;
}
}; };
namespace detail { namespace detail {

View File

@ -33,8 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_PEER_CLASS_TYPE_FILTER_HPP_INCLUDED #ifndef TORRENT_PEER_CLASS_TYPE_FILTER_HPP_INCLUDED
#define TORRENT_PEER_CLASS_TYPE_FILTER_HPP_INCLUDED #define TORRENT_PEER_CLASS_TYPE_FILTER_HPP_INCLUDED
#include <cstring> // for memset
#include <cstdint> #include <cstdint>
#include <array>
namespace libtorrent { namespace libtorrent {
@ -45,8 +45,8 @@ namespace libtorrent {
{ {
peer_class_type_filter() peer_class_type_filter()
{ {
std::memset(m_peer_class_type_mask, 0xff, sizeof(m_peer_class_type_mask)); m_peer_class_type_mask.fill(0xffffffff);
std::memset(m_peer_class_type, 0, sizeof(m_peer_class_type)); m_peer_class_type.fill(0);
} }
enum socket_type_t : std::uint8_t enum socket_type_t : std::uint8_t
@ -121,12 +121,19 @@ namespace libtorrent {
return peer_class_mask; return peer_class_mask;
} }
friend bool operator==(peer_class_type_filter const& lhs
, peer_class_type_filter const& rhs)
{
return lhs.m_peer_class_type_mask == rhs.m_peer_class_type_mask
&& lhs.m_peer_class_type == rhs.m_peer_class_type;
}
private: private:
// maps socket type to a bitmask that's used to filter out // maps socket type to a bitmask that's used to filter out
// (mask) bits from the m_peer_class_filter. // (mask) bits from the m_peer_class_filter.
std::uint32_t m_peer_class_type_mask[num_socket_types]; std::array<std::uint32_t, num_socket_types> m_peer_class_type_mask;
// peer class bitfield added based on socket type // peer class bitfield added based on socket type
std::uint32_t m_peer_class_type[num_socket_types]; std::array<std::uint32_t, num_socket_types> m_peer_class_type;
}; };
} }

View File

@ -643,8 +643,11 @@ namespace libtorrent {
// The ``peer_class`` argument cannot be greater than 31. The bitmasks // The ``peer_class`` argument cannot be greater than 31. The bitmasks
// representing peer classes in the ``peer_class_filter`` are 32 bits. // representing peer classes in the ``peer_class_filter`` are 32 bits.
// //
// The ``get_peer_class_filter()`` function returns the current filter.
//
// For more information, see peer-classes_. // For more information, see peer-classes_.
void set_peer_class_filter(ip_filter const& f); void set_peer_class_filter(ip_filter const& f);
ip_filter get_peer_class_filter() const;
// Sets and gets the *peer class type filter*. This is controls automatic // Sets and gets the *peer class type filter*. This is controls automatic
// peer class assignments to peers based on what kind of socket it is. // peer class assignments to peers based on what kind of socket it is.
@ -659,8 +662,8 @@ namespace libtorrent {
// 3. peer-class type filter, adding classes // 3. peer-class type filter, adding classes
// //
// For more information, see peer-classes_. // For more information, see peer-classes_.
// TODO: add get_peer_class_type_filter() as well
void set_peer_class_type_filter(peer_class_type_filter const& f); void set_peer_class_type_filter(peer_class_type_filter const& f);
peer_class_type_filter get_peer_class_type_filter() const;
// Creates a new peer class (see peer-classes_) with the given name. The // Creates a new peer class (see peer-classes_) with the given name. The
// returned integer is the new peer class identifier. Peer classes may // returned integer is the new peer class identifier. Peer classes may

View File

@ -52,6 +52,7 @@ namespace libtorrent { namespace dht {
bool dos_blocker::incoming(address const& addr, time_point const now, dht_logger* logger) bool dos_blocker::incoming(address const& addr, time_point const now, dht_logger* logger)
{ {
TORRENT_UNUSED(logger);
node_ban_entry* match = nullptr; node_ban_entry* match = nullptr;
node_ban_entry* min = m_ban_nodes; node_ban_entry* min = m_ban_nodes;
for (node_ban_entry* i = m_ban_nodes; i < m_ban_nodes + num_ban_nodes; ++i) for (node_ban_entry* i = m_ban_nodes; i < m_ban_nodes + num_ban_nodes; ++i)

View File

@ -724,6 +724,7 @@ namespace libtorrent {
#endif #endif
if (t->is_upload_only()) send_not_interested(); if (t->is_upload_only()) send_not_interested();
else t->peer_is_interesting(*this); else t->peer_is_interesting(*this);
disconnect_if_redundant();
return; return;
} }
@ -1911,6 +1912,7 @@ namespace libtorrent {
if (t && t->has_picker()) if (t && t->has_picker())
t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); t->picker().check_peer_invariant(m_have_piece, peer_info_struct());
#endif #endif
if (disconnect_if_redundant()) return;
} }
// it's important to update whether we're interested in this peer before // it's important to update whether we're interested in this peer before

View File

@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/lazy_entry.hpp" #include "libtorrent/lazy_entry.hpp"
#include "libtorrent/peer_class.hpp" #include "libtorrent/peer_class.hpp"
#include "libtorrent/peer_class_type_filter.hpp"
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/read_resume_data.hpp" #include "libtorrent/read_resume_data.hpp"
@ -838,11 +839,21 @@ namespace {
async_call(&session_impl::set_peer_class_filter, f); async_call(&session_impl::set_peer_class_filter, f);
} }
ip_filter session_handle::get_peer_class_filter() const
{
return sync_call_ret<ip_filter>(&session_impl::get_peer_class_filter);
}
void session_handle::set_peer_class_type_filter(peer_class_type_filter const& f) void session_handle::set_peer_class_type_filter(peer_class_type_filter const& f)
{ {
async_call(&session_impl::set_peer_class_type_filter, f); async_call(&session_impl::set_peer_class_type_filter, f);
} }
peer_class_type_filter session_handle::get_peer_class_type_filter() const
{
return sync_call_ret<peer_class_type_filter>(&session_impl::get_peer_class_type_filter);
}
peer_class_t session_handle::create_peer_class(char const* name) peer_class_t session_handle::create_peer_class(char const* name)
{ {
return sync_call_ret<peer_class_t>(&session_impl::create_peer_class, name); return sync_call_ret<peer_class_t>(&session_impl::create_peer_class, name);

View File

@ -290,7 +290,7 @@ namespace aux {
{"0.0.0.0", "255.255.255.255", gfilter}, {"0.0.0.0", "255.255.255.255", gfilter},
// local networks // local networks
{"10.0.0.0", "10.255.255.255", lfilter}, {"10.0.0.0", "10.255.255.255", lfilter},
{"172.16.0.0", "172.16.255.255", lfilter}, {"172.16.0.0", "172.31.255.255", lfilter},
{"192.168.0.0", "192.168.255.255", lfilter}, {"192.168.0.0", "192.168.255.255", lfilter},
// link-local // link-local
{"169.254.0.0", "169.254.255.255", lfilter}, {"169.254.0.0", "169.254.255.255", lfilter},
@ -303,6 +303,8 @@ namespace aux {
{ {
// everything // everything
{"::0", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", gfilter}, {"::0", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", gfilter},
// local networks
{"fc00::", "fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", lfilter},
// link-local // link-local
{"fe80::", "febf::ffff:ffff:ffff:ffff:ffff:ffff:ffff", lfilter}, {"fe80::", "febf::ffff:ffff:ffff:ffff:ffff:ffff:ffff", lfilter},
// loop-back // loop-back

View File

@ -3257,6 +3257,8 @@ TORRENT_TEST(read_only_node)
} }
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
// these tests rely on logging being enabled
TORRENT_TEST(invalid_error_msg) TORRENT_TEST(invalid_error_msg)
{ {
// TODO: 3 use dht_test_setup class to simplify the node setup // TODO: 3 use dht_test_setup class to simplify the node setup

View File

@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_class_set.hpp" #include "libtorrent/peer_class_set.hpp"
#include "libtorrent/peer_class_type_filter.hpp" #include "libtorrent/peer_class_type_filter.hpp"
#include "libtorrent/aux_/path.hpp" #include "libtorrent/aux_/path.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/session.hpp"
using namespace lt; using namespace lt;
@ -115,3 +117,37 @@ TORRENT_TEST(peer_class)
TEST_CHECK(pool.at(id1) == nullptr); TEST_CHECK(pool.at(id1) == nullptr);
} }
TORRENT_TEST(session_peer_class_filter)
{
using namespace libtorrent;
session ses;
peer_class_t my_class = ses.create_peer_class("200.1.x.x IP range");
ip_filter f;
f.add_rule(address_v4::from_string("200.1.1.0")
, address_v4::from_string("200.1.255.255")
, 1 << static_cast<std::uint32_t>(my_class));
ses.set_peer_class_filter(f);
#if TORRENT_USE_IPV6
TEST_CHECK(std::get<0>(ses.get_peer_class_filter().export_filter())
== std::get<0>(f.export_filter()));
#else
TEST_CHECK(ses.get_peer_class_filter().export_filter() == f.export_filter());
#endif
}
TORRENT_TEST(session_peer_class_type_filter)
{
using namespace libtorrent;
session ses;
peer_class_t my_class = ses.create_peer_class("all utp sockets");
peer_class_type_filter f;
f.add(peer_class_type_filter::utp_socket, my_class);
f.disallow(peer_class_type_filter::utp_socket, session::global_peer_class_id);
ses.set_peer_class_type_filter(f);
TEST_CHECK(ses.get_peer_class_type_filter() == f);
}