forked from premiere/premiere-libtorrent
simplify connection attempt distribution logic to not lower the connection rate with a downloading torrent among seeding ones
This commit is contained in:
parent
8f3c3de1e2
commit
ea59a9be22
|
@ -433,7 +433,6 @@ namespace libtorrent
|
|||
|
||||
bool want_more_peers() const;
|
||||
bool try_connect_peer();
|
||||
void give_connect_points(int points);
|
||||
void add_peer(tcp::endpoint const& adr, int source);
|
||||
|
||||
// the number of peers that belong to this torrent
|
||||
|
@ -1221,19 +1220,9 @@ namespace libtorrent
|
|||
// the maximum number of uploads for this torrent
|
||||
unsigned int m_max_uploads:24;
|
||||
|
||||
// this is the deficit counter in the Deficit Round Robin
|
||||
// used to determine which torrent gets the next
|
||||
// connection attempt. See:
|
||||
// http://www.ecs.umass.edu/ece/wolf/courses/ECE697J/papers/DRR.pdf
|
||||
// The quanta assigned to each torrent depends on the torrents
|
||||
// priority, whether it's a seed and the number of connected
|
||||
// peers it has. This has the effect that some torrents
|
||||
// will have more connection attempts than other. Each
|
||||
// connection attempt costs 100 points from the deficit
|
||||
// counter. points are deducted in try_connect_peer and
|
||||
// increased in give_connect_points. Outside of the
|
||||
// torrent object, these points are called connect_points.
|
||||
boost::uint8_t m_deficit_counter;
|
||||
// these are the flags sent in on a call to save_resume_data
|
||||
// we need to save them to check them in write_resume_data
|
||||
boost::uint8_t m_save_resume_flags;
|
||||
|
||||
// the number of unchoked peers in this torrent
|
||||
unsigned int m_num_uploads:24;
|
||||
|
@ -1334,10 +1323,6 @@ namespace libtorrent
|
|||
// round-robin index into m_interfaces
|
||||
mutable boost::uint8_t m_interface_index;
|
||||
|
||||
// these are the flags sent in on a call to save_resume_data
|
||||
// we need to save them to check them in write_resume_data
|
||||
boost::uint8_t m_save_resume_flags;
|
||||
|
||||
// set to true when this torrent has been paused but
|
||||
// is waiting to finish all current download requests
|
||||
// before actually closing all connections
|
||||
|
|
|
@ -3399,43 +3399,42 @@ namespace aux {
|
|||
torrent& t = *m_next_connect_torrent->second;
|
||||
if (t.want_more_peers())
|
||||
{
|
||||
// 133 is so that the average of downloaders with
|
||||
// more than average peers and less than average
|
||||
// peers will end up being 100 (i.e. 133 / 2 = 66)
|
||||
int connect_points = 133;
|
||||
// have a bias against torrents with more peers
|
||||
// than average
|
||||
if (!t.is_seed() && t.num_peers() > average_peers)
|
||||
connect_points /= 2;
|
||||
// if this is a seed and there is a torrent that
|
||||
// is downloading, lower the rate at which this
|
||||
// torrent gets connections.
|
||||
// dividing by num_seeds will have the effect
|
||||
// that all seed will get as many connections
|
||||
// together, as a single downloading torrent.
|
||||
if (t.is_seed() && num_downloads > 0)
|
||||
connect_points /= num_seeds + 1;
|
||||
if (connect_points <= 0) connect_points = 1;
|
||||
t.give_connect_points(connect_points);
|
||||
TORRENT_TRY
|
||||
// have a bias to give more connection attempts
|
||||
// to downloading torrents than seed, and even
|
||||
// more to downloading torrents with less than
|
||||
// average number of connections
|
||||
int num_attempts = 1;
|
||||
if (!t.is_seed())
|
||||
{
|
||||
if (t.try_connect_peer())
|
||||
{
|
||||
--max_connections;
|
||||
--free_slots;
|
||||
steps_since_last_connect = 0;
|
||||
#ifdef TORRENT_STATS
|
||||
++m_connection_attempts;
|
||||
#endif
|
||||
}
|
||||
++num_attempts;
|
||||
if (t.num_peers() < average_peers)
|
||||
++num_attempts;
|
||||
}
|
||||
TORRENT_CATCH(std::bad_alloc&)
|
||||
for (int i = 0; i < num_attempts; ++i)
|
||||
{
|
||||
// we ran out of memory trying to connect to a peer
|
||||
// lower the global limit to the number of peers
|
||||
// we already have
|
||||
m_settings.connections_limit = num_connections();
|
||||
if (m_settings.connections_limit < 2) m_settings.connections_limit = 2;
|
||||
TORRENT_TRY
|
||||
{
|
||||
if (t.try_connect_peer())
|
||||
{
|
||||
--max_connections;
|
||||
--free_slots;
|
||||
steps_since_last_connect = 0;
|
||||
#ifdef TORRENT_STATS
|
||||
++m_connection_attempts;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
TORRENT_CATCH(std::bad_alloc&)
|
||||
{
|
||||
// we ran out of memory trying to connect to a peer
|
||||
// lower the global limit to the number of peers
|
||||
// we already have
|
||||
m_settings.connections_limit = num_connections();
|
||||
if (m_settings.connections_limit < 2) m_settings.connections_limit = 2;
|
||||
}
|
||||
if (free_slots <= -m_half_open.limit()) break;
|
||||
if (max_connections == 0) break;
|
||||
if (num_connections() >= m_settings.connections_limit) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,7 +295,6 @@ namespace libtorrent
|
|||
// PRINT_OFFSETOF(torrent, m_seeding_time:24)
|
||||
PRINT_OFFSETOF(torrent, m_time_scaler)
|
||||
// PRINT_OFFSETOF(torrent, m_max_uploads:24)
|
||||
PRINT_OFFSETOF(torrent, m_deficit_counter)
|
||||
// PRINT_OFFSETOF(torrent, m_num_uploads:24)
|
||||
// PRINT_OFFSETOF(torrent, m_block_size_shift:5)
|
||||
// PRINT_OFFSETOF(torrent, m_has_incoming:1)
|
||||
|
@ -397,7 +396,7 @@ namespace libtorrent
|
|||
, m_seeding_time(0)
|
||||
, m_time_scaler(0)
|
||||
, m_max_uploads((1<<24)-1)
|
||||
, m_deficit_counter(0)
|
||||
, m_save_resume_flags(0)
|
||||
, m_num_uploads(0)
|
||||
, m_block_size_shift(root2(block_size))
|
||||
, m_has_incoming(false)
|
||||
|
@ -423,7 +422,6 @@ namespace libtorrent
|
|||
, m_last_upload(0)
|
||||
, m_downloaders(0xffffff)
|
||||
, m_interface_index(0)
|
||||
, m_save_resume_flags(0)
|
||||
, m_graceful_pause_mode(false)
|
||||
, m_need_connect_boost(true)
|
||||
, m_lsd_seq(0)
|
||||
|
@ -7796,21 +7794,10 @@ namespace libtorrent
|
|||
{
|
||||
TORRENT_ASSERT(m_ses.is_network_thread());
|
||||
TORRENT_ASSERT(want_more_peers());
|
||||
if (m_deficit_counter < 100) return false;
|
||||
m_deficit_counter -= 100;
|
||||
bool ret = m_policy.connect_one_peer(m_ses.session_time());
|
||||
return ret;
|
||||
}
|
||||
|
||||
void torrent::give_connect_points(int points)
|
||||
{
|
||||
TORRENT_ASSERT(m_ses.is_network_thread());
|
||||
TORRENT_ASSERT(points <= 200);
|
||||
TORRENT_ASSERT(points > 0);
|
||||
TORRENT_ASSERT(want_more_peers());
|
||||
m_deficit_counter += points;
|
||||
}
|
||||
|
||||
void torrent::add_peer(tcp::endpoint const& adr, int source)
|
||||
{
|
||||
TORRENT_ASSERT(m_ses.is_network_thread());
|
||||
|
|
Loading…
Reference in New Issue