forked from premiere/premiere-libtorrent
more use of auto, const and minor cleanup in session_impl.cpp
This commit is contained in:
parent
d0ea585859
commit
fe09ca9b97
|
@ -2609,11 +2609,11 @@ namespace {
|
||||||
// if we failed to accept an incoming connection
|
// if we failed to accept an incoming connection
|
||||||
// because we have too many files open, try again
|
// because we have too many files open, try again
|
||||||
// and lower the number of file descriptors used
|
// and lower the number of file descriptors used
|
||||||
// elsewere.
|
// elsewhere.
|
||||||
if (m_settings.get_int(settings_pack::connections_limit) > 10)
|
if (m_settings.get_int(settings_pack::connections_limit) > 10)
|
||||||
{
|
{
|
||||||
// now, disconnect a random peer
|
// now, disconnect a random peer
|
||||||
torrent_map::iterator i = std::max_element(m_torrents.begin(), m_torrents.end()
|
auto const i = std::max_element(m_torrents.begin(), m_torrents.end()
|
||||||
, [](torrent_map::value_type const& lhs, torrent_map::value_type const& rhs)
|
, [](torrent_map::value_type const& lhs, torrent_map::value_type const& rhs)
|
||||||
{ return lhs.second->num_peers() < rhs.second->num_peers(); });
|
{ return lhs.second->num_peers() < rhs.second->num_peers(); });
|
||||||
|
|
||||||
|
@ -2985,7 +2985,7 @@ namespace {
|
||||||
|
|
||||||
TORRENT_ASSERT(sp.use_count() > 0);
|
TORRENT_ASSERT(sp.use_count() > 0);
|
||||||
|
|
||||||
connection_map::iterator i = m_connections.find(sp);
|
auto const i = m_connections.find(sp);
|
||||||
// make sure the next disk peer round-robin cursor stays valid
|
// make sure the next disk peer round-robin cursor stays valid
|
||||||
if (i != m_connections.end()) m_connections.erase(i);
|
if (i != m_connections.end()) m_connections.erase(i);
|
||||||
}
|
}
|
||||||
|
@ -3282,10 +3282,9 @@ namespace {
|
||||||
case settings_pack::peer_proportional:
|
case settings_pack::peer_proportional:
|
||||||
{
|
{
|
||||||
int num_peers[2][2] = {{0, 0}, {0, 0}};
|
int num_peers[2][2] = {{0, 0}, {0, 0}};
|
||||||
for (connection_map::iterator i = m_connections.begin()
|
for (auto const& i : m_connections)
|
||||||
, end(m_connections.end());i != end; ++i)
|
|
||||||
{
|
{
|
||||||
peer_connection& p = *(*i);
|
peer_connection& p = *i;
|
||||||
if (p.in_handshake()) continue;
|
if (p.in_handshake()) continue;
|
||||||
int protocol = 0;
|
int protocol = 0;
|
||||||
if (is_utp(*p.get_socket())) protocol = 1;
|
if (is_utp(*p.get_socket())) protocol = 1;
|
||||||
|
@ -3488,13 +3487,13 @@ namespace {
|
||||||
{
|
{
|
||||||
// every 90 seconds, disconnect the worst peers
|
// every 90 seconds, disconnect the worst peers
|
||||||
// if we have reached the connection limit
|
// if we have reached the connection limit
|
||||||
torrent_map::iterator i = std::max_element(m_torrents.begin(), m_torrents.end()
|
auto const i = std::max_element(m_torrents.begin(), m_torrents.end()
|
||||||
, [] (torrent_map::value_type const& lhs, torrent_map::value_type const& rhs)
|
, [] (torrent_map::value_type const& lhs, torrent_map::value_type const& rhs)
|
||||||
{ return lhs.second->num_peers() < rhs.second->num_peers(); });
|
{ return lhs.second->num_peers() < rhs.second->num_peers(); });
|
||||||
|
|
||||||
TORRENT_ASSERT(i != m_torrents.end());
|
TORRENT_ASSERT(i != m_torrents.end());
|
||||||
int peers_to_disconnect = (std::min)((std::max)(
|
int const peers_to_disconnect = std::min(std::max(
|
||||||
int(i->second->num_peers() * m_settings.get_int(settings_pack::peer_turnover) / 100), 1)
|
i->second->num_peers() * m_settings.get_int(settings_pack::peer_turnover) / 100, 1)
|
||||||
, i->second->num_connect_candidates());
|
, i->second->num_connect_candidates());
|
||||||
i->second->disconnect_peers(peers_to_disconnect
|
i->second->disconnect_peers(peers_to_disconnect
|
||||||
, error_code(errors::optimistic_disconnect));
|
, error_code(errors::optimistic_disconnect));
|
||||||
|
@ -3514,7 +3513,7 @@ namespace {
|
||||||
|| t->max_connections() < 6)
|
|| t->max_connections() < 6)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int peers_to_disconnect = (std::min)((std::max)(t->num_peers()
|
int const peers_to_disconnect = (std::min)((std::max)(t->num_peers()
|
||||||
* m_settings.get_int(settings_pack::peer_turnover) / 100, 1)
|
* m_settings.get_int(settings_pack::peer_turnover) / 100, 1)
|
||||||
, t->num_connect_candidates());
|
, t->num_connect_candidates());
|
||||||
t->disconnect_peers(peers_to_disconnect, errors::optimistic_disconnect);
|
t->disconnect_peers(peers_to_disconnect, errors::optimistic_disconnect);
|
||||||
|
@ -3560,7 +3559,7 @@ namespace {
|
||||||
|
|
||||||
void session_impl::prioritize_connections(std::weak_ptr<torrent> t)
|
void session_impl::prioritize_connections(std::weak_ptr<torrent> t)
|
||||||
{
|
{
|
||||||
m_prio_torrents.push_back(std::make_pair(t, 10));
|
m_prio_torrents.emplace_back(t, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
|
@ -3693,8 +3692,8 @@ namespace {
|
||||||
|
|
||||||
ADD_OUTSTANDING_ASYNC("session_impl::on_lsd_announce");
|
ADD_OUTSTANDING_ASYNC("session_impl::on_lsd_announce");
|
||||||
// announce on local network every 5 minutes
|
// announce on local network every 5 minutes
|
||||||
int delay = (std::max)(m_settings.get_int(settings_pack::local_service_announce_interval)
|
int const delay = std::max(m_settings.get_int(settings_pack::local_service_announce_interval)
|
||||||
/ (std::max)(int(m_torrents.size()), 1), 1);
|
/ std::max(int(m_torrents.size()), 1), 1);
|
||||||
error_code ec;
|
error_code ec;
|
||||||
m_lsd_announce_timer.expires_from_now(seconds(delay), ec);
|
m_lsd_announce_timer.expires_from_now(seconds(delay), ec);
|
||||||
m_lsd_announce_timer.async_wait([this](error_code const& err) {
|
m_lsd_announce_timer.async_wait([this](error_code const& err) {
|
||||||
|
@ -3987,7 +3986,7 @@ namespace {
|
||||||
|
|
||||||
int num_opt_unchoke = m_settings.get_int(settings_pack::num_optimistic_unchoke_slots);
|
int num_opt_unchoke = m_settings.get_int(settings_pack::num_optimistic_unchoke_slots);
|
||||||
int const allowed_unchoke_slots = int(m_stats_counters[counters::num_unchoke_slots]);
|
int const allowed_unchoke_slots = int(m_stats_counters[counters::num_unchoke_slots]);
|
||||||
if (num_opt_unchoke == 0) num_opt_unchoke = (std::max)(1, allowed_unchoke_slots / 5);
|
if (num_opt_unchoke == 0) num_opt_unchoke = std::max(1, allowed_unchoke_slots / 5);
|
||||||
if (num_opt_unchoke > int(opt_unchoke.size())) num_opt_unchoke =
|
if (num_opt_unchoke > int(opt_unchoke.size())) num_opt_unchoke =
|
||||||
int(opt_unchoke.size());
|
int(opt_unchoke.size());
|
||||||
|
|
||||||
|
@ -4022,7 +4021,7 @@ namespace {
|
||||||
// remove this peer from prev_opt_unchoke, to prevent us from
|
// remove this peer from prev_opt_unchoke, to prevent us from
|
||||||
// choking it later. This peer gets another round of optimistic
|
// choking it later. This peer gets another round of optimistic
|
||||||
// unchoke
|
// unchoke
|
||||||
std::vector<torrent_peer*>::iterator existing =
|
auto const existing =
|
||||||
std::find(prev_opt_unchoke.begin(), prev_opt_unchoke.end(), pi);
|
std::find(prev_opt_unchoke.begin(), prev_opt_unchoke.end(), pi);
|
||||||
TORRENT_ASSERT(existing != prev_opt_unchoke.end());
|
TORRENT_ASSERT(existing != prev_opt_unchoke.end());
|
||||||
prev_opt_unchoke.erase(existing);
|
prev_opt_unchoke.erase(existing);
|
||||||
|
@ -4126,7 +4125,7 @@ namespace {
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
int steps_since_last_connect = 0;
|
int steps_since_last_connect = 0;
|
||||||
int num_torrents = int(want_peers_finished.size() + want_peers_download.size());
|
int const num_torrents = int(want_peers_finished.size() + want_peers_download.size());
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (m_next_downloading_connect_torrent >= int(want_peers_download.size()))
|
if (m_next_downloading_connect_torrent >= int(want_peers_download.size()))
|
||||||
|
@ -4263,7 +4262,7 @@ namespace {
|
||||||
// we don't know at what rate we can upload. If we have a
|
// we don't know at what rate we can upload. If we have a
|
||||||
// measurement of the peak, use that + 10kB/s, otherwise
|
// measurement of the peak, use that + 10kB/s, otherwise
|
||||||
// assume 20 kB/s
|
// assume 20 kB/s
|
||||||
max_upload_rate = (std::max)(20000, m_peak_up_rate + 10000);
|
max_upload_rate = std::max(20000, m_peak_up_rate + 10000);
|
||||||
if (m_alerts.should_post<performance_alert>())
|
if (m_alerts.should_post<performance_alert>())
|
||||||
m_alerts.emplace_alert<performance_alert>(torrent_handle()
|
m_alerts.emplace_alert<performance_alert>(torrent_handle()
|
||||||
, performance_alert::bittyrant_with_no_uplimit);
|
, performance_alert::bittyrant_with_no_uplimit);
|
||||||
|
@ -4292,7 +4291,7 @@ namespace {
|
||||||
int const unchoked_counter_optimistic
|
int const unchoked_counter_optimistic
|
||||||
= int(m_stats_counters[counters::num_peers_up_unchoked_optimistic]);
|
= int(m_stats_counters[counters::num_peers_up_unchoked_optimistic]);
|
||||||
int const num_opt_unchoke = (unchoked_counter_optimistic == 0)
|
int const num_opt_unchoke = (unchoked_counter_optimistic == 0)
|
||||||
? (std::max)(1, allowed_upload_slots / 5) : unchoked_counter_optimistic;
|
? std::max(1, allowed_upload_slots / 5) : unchoked_counter_optimistic;
|
||||||
|
|
||||||
int unchoke_set_size = allowed_upload_slots - num_opt_unchoke;
|
int unchoke_set_size = allowed_upload_slots - num_opt_unchoke;
|
||||||
|
|
||||||
|
@ -4369,7 +4368,7 @@ namespace {
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
|
|
||||||
torrent_map::const_iterator i = m_torrents.find(info_hash);
|
auto const i = m_torrents.find(info_hash);
|
||||||
#if TORRENT_USE_INVARIANT_CHECKS
|
#if TORRENT_USE_INVARIANT_CHECKS
|
||||||
for (auto const& te : m_torrents)
|
for (auto const& te : m_torrents)
|
||||||
{
|
{
|
||||||
|
@ -4461,7 +4460,7 @@ namespace {
|
||||||
sha1_hash obfuscated = info_hash;
|
sha1_hash obfuscated = info_hash;
|
||||||
obfuscated ^= xor_mask;
|
obfuscated ^= xor_mask;
|
||||||
|
|
||||||
torrent_map::iterator i = m_obfuscated_torrents.find(obfuscated);
|
auto const i = m_obfuscated_torrents.find(obfuscated);
|
||||||
if (i == m_obfuscated_torrents.end()) return nullptr;
|
if (i == m_obfuscated_torrents.end()) return nullptr;
|
||||||
return i->second.get();
|
return i->second.get();
|
||||||
}
|
}
|
||||||
|
@ -4942,7 +4941,7 @@ namespace {
|
||||||
// if we still can't find the torrent, look for it by url
|
// if we still can't find the torrent, look for it by url
|
||||||
if (!torrent_ptr && !params.url.empty())
|
if (!torrent_ptr && !params.url.empty())
|
||||||
{
|
{
|
||||||
torrent_map::iterator i = std::find_if(m_torrents.begin(), m_torrents.end()
|
auto const i = std::find_if(m_torrents.begin(), m_torrents.end()
|
||||||
, [¶ms](torrent_map::value_type const& te)
|
, [¶ms](torrent_map::value_type const& te)
|
||||||
{ return te.second->url() == params.url; });
|
{ return te.second->url() == params.url; });
|
||||||
if (i != m_torrents.end())
|
if (i != m_torrents.end())
|
||||||
|
@ -6214,13 +6213,12 @@ namespace {
|
||||||
{
|
{
|
||||||
// if this flag changed, update all web seed connections
|
// if this flag changed, update all web seed connections
|
||||||
bool report = m_settings.get_bool(settings_pack::report_web_seed_downloads);
|
bool report = m_settings.get_bool(settings_pack::report_web_seed_downloads);
|
||||||
for (connection_map::iterator i = m_connections.begin()
|
for (auto const& c : m_connections)
|
||||||
, end(m_connections.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
connection_type const type = (*i)->type();
|
connection_type const type = c->type();
|
||||||
if (type == connection_type::url_seed
|
if (type == connection_type::url_seed
|
||||||
|| type == connection_type::http_seed)
|
|| type == connection_type::http_seed)
|
||||||
(*i)->ignore_stats(!report);
|
c->ignore_stats(!report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue