introduce a proper type for pex flags to improve type-safety

This commit is contained in:
arvidn 2017-12-17 14:15:38 +01:00 committed by Arvid Norberg
parent 0848d9b7f5
commit bb945f5cf4
11 changed files with 126 additions and 69 deletions

View File

@ -21,6 +21,7 @@
#include "libtorrent/create_torrent.hpp" // for create_flags_t
#include "libtorrent/portmap.hpp" // for port_mapping_t
#include "libtorrent/peer_class.hpp"
#include "libtorrent/pex_flags.hpp"
#include <vector>
using namespace boost::python;
@ -323,6 +324,7 @@ void bind_converters()
to_python_converter<lt::reopen_network_flags_t, from_bitfield_flag<lt::reopen_network_flags_t>>();
to_python_converter<lt::file_flags_t, from_bitfield_flag<lt::file_flags_t>>();
to_python_converter<lt::create_flags_t, from_bitfield_flag<lt::create_flags_t>>();
to_python_converter<lt::pex_flags_t, from_bitfield_flag<lt::pex_flags_t>>();
// work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@ -387,4 +389,5 @@ void bind_converters()
to_bitfield_flag<lt::reopen_network_flags_t>();
to_bitfield_flag<lt::file_flags_t>();
to_bitfield_flag<lt::create_flags_t>();
to_bitfield_flag<lt::pex_flags_t>();
}

View File

@ -97,6 +97,7 @@ nobase_include_HEADERS = \
peer_id.hpp \
peer_info.hpp \
peer_request.hpp \
pex_flags.hpp \
piece_block.hpp \
piece_block_progress.hpp \
piece_picker.hpp \

