deprecated setters for max connections, max half-open, upload and download rates and unchoke slots. These are now set through session_settings
This commit is contained in:
@@ -319,6 +319,13 @@ namespace aux {
|
||||
TORRENT_SETTING(boolean, ignore_resume_timestamps)
|
||||
TORRENT_SETTING(boolean, anonymous_mode)
|
||||
TORRENT_SETTING(integer, tick_interval)
|
||||
TORRENT_SETTING(integer, upload_rate_limit)
|
||||
TORRENT_SETTING(integer, download_rate_limit)
|
||||
TORRENT_SETTING(integer, local_upload_rate_limit)
|
||||
TORRENT_SETTING(integer, local_download_rate_limit)
|
||||
TORRENT_SETTING(integer, unchoke_slots_limit)
|
||||
TORRENT_SETTING(integer, half_open_limit)
|
||||
TORRENT_SETTING(integer, connections_limit)
|
||||
};
|
||||
|
||||
#undef TORRENT_SETTING
|
||||
@@ -486,9 +493,7 @@ namespace aux {
|
||||
#endif
|
||||
, m_abort(false)
|
||||
, m_paused(false)
|
||||
, m_max_uploads(8)
|
||||
, m_allowed_upload_slots(8)
|
||||
, m_max_connections(200)
|
||||
, m_num_unchoked(0)
|
||||
, m_unchoke_time_scaler(0)
|
||||
, m_auto_manage_time_scaler(0)
|
||||
@@ -617,6 +622,7 @@ namespace aux {
|
||||
// before XP SP2, there was no limit
|
||||
m_half_open.limit(0);
|
||||
}
|
||||
m_settings.half_open_limit = m_half_open.limit();
|
||||
#endif
|
||||
|
||||
m_bandwidth_channel[peer_connection::download_channel] = &m_download_channel;
|
||||
@@ -724,11 +730,12 @@ namespace aux {
|
||||
rl.rlim_cur -= 20;
|
||||
|
||||
// 80% of the available file descriptors should go
|
||||
m_max_connections = (std::min)(m_max_connections, int(rl.rlim_cur * 8 / 10));
|
||||
m_settings.connections_limit = (std::min)(m_settings.connections_limit
|
||||
, int(rl.rlim_cur * 8 / 10));
|
||||
// 20% goes towards regular files
|
||||
m_files.resize((std::min)(m_files.size_limit(), int(rl.rlim_cur * 2 / 10)));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
(*m_logger) << time_now_string() << " max connections: " << m_max_connections << "\n";
|
||||
(*m_logger) << time_now_string() << " max connections: " << m_settings.connections_limit << "\n";
|
||||
(*m_logger) << time_now_string() << " max files: " << m_files.size_limit() << "\n";
|
||||
#endif
|
||||
}
|
||||
@@ -750,6 +757,10 @@ namespace aux {
|
||||
|
||||
url_random((char*)&m_peer_id[print.length()], (char*)&m_peer_id[0] + 20);
|
||||
|
||||
update_rate_settings();
|
||||
update_connections_limit();
|
||||
update_unchoke_limit();
|
||||
|
||||
m_thread.reset(new thread(boost::bind(&session_impl::main_thread, this)));
|
||||
}
|
||||
|
||||
@@ -790,18 +801,6 @@ namespace aux {
|
||||
|
||||
entry& e = *eptr;
|
||||
|
||||
if (flags & session::save_settings)
|
||||
{
|
||||
// TODO: move these to session_settings
|
||||
e["upload_rate_limit"] = upload_rate_limit();
|
||||
e["download_rate_limit"] = download_rate_limit();
|
||||
e["local_upload_rate_limit"] = local_upload_rate_limit();
|
||||
e["local_download_rate_limit"] = local_download_rate_limit();
|
||||
e["max_uploads"] = max_uploads();
|
||||
e["max_half_open_connections"] = max_half_open_connections();
|
||||
e["max_connections"] = max_connections();
|
||||
}
|
||||
|
||||
for (int i = 0; i < sizeof(all_settings)/sizeof(all_settings[0]); ++i)
|
||||
{
|
||||
session_category const& c = all_settings[i];
|
||||
@@ -866,14 +865,6 @@ namespace aux {
|
||||
|
||||
if (e->type() != lazy_entry::dict_t) return;
|
||||
|
||||
set_upload_rate_limit(e->dict_find_int_value("upload_rate_limit", 0));
|
||||
set_download_rate_limit(e->dict_find_int_value("download_rate_limit", 0));
|
||||
set_local_upload_rate_limit(e->dict_find_int_value("local_upload_rate_limit", 0));
|
||||
set_local_download_rate_limit(e->dict_find_int_value("local_download_rate_limit", 0));
|
||||
set_max_uploads(e->dict_find_int_value("max_uploads", 0));
|
||||
set_max_half_open_connections(e->dict_find_int_value("max_half_open_connections", 0));
|
||||
set_max_connections(e->dict_find_int_value("max_connections", 0));
|
||||
|
||||
for (int i = 0; i < sizeof(all_settings)/sizeof(all_settings[0]); ++i)
|
||||
{
|
||||
session_category const& c = all_settings[i];
|
||||
@@ -881,6 +872,17 @@ namespace aux {
|
||||
if (!settings) continue;
|
||||
load_struct(*settings, reinterpret_cast<char*>(this) + c.offset, c.map, c.num_entries);
|
||||
}
|
||||
|
||||
update_rate_settings();
|
||||
|
||||
update_connections_limit();
|
||||
update_unchoke_limit();
|
||||
|
||||
// in case we just set a socks proxy, we might have to
|
||||
// open the socks incoming connection
|
||||
if (!m_socks_listen_socket) open_new_incoming_socks_connection();
|
||||
m_udp_socket.set_proxy_settings(m_proxy);
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
settings = e->dict_find_dict("dht");
|
||||
if (settings)
|
||||
@@ -1265,6 +1267,9 @@ namespace aux {
|
||||
|| m_settings.low_prio_disk != s.low_prio_disk)
|
||||
update_disk_io_thread = true;
|
||||
|
||||
bool connections_limit_changed = m_settings.connections_limit != s.connections_limit;
|
||||
bool unchoke_limit_changed = m_settings.unchoke_slots_limit != s.unchoke_slots_limit;
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// support deprecated choker settings
|
||||
if (s.choking_algorithm == session_settings::rate_based_choker)
|
||||
@@ -1342,6 +1347,11 @@ namespace aux {
|
||||
|
||||
m_settings = s;
|
||||
|
||||
update_rate_settings();
|
||||
|
||||
if (connections_limit_changed) update_connections_limit();
|
||||
if (unchoke_limit_changed) update_unchoke_limit();
|
||||
|
||||
// enable anonymous mode. We don't want to accept any incoming
|
||||
// connections, except through a proxy.
|
||||
if (anonymous)
|
||||
@@ -1376,10 +1386,10 @@ namespace aux {
|
||||
}
|
||||
|
||||
if (s.choking_algorithm == session_settings::fixed_slots_choker)
|
||||
m_allowed_upload_slots = m_max_uploads;
|
||||
m_allowed_upload_slots = m_settings.unchoke_slots_limit;
|
||||
else if (s.choking_algorithm == session_settings::auto_expand_choker
|
||||
&& m_allowed_upload_slots < m_max_uploads)
|
||||
m_allowed_upload_slots = m_max_uploads;
|
||||
&& m_allowed_upload_slots < m_settings.unchoke_slots_limit)
|
||||
m_allowed_upload_slots = m_settings.unchoke_slots_limit;
|
||||
|
||||
// replace all occurances of '\n' with ' '.
|
||||
std::string::iterator i = m_settings.user_agent.begin();
|
||||
@@ -1791,8 +1801,8 @@ namespace aux {
|
||||
// because we have too many files open, try again
|
||||
// and lower the number of file descriptors used
|
||||
// elsewere.
|
||||
if (m_max_connections > 10)
|
||||
--m_max_connections;
|
||||
if (m_settings.connections_limit > 10)
|
||||
--m_settings.connections_limit;
|
||||
// try again, but still alert the user of the problem
|
||||
async_accept(listener);
|
||||
}
|
||||
@@ -1844,10 +1854,10 @@ namespace aux {
|
||||
// don't allow more connections than the max setting
|
||||
bool reject = false;
|
||||
if (m_settings.ignore_limits_on_local_network && is_local(endp.address()))
|
||||
reject = max_connections() < INT_MAX / 12
|
||||
&& num_connections() >= max_connections() * 12 / 10;
|
||||
reject = m_settings.connections_limit < INT_MAX / 12
|
||||
&& num_connections() >= m_settings.connections_limit * 12 / 10;
|
||||
else
|
||||
reject = num_connections() >= max_connections();
|
||||
reject = num_connections() >= m_settings.connections_limit;
|
||||
|
||||
if (reject)
|
||||
{
|
||||
@@ -1859,7 +1869,7 @@ namespace aux {
|
||||
}
|
||||
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||
(*m_logger) << "number of connections limit exceeded (conns: "
|
||||
<< num_connections() << ", limit: " << max_connections()
|
||||
<< num_connections() << ", limit: " << m_settings.connections_limit
|
||||
<< "), connection rejected\n";
|
||||
#endif
|
||||
return;
|
||||
@@ -2393,7 +2403,7 @@ namespace aux {
|
||||
int free_slots = m_half_open.free_slots();
|
||||
if (!m_torrents.empty()
|
||||
&& free_slots > -m_half_open.limit()
|
||||
&& num_connections() < m_max_connections
|
||||
&& num_connections() < m_settings.connections_limit
|
||||
&& !m_abort
|
||||
&& m_settings.connection_speed > 0)
|
||||
{
|
||||
@@ -2446,8 +2456,8 @@ namespace aux {
|
||||
// we ran out of memory trying to connect to a peer
|
||||
// lower the global limit to the number of peers
|
||||
// we already have
|
||||
m_max_connections = num_connections();
|
||||
if (m_max_connections < 2) m_max_connections = 2;
|
||||
m_settings.connections_limit = num_connections();
|
||||
if (m_settings.connections_limit < 2) m_settings.connections_limit = 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -2466,7 +2476,7 @@ namespace aux {
|
||||
// attempts this tick, abort
|
||||
if (max_connections == 0) break;
|
||||
// maintain the global limit on number of connections
|
||||
if (num_connections() >= m_max_connections) break;
|
||||
if (num_connections() >= m_settings.connections_limit) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2510,7 +2520,7 @@ namespace aux {
|
||||
{
|
||||
m_disconnect_time_scaler = 90;
|
||||
|
||||
if (num_connections() >= max_connections() * m_settings.peer_turnover_cutoff
|
||||
if (num_connections() >= m_settings.connections_limit * m_settings.peer_turnover_cutoff
|
||||
&& !m_torrents.empty())
|
||||
{
|
||||
// every 90 seconds, disconnect the worst peers
|
||||
@@ -2979,7 +2989,7 @@ namespace aux {
|
||||
++m_allowed_upload_slots;
|
||||
}
|
||||
else if (m_upload_rate.queue_size() > 1
|
||||
&& m_allowed_upload_slots > m_max_uploads)
|
||||
&& m_allowed_upload_slots > m_settings.unchoke_slots_limit)
|
||||
{
|
||||
--m_allowed_upload_slots;
|
||||
}
|
||||
@@ -3753,16 +3763,98 @@ namespace aux {
|
||||
TORRENT_ASSERT(m_connections.empty());
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
int session_impl::max_connections() const
|
||||
{
|
||||
return m_settings.connections_limit;
|
||||
}
|
||||
|
||||
int session_impl::max_uploads() const
|
||||
{
|
||||
return m_settings.unchoke_slots_limit;
|
||||
}
|
||||
|
||||
int session_impl::max_half_open_connections() const
|
||||
{
|
||||
return m_settings.half_open_limit;
|
||||
}
|
||||
|
||||
void session_impl::set_local_download_rate_limit(int bytes_per_second)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.local_download_rate_limit = bytes_per_second;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_local_upload_rate_limit(int bytes_per_second)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.local_upload_rate_limit = bytes_per_second;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_download_rate_limit(int bytes_per_second)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.download_rate_limit = bytes_per_second;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_upload_rate_limit(int bytes_per_second)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.upload_rate_limit = bytes_per_second;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_max_half_open_connections(int limit)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.half_open_limit = limit;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_max_connections(int limit)
|
||||
{
|
||||
session_settings s = m_settings;
|
||||
s.connections_limit = limit;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
void session_impl::set_max_uploads(int limit)
|
||||
{
|
||||
TORRENT_ASSERT(limit >= 0 || limit == -1);
|
||||
session_settings s = m_settings;
|
||||
s.unchoke_slots_limit = limit;
|
||||
set_settings(s);
|
||||
}
|
||||
|
||||
INVARIANT_CHECK;
|
||||
int session_impl::local_upload_rate_limit() const
|
||||
{
|
||||
return m_local_upload_channel.throttle();
|
||||
}
|
||||
|
||||
if (limit < 0) limit = (std::numeric_limits<int>::max)();
|
||||
if (m_max_uploads == limit) return;
|
||||
m_max_uploads = limit;
|
||||
m_allowed_upload_slots = limit;
|
||||
int session_impl::local_download_rate_limit() const
|
||||
{
|
||||
return m_local_download_channel.throttle();
|
||||
}
|
||||
|
||||
int session_impl::upload_rate_limit() const
|
||||
{
|
||||
return m_upload_channel.throttle();
|
||||
}
|
||||
|
||||
int session_impl::download_rate_limit() const
|
||||
{
|
||||
return m_download_channel.throttle();
|
||||
}
|
||||
#endif
|
||||
|
||||
void session_impl::update_unchoke_limit()
|
||||
{
|
||||
if (m_settings.unchoke_slots_limit < 0)
|
||||
m_settings.unchoke_slots_limit = (std::numeric_limits<int>::max)();
|
||||
|
||||
m_allowed_upload_slots = m_settings.unchoke_slots_limit;
|
||||
if (m_settings.num_optimistic_unchoke_slots >= m_allowed_upload_slots / 2)
|
||||
{
|
||||
if (m_alerts.should_post<performance_alert>())
|
||||
@@ -3771,37 +3863,59 @@ namespace aux {
|
||||
}
|
||||
}
|
||||
|
||||
void session_impl::set_max_connections(int limit)
|
||||
void session_impl::update_rate_settings()
|
||||
{
|
||||
if (m_settings.half_open_limit <= 0) m_settings.half_open_limit
|
||||
= (std::numeric_limits<int>::max)();
|
||||
m_half_open.limit(m_settings.half_open_limit);
|
||||
|
||||
if (m_settings.local_download_rate_limit < 0)
|
||||
m_settings.local_download_rate_limit = 0;
|
||||
m_local_download_channel.throttle(m_settings.local_download_rate_limit);
|
||||
|
||||
if (m_settings.local_upload_rate_limit < 0)
|
||||
m_settings.local_upload_rate_limit = 0;
|
||||
m_local_upload_channel.throttle(m_settings.local_upload_rate_limit);
|
||||
|
||||
if (m_settings.download_rate_limit < 0)
|
||||
m_settings.download_rate_limit = 0;
|
||||
m_download_channel.throttle(m_settings.download_rate_limit);
|
||||
|
||||
if (m_settings.upload_rate_limit < 0)
|
||||
m_settings.upload_rate_limit = 0;
|
||||
m_upload_channel.throttle(m_settings.upload_rate_limit);
|
||||
}
|
||||
|
||||
void session_impl::update_connections_limit()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (limit <= 0)
|
||||
if (m_settings.connections_limit <= 0)
|
||||
{
|
||||
limit = (std::numeric_limits<int>::max)();
|
||||
m_settings.connections_limit = (std::numeric_limits<int>::max)();
|
||||
#if TORRENT_USE_RLIMIT
|
||||
rlimit l;
|
||||
if (getrlimit(RLIMIT_NOFILE, &l) == 0
|
||||
&& l.rlim_cur != RLIM_INFINITY)
|
||||
{
|
||||
limit = l.rlim_cur - m_settings.file_pool_size;
|
||||
if (limit < 5) limit = 5;
|
||||
m_settings.connections_limit = l.rlim_cur - m_settings.file_pool_size;
|
||||
if (m_settings.connections_limit < 5) m_settings.connections_limit = 5;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
m_max_connections = limit;
|
||||
|
||||
if (num_connections() > max_connections() && !m_torrents.empty())
|
||||
if (num_connections() > m_settings.connections_limit && !m_torrents.empty())
|
||||
{
|
||||
// if we have more connections that we're allowed, disconnect
|
||||
// peers from the torrents so that they are all as even as possible
|
||||
|
||||
int to_disconnect = num_connections() - max_connections();
|
||||
int to_disconnect = num_connections() - m_settings.connections_limit;
|
||||
|
||||
int last_average = 0;
|
||||
int average = max_connections() / m_torrents.size();
|
||||
int average = m_settings.connections_limit / m_torrents.size();
|
||||
|
||||
// the number of slots that are unused by torrents
|
||||
int extra = max_connections() % m_torrents.size();
|
||||
int extra = m_settings.connections_limit % m_torrents.size();
|
||||
|
||||
// run 3 iterations of this, then we're probably close enough
|
||||
for (int iter = 0; iter < 4; ++iter)
|
||||
@@ -3848,46 +3962,6 @@ namespace aux {
|
||||
}
|
||||
}
|
||||
|
||||
void session_impl::set_max_half_open_connections(int limit)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (limit <= 0) limit = (std::numeric_limits<int>::max)();
|
||||
m_half_open.limit(limit);
|
||||
}
|
||||
|
||||
void session_impl::set_local_download_rate_limit(int bytes_per_second)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (bytes_per_second <= 0) bytes_per_second = 0;
|
||||
m_local_download_channel.throttle(bytes_per_second);
|
||||
}
|
||||
|
||||
void session_impl::set_local_upload_rate_limit(int bytes_per_second)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (bytes_per_second <= 0) bytes_per_second = 0;
|
||||
m_local_upload_channel.throttle(bytes_per_second);
|
||||
}
|
||||
|
||||
void session_impl::set_download_rate_limit(int bytes_per_second)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (bytes_per_second <= 0) bytes_per_second = 0;
|
||||
m_download_channel.throttle(bytes_per_second);
|
||||
}
|
||||
|
||||
void session_impl::set_upload_rate_limit(int bytes_per_second)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (bytes_per_second <= 0) bytes_per_second = 0;
|
||||
m_upload_channel.throttle(bytes_per_second);
|
||||
}
|
||||
|
||||
void session_impl::set_alert_dispatch(boost::function<void(std::auto_ptr<alert>)> const& fun)
|
||||
{
|
||||
m_alerts.set_dispatch_function(fun);
|
||||
@@ -3916,26 +3990,6 @@ namespace aux {
|
||||
return m_alerts.set_alert_queue_size_limit(queue_size_limit_);
|
||||
}
|
||||
|
||||
int session_impl::local_upload_rate_limit() const
|
||||
{
|
||||
return m_local_upload_channel.throttle();
|
||||
}
|
||||
|
||||
int session_impl::local_download_rate_limit() const
|
||||
{
|
||||
return m_local_download_channel.throttle();
|
||||
}
|
||||
|
||||
int session_impl::upload_rate_limit() const
|
||||
{
|
||||
return m_upload_channel.throttle();
|
||||
}
|
||||
|
||||
int session_impl::download_rate_limit() const
|
||||
{
|
||||
return m_download_channel.throttle();
|
||||
}
|
||||
|
||||
void session_impl::start_lsd()
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
@@ -4155,10 +4209,10 @@ namespace aux {
|
||||
TORRENT_ASSERT(int(unique.size()) == total_downloaders);
|
||||
|
||||
std::set<peer_connection*> unique_peers;
|
||||
TORRENT_ASSERT(m_max_connections > 0);
|
||||
TORRENT_ASSERT(m_max_uploads >= 0);
|
||||
TORRENT_ASSERT(m_settings.connections_limit > 0);
|
||||
TORRENT_ASSERT(m_settings.unchoke_slots_limit >= 0);
|
||||
if (m_settings.choking_algorithm == session_settings::auto_expand_choker)
|
||||
TORRENT_ASSERT(m_allowed_upload_slots >= m_max_uploads);
|
||||
TORRENT_ASSERT(m_allowed_upload_slots >= m_settings.unchoke_slots_limit);
|
||||
int unchokes = 0;
|
||||
int num_optimistic = 0;
|
||||
for (connection_map::const_iterator i = m_connections.begin();
|
||||
|
Reference in New Issue
Block a user