convert peer_flags and peer_source_flags to type-safe flags

This commit is contained in:
arvidn 2017-07-16 11:26:00 -07:00 committed by Arvid Norberg
parent 4947602a2f
commit c4659bc345
25 changed files with 344 additions and 241 deletions

View File

@ -124,6 +124,7 @@ set(sources
version
ffs
add_torrent_params
peer_info
# -- extensions --
ut_pex

View File

@ -675,6 +675,7 @@ SOURCES =
file_progress
ffs
add_torrent_params
peer_info
# -- extensions --
ut_pex

View File

@ -13,6 +13,7 @@
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/disk_interface.hpp" // for open_file_state
#include "libtorrent/aux_/noexcept_movable.hpp"
#include "libtorrent/peer_info.hpp"
#include <vector>
using namespace boost::python;
@ -290,6 +291,8 @@ void bind_converters()
to_python_converter<lt::piece_index_t, from_strong_typedef<lt::piece_index_t>>();
to_python_converter<lt::file_index_t, from_strong_typedef<lt::file_index_t>>();
to_python_converter<lt::torrent_flags_t, from_bitfield_flag<lt::torrent_flags_t>>();
to_python_converter<lt::peer_flags_t, from_bitfield_flag<lt::peer_flags_t>>();
to_python_converter<lt::peer_source_flags_t, from_bitfield_flag<lt::peer_source_flags_t>>();
// work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
@ -333,4 +336,6 @@ void bind_converters()
to_strong_typedef<lt::piece_index_t>();
to_strong_typedef<lt::file_index_t>();
to_bitfield_flag<lt::torrent_flags_t>();
to_bitfield_flag<lt::peer_flags_t>();
to_bitfield_flag<lt::peer_source_flags_t>();
}

View File