View File

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/deque.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
#include "libtorrent/string_view.hpp"
#include "libtorrent/pex_flags.hpp"
namespace libtorrent {
@ -92,6 +93,9 @@ namespace libtorrent {
std::vector<torrent_peer*> erased;
};
struct erase_peer_flags_tag;
using erase_peer_flags_t = flags::bitfield_flag<std::uint8_t, erase_peer_flags_tag>;
class TORRENT_EXTRA_EXPORT peer_list : single_threaded
{
public:
@ -105,27 +109,19 @@ namespace libtorrent {
#if TORRENT_USE_I2P
torrent_peer* add_i2p_peer(string_view destination
, peer_source_flags_t src, char flags
, peer_source_flags_t src, pex_flags_t flags
, torrent_state* state);
#endif
enum
{
// these flags match the flags passed in ut_pex
// messages
flag_encryption = 0x1,
flag_seed = 0x2,
flag_utp = 0x4,
flag_holepunch = 0x8
};
// this is called once for every torrent_peer we get from
// the tracker, pex, lsd or dht.
torrent_peer* add_peer(const tcp::endpoint& remote
, peer_source_flags_t source, char flags, torrent_state* state);
torrent_peer* add_peer(tcp::endpoint const& remote
, peer_source_flags_t source, pex_flags_t flags
, torrent_state* state);
// false means duplicate connection
bool update_peer_port(int port, torrent_peer* p, peer_source_flags_t src
bool update_peer_port(int port, torrent_peer* p
, peer_source_flags_t src
, torrent_state* state);
// called when an incoming connection is accepted
@ -203,9 +199,10 @@ namespace libtorrent {
void update_connect_candidates(int delta);
void update_peer(torrent_peer* p, peer_source_flags_t src, int flags
, tcp::endpoint const& remote);
bool insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state);
void update_peer(torrent_peer* p, peer_source_flags_t src
, pex_flags_t flags, tcp::endpoint const& remote);
bool insert_peer(torrent_peer* p, iterator iter
, pex_flags_t flags, torrent_state* state);
bool compare_peer_erase(torrent_peer const& lhs, torrent_peer const& rhs) const;
bool compare_peer(torrent_peer const* lhs, torrent_peer const* rhs
@ -219,8 +216,8 @@ namespace libtorrent {
bool is_force_erase_candidate(torrent_peer const& pe) const;
bool should_erase_immediately(torrent_peer const& p) const;
enum flags_t { force_erase = 1 };
void erase_peers(torrent_state* state, int flags = 0);
static constexpr erase_peer_flags_t force_erase = 1_bit;
void erase_peers(torrent_state* state, erase_peer_flags_t flags = {});
peers_t m_peers;

View File

@ -0,0 +1,52 @@
/*
Copyright (c) 2017, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_PEX_FLAGS_HPP_INCLUDE
#define TORRENT_PEX_FLAGS_HPP_INCLUDE
#include "libtorrent/flags.hpp"
namespace libtorrent {
struct pex_flags_tag;
using pex_flags_t = flags::bitfield_flag<std::uint8_t, pex_flags_tag>;
// these flags match the flags passed in ut_pex
// messages
constexpr pex_flags_t pex_encryption = 1_bit;
constexpr pex_flags_t pex_seed = 2_bit;
constexpr pex_flags_t pex_utp = 3_bit;
constexpr pex_flags_t pex_holepunch = 4_bit;
}
#endif

View File

@ -674,7 +674,7 @@ namespace libtorrent {
bool try_connect_peer();
torrent_peer* add_peer(tcp::endpoint const& adr
, peer_source_flags_t source, int flags = 0);
, peer_source_flags_t source, pex_flags_t flags = {});
bool ban_peer(torrent_peer* tp);
void update_peer_port(int port, torrent_peer* p, peer_source_flags_t src);
void set_seed(torrent_peer* p, bool s);

View File

@ -57,6 +57,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_flags.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
#include "libtorrent/download_priority.hpp"
#include "libtorrent/pex_flags.hpp"
namespace libtorrent {
namespace aux {
@ -1126,7 +1127,7 @@ namespace aux {
// connections to the peer fail
// ==== ==========================================
void connect_peer(tcp::endpoint const& adr, peer_source_flags_t source = {}
, int flags = 0x1 + 0x4 + 0x8) const;
, pex_flags_t flags = pex_encryption | pex_utp | pex_holepunch) const;
// ``set_max_uploads()`` sets the maximum number of peers that's unchoked
// at the same time on this torrent. If you set this to -1, there will be

View File

@ -114,6 +114,8 @@ namespace {
namespace libtorrent {
constexpr erase_peer_flags_t peer_list::force_erase;
peer_list::peer_list(torrent_peer_allocator_interface& alloc)
: m_locked_peer(nullptr)
, m_peer_allocator(alloc)
@ -324,7 +326,7 @@ namespace libtorrent {
return pe.connection == nullptr;
}
void peer_list::erase_peers(torrent_state* state, int flags)
void peer_list::erase_peers(torrent_state* state, erase_peer_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -889,7 +891,8 @@ namespace libtorrent {
}
// this is an internal function
bool peer_list::insert_peer(torrent_peer* p, iterator iter, int flags
bool peer_list::insert_peer(torrent_peer* p, iterator iter
, pex_flags_t const flags
, torrent_state* state)
{
TORRENT_ASSERT(is_single_thread());
@ -928,17 +931,17 @@ namespace libtorrent {
if (m_round_robin >= iter - m_peers.begin()) ++m_round_robin;
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
if (flags & flag_encryption) p->pe_support = true;
if (flags & pex_encryption) p->pe_support = true;
#endif
if (flags & flag_seed)
if (flags & pex_seed)
{
p->seed = true;
TORRENT_ASSERT(m_num_seeds < int(m_peers.size()));
++m_num_seeds;
}
if (flags & flag_utp)
if (flags & pex_utp)
p->supports_utp = true;
if (flags & flag_holepunch)
if (flags & pex_holepunch)
p->supports_holepunch = true;
if (is_connect_candidate(*p))
update_connect_candidates(1);
@ -947,7 +950,7 @@ namespace libtorrent {
}
void peer_list::update_peer(torrent_peer* p, peer_source_flags_t const src
, int flags, tcp::endpoint const& remote)
, pex_flags_t const flags, tcp::endpoint const& remote)
{
TORRENT_ASSERT(is_single_thread());
bool const was_conn_cand = is_connect_candidate(*p);
@ -969,7 +972,7 @@ namespace libtorrent {
// if we're connected to this peer
// we already know if it's a seed or not
// so we don't have to trust this source
if ((flags & flag_seed) && !p->connection)
if ((flags & pex_seed) && !p->connection)
{
if (!p->seed)
{
@ -978,9 +981,9 @@ namespace libtorrent {
}
p->seed = true;
}
if (flags & flag_utp)
if (flags & pex_utp)
p->supports_utp = true;
if (flags & flag_holepunch)
if (flags & pex_holepunch)
p->supports_holepunch = true;
if (was_conn_cand != is_connect_candidate(*p))
@ -1003,7 +1006,8 @@ namespace libtorrent {
#if TORRENT_USE_I2P
torrent_peer* peer_list::add_i2p_peer(string_view const destination
, peer_source_flags_t const src, char flags, torrent_state* state)
, peer_source_flags_t const src, pex_flags_t const flags
, torrent_state* state)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -1035,7 +1039,7 @@ namespace libtorrent {
// if this returns non-nullptr, the torrent need to post status update
torrent_peer* peer_list::add_peer(tcp::endpoint const& remote
, peer_source_flags_t const src, char flags
, peer_source_flags_t const src, pex_flags_t const flags
, torrent_state* state)
{
TORRENT_ASSERT(is_single_thread());

View File

@ -2630,8 +2630,8 @@ namespace libtorrent {
if (torrent_file().priv() || (torrent_file().is_i2p()
&& !settings().get_bool(settings_pack::allow_i2p_mixed))) return;
std::for_each(peers.begin(), peers.end(), std::bind(
&torrent::add_peer, this, _1, peer_info::dht, 0));
for (auto& p : peers)
add_peer(p, peer_info::dht);
do_connect_boost();
@ -3194,7 +3194,7 @@ namespace libtorrent {
{
torrent_state st = get_peer_list_state();
need_peer_list();
if (m_peer_list->add_i2p_peer(i.hostname.c_str (), peer_info::tracker, 0, &st))
if (m_peer_list->add_i2p_peer(i.hostname.c_str (), peer_info::tracker, {}, &st))
state_updated();
peers_erased(st.erased);
}
@ -3405,7 +3405,7 @@ namespace libtorrent {
need_peer_list();
torrent_state st = get_peer_list_state();
if (m_peer_list->add_i2p_peer(dest, peer_info::tracker, 0, &st))
if (m_peer_list->add_i2p_peer(dest, peer_info::tracker, {}, &st))
state_updated();
peers_erased(st.erased);
}
@ -7286,9 +7286,8 @@ namespace libtorrent {
seeds.push_back(p);
}
}
std::for_each(seeds.begin(), seeds.end()
, std::bind(&peer_connection::disconnect, _1, errors::torrent_finished
, operation_t::bittorrent, 0));
for (auto& p : seeds)
p->disconnect(errors::torrent_finished, operation_t::bittorrent, 0);
}
if (m_abort) return;
@ -8891,8 +8890,7 @@ namespace libtorrent {
if (!m_trackers.empty())
{
// tell the tracker that we're back
std::for_each(m_trackers.begin(), m_trackers.end()
, std::bind(&announce_entry::reset, _1));
for (auto& t : m_trackers) t.reset();
}
// reset the stats, since from the tracker's
@ -10013,7 +10011,7 @@ namespace libtorrent {
}
torrent_peer* torrent::add_peer(tcp::endpoint const& adr
, peer_source_flags_t const source, int const flags)
, peer_source_flags_t const source, pex_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
@ -10090,7 +10088,7 @@ namespace libtorrent {
need_peer_list();
torrent_state st = get_peer_list_state();
torrent_peer* p = m_peer_list->add_peer(adr, source, char(flags), &st);
torrent_peer* p = m_peer_list->add_peer(adr, source, flags, &st);
peers_erased(st.erased);
#ifndef TORRENT_DISABLE_LOGGING

View File

@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/write_resume_data.hpp"
#include "libtorrent/torrent_flags.hpp"
#include "libtorrent/pex_flags.hpp"
#ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/peer_info.hpp" // for peer_list_entry
@ -749,7 +750,7 @@ namespace libtorrent {
#endif
void torrent_handle::connect_peer(tcp::endpoint const& adr
, peer_source_flags_t const source, int flags) const
, peer_source_flags_t const source, pex_flags_t const flags) const
{
async_call(&torrent::add_peer, adr, source, flags);
}

View File

@ -166,24 +166,24 @@ namespace libtorrent {namespace {
// flag is received from a peer, it can be
// used as a rendezvous point in case direct
// connections to the peer fail
int flags = p->is_seed() ? 2 : 0;
pex_flags_t flags = p->is_seed() ? pex_seed : pex_flags_t{};
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
flags |= p->supports_encryption() ? 1 : 0;
flags |= p->supports_encryption() ? pex_encryption : pex_flags_t{};
#endif
flags |= is_utp(*p->get_socket()) ? 4 : 0;
flags |= p->supports_holepunch() ? 8 : 0;
flags |= is_utp(*p->get_socket()) ? pex_utp : pex_flags_t{};
flags |= p->supports_holepunch() ? pex_holepunch : pex_flags_t{};
// i->first was added since the last time
if (remote.address().is_v4())
{
detail::write_endpoint(remote, pla_out);
detail::write_uint8(flags, plf_out);
detail::write_uint8(static_cast<std::uint8_t>(flags), plf_out);
}
#if TORRENT_USE_IPV6
else
{
detail::write_endpoint(remote, pla6_out);
detail::write_uint8(flags, plf6_out);
detail::write_uint8(static_cast<std::uint8_t>(flags), plf6_out);
}
#endif
++num_added;
@ -333,7 +333,7 @@ namespace libtorrent {namespace {
for (int i = 0; i < num_peers; ++i)
{
tcp::endpoint const adr = detail::read_v4_endpoint<tcp::endpoint>(in);
char const flags = *fin++;
pex_flags_t const flags(static_cast<std::uint8_t>(*fin++));
if (int(m_peers.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers))
break;
@ -386,7 +386,7 @@ namespace libtorrent {namespace {
for (int i = 0; i < num_peers; ++i)
{
tcp::endpoint const adr = detail::read_v6_endpoint<tcp::endpoint>(in);
char const flags = *fin++;
pex_flags_t const flags(static_cast<std::uint8_t>(*fin++));
// ignore local addresses unless the peer is local to us
if (is_local(adr.address()) && !is_local(m_pc.remote().address())) continue;
if (int(m_peers6.size()) >= m_torrent.settings().get_int(settings_pack::max_pex_peers))

View File

@ -178,7 +178,7 @@ torrent_state init_state()
torrent_peer* add_peer(peer_list& p, torrent_state& st, tcp::endpoint const& ep)
{
int cc = p.num_connect_candidates();
torrent_peer* peer = p.add_peer(ep, {}, 0, &st);
torrent_peer* peer = p.add_peer(ep, {}, {}, &st);
if (peer)
{
TEST_EQUAL(p.num_connect_candidates(), cc + 1);
@ -209,13 +209,13 @@ TORRENT_TEST(multiple_ips_disallowed)
peer_list p(allocator);
t.m_p = &p;
TEST_EQUAL(p.num_connect_candidates(), 0);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, {}, &st);
TEST_EQUAL(p.num_peers(), 1);
TEST_EQUAL(p.num_connect_candidates(), 1);
st.erased.clear();
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, {}, &st);
TEST_EQUAL(p.num_peers(), 1);
TEST_EQUAL(peer1, peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -231,12 +231,12 @@ TORRENT_TEST(multiple_ips_allowed)
st.allow_multiple_connections_per_ip = true;
peer_list p(allocator);
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, {}, &st);
TEST_EQUAL(p.num_connect_candidates(), 1);
TEST_EQUAL(p.num_peers(), 1);
st.erased.clear();
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, {}, &st);
TEST_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 2);
@ -253,7 +253,7 @@ TORRENT_TEST(multiple_ips_allowed2)
st.allow_multiple_connections_per_ip = true;
peer_list p(allocator);
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, {}, &st);
TEST_EQUAL(p.num_connect_candidates(), 1);
st.erased.clear();
@ -269,7 +269,7 @@ TORRENT_TEST(multiple_ips_allowed2)
TEST_CHECK(tp == nullptr);
st.erased.clear();
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, {}, &st);
TEST_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -292,7 +292,7 @@ TORRENT_TEST(multiple_ips_disallowed2)
st.allow_multiple_connections_per_ip = false;
peer_list p(allocator);
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, {}, &st);
TEST_EQUAL(p.num_connect_candidates(), 1);
TEST_EQUAL(peer1->port, 3000);
st.erased.clear();
@ -309,7 +309,7 @@ TORRENT_TEST(multiple_ips_disallowed2)
TEST_CHECK(tp == nullptr);
st.erased.clear();
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, {}, &st);
TEST_EQUAL(p.num_peers(), 1);
TEST_EQUAL(peer2->port, 9020);
TEST_CHECK(peer1 == peer2);
@ -350,7 +350,7 @@ TORRENT_TEST(update_peer_port_collide)
peer_list p(allocator);
t.m_p = &p;
torrent_peer* peer2 = p.add_peer(ep("10.0.0.1", 4000), {}, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.1", 4000), {}, {}, &st);
TEST_CHECK(peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -520,7 +520,7 @@ TORRENT_TEST(erase_peers)
TEST_EQUAL(p.num_peers(), 100);
// trigger the eviction of one peer
torrent_peer* peer = p.add_peer(rand_tcp_ep(), {}, 0, &st);
torrent_peer* peer = p.add_peer(rand_tcp_ep(), {}, {}, &st);
// we either removed an existing peer, or rejected this one
// either is valid behavior when the list is full
TEST_CHECK(st.erased.size() == 1 || peer == nullptr);
@ -539,7 +539,7 @@ TORRENT_TEST(set_ip_filter)
for (int i = 0; i < 100; ++i)
{
p.add_peer(tcp::endpoint(
address_v4((10 << 24) + ((i + 10) << 16)), 353), {}, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), 353), {}, {}, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
}
@ -569,7 +569,7 @@ TORRENT_TEST(set_port_filter)
for (int i = 0; i < 100; ++i)
{
p.add_peer(tcp::endpoint(
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, {}, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
}
@ -599,7 +599,7 @@ TORRENT_TEST(set_max_failcount)
for (int i = 0; i < 100; ++i)
{
torrent_peer* peer = p.add_peer(tcp::endpoint(
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, {}, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
// every other peer has a failcount of 1
@ -629,7 +629,7 @@ TORRENT_TEST(set_seed)
for (int i = 0; i < 100; ++i)
{
torrent_peer* peer = p.add_peer(tcp::endpoint(
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, {}, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
// make every other peer a seed
@ -908,7 +908,7 @@ TORRENT_TEST(new_peer_size_limit)
torrent_peer* peer5 = add_peer(p, st, ep("10.0.0.5", 8080));
TEST_CHECK(peer5);
TEST_EQUAL(p.num_peers(), 5);
torrent_peer* peer6 = p.add_peer(ep("10.0.0.6", 8080), {}, 0, &st);
torrent_peer* peer6 = p.add_peer(ep("10.0.0.6", 8080), {}, {}, &st);
TEST_CHECK(peer6 == nullptr);
TEST_EQUAL(p.num_peers(), 5);