optimize torrent::status to scale better with the number of peers
This commit is contained in:
parent
94ae0e433b
commit
402d6bb6b6
|
@ -1077,9 +1077,15 @@ namespace libtorrent
|
|||
// completed, m_completed_time is 0
|
||||
time_t m_added_time;
|
||||
time_t m_completed_time;
|
||||
time_t m_last_seen_complete;
|
||||
time_t m_last_saved_resume;
|
||||
|
||||
// this was the last time _we_ saw a seed in this swarm
|
||||
time_t m_last_seen_complete;
|
||||
|
||||
// this is the time last any of our peers saw a seed
|
||||
// in this swarm
|
||||
time_t m_swarm_last_seen_complete;
|
||||
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
// this is SHA1("req2" + info-hash), used for
|
||||
// encrypted hand shakes
|
||||
|
|
|
@ -263,8 +263,9 @@ namespace libtorrent
|
|||
PRINT_OFFSETOF(torrent, m_storage_constructor)
|
||||
PRINT_OFFSETOF(torrent, m_added_time)
|
||||
PRINT_OFFSETOF(torrent, m_completed_time)
|
||||
PRINT_OFFSETOF(torrent, m_last_seen_complete)
|
||||
PRINT_OFFSETOF(torrent, m_last_saved_resume)
|
||||
PRINT_OFFSETOF(torrent, m_last_seen_complete)
|
||||
PRINT_OFFSETOF(torrent, m_swarm_last_seen_complete)
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
PRINT_OFFSETOF(torrent, m_obfuscated_hash)
|
||||
#endif
|
||||
|
@ -364,8 +365,9 @@ namespace libtorrent
|
|||
, m_storage_constructor(p.storage)
|
||||
, m_added_time(time(0))
|
||||
, m_completed_time(0)
|
||||
, m_last_seen_complete(0)
|
||||
, m_last_saved_resume(time(0))
|
||||
, m_last_seen_complete(0)
|
||||
, m_swarm_last_seen_complete(0)
|
||||
, m_ratio(0.f)
|
||||
, m_available_free_upload(0)
|
||||
, m_average_piece_time(0)
|
||||
|
@ -7432,12 +7434,16 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
m_swarm_last_seen_complete = m_last_seen_complete;
|
||||
for (peer_iterator i = m_connections.begin();
|
||||
i != m_connections.end();)
|
||||
{
|
||||
peer_connection* p = *i;
|
||||
++i;
|
||||
|
||||
// look for the peer that saw a seed most recently
|
||||
m_swarm_last_seen_complete = (std::max)(p->last_seen_complete(), m_swarm_last_seen_complete);
|
||||
|
||||
if (!p->ignore_stats())
|
||||
m_stat += p->statistics();
|
||||
|
||||
|
@ -8267,8 +8273,7 @@ namespace libtorrent
|
|||
st->down_bandwidth_queue = 0;
|
||||
st->priority = m_priority;
|
||||
|
||||
st->num_peers = (int)std::count_if(m_connections.begin(), m_connections.end()
|
||||
, !boost::bind(&peer_connection::is_connecting, _1));
|
||||
st->num_peers = int(m_connections.size()) - m_num_connecting;
|
||||
|
||||
st->list_peers = m_policy.num_peers();
|
||||
st->list_seeds = m_policy.num_seeds();
|
||||
|
@ -8432,20 +8437,7 @@ namespace libtorrent
|
|||
st->distributed_copies = -1.f;
|
||||
}
|
||||
|
||||
if (flags & torrent_handle::query_last_seen_complete)
|
||||
{
|
||||
time_t last = last_seen_complete();
|
||||
for (std::set<peer_connection*>::const_iterator i = m_connections.begin()
|
||||
, end(m_connections.end()); i != end; ++i)
|
||||
{
|
||||
last = (std::max)(last, (*i)->last_seen_complete());
|
||||
}
|
||||
st->last_seen_complete = last;
|
||||
}
|
||||
else
|
||||
{
|
||||
st->last_seen_complete = 0;
|
||||
}
|
||||
st->last_seen_complete = m_swarm_last_seen_complete;
|
||||
}
|
||||
|
||||
void torrent::add_redundant_bytes(int b, torrent::wasted_reason_t reason)
|
||||
|
|
Loading…
Reference in New Issue