finally rename policy to peer_list

This commit is contained in:
Arvid Norberg 2014-10-26 07:34:31 +00:00
parent 1c448331d5
commit 85cc72835e
15 changed files with 133 additions and 137 deletions

View File

@ -50,7 +50,7 @@ set(sources
piece_picker piece_picker
platform_util platform_util
proxy_base proxy_base
policy peer_list
puff puff
random random
request_blocks request_blocks

View File

@ -545,7 +545,7 @@ SOURCES =
natpmp natpmp
packet_buffer packet_buffer
piece_picker piece_picker
policy peer_list
proxy_base proxy_base
puff puff
random random

View File

@ -16,11 +16,11 @@
+-------------------+ | | +-------------------+ | |
| cGRE torrent_info |<---+ | m_socket | cGRE torrent_info |<---+ | m_socket
+-------------------+ | | +--------------------------+ +-------------------+ | | +--------------------------+
| +------+->| socket_type (variant) | m_peer_list | +------+->| socket_type (variant) |
+--------+ m_policy | | | (TCP/uTP/SSL/socks5/...) | +-----------+ | | | (TCP/uTP/SSL/socks5/...) |
| policy |<---------+ | +--------------------------+ | peer_list |<---------+ | +--------------------------+
+------+-+ v +---------+-+ v
list of all | m_peers[] +--------------+ list of all | m_peers[] +--------------+
peers we +-------------->| policy::peer ++ contains contact information peers we +-------------->| torrent_peer ++ contains contact information
know of ++-------------+| for peers we're not necessarily know of ++-------------+| for peers we're not necessarily
+--------------+ connected to +--------------+ connected to

View File

@ -46,15 +46,12 @@ A *torrent* object represents all the state of swarm download. This includes
a piece picker, a list of peer connections, file storage (torrent file). One a piece picker, a list of peer connections, file storage (torrent file). One
important distiction is between a connected peer (*peer_connection*) and a peer important distiction is between a connected peer (*peer_connection*) and a peer
we just know about, and may have been connected to, and may connect to in the we just know about, and may have been connected to, and may connect to in the
future (*policy::peer*). The list of (not connected) peers may grow very large future (*torrent_peer*). The list of (not connected) peers may grow very large
if not limited (through tracker responses, DHT and peer exchange). This list if not limited (through tracker responses, DHT and peer exchange). This list
is typically limited to a few thousand peers. is typically limited to a few thousand peers.
The *policy* in libtorrent is somewhat poorly named. It was initially intended The *peer_list* maintains a potentially large list of known peers for a swarm
to be a customization point where a client could define peer selection behavior (not necessarily connected).
and unchoke logic. It didn't end up being though, and a more accurate name would
be peer_list. It really just maintains a potentially large list of known peers
for a swarm (not necessarily connected).
structure structure
========= =========
@ -95,8 +92,8 @@ torrent
peer_connection peer_connection
--------------- ---------------
policy peer_list
------ ---------
piece_picker piece_picker
------------ ------------

View File

@ -95,7 +95,7 @@ nobase_include_HEADERS = \
piece_block_progress.hpp \ piece_block_progress.hpp \
piece_picker.hpp \ piece_picker.hpp \
platform_util.hpp \ platform_util.hpp \
policy.hpp \ peer_list.hpp \
proxy_base.hpp \ proxy_base.hpp \
puff.hpp \ puff.hpp \
random.hpp \ random.hpp \

View File

@ -57,8 +57,8 @@ namespace libtorrent
struct torrent_peer_allocator_interface; struct torrent_peer_allocator_interface;
// this object is used to communicate torrent state and // this object is used to communicate torrent state and
// some configuration to the policy object. This make // some configuration to the peer_list object. This make
// the policy type not depend on the torrent type directly. // the peer_list type not depend on the torrent type directly.
struct torrent_state struct torrent_state
{ {
torrent_state() torrent_state()
@ -75,7 +75,7 @@ namespace libtorrent
bool is_finished; bool is_finished;
bool allow_multiple_connections_per_ip; bool allow_multiple_connections_per_ip;
// this is set by policy::add_peer to either true or false // this is set by peer_list::add_peer to either true or false
// true means the peer we just added was new, false means // true means the peer we just added was new, false means
// we already knew about the peer // we already knew about the peer
bool first_time_seen; bool first_time_seen;
@ -101,12 +101,11 @@ namespace libtorrent
std::vector<torrent_peer*> erased; std::vector<torrent_peer*> erased;
}; };
// TODO: 3 this class should be renamed peer_list class TORRENT_EXTRA_EXPORT peer_list : single_threaded
class TORRENT_EXTRA_EXPORT policy : single_threaded
{ {
public: public:
policy(); 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, int src, char flags

View File

@ -59,7 +59,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent_info.hpp" #include "libtorrent/torrent_info.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/address.hpp" #include "libtorrent/address.hpp"
#include "libtorrent/policy.hpp" #include "libtorrent/peer_list.hpp"
#include "libtorrent/tracker_manager.hpp" #include "libtorrent/tracker_manager.hpp"
#include "libtorrent/stat.hpp" #include "libtorrent/stat.hpp"
#include "libtorrent/alert.hpp" #include "libtorrent/alert.hpp"
@ -227,7 +227,7 @@ namespace libtorrent
// the state of this torrent (queued, checking, downloading, etc.) // the state of this torrent (queued, checking, downloading, etc.)
boost::uint32_t m_state:3; boost::uint32_t m_state:3;
boost::scoped_ptr<policy> m_policy; boost::scoped_ptr<peer_list> m_peer_list;
}; };
// a torrent is a class that holds information // a torrent is a class that holds information
@ -622,7 +622,7 @@ namespace libtorrent
void update_peer_port(int port, torrent_peer* p, int src); void update_peer_port(int port, torrent_peer* p, int 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<policy::iterator, policy::iterator> find_peers(address const& a); std::pair<peer_list::iterator, peer_list::iterator> find_peers(address const& a);
// the number of peers that belong to this torrent // the number of peers that belong to this torrent
int num_peers() const { return (int)m_connections.size(); } int num_peers() const { return (int)m_connections.size(); }
@ -934,8 +934,8 @@ namespace libtorrent
return m_picker.get() != 0; return m_picker.get() != 0;
} }
int num_known_peers() const { return m_policy ? m_policy->num_peers() : 0; } int num_known_peers() const { return m_peer_list ? m_peer_list->num_peers() : 0; }
int num_connect_candidates() const { return m_policy ? m_policy->num_connect_candidates() : 0; } int num_connect_candidates() const { return m_peer_list ? m_peer_list->num_connect_candidates() : 0; }
piece_manager& storage(); piece_manager& storage();
bool has_storage() const { return m_storage.get(); } bool has_storage() const { return m_storage.get(); }
@ -1100,9 +1100,9 @@ namespace libtorrent
void inc_stats_counter(int c, int value = 1); void inc_stats_counter(int c, int value = 1);
// initialize the torrent_state structure passed to policy // initialize the torrent_state structure passed to peer_list
// member functions. Don't forget to also call peers_erased() // member functions. Don't forget to also call peers_erased()
// on the erased member after the policy call // on the erased member after the peer_list call
torrent_state get_policy_state(); torrent_state get_policy_state();
void construct_storage(); void construct_storage();
@ -1482,7 +1482,7 @@ namespace libtorrent
unsigned int m_seeding_time:24; unsigned int m_seeding_time:24;
// this is a counter that is decreased every // this is a counter that is decreased every
// second, and when it reaches 0, the policy::pulse() // second, and when it reaches 0, the peer_list::pulse()
// is called and the time scaler is reset to 10. // is called and the time scaler is reset to 10.
boost::int8_t m_time_scaler; boost::int8_t m_time_scaler;

View File

@ -95,7 +95,7 @@ libtorrent_rasterbar_la_SOURCES = \
platform_util.cpp \ platform_util.cpp \
packet_buffer.cpp \ packet_buffer.cpp \
proxy_base.cpp \ proxy_base.cpp \
policy.cpp \ peer_list.cpp \
puff.cpp \ puff.cpp \
random.cpp \ random.cpp \
request_blocks.cpp \ request_blocks.cpp \

View File

@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/version.hpp" #include "libtorrent/version.hpp"
#include "libtorrent/extensions.hpp" #include "libtorrent/extensions.hpp"
#include "libtorrent/aux_/session_interface.hpp" #include "libtorrent/aux_/session_interface.hpp"
#include "libtorrent/policy.hpp" #include "libtorrent/peer_list.hpp"
#include "libtorrent/socket_type.hpp" #include "libtorrent/socket_type.hpp"
#include "libtorrent/assert.hpp" #include "libtorrent/assert.hpp"
#include "libtorrent/broadcast_socket.hpp" #include "libtorrent/broadcast_socket.hpp"

View File

@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_connection.hpp" #include "libtorrent/peer_connection.hpp"
#include "libtorrent/web_peer_connection.hpp" #include "libtorrent/web_peer_connection.hpp"
#include "libtorrent/policy.hpp" #include "libtorrent/peer_list.hpp"
#include "libtorrent/socket.hpp" #include "libtorrent/socket.hpp"
#include "libtorrent/socket_type.hpp" #include "libtorrent/socket_type.hpp"
#include "libtorrent/invariant_check.hpp" #include "libtorrent/invariant_check.hpp"
@ -123,7 +123,7 @@ namespace
namespace libtorrent namespace libtorrent
{ {
policy::policy() peer_list::peer_list()
: m_locked_peer(NULL) : m_locked_peer(NULL)
, m_num_seeds(0) , m_num_seeds(0)
, m_finished(0) , m_finished(0)
@ -137,7 +137,7 @@ namespace libtorrent
// fills in 'erased' with torrent_peer pointers that were removed // fills in 'erased' with torrent_peer pointers that were removed
// from the peer list. Any references to these peers must be cleared // from the peer list. Any references to these peers must be cleared
// immediately after this call returns. For instance, in the piece picker. // immediately after this call returns. For instance, in the piece picker.
void policy::apply_ip_filter(ip_filter const& filter, torrent_state* state, std::vector<address>& banned) void peer_list::apply_ip_filter(ip_filter const& filter, torrent_state* state, std::vector<address>& banned)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -185,7 +185,7 @@ namespace libtorrent
} }
} }
void policy::clear_peer_prio() void peer_list::clear_peer_prio()
{ {
for (peers_t::iterator i = m_peers.begin() for (peers_t::iterator i = m_peers.begin()
, end(m_peers.end()); i != end; ++i) , end(m_peers.end()); i != end; ++i)
@ -196,7 +196,7 @@ namespace libtorrent
// fills in 'erased' with torrent_peer pointers that were removed // fills in 'erased' with torrent_peer pointers that were removed
// from the peer list. Any references to these peers must be cleared // from the peer list. Any references to these peers must be cleared
// immediately after this call returns. For instance, in the piece picker. // immediately after this call returns. For instance, in the piece picker.
void policy::apply_port_filter(port_filter const& filter, torrent_state* state, std::vector<address>& banned) void peer_list::apply_port_filter(port_filter const& filter, torrent_state* state, std::vector<address>& banned)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -244,7 +244,7 @@ namespace libtorrent
} }
} }
void policy::erase_peer(torrent_peer* p, torrent_state* state) void peer_list::erase_peer(torrent_peer* p, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -262,7 +262,7 @@ namespace libtorrent
// erased through this function. This way we can make // erased through this function. This way we can make
// sure that any references to the peer are removed // sure that any references to the peer are removed
// as well, such as in the piece picker. // as well, such as in the piece picker.
void policy::erase_peer(iterator i, torrent_state* state) void peer_list::erase_peer(iterator i, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -295,7 +295,7 @@ namespace libtorrent
m_peers.erase(i); m_peers.erase(i);
} }
bool policy::should_erase_immediately(torrent_peer const& p) const bool peer_list::should_erase_immediately(torrent_peer const& p) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p.in_use); TORRENT_ASSERT(p.in_use);
@ -303,7 +303,7 @@ namespace libtorrent
return p.source == peer_info::resume_data; return p.source == peer_info::resume_data;
} }
bool policy::is_erase_candidate(torrent_peer const& pe) const bool peer_list::is_erase_candidate(torrent_peer const& pe) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(pe.in_use); TORRENT_ASSERT(pe.in_use);
@ -315,7 +315,7 @@ namespace libtorrent
|| (pe.source == peer_info::resume_data); || (pe.source == peer_info::resume_data);
} }
bool policy::is_force_erase_candidate(torrent_peer const& pe) const bool peer_list::is_force_erase_candidate(torrent_peer const& pe) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(pe.in_use); TORRENT_ASSERT(pe.in_use);
@ -323,7 +323,7 @@ namespace libtorrent
return pe.connection == 0; return pe.connection == 0;
} }
void policy::erase_peers(torrent_state* state, int flags) void peer_list::erase_peers(torrent_state* state, int flags)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -395,7 +395,7 @@ namespace libtorrent
} }
// returns true if the peer was actually banned // returns true if the peer was actually banned
bool policy::ban_peer(torrent_peer* p) bool peer_list::ban_peer(torrent_peer* p)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -410,7 +410,7 @@ namespace libtorrent
return true; return true;
} }
void policy::set_connection(torrent_peer* p, peer_connection_interface* c) void peer_list::set_connection(torrent_peer* p, peer_connection_interface* c)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -423,7 +423,7 @@ namespace libtorrent
if (was_conn_cand) update_connect_candidates(-1); if (was_conn_cand) update_connect_candidates(-1);
} }
void policy::inc_failcount(torrent_peer* p) void peer_list::inc_failcount(torrent_peer* p)
{ {
// failcount is a 5 bit value // failcount is a 5 bit value
if (p->failcount == 31) return; if (p->failcount == 31) return;
@ -434,7 +434,7 @@ namespace libtorrent
update_connect_candidates(-1); update_connect_candidates(-1);
} }
void policy::set_failcount(torrent_peer* p, int f) void peer_list::set_failcount(torrent_peer* p, int f)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -448,7 +448,7 @@ namespace libtorrent
} }
} }
bool policy::is_connect_candidate(torrent_peer const& p) const bool peer_list::is_connect_candidate(torrent_peer const& p) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p.in_use); TORRENT_ASSERT(p.in_use);
@ -463,7 +463,7 @@ namespace libtorrent
return true; return true;
} }
void policy::find_connect_candidates(std::vector<torrent_peer*>& peers, int session_time, torrent_state* state) void peer_list::find_connect_candidates(std::vector<torrent_peer*>& peers, int session_time, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -538,7 +538,7 @@ namespace libtorrent
// insert this candidate sorted into peers // insert this candidate sorted into peers
std::vector<torrent_peer*>::iterator i = std::lower_bound(peers.begin(), peers.end() std::vector<torrent_peer*>::iterator i = std::lower_bound(peers.begin(), peers.end()
, &pe, boost::bind(&policy::compare_peer, this, _1, _2, boost::cref(external), external_port)); , &pe, boost::bind(&peer_list::compare_peer, this, _1, _2, boost::cref(external), external_port));
peers.insert(i, &pe); peers.insert(i, &pe);
} }
@ -549,7 +549,7 @@ namespace libtorrent
} }
} }
bool policy::new_connection(peer_connection_interface& c, int session_time, torrent_state* state) bool peer_list::new_connection(peer_connection_interface& c, int session_time, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
// TORRENT_ASSERT(!c.is_outgoing()); // TORRENT_ASSERT(!c.is_outgoing());
@ -769,7 +769,7 @@ namespace libtorrent
return true; return true;
} }
bool policy::update_peer_port(int port, torrent_peer* p, int src, torrent_state* state) bool peer_list::update_peer_port(int port, torrent_peer* p, int src, torrent_state* state)
{ {
TORRENT_ASSERT(p != 0); TORRENT_ASSERT(p != 0);
TORRENT_ASSERT(p->connection); TORRENT_ASSERT(p->connection);
@ -841,7 +841,7 @@ namespace libtorrent
// it's important that we don't dereference // it's important that we don't dereference
// p here, since it is allowed to be a dangling // p here, since it is allowed to be a dangling
// pointer. see smart_ban.cpp // pointer. see smart_ban.cpp
bool policy::has_peer(torrent_peer const* p) const bool peer_list::has_peer(torrent_peer const* p) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
// find p in m_peers // find p in m_peers
@ -853,7 +853,7 @@ namespace libtorrent
return false; return false;
} }
void policy::set_seed(torrent_peer* p, bool s) void peer_list::set_seed(torrent_peer* p, bool s)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
if (p == 0) return; if (p == 0) return;
@ -878,7 +878,7 @@ namespace libtorrent
} }
// this is an internal function // this is an internal function
bool policy::insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state) bool peer_list::insert_peer(torrent_peer* p, iterator iter, int flags, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(p); TORRENT_ASSERT(p);
@ -934,7 +934,7 @@ namespace libtorrent
return true; return true;
} }
void policy::update_peer(torrent_peer* p, int src, int flags void peer_list::update_peer(torrent_peer* p, int 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());
@ -977,7 +977,7 @@ namespace libtorrent
} }
} }
void policy::update_connect_candidates(int delta) void peer_list::update_connect_candidates(int delta)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
if (delta == 0) return; if (delta == 0) return;
@ -990,7 +990,7 @@ namespace libtorrent
} }
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
torrent_peer* policy::add_i2p_peer(char const* destination, int src, char flags, torrent_state* state) torrent_peer* peer_list::add_i2p_peer(char const* destination, int src, char flags, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1038,7 +1038,7 @@ namespace libtorrent
#endif // TORRENT_USE_I2P #endif // TORRENT_USE_I2P
// if this returns non-NULL, the torrent need to post status update // if this returns non-NULL, the torrent need to post status update
torrent_peer* policy::add_peer(tcp::endpoint const& remote, int src, char flags torrent_peer* peer_list::add_peer(tcp::endpoint const& remote, int src, char flags
, torrent_state* state) , torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
@ -1123,7 +1123,7 @@ namespace libtorrent
return p; return p;
} }
torrent_peer* policy::connect_one_peer(int session_time, torrent_state* state) torrent_peer* peer_list::connect_one_peer(int session_time, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1165,7 +1165,7 @@ namespace libtorrent
} }
// this is called whenever a peer connection is closed // this is called whenever a peer connection is closed
void policy::connection_closed(const peer_connection_interface& c void peer_list::connection_closed(const peer_connection_interface& c
, int session_time, torrent_state* state) , int session_time, torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
@ -1236,7 +1236,7 @@ namespace libtorrent
} }
} }
void policy::recalculate_connect_candidates(torrent_state* state) void peer_list::recalculate_connect_candidates(torrent_state* state)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1254,7 +1254,7 @@ namespace libtorrent
} }
#if TORRENT_USE_ASSERTS #if TORRENT_USE_ASSERTS
bool policy::has_connection(const peer_connection_interface* c) bool peer_list::has_connection(const peer_connection_interface* c)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK; INVARIANT_CHECK;
@ -1276,7 +1276,7 @@ namespace libtorrent
#endif #endif
#if TORRENT_USE_INVARIANT_CHECKS #if TORRENT_USE_INVARIANT_CHECKS
void policy::check_invariant() const void peer_list::check_invariant() const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(m_num_connect_candidates >= 0); TORRENT_ASSERT(m_num_connect_candidates >= 0);
@ -1322,7 +1322,7 @@ namespace libtorrent
#endif // TORRENT_DEBUG #endif // TORRENT_DEBUG
// this returns true if lhs is a better erase candidate than rhs // this returns true if lhs is a better erase candidate than rhs
bool policy::compare_peer_erase(torrent_peer const& lhs, torrent_peer const& rhs) const bool peer_list::compare_peer_erase(torrent_peer const& lhs, torrent_peer const& rhs) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(lhs.connection == 0); TORRENT_ASSERT(lhs.connection == 0);
@ -1346,7 +1346,7 @@ namespace libtorrent
} }
// this returns true if lhs is a better connect candidate than rhs // this returns true if lhs is a better connect candidate than rhs
bool policy::compare_peer(torrent_peer const* lhs, torrent_peer const* rhs bool peer_list::compare_peer(torrent_peer const* lhs, torrent_peer const* rhs
, external_ip const& external, int external_port) const , external_ip const& external, int external_port) const
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());

