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 version
ffs ffs
add_torrent_params add_torrent_params
peer_info
# -- extensions -- # -- extensions --
ut_pex ut_pex

View File

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

View File

@ -13,6 +13,7 @@
#include "libtorrent/sha1_hash.hpp" #include "libtorrent/sha1_hash.hpp"
#include "libtorrent/disk_interface.hpp" // for open_file_state #include "libtorrent/disk_interface.hpp" // for open_file_state
#include "libtorrent/aux_/noexcept_movable.hpp" #include "libtorrent/aux_/noexcept_movable.hpp"
#include "libtorrent/peer_info.hpp"
#include <vector> #include <vector>
using namespace boost::python; 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::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::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::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 // work-around types
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple< 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::piece_index_t>();
to_strong_typedef<lt::file_index_t>(); to_strong_typedef<lt::file_index_t>();
to_bitfield_flag<lt::torrent_flags_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() void bind_peer_info()
{ {
scope pi = class_<peer_info>("peer_info") scope pi = class_<peer_info>("peer_info")
.def_readonly("flags", &peer_info::flags) .add_property("flags", make_getter(&peer_info::flags, by_value()))
.def_readonly("source", &peer_info::source) .add_property("source", make_getter(&peer_info::source, by_value()))
.def_readonly("read_state", &peer_info::read_state) .def_readonly("read_state", &peer_info::read_state)
.def_readonly("write_state", &peer_info::write_state) .def_readonly("write_state", &peer_info::write_state)
.add_property("ip", get_ip) .add_property("ip", get_ip)
@ -103,27 +103,27 @@ void bind_peer_info()
; ;
// flags // flags
pi.attr("interesting") = (int)peer_info::interesting; pi.attr("interesting") = peer_info::interesting;
pi.attr("choked") = (int)peer_info::choked; pi.attr("choked") = peer_info::choked;
pi.attr("remote_interested") = (int)peer_info::remote_interested; pi.attr("remote_interested") = peer_info::remote_interested;
pi.attr("remote_choked") = (int)peer_info::remote_choked; pi.attr("remote_choked") = peer_info::remote_choked;
pi.attr("supports_extensions") = (int)peer_info::supports_extensions; pi.attr("supports_extensions") = peer_info::supports_extensions;
pi.attr("local_connection") = (int)peer_info::local_connection; pi.attr("local_connection") = peer_info::local_connection;
pi.attr("handshake") = (int)peer_info::handshake; pi.attr("handshake") = peer_info::handshake;
pi.attr("connecting") = (int)peer_info::connecting; pi.attr("connecting") = peer_info::connecting;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
pi.attr("queued") = (int)peer_info::queued; pi.attr("queued") = peer_info::queued;
#endif #endif
pi.attr("on_parole") = (int)peer_info::on_parole; pi.attr("on_parole") = peer_info::on_parole;
pi.attr("seed") = (int)peer_info::seed; pi.attr("seed") = peer_info::seed;
pi.attr("optimistic_unchoke") = (int)peer_info::optimistic_unchoke; pi.attr("optimistic_unchoke") = peer_info::optimistic_unchoke;
pi.attr("snubbed") = (int)peer_info::snubbed; pi.attr("snubbed") = peer_info::snubbed;
pi.attr("upload_only") = (int)peer_info::upload_only; pi.attr("upload_only") = peer_info::upload_only;
pi.attr("endgame_mode") = (int)peer_info::endgame_mode; pi.attr("endgame_mode") = peer_info::endgame_mode;
pi.attr("holepunched") = (int)peer_info::holepunched; pi.attr("holepunched") = peer_info::holepunched;
#ifndef TORRENT_DISABLE_ENCRYPTION #ifndef TORRENT_DISABLE_ENCRYPTION
pi.attr("rc4_encrypted") = (int)peer_info::rc4_encrypted; pi.attr("rc4_encrypted") = peer_info::rc4_encrypted;
pi.attr("plaintext_encrypted") = (int)peer_info::plaintext_encrypted; pi.attr("plaintext_encrypted") = peer_info::plaintext_encrypted;
#endif #endif
// connection_type // connection_type
@ -131,11 +131,11 @@ void bind_peer_info()
pi.attr("web_seed") = (int)peer_info::web_seed; pi.attr("web_seed") = (int)peer_info::web_seed;
// source // source
pi.attr("tracker") = (int)peer_info::tracker; pi.attr("tracker") = peer_info::tracker;
pi.attr("dht") = (int)peer_info::dht; pi.attr("dht") = peer_info::dht;
pi.attr("pex") = (int)peer_info::pex; pi.attr("pex") = peer_info::pex;
pi.attr("lsd") = (int)peer_info::lsd; pi.attr("lsd") = peer_info::lsd;
pi.attr("resume_data") = (int)peer_info::resume_data; pi.attr("resume_data") = peer_info::resume_data;
// read/write state // read/write state
pi.attr("bw_idle") = (int)peer_info::bw_idle; pi.attr("bw_idle") = (int)peer_info::bw_idle;

View File

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

View File

@ -487,7 +487,7 @@ int print_peer_info(std::string& out
if (print_peer_rate) 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" std::snprintf(str, sizeof(str), " %s"
, unchoked ? add_suffix(i->estimated_reciprocation_rate, "/s").c_str() : " "); , 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; int const index = pp ? peer_index(pp->blocks[j].peer(), peers) % 36 : -1;
char const* chr = " "; 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 = ""; 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 const& rhs) noexcept = default;
constexpr bitfield_flag(bitfield_flag&& rhs) noexcept = default; constexpr bitfield_flag(bitfield_flag&& rhs) noexcept = default;
constexpr bitfield_flag() noexcept : m_val(0) {} constexpr bitfield_flag() noexcept : m_val(0) {}
#ifdef TORRENT_NO_DEPRECATE
explicit constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {} explicit constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {}
#ifdef TORRENT_NO_DEPRECATE
explicit constexpr operator UnderlyingType() const noexcept { return m_val; } explicit constexpr operator UnderlyingType() const noexcept { return m_val; }
#else #else
constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {}
constexpr operator UnderlyingType() const noexcept { return m_val; } constexpr operator UnderlyingType() const noexcept { return m_val; }
#endif #endif
explicit constexpr operator bool() const noexcept { return m_val != 0; } 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/bitfield.hpp"
#include "libtorrent/time.hpp" #include "libtorrent/time.hpp"
#include "libtorrent/units.hpp" #include "libtorrent/units.hpp"
#include "libtorrent/flags.hpp"
namespace libtorrent { 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 // holds information and statistics about one peer
// that libtorrent is connected to // that libtorrent is connected to
struct TORRENT_EXPORT peer_info struct TORRENT_EXPORT peer_info
@ -73,148 +88,133 @@ namespace libtorrent {
// the time until all blocks in the request queue will be downloaded // the time until all blocks in the request queue will be downloaded
time_duration download_queue_time; time_duration download_queue_time;
// flags for the peer_info::flags field. Indicates various states // **we** are interested in pieces from this peer.
// the peer may be in. These flags are not mutually exclusive, but static constexpr peer_flags_t interesting{0x1};
// not every combination of them makes sense either.
enum peer_flags_t
{
// **we** are interested in pieces from this peer.
interesting = 0x1,
// **we** have choked this peer. // **we** have choked this peer.
choked = 0x2, static constexpr peer_flags_t choked{0x2};
// the peer is interested in **us** // the peer is interested in **us**
remote_interested = 0x4, static constexpr peer_flags_t remote_interested{0x4};
// the peer has choked **us**. // the peer has choked **us**.
remote_choked = 0x8, static constexpr peer_flags_t remote_choked{0x8};
// means that this peer supports the // means that this peer supports the
// `extension protocol`__. // `extension protocol`__.
// //
// __ extension_protocol.html // __ extension_protocol.html
supports_extensions = 0x10, static constexpr peer_flags_t supports_extensions{0x10};
// The connection was initiated by us, the peer has a // The connection was initiated by us, the peer has a
// listen port open, and that port is the same as in the // listen port open, and that port is the same as in the
// address of this peer. If this flag is not set, this // address of this peer. If this flag is not set, this
// peer connection was opened by this peer connecting to // peer connection was opened by this peer connecting to
// us. // us.
local_connection = 0x20, static constexpr peer_flags_t local_connection{0x20};
// The connection is opened, and waiting for the // The connection is opened, and waiting for the
// handshake. Until the handshake is done, the peer // handshake. Until the handshake is done, the peer
// cannot be identified. // cannot be identified.
handshake = 0x40, static constexpr peer_flags_t handshake{0x40};
// The connection is in a half-open state (i.e. it is // The connection is in a half-open state (i.e. it is
// being connected). // being connected).
connecting = 0x80, static constexpr peer_flags_t connecting{0x80};
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// The connection is currently queued for a connection // The connection is currently queued for a connection
// attempt. This may happen if there is a limit set on // attempt. This may happen if there is a limit set on
// the number of half-open TCP connections. // the number of half-open TCP connections.
queued = 0x100, static constexpr peer_flags_t queued{0x100};
#else
// hidden
deprecated__ = 0x100,
#endif #endif
// The peer has participated in a piece that failed the // The peer has participated in a piece that failed the
// hash check, and is now "on parole", which means we're // hash check, and is now "on parole", which means we're
// only requesting whole pieces from this peer until // only requesting whole pieces from this peer until
// it either fails that piece or proves that it doesn't // it either fails that piece or proves that it doesn't
// send bad data. // send bad data.
on_parole = 0x200, static constexpr peer_flags_t on_parole{0x200};
// This peer is a seed (it has all the pieces). // This peer is a seed (it has all the pieces).
seed = 0x400, static constexpr peer_flags_t seed{0x400};
// This peer is subject to an optimistic unchoke. It has // This peer is subject to an optimistic unchoke. It has
// been unchoked for a while to see if it might unchoke // been unchoked for a while to see if it might unchoke
// us in return an earn an upload/unchoke slot. If it // us in return an earn an upload/unchoke slot. If it
// doesn't within some period of time, it will be choked // doesn't within some period of time, it will be choked
// and another peer will be optimistically unchoked. // and another peer will be optimistically unchoked.
optimistic_unchoke = 0x800, static constexpr peer_flags_t optimistic_unchoke{0x800};
// This peer has recently failed to send a block within // This peer has recently failed to send a block within
// the request timeout from when the request was sent. // the request timeout from when the request was sent.
// We're currently picking one block at a time from this // We're currently picking one block at a time from this
// peer. // peer.
snubbed = 0x1000, static constexpr peer_flags_t snubbed{0x1000};
// This peer has either explicitly (with an extension) // This peer has either explicitly (with an extension)
// or implicitly (by becoming a seed) told us that it // or implicitly (by becoming a seed) told us that it
// will not downloading anything more, regardless of // will not downloading anything more, regardless of
// which pieces we have. // which pieces we have.
upload_only = 0x2000, static constexpr peer_flags_t upload_only{0x2000};
// This means the last time this peer picket a piece, // This means the last time this peer picket a piece,
// it could not pick as many as it wanted because there // it could not pick as many as it wanted because there
// were not enough free ones. i.e. all pieces this peer // were not enough free ones. i.e. all pieces this peer
// has were already requested from other peers. // has were already requested from other peers.
endgame_mode = 0x4000, static constexpr peer_flags_t endgame_mode{0x4000};
// This flag is set if the peer was in holepunch mode // This flag is set if the peer was in holepunch mode
// when the connection succeeded. This typically only // when the connection succeeded. This typically only
// happens if both peers are behind a NAT and the peers // happens if both peers are behind a NAT and the peers
// connect via the NAT holepunch mechanism. // connect via the NAT holepunch mechanism.
holepunched = 0x8000, static constexpr peer_flags_t holepunched{0x8000};
// indicates that this socket is running on top of the // indicates that this socket is running on top of the
// I2P transport. // I2P transport.
i2p_socket = 0x10000, static constexpr peer_flags_t i2p_socket{0x10000};
// indicates that this socket is a uTP socket // indicates that this socket is a uTP socket
utp_socket = 0x20000, static constexpr peer_flags_t utp_socket{0x20000};
// indicates that this socket is running on top of an SSL // indicates that this socket is running on top of an SSL
// (TLS) channel // (TLS) channel
ssl_socket = 0x40000, static constexpr peer_flags_t ssl_socket{0x40000};
// this connection is obfuscated with RC4 // this connection is obfuscated with RC4
rc4_encrypted = 0x100000, static constexpr peer_flags_t rc4_encrypted{0x100000};
// the handshake of this connection was obfuscated // the handshake of this connection was obfuscated
// with a diffie-hellman exchange // with a Diffie-Hellman exchange
plaintext_encrypted = 0x200000 static constexpr peer_flags_t plaintext_encrypted{0x200000};
};
// tells you in which state the peer is in. It is set to // tells you in which state the peer is in. It is set to
// any combination of the peer_flags_t enum. // any combination of the peer_flags_t enum.
std::uint32_t flags; peer_flags_t flags;
// the flags indicating which sources a peer can // The peer was received from the tracker.
// have come from. A peer may have been seen from static constexpr peer_source_flags_t tracker{0x1};
// multiple sources
enum peer_source_flags
{
// The peer was received from the tracker.
tracker = 0x1,
// The peer was received from the kademlia DHT. // The peer was received from the kademlia DHT.
dht = 0x2, static constexpr peer_source_flags_t dht{0x2};
// The peer was received from the peer exchange // The peer was received from the peer exchange
// extension. // extension.
pex = 0x4, static constexpr peer_source_flags_t pex{0x4};
// The peer was received from the local service // The peer was received from the local service
// discovery (The peer is on the local network). // discovery (The peer is on the local network).
lsd = 0x8, static constexpr peer_source_flags_t lsd{0x8};
// The peer was added from the fast resume data. // The peer was added from the fast resume data.
resume_data = 0x10, static constexpr peer_source_flags_t resume_data{0x10};
// we received an incoming connection from this peer // we received an incoming connection from this peer
incoming = 0x20 static constexpr peer_source_flags_t incoming{0x20};
};
// a combination of flags describing from which sources this peer // a combination of flags describing from which sources this peer
// was received. See peer_source_flags. // 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 // the current upload and download speed we have to and from this peer
// (including any protocol messages). updated about once per second // (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/debug.hpp"
#include "libtorrent/peer_connection_interface.hpp" #include "libtorrent/peer_connection_interface.hpp"
#include "libtorrent/aux_/deque.hpp" #include "libtorrent/aux_/deque.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent { namespace libtorrent {
@ -112,7 +113,8 @@ namespace libtorrent {
peer_list(); peer_list();
#if TORRENT_USE_I2P #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); , torrent_state* state);
#endif #endif
@ -129,10 +131,11 @@ namespace libtorrent {
// this is called once for every torrent_peer we get from // this is called once for every torrent_peer we get from
// the tracker, pex, lsd or dht. // the tracker, pex, lsd or dht.
torrent_peer* add_peer(const tcp::endpoint& remote 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 // 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 // called when an incoming connection is accepted
// false means the connection was refused or failed // false means the connection was refused or failed
@ -209,7 +212,7 @@ namespace libtorrent {
void update_connect_candidates(int delta); 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); , tcp::endpoint const& remote, char const* destination);
bool insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state); 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 #ifndef TORRENT_REQUEST_BLOCKS_HPP_INCLUDED
#define TORRENT_REQUEST_BLOCKS_HPP_INCLUDED #define TORRENT_REQUEST_BLOCKS_HPP_INCLUDED
#include "libtorrent/peer_info.hpp"
namespace libtorrent { namespace libtorrent {
class torrent; class torrent;
@ -48,7 +50,7 @@ namespace libtorrent {
// to connecting to peers with higher rank. This is to avoid // to connecting to peers with higher rank. This is to avoid
// problems when our peer list is diluted by stale peers from // problems when our peer list is diluted by stale peers from
// the resume data for instance // the resume data for instance
int source_rank(int source_bitmask); int source_rank(peer_source_flags_t source_bitmask);
} }
#endif #endif

View File

@ -147,7 +147,7 @@ namespace libtorrent {
// connection, just to count hash failures // connection, just to count hash failures
// it's also used to hold the peer_connection // it's also used to hold the peer_connection
// pointer, when the web seed is connected // 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 // this is initialized to true, but if we discover the
// server not to support it, it's set to false, and we // 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 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 add_extension_fun(std::function<std::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata); , 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 #endif
peer_connection* find_lowest_ranking_peer() const; peer_connection* find_lowest_ranking_peer() const;
@ -661,9 +662,10 @@ namespace libtorrent {
void update_gauge(); void update_gauge();
bool try_connect_peer(); 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); 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 set_seed(torrent_peer* p, bool s);
void clear_failcount(torrent_peer* p); void clear_failcount(torrent_peer* p);
std::pair<peer_list::iterator, peer_list::iterator> find_peers(address const& a); 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/aux_/vector.hpp"
#include "libtorrent/storage_defs.hpp" #include "libtorrent/storage_defs.hpp"
#include "libtorrent/torrent_flags.hpp" #include "libtorrent/torrent_flags.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent { namespace aux { namespace libtorrent { namespace aux {
@ -1100,7 +1101,7 @@ namespace libtorrent { namespace aux {
// used as a rendezvous point in case direct // used as a rendezvous point in case direct
// connections to the peer fail // 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; , int flags = 0x1 + 0x4 + 0x8) const;
// ``set_max_uploads()`` sets the maximum number of peers that's unchoked // ``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/config.hpp"
#include "libtorrent/address.hpp" #include "libtorrent/address.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
namespace libtorrent { namespace libtorrent {
@ -50,7 +51,7 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT torrent_peer 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_download() const;
std::int64_t total_upload() const; std::int64_t total_upload() const;
@ -146,6 +147,9 @@ namespace libtorrent {
// from peer_info. // from peer_info.
std::uint32_t source:6; 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) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// Hints encryption support of torrent_peer. Only effective // Hints encryption support of torrent_peer. Only effective
// for and when the outgoing encryption policy // for and when the outgoing encryption policy
@ -199,7 +203,7 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT ipv4_peer : torrent_peer 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(ipv4_peer const& p);
ipv4_peer& operator=(ipv4_peer const& p); ipv4_peer& operator=(ipv4_peer const& p);
@ -209,7 +213,7 @@ namespace libtorrent {
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
struct TORRENT_EXTRA_EXPORT i2p_peer : torrent_peer 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 const&);
~i2p_peer(); ~i2p_peer();
i2p_peer& operator=(i2p_peer const&); i2p_peer& operator=(i2p_peer const&);
@ -221,7 +225,7 @@ namespace libtorrent {
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
struct TORRENT_EXTRA_EXPORT ipv6_peer : torrent_peer 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); ipv6_peer(ipv6_peer const& p);
const address_v6::bytes_type addr; const address_v6::bytes_type addr;

View File

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

View File

@ -4460,27 +4460,27 @@ namespace libtorrent {
p.last_active = now - (std::max)(m_last_sent, m_last_receive); p.last_active = now - (std::max)(m_last_sent, m_last_receive);
// this will set the flags so that we can update them later // this will set the flags so that we can update them later
p.flags = 0; p.flags = {};
get_specific_peer_info(p); get_specific_peer_info(p);
p.flags |= is_seed() ? peer_info::seed : 0; if (is_seed()) p.flags |= peer_info::seed;
p.flags |= m_snubbed ? peer_info::snubbed : 0; if (m_snubbed) p.flags |= peer_info::snubbed;
p.flags |= m_upload_only ? peer_info::upload_only : 0; if (m_upload_only) p.flags |= peer_info::upload_only;
p.flags |= m_endgame_mode ? peer_info::endgame_mode : 0; if (m_endgame_mode) p.flags |= peer_info::endgame_mode;
p.flags |= m_holepunch_mode ? peer_info::holepunched : 0; if (m_holepunch_mode) p.flags |= peer_info::holepunched;
if (peer_info_struct()) if (peer_info_struct())
{ {
torrent_peer* pi = peer_info_struct(); torrent_peer* pi = peer_info_struct();
TORRENT_ASSERT(pi->in_use); TORRENT_ASSERT(pi->in_use);
p.source = pi->source; p.source = peer_source_flags_t(pi->source);
p.failcount = pi->failcount; p.failcount = pi->failcount;
p.num_hashfails = pi->hashfails; p.num_hashfails = pi->hashfails;
p.flags |= pi->on_parole ? peer_info::on_parole : 0; if (pi->on_parole) p.flags |= peer_info::on_parole;
p.flags |= pi->optimistically_unchoked ? peer_info::optimistic_unchoke : 0; if (pi->optimistically_unchoked) p.flags |= peer_info::optimistic_unchoke;
} }
else else
{ {
p.source = 0; p.source = {};
p.failcount = 0; p.failcount = 0;
p.num_hashfails = 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(is_single_thread());
TORRENT_ASSERT(p.in_use); TORRENT_ASSERT(p.in_use);
if (&p == m_locked_peer) return false; 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 bool peer_list::is_erase_candidate(torrent_peer const& pe) const
@ -314,7 +314,7 @@ namespace libtorrent {
if (is_connect_candidate(pe)) return false; if (is_connect_candidate(pe)) return false;
return (pe.failcount > 0) 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 bool peer_list::is_force_erase_candidate(torrent_peer const& pe) const
@ -753,10 +753,10 @@ namespace libtorrent {
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (is_v6) if (is_v6)
new (p) ipv6_peer(c.remote(), false, 0); new (p) ipv6_peer(c.remote(), false, {});
else else
#endif #endif
new (p) ipv4_peer(c.remote(), false, 0); new (p) ipv4_peer(c.remote(), false, {});
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
p->in_use = true; p->in_use = true;
@ -768,7 +768,7 @@ namespace libtorrent {
i = *iter; i = *iter;
i->source = peer_info::incoming; i->source = static_cast<std::uint8_t>(peer_info::incoming);
} }
TORRENT_ASSERT(i); TORRENT_ASSERT(i);
@ -789,7 +789,8 @@ namespace libtorrent {
return true; 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 != nullptr);
TORRENT_ASSERT(p->connection); TORRENT_ASSERT(p->connection);
@ -816,7 +817,7 @@ namespace libtorrent {
// if we already have an entry with this // if we already have an entry with this
// new endpoint, disconnect this one // new endpoint, disconnect this one
pp.connectable = true; pp.connectable = true;
pp.source |= src; pp.source |= static_cast<std::uint8_t>(src);
if (!was_conn_cand && is_connect_candidate(pp)) if (!was_conn_cand && is_connect_candidate(pp))
update_connect_candidates(1); update_connect_candidates(1);
// calling disconnect() on a peer, may actually end // calling disconnect() on a peer, may actually end
@ -850,7 +851,7 @@ namespace libtorrent {
bool const was_conn_cand = is_connect_candidate(*p); bool const was_conn_cand = is_connect_candidate(*p);
p->port = std::uint16_t(port); p->port = std::uint16_t(port);
p->source |= src; p->source |= static_cast<std::uint8_t>(src);
p->connectable = true; p->connectable = true;
if (was_conn_cand != is_connect_candidate(*p)) if (was_conn_cand != is_connect_candidate(*p))
@ -905,7 +906,7 @@ namespace libtorrent {
if (max_peerlist_size if (max_peerlist_size
&& int(m_peers.size()) >= 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); erase_peers(state);
if (int(m_peers.size()) >= max_peerlist_size) if (int(m_peers.size()) >= max_peerlist_size)
@ -950,7 +951,8 @@ namespace libtorrent {
return true; 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*/) , tcp::endpoint const& remote, char const* /* destination*/)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
@ -961,7 +963,7 @@ namespace libtorrent {
TORRENT_ASSERT(p->address() == remote.address()); TORRENT_ASSERT(p->address() == remote.address());
p->port = remote.port(); p->port = remote.port();
p->source |= src; p->source |= static_cast<std::uint8_t>(src);
// if this peer has failed before, decrease the // if this peer has failed before, decrease the
// counter to allow it another try, since somebody // counter to allow it another try, since somebody
@ -1007,7 +1009,8 @@ namespace libtorrent {
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
// TODO: 3 use string_view for destination // 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()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1055,7 +1058,8 @@ namespace libtorrent {
#endif // TORRENT_USE_I2P #endif // TORRENT_USE_I2P
// if this returns non-nullptr, the torrent need to post status update // 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_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
@ -1351,8 +1355,8 @@ namespace libtorrent {
if (lhs.failcount != rhs.failcount) if (lhs.failcount != rhs.failcount)
return lhs.failcount > rhs.failcount; return lhs.failcount > rhs.failcount;
bool lhs_resume_data_source = lhs.source == peer_info::resume_data; bool const lhs_resume_data_source = lhs.peer_source() == peer_info::resume_data;
bool rhs_resume_data_source = rhs.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 // prefer to drop peers whose only source is resume data
if (lhs_resume_data_source != rhs_resume_data_source) if (lhs_resume_data_source != rhs_resume_data_source)
@ -1381,8 +1385,8 @@ namespace libtorrent {
if (lhs->last_connected != rhs->last_connected) if (lhs->last_connected != rhs->last_connected)
return lhs->last_connected < rhs->last_connected; return lhs->last_connected < rhs->last_connected;
int lhs_rank = source_rank(lhs->source); int const lhs_rank = source_rank(lhs->peer_source());
int rhs_rank = source_rank(rhs->source); int const rhs_rank = source_rank(rhs->peer_source());
if (lhs_rank != rhs_rank) return lhs_rank > rhs_rank; if (lhs_rank != rhs_rank) return lhs_rank > rhs_rank;
std::uint32_t lhs_peer_rank = lhs->rank(external, external_port); std::uint32_t lhs_peer_rank = lhs->rank(external, external_port);

View File

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

View File

@ -9986,7 +9986,8 @@ namespace libtorrent {
return true; 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()); TORRENT_ASSERT(is_single_thread());
@ -10141,7 +10142,8 @@ namespace libtorrent {
return m_peer_list->find_peers(a); 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(); need_peer_list();
torrent_state st = get_peer_list_state(); torrent_state st = get_peer_list_state();
@ -10496,11 +10498,11 @@ namespace {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void torrent::notify_extension_add_peer(tcp::endpoint const& ip 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) 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 #endif

View File

@ -676,7 +676,8 @@ namespace libtorrent {
#endif #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); async_call(&torrent::add_peer, adr, source, flags);
} }

View File

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

View File

@ -875,7 +875,7 @@ TORRENT_TEST(dont_have)
TEST_EQUAL(pi.size(), 1); TEST_EQUAL(pi.size(), 1);
if (pi.size() != 1) return; 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.count(), pi[0].pieces.size() - 1);
TEST_EQUAL(pi[0].pieces[piece_index_t(3)], false); TEST_EQUAL(pi[0].pieces[piece_index_t(3)], false);
TEST_EQUAL(pi[0].pieces[piece_index_t(2)], true); 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) torrent_peer* add_peer(peer_list& p, torrent_state& st, tcp::endpoint const& ep)
{ {
int cc = p.num_connect_candidates(); 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) if (peer)
{ {
TEST_EQUAL(p.num_connect_candidates(), cc + 1); TEST_EQUAL(p.num_connect_candidates(), cc + 1);
@ -210,13 +210,13 @@ TORRENT_TEST(multiple_ips_disallowed)
peer_list p; peer_list p;
t.m_p = &p; t.m_p = &p;
TEST_EQUAL(p.num_connect_candidates(), 0); 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_peers(), 1);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
st.erased.clear(); 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(p.num_peers(), 1);
TEST_EQUAL(peer1, peer2); TEST_EQUAL(peer1, peer2);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -232,12 +232,12 @@ TORRENT_TEST(multiple_ips_allowed)
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
peer_list p; peer_list p;
t.m_p = &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_connect_candidates(), 1);
TEST_EQUAL(p.num_peers(), 1); TEST_EQUAL(p.num_peers(), 1);
st.erased.clear(); 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_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2); TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 2); TEST_EQUAL(p.num_connect_candidates(), 2);
@ -254,7 +254,7 @@ TORRENT_TEST(multiple_ips_allowed2)
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
peer_list p; peer_list p;
t.m_p = &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_connect_candidates(), 1);
st.erased.clear(); st.erased.clear();
@ -270,7 +270,7 @@ TORRENT_TEST(multiple_ips_allowed2)
TEST_CHECK(tp == nullptr); TEST_CHECK(tp == nullptr);
st.erased.clear(); 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_EQUAL(p.num_peers(), 2);
TEST_CHECK(peer1 != peer2); TEST_CHECK(peer1 != peer2);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -293,7 +293,7 @@ TORRENT_TEST(multiple_ips_disallowed2)
st.allow_multiple_connections_per_ip = false; st.allow_multiple_connections_per_ip = false;
peer_list p; peer_list p;
t.m_p = &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_connect_candidates(), 1);
TEST_EQUAL(peer1->port, 3000); TEST_EQUAL(peer1->port, 3000);
st.erased.clear(); st.erased.clear();
@ -310,7 +310,7 @@ TORRENT_TEST(multiple_ips_disallowed2)
TEST_CHECK(tp == nullptr); TEST_CHECK(tp == nullptr);
st.erased.clear(); 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(p.num_peers(), 1);
TEST_EQUAL(peer2->port, 9020); TEST_EQUAL(peer2->port, 9020);
TEST_CHECK(peer1 == peer2); TEST_CHECK(peer1 == peer2);
@ -351,7 +351,7 @@ TORRENT_TEST(update_peer_port_collide)
peer_list p; peer_list p;
t.m_p = &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_CHECK(peer2);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -521,7 +521,7 @@ TORRENT_TEST(erase_peers)
TEST_EQUAL(p.num_peers(), 100); TEST_EQUAL(p.num_peers(), 100);
// trigger the eviction of one peer // 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 // we either removed an existing peer, or rejected this one
// either is valid behavior when the list is full // either is valid behavior when the list is full
TEST_CHECK(st.erased.size() == 1 || peer == nullptr); TEST_CHECK(st.erased.size() == 1 || peer == nullptr);
@ -540,7 +540,7 @@ TORRENT_TEST(set_ip_filter)
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
p.add_peer(tcp::endpoint( 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); TEST_EQUAL(st.erased.size(), 0);
st.erased.clear(); st.erased.clear();
} }
@ -570,7 +570,7 @@ TORRENT_TEST(set_port_filter)
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
p.add_peer(tcp::endpoint( 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); TEST_EQUAL(st.erased.size(), 0);
st.erased.clear(); st.erased.clear();
} }
@ -600,7 +600,7 @@ TORRENT_TEST(set_max_failcount)
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
torrent_peer* peer = p.add_peer(tcp::endpoint( 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); TEST_EQUAL(st.erased.size(), 0);
st.erased.clear(); st.erased.clear();
// every other peer has a failcount of 1 // every other peer has a failcount of 1
@ -630,7 +630,7 @@ TORRENT_TEST(set_seed)
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
torrent_peer* peer = p.add_peer(tcp::endpoint( 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); TEST_EQUAL(st.erased.size(), 0);
st.erased.clear(); st.erased.clear();
// make every other peer a seed // 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)); torrent_peer* peer5 = add_peer(p, st, ep("10.0.0.5", 8080));
TEST_CHECK(peer5); TEST_CHECK(peer5);
TEST_EQUAL(p.num_peers(), 5); 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_CHECK(peer6 == nullptr);
TEST_EQUAL(p.num_peers(), 5); 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; tcp::endpoint endp;
ipv4_peer tmp0(endp, false, 0); ipv4_peer tmp0(endp, false, {});
ipv4_peer tmp1(endp, false, 0); ipv4_peer tmp1(endp, false, {});
ipv4_peer tmp2(endp, false, 0); ipv4_peer tmp2(endp, false, {});
ipv4_peer tmp3(endp, false, 0); ipv4_peer tmp3(endp, false, {});
ipv4_peer tmp4(endp, false, 0); ipv4_peer tmp4(endp, false, {});
ipv4_peer tmp5(endp, false, 0); ipv4_peer tmp5(endp, false, {});
ipv4_peer tmp6(endp, false, 0); ipv4_peer tmp6(endp, false, {});
ipv4_peer tmp7(endp, false, 0); ipv4_peer tmp7(endp, false, {});
ipv4_peer tmp8(endp, false, 0); ipv4_peer tmp8(endp, false, {});
ipv4_peer tmp9(endp, false, 0); ipv4_peer tmp9(endp, false, {});
ipv4_peer peer_struct(endp, true, 0); ipv4_peer peer_struct(endp, true, {});
ipv4_peer* tmp_peer = &tmp1; ipv4_peer* tmp_peer = &tmp1;
static std::vector<piece_index_t> const empty_vector; 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()); lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses 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.size(), 3);
TEST_EQUAL(file_priorities[0], 4); TEST_EQUAL(file_priorities[0], 4);
@ -307,7 +307,7 @@ TORRENT_TEST(file_priorities_default_deprecated)
TORRENT_TEST(file_priorities_in_resume_deprecated) TORRENT_TEST(file_priorities_in_resume_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 1); 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) TORRENT_TEST(file_priorities_in_resume_and_params_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 4); TEST_EQUAL(file_priorities[0], 4);
@ -370,7 +370,7 @@ TORRENT_TEST(file_priorities_seed_mode_deprecated)
TORRENT_TEST(resume_save_load_deprecated) TORRENT_TEST(resume_save_load_deprecated)
{ {
lt::session ses(settings()); 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(); h.save_resume_data();
@ -392,7 +392,7 @@ TORRENT_TEST(resume_save_load_deprecated)
TORRENT_TEST(resume_save_load_resume_deprecated) TORRENT_TEST(resume_save_load_resume_deprecated)
{ {
lt::session ses(settings()); 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(); h.save_resume_data();
@ -429,7 +429,7 @@ TORRENT_TEST(file_priorities_resume_override_deprecated)
TORRENT_TEST(file_priorities_resume_deprecated) TORRENT_TEST(file_priorities_resume_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 1); TEST_EQUAL(file_priorities[0], 1);
@ -440,7 +440,7 @@ TORRENT_TEST(file_priorities_resume_deprecated)
TORRENT_TEST(file_priorities1_deprecated) TORRENT_TEST(file_priorities1_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 0); TEST_EQUAL(file_priorities[0], 0);
@ -453,7 +453,7 @@ TORRENT_TEST(file_priorities1_deprecated)
TORRENT_TEST(file_priorities2_deprecated) TORRENT_TEST(file_priorities2_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 1); TEST_EQUAL(file_priorities[0], 1);
@ -464,7 +464,7 @@ TORRENT_TEST(file_priorities2_deprecated)
TORRENT_TEST(file_priorities3_deprecated) TORRENT_TEST(file_priorities3_deprecated)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 4); TEST_EQUAL(file_priorities[0], 4);
@ -476,7 +476,7 @@ TORRENT_TEST(plain_deprecated)
{ {
lt::session ses(settings()); 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); default_tests(s);
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
TEST_EQUAL(s.save_path, "c:\\add_torrent_params save_path"); 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) TORRENT_TEST(file_priorities_default)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 4); 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 // in share mode file priorities should always be 0
lt::session ses(settings()); lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, std::vector<int> file_priorities = test_resume_flags(ses
torrent_flags::share_mode, "", "123").file_priorities(); , torrent_flags::share_mode, "", "123").file_priorities();
TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0); 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 // in share mode file priorities should always be 0
lt::session ses(settings()); lt::session ses(settings());
std::vector<int> file_priorities = test_resume_flags(ses, std::vector<int> file_priorities = test_resume_flags(ses
torrent_flags::share_mode, "123", "").file_priorities(); , torrent_flags::share_mode, "123", "").file_priorities();
TEST_EQUAL(file_priorities.size(), 3); TEST_EQUAL(file_priorities.size(), 3);
TEST_EQUAL(file_priorities[0], 0); TEST_EQUAL(file_priorities[0], 0);
@ -934,7 +934,7 @@ TORRENT_TEST(seed_mode_preserve)
TORRENT_TEST(resume_save_load) TORRENT_TEST(resume_save_load)
{ {
lt::session ses(settings()); 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(); h.save_resume_data();
@ -956,7 +956,7 @@ TORRENT_TEST(resume_save_load)
TORRENT_TEST(resume_save_load_resume) TORRENT_TEST(resume_save_load_resume)
{ {
lt::session ses(settings()); 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(); h.save_resume_data();
@ -978,7 +978,7 @@ TORRENT_TEST(resume_save_load_resume)
TORRENT_TEST(file_priorities_resume) TORRENT_TEST(file_priorities_resume)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 1); TEST_EQUAL(file_priorities[0], 1);
@ -989,7 +989,7 @@ TORRENT_TEST(file_priorities_resume)
TORRENT_TEST(file_priorities1) TORRENT_TEST(file_priorities1)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 0); TEST_EQUAL(file_priorities[0], 0);
@ -1002,7 +1002,7 @@ TORRENT_TEST(file_priorities1)
TORRENT_TEST(file_priorities2) TORRENT_TEST(file_priorities2)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 1); TEST_EQUAL(file_priorities[0], 1);
@ -1013,7 +1013,7 @@ TORRENT_TEST(file_priorities2)
TORRENT_TEST(file_priorities3) TORRENT_TEST(file_priorities3)
{ {
lt::session ses(settings()); 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.size(), 3);
TEST_EQUAL(file_priorities[0], 4); TEST_EQUAL(file_priorities[0], 4);