@ -51,8 +51,8 @@ using by_value = return_value_policy<return_by_value>;
void bind_peer_info()
{
scope pi = class_<peer_info>("peer_info")
.def_readonly("flags", &peer_info::flags)
.def_readonly("source", &peer_info::source)
.add_property("flags", make_getter(&peer_info::flags, by_value()))
.add_property("source", make_getter(&peer_info::source, by_value()))
.def_readonly("read_state", &peer_info::read_state)
.def_readonly("write_state", &peer_info::write_state)
.add_property("ip", get_ip)
@ -103,27 +103,27 @@ void bind_peer_info()
;
// flags
pi.attr("interesting") = (int)peer_info::interesting;
pi.attr("choked") = (int)peer_info::choked;
pi.attr("remote_interested") = (int)peer_info::remote_interested;
pi.attr("remote_choked") = (int)peer_info::remote_choked;
pi.attr("supports_extensions") = (int)peer_info::supports_extensions;
pi.attr("local_connection") = (int)peer_info::local_connection;
pi.attr("handshake") = (int)peer_info::handshake;
pi.attr("connecting") = (int)peer_info::connecting;
pi.attr("interesting") = peer_info::interesting;
pi.attr("choked") = peer_info::choked;
pi.attr("remote_interested") = peer_info::remote_interested;
pi.attr("remote_choked") = peer_info::remote_choked;
pi.attr("supports_extensions") = peer_info::supports_extensions;
pi.attr("local_connection") = peer_info::local_connection;
pi.attr("handshake") = peer_info::handshake;
pi.attr("connecting") = peer_info::connecting;
#ifndef TORRENT_NO_DEPRECATE
pi.attr("queued") = (int)peer_info::queued;
pi.attr("queued") = peer_info::queued;
#endif
pi.attr("on_parole") = (int)peer_info::on_parole;
pi.attr("seed") = (int)peer_info::seed;
pi.attr("optimistic_unchoke") = (int)peer_info::optimistic_unchoke;
pi.attr("snubbed") = (int)peer_info::snubbed;
pi.attr("upload_only") = (int)peer_info::upload_only;
pi.attr("endgame_mode") = (int)peer_info::endgame_mode;
pi.attr("holepunched") = (int)peer_info::holepunched;
pi.attr("on_parole") = peer_info::on_parole;
pi.attr("seed") = peer_info::seed;
pi.attr("optimistic_unchoke") = peer_info::optimistic_unchoke;
pi.attr("snubbed") = peer_info::snubbed;
pi.attr("upload_only") = peer_info::upload_only;
pi.attr("endgame_mode") = peer_info::endgame_mode;
pi.attr("holepunched") = peer_info::holepunched;
#ifndef TORRENT_DISABLE_ENCRYPTION
pi.attr("rc4_encrypted") = (int)peer_info::rc4_encrypted;
pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted;
pi.attr("rc4_encrypted") = peer_info::rc4_encrypted;
pi.attr("plaintext_encrypted") = peer_info::plaintext_encrypted;
#endif
// connection_type
@ -131,11 +131,11 @@ void bind_peer_info()
pi.attr("web_seed") = (int)peer_info::web_seed;
// source
pi.attr("tracker") = (int)peer_info::tracker;
pi.attr("dht") = (int)peer_info::dht;
pi.attr("pex") = (int)peer_info::pex;
pi.attr("lsd") = (int)peer_info::lsd;
pi.attr("resume_data") = (int)peer_info::resume_data;
pi.attr("tracker") = peer_info::tracker;
pi.attr("dht") = peer_info::dht;
pi.attr("pex") = peer_info::pex;
pi.attr("lsd") = peer_info::lsd;
pi.attr("resume_data") = peer_info::resume_data;
// read/write state
pi.attr("bw_idle") = (int)peer_info::bw_idle;

View File

@ -201,3 +201,8 @@ crypto
uri
infohashes
rw
holepunch
TLS
RC4
Hellman
html

View File

@ -487,7 +487,7 @@ int print_peer_info(std::string& out
if (print_peer_rate)
{
bool const unchoked = (i->flags & lt::peer_info::choked) == 0;
bool const unchoked = !(i->flags & lt::peer_info::choked);
std::snprintf(str, sizeof(str), " %s"
, unchoked ? add_suffix(i->estimated_reciprocation_rate, "/s").c_str() : " ");
@ -984,7 +984,7 @@ void print_piece(lt::partial_piece_info const* pp
{
int const index = pp ? peer_index(pp->blocks[j].peer(), peers) % 36 : -1;
char const* chr = " ";
bool const snubbed = index >= 0 ? ((peers[index].flags & lt::peer_info::snubbed) != 0) : false;
bool const snubbed = index >= 0 ? bool(peers[index].flags & lt::peer_info::snubbed) : false;
char const* color = "";

View File

@ -48,11 +48,10 @@ struct bitfield_flag
constexpr bitfield_flag(bitfield_flag const& rhs) noexcept = default;
constexpr bitfield_flag(bitfield_flag&& rhs) noexcept = default;
constexpr bitfield_flag() noexcept : m_val(0) {}
#ifdef TORRENT_NO_DEPRECATE
explicit constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {}
#ifdef TORRENT_NO_DEPRECATE
explicit constexpr operator UnderlyingType() const noexcept { return m_val; }
#else
constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {}
constexpr operator UnderlyingType() const noexcept { return m_val; }
#endif
explicit constexpr operator bool() const noexcept { return m_val != 0; }

View File

@ -40,9 +40,24 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bitfield.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/flags.hpp"
namespace libtorrent {
// hidden
struct peer_flags_tag;
struct peer_source_flags_tag;
// flags for the peer_info::flags field. Indicates various states
// the peer may be in. These flags are not mutually exclusive, but
// not every combination of them makes sense either.
using peer_flags_t = flags::bitfield_flag<std::uint32_t, peer_flags_tag>;
// the flags indicating which sources a peer can
// have come from. A peer may have been seen from
// multiple sources
using peer_source_flags_t = flags::bitfield_flag<std::uint8_t, peer_source_flags_tag>;
// holds information and statistics about one peer
// that libtorrent is connected to
struct TORRENT_EXPORT peer_info
@ -73,148 +88,133 @@ namespace libtorrent {
// the time until all blocks in the request queue will be downloaded
time_duration download_queue_time;
// flags for the peer_info::flags field. Indicates various states
// the peer may be in. These flags are not mutually exclusive, but
// not every combination of them makes sense either.
enum peer_flags_t
{
// **we** are interested in pieces from this peer.
interesting = 0x1,
// **we** are interested in pieces from this peer.
static constexpr peer_flags_t interesting{0x1};
// **we** have choked this peer.
choked = 0x2,
// **we** have choked this peer.
static constexpr peer_flags_t choked{0x2};
// the peer is interested in **us**
remote_interested = 0x4,
// the peer is interested in **us**
static constexpr peer_flags_t remote_interested{0x4};
// the peer has choked **us**.
remote_choked = 0x8,
// the peer has choked **us**.
static constexpr peer_flags_t remote_choked{0x8};
// means that this peer supports the
// `extension protocol`__.
//
// __ extension_protocol.html
supports_extensions = 0x10,
// means that this peer supports the
// `extension protocol`__.
//
// __ extension_protocol.html
static constexpr peer_flags_t supports_extensions{0x10};
// The connection was initiated by us, the peer has a
// listen port open, and that port is the same as in the
// address of this peer. If this flag is not set, this
// peer connection was opened by this peer connecting to
// us.
local_connection = 0x20,
// The connection was initiated by us, the peer has a
// listen port open, and that port is the same as in the
// address of this peer. If this flag is not set, this
// peer connection was opened by this peer connecting to
// us.
static constexpr peer_flags_t local_connection{0x20};
// The connection is opened, and waiting for the
// handshake. Until the handshake is done, the peer
// cannot be identified.
handshake = 0x40,
// The connection is opened, and waiting for the
// handshake. Until the handshake is done, the peer
// cannot be identified.
static constexpr peer_flags_t handshake{0x40};
// The connection is in a half-open state (i.e. it is
// being connected).
connecting = 0x80,
// The connection is in a half-open state (i.e. it is
// being connected).
static constexpr peer_flags_t connecting{0x80};
#ifndef TORRENT_NO_DEPRECATE
// The connection is currently queued for a connection
// attempt. This may happen if there is a limit set on
// the number of half-open TCP connections.
queued = 0x100,
#else
// hidden
deprecated__ = 0x100,
// The connection is currently queued for a connection
// attempt. This may happen if there is a limit set on
// the number of half-open TCP connections.
static constexpr peer_flags_t queued{0x100};
#endif
// The peer has participated in a piece that failed the
// hash check, and is now "on parole", which means we're
// only requesting whole pieces from this peer until
// it either fails that piece or proves that it doesn't
// send bad data.
on_parole = 0x200,
// The peer has participated in a piece that failed the
// hash check, and is now "on parole", which means we're
// only requesting whole pieces from this peer until
// it either fails that piece or proves that it doesn't
// send bad data.
static constexpr peer_flags_t on_parole{0x200};
// This peer is a seed (it has all the pieces).
seed = 0x400,
// This peer is a seed (it has all the pieces).
static constexpr peer_flags_t seed{0x400};
// This peer is subject to an optimistic unchoke. It has
// been unchoked for a while to see if it might unchoke
// us in return an earn an upload/unchoke slot. If it
// doesn't within some period of time, it will be choked
// and another peer will be optimistically unchoked.
optimistic_unchoke = 0x800,
// This peer is subject to an optimistic unchoke. It has
// been unchoked for a while to see if it might unchoke
// us in return an earn an upload/unchoke slot. If it
// doesn't within some period of time, it will be choked
// and another peer will be optimistically unchoked.
static constexpr peer_flags_t optimistic_unchoke{0x800};
// This peer has recently failed to send a block within
// the request timeout from when the request was sent.
// We're currently picking one block at a time from this
// peer.
snubbed = 0x1000,
// This peer has recently failed to send a block within
// the request timeout from when the request was sent.
// We're currently picking one block at a time from this
// peer.
static constexpr peer_flags_t snubbed{0x1000};
// This peer has either explicitly (with an extension)
// or implicitly (by becoming a seed) told us that it
// will not downloading anything more, regardless of
// which pieces we have.
upload_only = 0x2000,
// This peer has either explicitly (with an extension)
// or implicitly (by becoming a seed) told us that it
// will not downloading anything more, regardless of
// which pieces we have.
static constexpr peer_flags_t upload_only{0x2000};
// This means the last time this peer picket a piece,
// it could not pick as many as it wanted because there
// were not enough free ones. i.e. all pieces this peer
// has were already requested from other peers.
endgame_mode = 0x4000,
// This means the last time this peer picket a piece,
// it could not pick as many as it wanted because there
// were not enough free ones. i.e. all pieces this peer
// has were already requested from other peers.
static constexpr peer_flags_t endgame_mode{0x4000};
// This flag is set if the peer was in holepunch mode
// when the connection succeeded. This typically only
// happens if both peers are behind a NAT and the peers
// connect via the NAT holepunch mechanism.
holepunched = 0x8000,
// This flag is set if the peer was in holepunch mode
// when the connection succeeded. This typically only
// happens if both peers are behind a NAT and the peers
// connect via the NAT holepunch mechanism.
static constexpr peer_flags_t holepunched{0x8000};
// indicates that this socket is running on top of the
// I2P transport.
i2p_socket = 0x10000,
// indicates that this socket is running on top of the
// I2P transport.
static constexpr peer_flags_t i2p_socket{0x10000};
// indicates that this socket is a uTP socket
utp_socket = 0x20000,
// indicates that this socket is a uTP socket
static constexpr peer_flags_t utp_socket{0x20000};
// indicates that this socket is running on top of an SSL
// (TLS) channel
ssl_socket = 0x40000,
// indicates that this socket is running on top of an SSL
// (TLS) channel
static constexpr peer_flags_t ssl_socket{0x40000};
// this connection is obfuscated with RC4
rc4_encrypted = 0x100000,
// this connection is obfuscated with RC4
static constexpr peer_flags_t rc4_encrypted{0x100000};
// the handshake of this connection was obfuscated
// with a diffie-hellman exchange
plaintext_encrypted = 0x200000
};
// the handshake of this connection was obfuscated
// with a Diffie-Hellman exchange
static constexpr peer_flags_t plaintext_encrypted{0x200000};
// tells you in which state the peer is in. It is set to
// any combination of the peer_flags_t enum.
std::uint32_t flags;
peer_flags_t flags;
// the flags indicating which sources a peer can
// have come from. A peer may have been seen from
// multiple sources
enum peer_source_flags
{
// The peer was received from the tracker.
tracker = 0x1,
// The peer was received from the tracker.
static constexpr peer_source_flags_t tracker{0x1};
// The peer was received from the kademlia DHT.
dht = 0x2,
// The peer was received from the kademlia DHT.
static constexpr peer_source_flags_t dht{0x2};
// The peer was received from the peer exchange
// extension.
pex = 0x4,
// The peer was received from the peer exchange
// extension.
static constexpr peer_source_flags_t pex{0x4};
// The peer was received from the local service
// discovery (The peer is on the local network).
lsd = 0x8,
// The peer was received from the local service
// discovery (The peer is on the local network).
static constexpr peer_source_flags_t lsd{0x8};
// The peer was added from the fast resume data.
resume_data = 0x10,
// The peer was added from the fast resume data.
static constexpr peer_source_flags_t resume_data{0x10};
// we received an incoming connection from this peer
incoming = 0x20
};
// we received an incoming connection from this peer
static constexpr peer_source_flags_t incoming{0x20};
// a combination of flags describing from which sources this peer
// was received. See peer_source_flags.
std::uint32_t source;
peer_source_flags_t source;
// the current upload and download speed we have to and from this peer
// (including any protocol messages). updated about once per second

View File

@ -47,6 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/debug.hpp"
#include "libtorrent/peer_connection_interface.hpp"
#include "libtorrent/aux_/deque.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent {
@ -112,7 +113,8 @@ namespace libtorrent {
peer_list();
#if TORRENT_USE_I2P
torrent_peer* add_i2p_peer(char const* destination, int src, char flags
torrent_peer* add_i2p_peer(char const* destination
, peer_source_flags_t src, char flags
, torrent_state* state);
#endif
@ -129,10 +131,11 @@ namespace libtorrent {
// 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
, int source, char flags, torrent_state* state);
, peer_source_flags_t source, char flags, torrent_state* state);
// false means duplicate connection
bool update_peer_port(int port, torrent_peer* p, int src, torrent_state* state);
bool update_peer_port(int port, torrent_peer* p, peer_source_flags_t src
, torrent_state* state);
// called when an incoming connection is accepted
// false means the connection was refused or failed
@ -209,7 +212,7 @@ namespace libtorrent {
void update_connect_candidates(int delta);
void update_peer(torrent_peer* p, int src, int flags
void update_peer(torrent_peer* p, peer_source_flags_t src, int flags
, tcp::endpoint const& remote, char const* destination);
bool insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state);

View File

@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_REQUEST_BLOCKS_HPP_INCLUDED
#define TORRENT_REQUEST_BLOCKS_HPP_INCLUDED
#include "libtorrent/peer_info.hpp"
namespace libtorrent {
class torrent;
@ -48,7 +50,7 @@ namespace libtorrent {
// to connecting to peers with higher rank. This is to avoid
// problems when our peer list is diluted by stale peers from
// the resume data for instance
int source_rank(int source_bitmask);
int source_rank(peer_source_flags_t source_bitmask);
}
#endif

View File

@ -147,7 +147,7 @@ namespace libtorrent {
// connection, just to count hash failures
// it's also used to hold the peer_connection
// pointer, when the web seed is connected
ipv4_peer peer_info{tcp::endpoint(), true, 0};
ipv4_peer peer_info{tcp::endpoint(), true, {}};
// this is initialized to true, but if we discover the
// server not to support it, it's set to false, and we
@ -356,7 +356,8 @@ namespace libtorrent {
void remove_extension(std::shared_ptr<torrent_plugin>);
void add_extension_fun(std::function<std::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata);
void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags);
void notify_extension_add_peer(tcp::endpoint const& ip
, peer_source_flags_t src, int flags);
#endif
peer_connection* find_lowest_ranking_peer() const;
@ -661,9 +662,10 @@ namespace libtorrent {
void update_gauge();
bool try_connect_peer();
torrent_peer* add_peer(tcp::endpoint const& adr, int source, int flags = 0);
torrent_peer* add_peer(tcp::endpoint const& adr
, peer_source_flags_t source, int flags = 0);
bool ban_peer(torrent_peer* tp);
void update_peer_port(int port, torrent_peer* p, int src);
void update_peer_port(int port, torrent_peer* p, peer_source_flags_t src);
void set_seed(torrent_peer* p, bool s);
void clear_failcount(torrent_peer* p);
std::pair<peer_list::iterator, peer_list::iterator> find_peers(address const& a);

View File

@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/storage_defs.hpp"
#include "libtorrent/torrent_flags.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent { namespace aux {
@ -1100,7 +1101,7 @@ namespace libtorrent { namespace aux {
// used as a rendezvous point in case direct
// connections to the peer fail
// ==== ==========================================
void connect_peer(tcp::endpoint const& adr, int source = 0
void connect_peer(tcp::endpoint const& adr, peer_source_flags_t source = {}
, int flags = 0x1 + 0x4 + 0x8) const;
// ``set_max_uploads()`` sets the maximum number of peers that's unchoked

View File

@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent {
@ -50,7 +51,7 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT torrent_peer
{
torrent_peer(std::uint16_t port, bool connectable, int src);
torrent_peer(std::uint16_t port, bool connectable, peer_source_flags_t src);
std::int64_t total_download() const;
std::int64_t total_upload() const;
@ -146,6 +147,9 @@ namespace libtorrent {
// from peer_info.
std::uint32_t source:6;
peer_source_flags_t peer_source() const
{ return peer_source_flags_t(source); }
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// Hints encryption support of torrent_peer. Only effective
// for and when the outgoing encryption policy
@ -199,7 +203,7 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT ipv4_peer : torrent_peer
{
ipv4_peer(tcp::endpoint const& ip, bool connectable, int src);
ipv4_peer(tcp::endpoint const& ip, bool connectable, peer_source_flags_t src);
ipv4_peer(ipv4_peer const& p);
ipv4_peer& operator=(ipv4_peer const& p);
@ -209,7 +213,7 @@ namespace libtorrent {
#if TORRENT_USE_I2P
struct TORRENT_EXTRA_EXPORT i2p_peer : torrent_peer
{
i2p_peer(char const* destination, bool connectable, int src);
i2p_peer(char const* destination, bool connectable, peer_source_flags_t src);
i2p_peer(i2p_peer const&);
~i2p_peer();
i2p_peer& operator=(i2p_peer const&);
@ -221,7 +225,7 @@ namespace libtorrent {
#if TORRENT_USE_IPV6
struct TORRENT_EXTRA_EXPORT ipv6_peer : torrent_peer
{
ipv6_peer(tcp::endpoint const& ip, bool connectable, int src);
ipv6_peer(tcp::endpoint const& ip, bool connectable, peer_source_flags_t src);
ipv6_peer(ipv6_peer const& p);
const address_v6::bytes_type addr;

View File

@ -162,6 +162,7 @@ libtorrent_rasterbar_la_SOURCES = \
file_progress.cpp \
ffs.cpp \
add_torrent_params.cpp \
peer_info.cpp \
\
$(KADEMLIA_SOURCES) \
\

View File

@ -4460,27 +4460,27 @@ namespace libtorrent {
p.last_active = now - (std::max)(m_last_sent, m_last_receive);
// this will set the flags so that we can update them later
p.flags = 0;
p.flags = {};
get_specific_peer_info(p);
p.flags |= is_seed() ? peer_info::seed : 0;
p.flags |= m_snubbed ? peer_info::snubbed : 0;
p.flags |= m_upload_only ? peer_info::upload_only : 0;
p.flags |= m_endgame_mode ? peer_info::endgame_mode : 0;
p.flags |= m_holepunch_mode ? peer_info::holepunched : 0;
if (is_seed()) p.flags |= peer_info::seed;
if (m_snubbed) p.flags |= peer_info::snubbed;
if (m_upload_only) p.flags |= peer_info::upload_only;
if (m_endgame_mode) p.flags |= peer_info::endgame_mode;
if (m_holepunch_mode) p.flags |= peer_info::holepunched;
if (peer_info_struct())
{
torrent_peer* pi = peer_info_struct();
TORRENT_ASSERT(pi->in_use);
p.source = pi->source;
p.source = peer_source_flags_t(pi->source);
p.failcount = pi->failcount;
p.num_hashfails = pi->hashfails;
p.flags |= pi->on_parole ? peer_info::on_parole : 0;
p.flags |= pi->optimistically_unchoked ? peer_info::optimistic_unchoke : 0;
if (pi->on_parole) p.flags |= peer_info::on_parole;
if (pi->optimistically_unchoked) p.flags |= peer_info::optimistic_unchoke;
}
else
{
p.source = 0;
p.source = {};
p.failcount = 0;
p.num_hashfails = 0;
}

70
src/peer_info.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
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.
*/
#include "libtorrent/peer_info.hpp"
namespace libtorrent {
// This will no longer be necessary with C++17
constexpr peer_flags_t peer_info::interesting;
constexpr peer_flags_t peer_info::choked;
constexpr peer_flags_t peer_info::remote_interested;
constexpr peer_flags_t peer_info::remote_choked;
constexpr peer_flags_t peer_info::supports_extensions;
constexpr peer_flags_t peer_info::local_connection;
constexpr peer_flags_t peer_info::handshake;
constexpr peer_flags_t peer_info::connecting;
#ifndef TORRENT_NO_DEPRECATE
constexpr peer_flags_t peer_info::queued;
#endif
constexpr peer_flags_t peer_info::on_parole;
constexpr peer_flags_t peer_info::seed;
constexpr peer_flags_t peer_info::optimistic_unchoke;
constexpr peer_flags_t peer_info::snubbed;
constexpr peer_flags_t peer_info::upload_only;
constexpr peer_flags_t peer_info::endgame_mode;
constexpr peer_flags_t peer_info::holepunched;
constexpr peer_flags_t peer_info::i2p_socket;
constexpr peer_flags_t peer_info::utp_socket;
constexpr peer_flags_t peer_info::ssl_socket;
constexpr peer_flags_t peer_info::rc4_encrypted;
constexpr peer_flags_t peer_info::plaintext_encrypted;
constexpr peer_source_flags_t peer_info::tracker;
constexpr peer_source_flags_t peer_info::dht;
constexpr peer_source_flags_t peer_info::pex;
constexpr peer_source_flags_t peer_info::lsd;
constexpr peer_source_flags_t peer_info::resume_data;
constexpr peer_source_flags_t peer_info::incoming;
}

View File

@ -302,7 +302,7 @@ namespace libtorrent {
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p.in_use);
if (&p == m_locked_peer) return false;
return p.source == peer_info::resume_data;
return p.peer_source() == peer_info::resume_data;
}
bool peer_list::is_erase_candidate(torrent_peer const& pe) const
@ -314,7 +314,7 @@ namespace libtorrent {
if (is_connect_candidate(pe)) return false;
return (pe.failcount > 0)
|| (pe.source == peer_info::resume_data);
|| (pe.peer_source() == peer_info::resume_data);
}
bool peer_list::is_force_erase_candidate(torrent_peer const& pe) const
@ -753,10 +753,10 @@ namespace libtorrent {
#if TORRENT_USE_IPV6
if (is_v6)
new (p) ipv6_peer(c.remote(), false, 0);
new (p) ipv6_peer(c.remote(), false, {});
else
#endif
new (p) ipv4_peer(c.remote(), false, 0);
new (p) ipv4_peer(c.remote(), false, {});
#if TORRENT_USE_ASSERTS
p->in_use = true;
@ -768,7 +768,7 @@ namespace libtorrent {
i = *iter;
i->source = peer_info::incoming;
i->source = static_cast<std::uint8_t>(peer_info::incoming);
}
TORRENT_ASSERT(i);
@ -789,7 +789,8 @@ namespace libtorrent {
return true;
}
bool peer_list::update_peer_port(int const port, torrent_peer* p, int src, torrent_state* state)
bool peer_list::update_peer_port(int const port, torrent_peer* p
, peer_source_flags_t const src, torrent_state* state)
{
TORRENT_ASSERT(p != nullptr);
TORRENT_ASSERT(p->connection);
@ -816,7 +817,7 @@ namespace libtorrent {
// if we already have an entry with this
// new endpoint, disconnect this one
pp.connectable = true;
pp.source |= src;
pp.source |= static_cast<std::uint8_t>(src);
if (!was_conn_cand && is_connect_candidate(pp))
update_connect_candidates(1);
// calling disconnect() on a peer, may actually end
@ -850,7 +851,7 @@ namespace libtorrent {
bool const was_conn_cand = is_connect_candidate(*p);
p->port = std::uint16_t(port);
p->source |= src;
p->source |= static_cast<std::uint8_t>(src);
p->connectable = true;
if (was_conn_cand != is_connect_candidate(*p))
@ -905,7 +906,7 @@ namespace libtorrent {
if (max_peerlist_size
&& int(m_peers.size()) >= max_peerlist_size)
{
if (p->source == peer_info::resume_data) return false;
if (p->peer_source() == peer_info::resume_data) return false;
erase_peers(state);
if (int(m_peers.size()) >= max_peerlist_size)
@ -950,7 +951,8 @@ namespace libtorrent {
return true;
}
void peer_list::update_peer(torrent_peer* p, int src, int flags
void peer_list::update_peer(torrent_peer* p, peer_source_flags_t const src
, int flags
, tcp::endpoint const& remote, char const* /* destination*/)
{
TORRENT_ASSERT(is_single_thread());
@ -961,7 +963,7 @@ namespace libtorrent {
TORRENT_ASSERT(p->address() == remote.address());
p->port = remote.port();
p->source |= src;
p->source |= static_cast<std::uint8_t>(src);
// if this peer has failed before, decrease the
// counter to allow it another try, since somebody
@ -1007,7 +1009,8 @@ namespace libtorrent {
#if TORRENT_USE_I2P
// TODO: 3 use string_view for destination
torrent_peer* peer_list::add_i2p_peer(char const* destination, int src, char flags, torrent_state* state)
torrent_peer* peer_list::add_i2p_peer(char const* destination
, peer_source_flags_t const src, char flags, torrent_state* state)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -1055,7 +1058,8 @@ namespace libtorrent {
#endif // TORRENT_USE_I2P
// if this returns non-nullptr, the torrent need to post status update
torrent_peer* peer_list::add_peer(tcp::endpoint const& remote, int src, char flags
torrent_peer* peer_list::add_peer(tcp::endpoint const& remote
, peer_source_flags_t const src, char flags
, torrent_state* state)
{
TORRENT_ASSERT(is_single_thread());
@ -1351,8 +1355,8 @@ namespace libtorrent {
if (lhs.failcount != rhs.failcount)
return lhs.failcount > rhs.failcount;
bool lhs_resume_data_source = lhs.source == peer_info::resume_data;
bool rhs_resume_data_source = rhs.source == peer_info::resume_data;
bool const lhs_resume_data_source = lhs.peer_source() == peer_info::resume_data;
bool const rhs_resume_data_source = rhs.peer_source() == peer_info::resume_data;
// prefer to drop peers whose only source is resume data
if (lhs_resume_data_source != rhs_resume_data_source)
@ -1381,8 +1385,8 @@ namespace libtorrent {
if (lhs->last_connected != rhs->last_connected)
return lhs->last_connected < rhs->last_connected;
int lhs_rank = source_rank(lhs->source);
int rhs_rank = source_rank(rhs->source);
int const lhs_rank = source_rank(lhs->peer_source());
int const rhs_rank = source_rank(rhs->peer_source());
if (lhs_rank != rhs_rank) return lhs_rank > rhs_rank;
std::uint32_t lhs_peer_rank = lhs->rank(external, external_port);

View File

@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
int source_rank(int source_bitmask)
int source_rank(peer_source_flags_t const source_bitmask)
{
int ret = 0;
if (source_bitmask & peer_info::tracker) ret |= 1 << 5;

View File

@ -9986,7 +9986,8 @@ namespace libtorrent {
return true;
}
torrent_peer* torrent::add_peer(tcp::endpoint const& adr, int source, int flags)
torrent_peer* torrent::add_peer(tcp::endpoint const& adr
, peer_source_flags_t const source, int flags)
{
TORRENT_ASSERT(is_single_thread());
@ -10141,7 +10142,8 @@ namespace libtorrent {
return m_peer_list->find_peers(a);
}
void torrent::update_peer_port(int port, torrent_peer* p, int src)
void torrent::update_peer_port(int port, torrent_peer* p
, peer_source_flags_t const src)
{
need_peer_list();
torrent_state st = get_peer_list_state();
@ -10496,11 +10498,11 @@ namespace {
#ifndef TORRENT_DISABLE_EXTENSIONS
void torrent::notify_extension_add_peer(tcp::endpoint const& ip
, int src, int flags)
, peer_source_flags_t const src, int flags)
{
for (auto& ext : m_extensions)
{
ext->on_add_peer(ip, src, flags);
ext->on_add_peer(ip, static_cast<std::uint8_t>(src), flags);
}
}
#endif

View File

@ -676,7 +676,8 @@ namespace libtorrent {
#endif
void torrent_handle::connect_peer(tcp::endpoint const& adr, int source, int flags) const
void torrent_handle::connect_peer(tcp::endpoint const& adr
, peer_source_flags_t const source, int flags) const
{
async_call(&torrent::add_peer, adr, source, flags);
}

View File

@ -141,7 +141,8 @@ namespace libtorrent {
return ret;
}
torrent_peer::torrent_peer(std::uint16_t port_, bool conn, int const src)
torrent_peer::torrent_peer(std::uint16_t port_, bool conn
, peer_source_flags_t const src)
: prev_amount_upload(0)
, prev_amount_download(0)
, connection(nullptr)
@ -156,7 +157,7 @@ namespace libtorrent {
, seed(false)
, fast_reconnects(0)
, trust_points(0)
, source(aux::numeric_cast<std::uint8_t>(src))
, source(static_cast<std::uint8_t>(src))
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// assume no support in order to
// prefer opening non-encrypted
@ -228,7 +229,8 @@ namespace libtorrent {
}
}
ipv4_peer::ipv4_peer(tcp::endpoint const& ep, bool c, int src)
ipv4_peer::ipv4_peer(tcp::endpoint const& ep, bool c
, peer_source_flags_t const src)
: torrent_peer(ep.port(), c, src)
, addr(ep.address().to_v4())
{
@ -244,7 +246,8 @@ namespace libtorrent {
ipv4_peer& ipv4_peer::operator=(ipv4_peer const& p) = default;
#if TORRENT_USE_I2P
i2p_peer::i2p_peer(char const* dest, bool connectable, int src)
i2p_peer::i2p_peer(char const* dest, bool connectable
, peer_source_flags_t const src)
: torrent_peer(0, connectable, src), destination(allocate_string_copy(dest))
{
#if TORRENT_USE_IPV6
@ -257,7 +260,7 @@ namespace libtorrent {
{ free(destination); }
i2p_peer::i2p_peer(const i2p_peer& rhs)
: torrent_peer(rhs.port, rhs.connectable, rhs.source)
: torrent_peer(rhs.port, rhs.connectable, rhs.peer_source())
, destination(allocate_string_copy(rhs.destination))
{}
@ -271,9 +274,8 @@ namespace libtorrent {
#endif // TORRENT_USE_I2P
#if TORRENT_USE_IPV6
ipv6_peer::ipv6_peer(
tcp::endpoint const& ep, bool c, int src
)
ipv6_peer::ipv6_peer(tcp::endpoint const& ep, bool c
, peer_source_flags_t const src)
: torrent_peer(ep.port(), c, src)
, addr(ep.address().to_v6().to_bytes())
{

View File

@ -875,7 +875,7 @@ TORRENT_TEST(dont_have)
TEST_EQUAL(pi.size(), 1);
if (pi.size() != 1) return;
TEST_EQUAL(pi[0].flags & peer_info::seed, 0);
TEST_CHECK(!(pi[0].flags & peer_info::seed));
TEST_EQUAL(pi[0].pieces.count(), pi[0].pieces.size() - 1);
TEST_EQUAL(pi[0].pieces[piece_index_t(3)], false);
TEST_EQUAL(pi[0].pieces[piece_index_t(2)], true);

View File

@ -179,7 +179,7 @@ torrent_state init_state(torrent_peer_allocator& allocator)
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, 0, &st);
torrent_peer* peer = p.add_peer(ep, {}, 0, &st);
if (peer)
{
TEST_EQUAL(p.num_connect_candidates(), cc + 1);
@ -210,13 +210,13 @@ TORRENT_TEST(multiple_ips_disallowed)
peer_list p;
t.m_p = &p;
TEST_EQUAL(p.num_connect_candidates(), 0);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), 0, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &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, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
TEST_EQUAL(p.num_peers(), 1);
TEST_EQUAL(peer1, peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -232,12 +232,12 @@ TORRENT_TEST(multiple_ips_allowed)
st.allow_multiple_connections_per_ip = true;
peer_list p;
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), 0, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &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, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
TEST_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 2);
@ -254,7 +254,7 @@ TORRENT_TEST(multiple_ips_allowed2)
st.allow_multiple_connections_per_ip = true;
peer_list p;
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), 0, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1);
st.erased.clear();
@ -270,7 +270,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, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
TEST_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -293,7 +293,7 @@ TORRENT_TEST(multiple_ips_disallowed2)
st.allow_multiple_connections_per_ip = false;
peer_list p;
t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), 0, 0, &st);
torrent_peer* peer1 = p.add_peer(ep("10.0.0.2", 3000), {}, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1);
TEST_EQUAL(peer1->port, 3000);
st.erased.clear();
@ -310,7 +310,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, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.2", 9020), {}, 0, &st);
TEST_EQUAL(p.num_peers(), 1);
TEST_EQUAL(peer2->port, 9020);
TEST_CHECK(peer1 == peer2);
@ -351,7 +351,7 @@ TORRENT_TEST(update_peer_port_collide)
peer_list p;
t.m_p = &p;
torrent_peer* peer2 = p.add_peer(ep("10.0.0.1", 4000), 0, 0, &st);
torrent_peer* peer2 = p.add_peer(ep("10.0.0.1", 4000), {}, 0, &st);
TEST_CHECK(peer2);
TEST_EQUAL(p.num_connect_candidates(), 1);
@ -521,7 +521,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, 0, &st);
torrent_peer* peer = p.add_peer(rand_tcp_ep(), {}, 0, &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);
@ -540,7 +540,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, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), 353), {}, 0, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
}
@ -570,7 +570,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, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
}
@ -600,7 +600,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, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
// every other peer has a failcount of 1
@ -630,7 +630,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, 0, &st);
address_v4((10 << 24) + ((i + 10) << 16)), i + 10), {}, 0, &st);
TEST_EQUAL(st.erased.size(), 0);
st.erased.clear();
// make every other peer a seed
@ -909,7 +909,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, 0, &st);
torrent_peer* peer6 = p.add_peer(ep("10.0.0.6", 8080), {}, 0, &st);
TEST_CHECK(peer6 == nullptr);
TEST_EQUAL(p.num_peers(), 5);

View File

@ -62,17 +62,17 @@ typed_bitfield<piece_index_t> string2vec(char const* have_str)
}
tcp::endpoint endp;
ipv4_peer tmp0(endp, false, 0);
ipv4_peer tmp1(endp, false, 0);
ipv4_peer tmp2(endp, false, 0);
ipv4_peer tmp3(endp, false, 0);
ipv4_peer tmp4(endp, false, 0);
ipv4_peer tmp5(endp, false, 0);
ipv4_peer tmp6(endp, false, 0);
ipv4_peer tmp7(endp, false, 0);
ipv4_peer tmp8(endp, false, 0);
ipv4_peer tmp9(endp, false, 0);
ipv4_peer peer_struct(endp, true, 0);
ipv4_peer tmp0(endp, false, {});
ipv4_peer tmp1(endp, false, {});
ipv4_peer tmp2(endp, false, {});
ipv4_peer tmp3(endp, false, {});
ipv4_peer tmp4(endp, false, {});
ipv4_peer tmp5(endp, false, {});
ipv4_peer tmp6(endp, false, {});
ipv4_peer tmp7(endp, false, {});
ipv4_peer tmp8(endp, false, {});
ipv4_peer tmp9(endp, false, {});
ipv4_peer peer_struct(endp, true, {});
ipv4_peer* tmp_peer = &tmp1;
static std::vector<piece_index_t> const empty_vector;

View File

@ -294,7 +294,7 @@ TORRENT_TEST(file_priorities_default_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses
, torrent_flags_t{}, "", "", true).file_priorities();
, {}, "", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -307,7 +307,7 @@ TORRENT_TEST(file_priorities_default_deprecated)
TORRENT_TEST(file_priorities_in_resume_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "", "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -320,7 +320,7 @@ TORRENT_TEST(file_priorities_in_resume_deprecated)
TORRENT_TEST(file_priorities_in_resume_and_params_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, 0, "456", "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "456", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -370,7 +370,7 @@ TORRENT_TEST(file_priorities_seed_mode_deprecated)
TORRENT_TEST(resume_save_load_deprecated)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "123", "", true);
torrent_handle h = test_resume_flags(ses, {}, "123", "", true);
h.save_resume_data();
@ -392,7 +392,7 @@ TORRENT_TEST(resume_save_load_deprecated)
TORRENT_TEST(resume_save_load_resume_deprecated)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "", "123", true);
torrent_handle h = test_resume_flags(ses, {}, "", "123", true);
h.save_resume_data();
@ -429,7 +429,7 @@ TORRENT_TEST(file_priorities_resume_override_deprecated)
TORRENT_TEST(file_priorities_resume_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "123", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "", "123", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -440,7 +440,7 @@ TORRENT_TEST(file_priorities_resume_deprecated)
TORRENT_TEST(file_priorities1_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "010", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "010", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -453,7 +453,7 @@ TORRENT_TEST(file_priorities1_deprecated)
TORRENT_TEST(file_priorities2_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "123", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "123", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -464,7 +464,7 @@ TORRENT_TEST(file_priorities2_deprecated)
TORRENT_TEST(file_priorities3_deprecated)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "4321", "", true).file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "4321", "", true).file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -476,7 +476,7 @@ TORRENT_TEST(plain_deprecated)
{
lt::session ses(settings());
torrent_status s = test_resume_flags(ses, torrent_flags_t{}, "", "", true).status();
torrent_status s = test_resume_flags(ses, {}, "", "", true).status();
default_tests(s);
#ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path");
@ -654,7 +654,7 @@ TORRENT_TEST(resume_override_torrent_deprecated)
TORRENT_TEST(file_priorities_default)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "", "").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);
@ -666,8 +666,8 @@ TORRENT_TEST(file_priorities_resume_seed_mode)
{
// in share mode file priorities should always be 0
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses,
torrent_flags::share_mode, "", "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses
, torrent_flags::share_mode, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -679,8 +679,8 @@ TORRENT_TEST(file_priorities_seed_mode)
{
// in share mode file priorities should always be 0
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses,
torrent_flags::share_mode, "123", "").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses
, torrent_flags::share_mode, "123", "").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -934,7 +934,7 @@ TORRENT_TEST(seed_mode_preserve)
TORRENT_TEST(resume_save_load)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "123", "");
torrent_handle h = test_resume_flags(ses, {}, "123", "");
h.save_resume_data();
@ -956,7 +956,7 @@ TORRENT_TEST(resume_save_load)
TORRENT_TEST(resume_save_load_resume)
{
lt::session ses(settings());
torrent_handle h = test_resume_flags(ses, torrent_flags_t{}, "", "123");
torrent_handle h = test_resume_flags(ses, {}, "", "123");
h.save_resume_data();
@ -978,7 +978,7 @@ TORRENT_TEST(resume_save_load_resume)
TORRENT_TEST(file_priorities_resume)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "", "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -989,7 +989,7 @@ TORRENT_TEST(file_priorities_resume)
TORRENT_TEST(file_priorities1)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "010").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "010").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0);
@ -1002,7 +1002,7 @@ TORRENT_TEST(file_priorities1)
TORRENT_TEST(file_priorities2)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "123").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 1);
@ -1013,7 +1013,7 @@ TORRENT_TEST(file_priorities2)
TORRENT_TEST(file_priorities3)
{
lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, torrent_flags_t{}, "4321").file_priorities();
std::vector<int> file_priorities = test_resume_flags(ses, {}, "4321").file_priorities();
TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 4);