View File

@ -248,7 +248,7 @@ namespace
h.update(j->buffer, j->d.io.buffer_size); h.update(j->buffer, j->d.io.buffer_size);
h.update((char const*)&m_salt, sizeof(m_salt)); h.update((char const*)&m_salt, sizeof(m_salt));
std::pair<policy::iterator, policy::iterator> range std::pair<peer_list::iterator, peer_list::iterator> range
= m_torrent.find_peers(a); = m_torrent.find_peers(a);
// there is no peer with this address anymore // there is no peer with this address anymore
@ -338,7 +338,7 @@ namespace
#endif #endif
// find the peer // find the peer
std::pair<policy::iterator, policy::iterator> range std::pair<peer_list::iterator, peer_list::iterator> range
= m_torrent.find_peers(a); = m_torrent.find_peers(a);
if (range.first == range.second) return; if (range.first == range.second) return;
torrent_peer* p = NULL; torrent_peer* p = NULL;

View File

@ -1027,11 +1027,11 @@ namespace libtorrent
// this is used to try leaving upload only mode periodically // this is used to try leaving upload only mode periodically
m_upload_mode_time = m_ses.session_time(); m_upload_mode_time = m_ses.session_time();
} }
else if (m_policy) else if (m_peer_list)
{ {
// reset last_connected, to force fast reconnect after leaving upload mode // reset last_connected, to force fast reconnect after leaving upload mode
for (policy::iterator i = m_policy->begin_peer() for (peer_list::iterator i = m_peer_list->begin_peer()
, end(m_policy->end_peer()); i != end; ++i) , end(m_peer_list->end_peer()); i != end; ++i)
{ {
(*i)->last_connected = 0; (*i)->last_connected = 0;
} }
@ -1048,8 +1048,8 @@ namespace libtorrent
void torrent::need_policy() void torrent::need_policy()
{ {
if (m_policy) return; if (m_peer_list) return;
m_policy.reset(new policy); m_peer_list.reset(new peer_list);
} }
void torrent::handle_disk_error(disk_io_job const* j, peer_connection* c) void torrent::handle_disk_error(disk_io_job const* j, peer_connection* c)
@ -2216,8 +2216,8 @@ namespace libtorrent
} }
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
if (m_policy && m_policy->num_peers() > 0) if (m_peer_list && m_peer_list->num_peers() > 0)
debug_log("resume added peers (%d)", m_policy->num_peers()); debug_log("resume added peers (%d)", m_peer_list->num_peers());
#endif #endif
// only report this error if the user actually provided resume data // only report this error if the user actually provided resume data
@ -3229,7 +3229,7 @@ namespace libtorrent
std::string hostname = i->hostname.substr(i->hostname.size() - 4); std::string hostname = i->hostname.substr(i->hostname.size() - 4);
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
need_policy(); need_policy();
if (m_policy->add_i2p_peer(hostname.c_str(), peer_info::tracker, 0, &st)) if (m_peer_list->add_i2p_peer(hostname.c_str(), peer_info::tracker, 0, &st))
state_updated(); state_updated();
peers_erased(st.erased); peers_erased(st.erased);
} }
@ -3364,13 +3364,13 @@ namespace libtorrent
if (conns > 0) m_need_connect_boost = false; if (conns > 0) m_need_connect_boost = false;
// if we don't know of any peers // if we don't know of any peers
if (!m_policy) return; if (!m_peer_list) return;
while (want_peers() && conns > 0) while (want_peers() && conns > 0)
{ {
--conns; --conns;
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
torrent_peer* p = m_policy->connect_one_peer(m_ses.session_time(), &st); torrent_peer* p = m_peer_list->connect_one_peer(m_ses.session_time(), &st);
peers_erased(st.erased); peers_erased(st.erased);
inc_stats_counter(counters::connection_attempt_loops, st.loop_counter); inc_stats_counter(counters::connection_attempt_loops, st.loop_counter);
if (p == NULL) if (p == NULL)
@ -3391,7 +3391,7 @@ namespace libtorrent
if (!connect_to_peer(p)) if (!connect_to_peer(p))
{ {
m_policy->inc_failcount(p); m_peer_list->inc_failcount(p);
update_want_peers(); update_want_peers();
} }
else else
@ -3455,7 +3455,7 @@ namespace libtorrent
need_policy(); need_policy();
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
if (m_policy->add_i2p_peer(dest, peer_info::tracker, 0, &st)) if (m_peer_list->add_i2p_peer(dest, peer_info::tracker, 0, &st))
state_updated(); state_updated();
peers_erased(st.erased); peers_erased(st.erased);
} }
@ -4108,7 +4108,7 @@ namespace libtorrent
// parts of this piece. // parts of this piece.
std::set<void*> peers; std::set<void*> peers;
// these torrent_peer pointers are owned by m_policy and they may be // these torrent_peer pointers are owned by m_peer_list and they may be
// invalidated if a peer disconnects. We cannot keep them across any // invalidated if a peer disconnects. We cannot keep them across any
// significant operations, but we should use them right away // significant operations, but we should use them right away
// ignore NULL pointers // ignore NULL pointers
@ -5837,7 +5837,7 @@ namespace libtorrent
} }
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
if (m_policy) m_policy->connection_closed(*p, m_ses.session_time(), &st); if (m_peer_list) m_peer_list->connection_closed(*p, m_ses.session_time(), &st);
peers_erased(st.erased); peers_erased(st.erased);
p->set_peer_info(0); p->set_peer_info(0);
@ -6915,10 +6915,10 @@ namespace libtorrent
std::vector<torrent_peer const*> deferred_peers; std::vector<torrent_peer const*> deferred_peers;
if (m_policy) if (m_peer_list)
{ {
for (policy::const_iterator i = m_policy->begin_peer() for (peer_list::const_iterator i = m_peer_list->begin_peer()
, end(m_policy->end_peer()); i != end; ++i) , end(m_peer_list->end_peer()); i != end; ++i)
{ {
error_code ec; error_code ec;
torrent_peer const* p = *i; torrent_peer const* p = *i;
@ -7048,11 +7048,11 @@ namespace libtorrent
void torrent::get_full_peer_list(std::vector<peer_list_entry>& v) const void torrent::get_full_peer_list(std::vector<peer_list_entry>& v) const
{ {
v.clear(); v.clear();
if (!m_policy) return; if (!m_peer_list) return;
v.reserve(m_policy->num_peers()); v.reserve(m_peer_list->num_peers());
for (policy::const_iterator i = m_policy->begin_peer(); for (peer_list::const_iterator i = m_peer_list->begin_peer();
i != m_policy->end_peer(); ++i) i != m_peer_list->end_peer(); ++i)
{ {
peer_list_entry e; peer_list_entry e;
e.ip = (*i)->ip(); e.ip = (*i)->ip();
@ -7191,7 +7191,7 @@ namespace libtorrent
#ifdef TORRENT_DEBUG #ifdef TORRENT_DEBUG
if (!settings().get_bool(settings_pack::allow_multiple_connections_per_ip)) if (!settings().get_bool(settings_pack::allow_multiple_connections_per_ip))
{ {
// this asserts that we don't have duplicates in the policy's peer list // this asserts that we don't have duplicates in the peer_list's peer list
peer_iterator i_ = std::find_if(m_connections.begin(), m_connections.end() peer_iterator i_ = std::find_if(m_connections.begin(), m_connections.end()
, boost::bind(&peer_connection::remote, _1) == peerinfo->ip()); , boost::bind(&peer_connection::remote, _1) == peerinfo->ip());
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
@ -7331,7 +7331,7 @@ namespace libtorrent
sorted_insert(m_connections, boost::get_pointer(c)); sorted_insert(m_connections, boost::get_pointer(c));
m_ses.insert_peer(c); m_ses.insert_peer(c);
need_policy(); need_policy();
m_policy->set_connection(peerinfo, c.get()); m_peer_list->set_connection(peerinfo, c.get());
if (peerinfo->seed) if (peerinfo->seed)
{ {
TORRENT_ASSERT(m_num_seeds < 0xffff); TORRENT_ASSERT(m_num_seeds < 0xffff);
@ -7624,7 +7624,7 @@ namespace libtorrent
#endif #endif
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
need_policy(); need_policy();
if (!m_policy->new_connection(*p, m_ses.session_time(), &st)) if (!m_peer_list->new_connection(*p, m_ses.session_time(), &st))
{ {
peers_erased(st.erased); peers_erased(st.erased);
#if defined TORRENT_LOGGING #if defined TORRENT_LOGGING
@ -7670,7 +7670,7 @@ namespace libtorrent
TORRENT_ASSERT(p->peer_info_struct() != NULL); TORRENT_ASSERT(p->peer_info_struct() != NULL);
// we need to do this after we've added the peer to the policy // we need to do this after we've added the peer to the peer_list
// since that's when the peer is assigned its peer_info object, // since that's when the peer is assigned its peer_info object,
// which holds the rank // which holds the rank
if (maybe_replace_peer) if (maybe_replace_peer)
@ -7690,14 +7690,14 @@ namespace libtorrent
p->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent); p->disconnect(errors::too_many_connections, peer_connection_interface::op_bittorrent);
// we have to do this here because from the peer's point of // we have to do this here because from the peer's point of
// it wasn't really attached to the torrent, but we do need // it wasn't really attached to the torrent, but we do need
// to let policy know we're removing it // to let peer_list know we're removing it
remove_peer(p); remove_peer(p);
return false; return false;
} }
} }
#if TORRENT_USE_INVARIANT_CHECKS #if TORRENT_USE_INVARIANT_CHECKS
if (m_policy) m_policy->check_invariant(); if (m_peer_list) m_peer_list->check_invariant();
#endif #endif
if (m_share_mode) if (m_share_mode)
@ -7747,7 +7747,7 @@ namespace libtorrent
// if we don't know of any more potential peers to connect to, there's // if we don't know of any more potential peers to connect to, there's
// no point in trying // no point in trying
if (!m_policy || m_policy->num_connect_candidates() == 0) if (!m_peer_list || m_peer_list->num_connect_candidates() == 0)
return false; return false;
// if the user disabled outgoing connections for seeding torrents, // if the user disabled outgoing connections for seeding torrents,
@ -8454,11 +8454,11 @@ namespace libtorrent
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
// make sure we haven't modified the peer object // make sure we haven't modified the peer object
// in a way that breaks the sort order // in a way that breaks the sort order
if (m_policy && m_policy->begin_peer() != m_policy->end_peer()) if (m_peer_list && m_peer_list->begin_peer() != m_peer_list->end_peer())
{ {
policy::const_iterator i = m_policy->begin_peer(); peer_list::const_iterator i = m_peer_list->begin_peer();
policy::const_iterator prev = i++; peer_list::const_iterator prev = i++;
policy::const_iterator end(m_policy->end_peer()); peer_list::const_iterator end(m_peer_list->end_peer());
peer_address_compare cmp; peer_address_compare cmp;
for (; i != end; ++i, ++prev) for (; i != end; ++i, ++prev)
{ {
@ -8779,10 +8779,10 @@ namespace libtorrent
// currently representable by the session_time) // currently representable by the session_time)
void torrent::step_session_time(int seconds) void torrent::step_session_time(int seconds)
{ {
if (m_policy) if (m_peer_list)
{ {
for (policy::iterator j = m_policy->begin_peer() for (peer_list::iterator j = m_peer_list->begin_peer()
, end(m_policy->end_peer()); j != end; ++j) , end(m_peer_list->end_peer()); j != end; ++j)
{ {
torrent_peer* pe = *j; torrent_peer* pe = *j;
@ -8862,10 +8862,10 @@ namespace libtorrent
int downloaders = 0; int downloaders = 0;
if (m_complete != 0xffffff) seeds = m_complete; if (m_complete != 0xffffff) seeds = m_complete;
else seeds = m_policy ? m_policy->num_seeds() : 0; else seeds = m_peer_list ? m_peer_list->num_seeds() : 0;
if (m_incomplete != 0xffffff) downloaders = m_incomplete; if (m_incomplete != 0xffffff) downloaders = m_incomplete;
else downloaders = m_policy ? m_policy->num_peers() - m_policy->num_seeds() : 0; else downloaders = m_peer_list ? m_peer_list->num_peers() - m_peer_list->num_seeds() : 0;
if (seeds == 0) if (seeds == 0)
{ {
@ -9392,7 +9392,7 @@ namespace libtorrent
m_announcing = true; m_announcing = true;
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
if ((!m_policy || m_policy->num_peers() < 50) && m_ses.dht()) if ((!m_peer_list || m_peer_list->num_peers() < 50) && m_ses.dht())
{ {
// we don't have any peers, prioritize // we don't have any peers, prioritize
// announcing this torrent with the DHT // announcing this torrent with the DHT
@ -10603,7 +10603,7 @@ namespace libtorrent
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
need_policy(); need_policy();
torrent_peer* p = m_policy->connect_one_peer(m_ses.session_time(), &st); torrent_peer* p = m_peer_list->connect_one_peer(m_ses.session_time(), &st);
peers_erased(st.erased); peers_erased(st.erased);
inc_stats_counter(counters::connection_attempt_loops, st.loop_counter); inc_stats_counter(counters::connection_attempt_loops, st.loop_counter);
@ -10615,7 +10615,7 @@ namespace libtorrent
if (!connect_to_peer(p)) if (!connect_to_peer(p))
{ {
m_policy->inc_failcount(p); m_peer_list->inc_failcount(p);
update_want_peers(); update_want_peers();
return false; return false;
} }
@ -10693,7 +10693,7 @@ namespace libtorrent
need_policy(); need_policy();
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
torrent_peer* p = m_policy->add_peer(adr, source, 0, &st); torrent_peer* p = m_peer_list->add_peer(adr, source, 0, &st);
peers_erased(st.erased); peers_erased(st.erased);
if (p) if (p)
{ {
@ -10719,7 +10719,7 @@ namespace libtorrent
return false; return false;
need_policy(); need_policy();
if (!m_policy->ban_peer(tp)) return false; if (!m_peer_list->ban_peer(tp)) return false;
update_want_peers(); update_want_peers();
inc_stats_counter(counters::num_banned_peers); inc_stats_counter(counters::num_banned_peers);
@ -10743,28 +10743,28 @@ namespace libtorrent
} }
need_policy(); need_policy();
m_policy->set_seed(p, s); m_peer_list->set_seed(p, s);
update_auto_sequential(); update_auto_sequential();
} }
void torrent::clear_failcount(torrent_peer* p) void torrent::clear_failcount(torrent_peer* p)
{ {
need_policy(); need_policy();
m_policy->set_failcount(p, 0); m_peer_list->set_failcount(p, 0);
update_want_peers(); update_want_peers();
} }
std::pair<policy::iterator, policy::iterator> torrent::find_peers(address const& a) std::pair<peer_list::iterator, peer_list::iterator> torrent::find_peers(address const& a)
{ {
need_policy(); need_policy();
return m_policy->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, int src)
{ {
need_policy(); need_policy();
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
m_policy->update_peer_port(port, p, src, &st); m_peer_list->update_peer_port(port, p, src, &st);
peers_erased(st.erased); peers_erased(st.erased);
update_want_peers(); update_want_peers();
} }
@ -10793,11 +10793,11 @@ namespace libtorrent
void torrent::ip_filter_updated() void torrent::ip_filter_updated()
{ {
if (!m_apply_ip_filter) return; if (!m_apply_ip_filter) return;
if (!m_policy) return; if (!m_peer_list) return;
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
std::vector<address> banned; std::vector<address> banned;
m_policy->apply_ip_filter(m_ses.get_ip_filter(), &st, banned); m_peer_list->apply_ip_filter(m_ses.get_ip_filter(), &st, banned);
if (alerts().should_post<peer_blocked_alert>()) if (alerts().should_post<peer_blocked_alert>())
{ {
@ -10813,11 +10813,11 @@ namespace libtorrent
void torrent::port_filter_updated() void torrent::port_filter_updated()
{ {
if (!m_apply_ip_filter) return; if (!m_apply_ip_filter) return;
if (!m_policy) return; if (!m_peer_list) return;
torrent_state st = get_policy_state(); torrent_state st = get_policy_state();
std::vector<address> banned; std::vector<address> banned;
m_policy->apply_port_filter(m_ses.get_port_filter(), &st, banned); m_peer_list->apply_port_filter(m_ses.get_port_filter(), &st, banned);
if (alerts().should_post<peer_blocked_alert>()) if (alerts().should_post<peer_blocked_alert>())
{ {
@ -10830,7 +10830,7 @@ namespace libtorrent
peers_erased(st.erased); peers_erased(st.erased);
} }
// this is called when torrent_peers are removed from the policy // this is called when torrent_peers are removed from the peer_list
// (peer-list). It removes any references we may have to those torrent_peers, // (peer-list). It removes any references we may have to those torrent_peers,
// so we don't leave then dangling // so we don't leave then dangling
void torrent::peers_erased(std::vector<torrent_peer*> const& peers) void torrent::peers_erased(std::vector<torrent_peer*> const& peers)
@ -11055,7 +11055,7 @@ namespace libtorrent
void torrent::new_external_ip() void torrent::new_external_ip()
{ {
if (m_policy) m_policy->clear_peer_prio(); if (m_peer_list) m_peer_list->clear_peer_prio();
} }
void torrent::set_state(torrent_status::state_t s) void torrent::set_state(torrent_status::state_t s)
@ -11211,9 +11211,9 @@ namespace libtorrent
st->num_peers = int(m_connections.size()) - m_num_connecting; st->num_peers = int(m_connections.size()) - m_num_connecting;
st->list_peers = m_policy ? m_policy->num_peers() : 0; st->list_peers = m_peer_list ? m_peer_list->num_peers() : 0;
st->list_seeds = m_policy ? m_policy->num_seeds() : 0; st->list_seeds = m_peer_list ? m_peer_list->num_seeds() : 0;
st->connect_candidates = m_policy ? m_policy->num_connect_candidates() : 0; st->connect_candidates = m_peer_list ? m_peer_list->num_connect_candidates() : 0;
st->seed_rank = seed_rank(settings()); st->seed_rank = seed_rank(settings());
st->all_time_upload = m_total_uploaded; st->all_time_upload = m_total_uploaded;

View File

@ -99,7 +99,7 @@ test-suite libtorrent :
[ run test_recheck.cpp ] [ run test_recheck.cpp ]
[ run test_stat_cache.cpp ] [ run test_stat_cache.cpp ]
[ run test_part_file.cpp ] [ run test_part_file.cpp ]
[ run test_policy.cpp ] [ run test_peer_list.cpp ]
[ run test_torrent_info.cpp ] [ run test_torrent_info.cpp ]
[ run test_time.cpp ] [ run test_time.cpp ]
[ run test_file_storage.cpp ] [ run test_file_storage.cpp ]

View File

@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/policy.hpp" #include "libtorrent/peer_list.hpp"
#include "libtorrent/torrent_handle.hpp" #include "libtorrent/torrent_handle.hpp"
#include "libtorrent/torrent_peer_allocator.hpp" #include "libtorrent/torrent_peer_allocator.hpp"
#include "libtorrent/peer_connection_interface.hpp" #include "libtorrent/peer_connection_interface.hpp"
@ -124,7 +124,7 @@ struct mock_torrent
} }
#endif #endif
policy* m_p; peer_list* m_p;
private: private:
@ -149,7 +149,7 @@ int test_main()
// when disallowing it // when disallowing it
{ {
mock_torrent t; mock_torrent t;
policy 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, 0, &st);
@ -170,7 +170,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
policy 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, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -190,7 +190,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
policy 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, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -227,7 +227,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = false; st.allow_multiple_connections_per_ip = false;
policy 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, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -259,7 +259,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = false; st.allow_multiple_connections_per_ip = false;
policy 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);
boost::shared_ptr<mock_peer_connection> c(new mock_peer_connection(true, ep("10.0.0.1", 8080))); boost::shared_ptr<mock_peer_connection> c(new mock_peer_connection(true, ep("10.0.0.1", 8080)));
@ -280,7 +280,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
policy 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, 0, &st);
@ -308,7 +308,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = false; st.allow_multiple_connections_per_ip = false;
policy 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, 0, &st);
TEST_EQUAL(p.num_connect_candidates(), 1); TEST_EQUAL(p.num_connect_candidates(), 1);
@ -352,7 +352,7 @@ int test_main()
{ {
mock_torrent t; mock_torrent t;
st.allow_multiple_connections_per_ip = false; st.allow_multiple_connections_per_ip = false;
policy p; peer_list p;
t.m_p = &p; t.m_p = &p;
torrent_peer* peer1 = p.add_peer(ep("10.0.0.1", 4000), 0, 0, &st); torrent_peer* peer1 = p.add_peer(ep("10.0.0.1", 4000), 0, 0, &st);
@ -393,7 +393,7 @@ int test_main()
mock_torrent t; mock_torrent t;
st.max_peerlist_size = 100; st.max_peerlist_size = 100;
st.allow_multiple_connections_per_ip = true; st.allow_multiple_connections_per_ip = true;
policy p; peer_list p;
t.m_p = &p; t.m_p = &p;
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)

View File

@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/policy.hpp" #include "libtorrent/peer_list.hpp"
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6() #include "libtorrent/broadcast_socket.hpp" // for supports_ipv6()
#include <boost/crc.hpp> #include <boost/crc.hpp>