inactive/auto managed fixes. fix client_test key input

This commit is contained in:
Arvid Norberg 2015-05-26 18:39:49 +00:00
parent c6f8dd408a
commit 09bc072c31
6 changed files with 84 additions and 44 deletions

View File

@ -135,9 +135,6 @@ struct set_keypress
bool sleep_and_input(int* c, int sleep)
{
// sets the terminal to single-character mode
// and resets when destructed
set_keypress s;
libtorrent::time_point start = libtorrent::clock_type::now();
int ret = 0;
retry:
@ -1204,6 +1201,12 @@ void print_piece(libtorrent::partial_piece_info* pp
int main(int argc, char* argv[])
{
#ifndef _WIN32
// sets the terminal to single-character mode
// and resets when destructed
set_keypress s;
#endif
if (argc == 1)
{
fprintf(stderr, "usage: client_test [OPTIONS] [TORRENT|MAGNETURL|URL]\n\n"

View File

@ -74,6 +74,7 @@ std::string add_suffix(float val, char const* suffix)
std::string color(std::string const& s, color_code c)
{
if (c == col_none) return s;
if (std::count(s.begin(), s.end(), ' ') == s.size()) return s;
char buf[1024];
snprintf(buf, sizeof(buf), "\x1b[3%dm%s\x1b[39m", c, s.c_str());

View File

@ -314,7 +314,7 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
progress_bar_color = col_green;
pos += snprintf(str + pos, sizeof(str) - pos, "%s%c%-3s %-50s %s%s %s (%s) "
"%s (%s) %5d:%-5d %s %s %c%s"
"%s (%s) %5d:%-5d %s %s %c"
, selection
, s.is_loaded ? 'L' : ' '
, queue_pos
@ -328,7 +328,7 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
, s.num_peers - s.num_seeds, s.num_seeds
, color(add_suffix(s.all_time_download), col_green).c_str()
, color(add_suffix(s.all_time_upload), col_red).c_str()
, s.need_save_resume?'S':' ', esc("0"));
, s.need_save_resume?'S':' ');
// if this is the selected torrent, restore the background color
if (selected)
@ -336,9 +336,6 @@ void torrent_view::print_torrent(lt::torrent_status const& s, bool selected)
pos += snprintf(str + pos, sizeof(str) - pos, "\x1b[K");
if (m_width + 1 < int(sizeof(str)))
str[m_width + 1] = '\0';
print(str);
}

View File

@ -950,8 +950,10 @@ namespace libtorrent
void on_tick(error_code const& e);
void try_connect_more_peers();
void auto_manage_checking_torrents(std::vector<torrent*>& list
, int& limit);
void auto_manage_torrents(std::vector<torrent*>& list
, int& checking_limit, int& dht_limit, int& tracker_limit
, int& dht_limit, int& tracker_limit
, int& lsd_limit, int& hard_limit, int type_limit);
void recalculate_auto_managed_torrents();
void recalculate_unchoke_slots();

View File

@ -3442,8 +3442,30 @@ retry:
m_next_lsd_torrent = m_torrents.begin();
}
void session_impl::auto_manage_checking_torrents(std::vector<torrent*>& list
, int& limit)
{
for (std::vector<torrent*>::iterator i = list.begin()
, end(list.end()); i != end; ++i)
{
torrent* t = *i;
TORRENT_ASSERT(t->state() == torrent_status::checking_files);
if (limit <= 0)
{
t->pause();
}
else
{
t->resume();
t->start_checking();
--limit;
}
}
}
void session_impl::auto_manage_torrents(std::vector<torrent*>& list
, int& checking_limit, int& dht_limit, int& tracker_limit
, int& dht_limit, int& tracker_limit
, int& lsd_limit, int& hard_limit, int type_limit)
{
for (std::vector<torrent*>::iterator i = list.begin()
@ -3451,17 +3473,7 @@ retry:
{
torrent* t = *i;
if (t->state() == torrent_status::checking_files)
{
if (checking_limit <= 0) t->pause();
else
{
t->resume();
t->start_checking();
--checking_limit;
}
continue;
}
TORRENT_ASSERT(t->state() != torrent_status::checking_files);
--dht_limit;
--lsd_limit;
@ -3533,36 +3545,56 @@ retry:
if (tracker_limit == -1)
tracker_limit = (std::numeric_limits<int>::max)();
// TODO: 3 deduct "force started" torrents from the hard_limit
// also deduct force started checking torrents from checking_limit
// deduct "force started" torrents from the hard_limit
// we don't have explicit access to the number of force started torrents,
// but we know how many started downloading and seeding torrents we have.
// if we subtract all non-force started torrents from the total, we get
// the number of force started.
hard_limit -= m_stats_counters[counters::num_downloading_torrents] -
downloaders.size();
hard_limit -= m_stats_counters[counters::num_seeding_torrents]
+ m_stats_counters[counters::num_upload_only_torrents] -
seeds.size();
// TODO: 3 also deduct force started checking torrents from checking_limit
// also deduct started inactive torrents from hard_limit
// TODO: 3 use partial_sort of "type limit" prefix of the list
std::sort(checking.begin(), checking.end()
, boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
// if hard_limit is <= 0, all torrents in these lists should be paused.
// The order is not relevant
if (hard_limit > 0)
{
// we only need to sort the first n torrents here, where n is the number
// of checking torrents we allow. The rest of the list is still used to
// make sure the remaining torrents are paused, but their order is not
// relevant
std::partial_sort(checking.begin(), checking.begin() +
(std::min)(checking_limit, int(checking.size())), checking.end()
, boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
std::sort(downloaders.begin(), downloaders.end()
, boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
std::partial_sort(downloaders.begin(), downloaders.begin() +
(std::min)(hard_limit, int(downloaders.size())), downloaders.end()
, boost::bind(&torrent::sequence_number, _1) < boost::bind(&torrent::sequence_number, _2));
std::sort(seeds.begin(), seeds.end()
, boost::bind(&torrent::seed_rank, _1, boost::ref(m_settings))
> boost::bind(&torrent::seed_rank, _2, boost::ref(m_settings)));
std::partial_sort(seeds.begin(), seeds.begin() +
(std::min)(hard_limit, int(seeds.size())), seeds.end()
, boost::bind(&torrent::seed_rank, _1, boost::ref(m_settings))
> boost::bind(&torrent::seed_rank, _2, boost::ref(m_settings)));
}
auto_manage_torrents(checking, checking_limit, dht_limit, tracker_limit, lsd_limit
, hard_limit, num_downloaders);
auto_manage_checking_torrents(checking, checking_limit);
if (settings().get_bool(settings_pack::auto_manage_prefer_seeds))
{
auto_manage_torrents(seeds, checking_limit, dht_limit, tracker_limit, lsd_limit
auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
, hard_limit, num_seeds);
auto_manage_torrents(downloaders, checking_limit, dht_limit, tracker_limit, lsd_limit
auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
, hard_limit, num_downloaders);
}
else
{
auto_manage_torrents(downloaders, checking_limit, dht_limit, tracker_limit, lsd_limit
auto_manage_torrents(downloaders, dht_limit, tracker_limit, lsd_limit
, hard_limit, num_downloaders);
auto_manage_torrents(seeds, checking_limit, dht_limit, tracker_limit, lsd_limit
auto_manage_torrents(seeds, dht_limit, tracker_limit, lsd_limit
, hard_limit, num_seeds);
}
}

View File

@ -7871,6 +7871,9 @@ namespace libtorrent
if (m_stat.low_pass_upload_rate() > 0 || m_stat.low_pass_download_rate() > 0)
return true;
// if we don't get ticks we won't become inactive
if (!m_inactive) return true;
return false;
}
@ -9193,7 +9196,7 @@ namespace libtorrent
, boost::bind(&torrent::on_save_resume_data, shared_from_this(), _1));
return true;
}
bool torrent::should_check_files() const
{
TORRENT_ASSERT(is_single_thread());
@ -9288,6 +9291,9 @@ namespace libtorrent
m_need_connect_boost = true;
m_inactive = false;
update_state_list();
update_want_tick();
m_active_time += m_ses.session_time() - m_started;
if (is_seed())
@ -9692,6 +9698,7 @@ namespace libtorrent
: m_ses.session_time() - m_became_seed);
}
// TODO: 2 if residual is not used, remove it
void torrent::second_tick(int tick_interval_ms, int /* residual */)
{
TORRENT_ASSERT(want_tick());
@ -9737,7 +9744,7 @@ namespace libtorrent
if (is_paused() && !m_graceful_pause_mode)
{
// let the stats fade out to 0
m_stat.second_tick(tick_interval_ms);
m_stat.second_tick(tick_interval_ms);
// if the rate is 0, there's no update because of network transfers
if (m_stat.low_pass_upload_rate() > 0 || m_stat.low_pass_download_rate() > 0)
state_updated();
@ -9825,7 +9832,7 @@ namespace libtorrent
// ---- WEB SEEDS ----
maybe_connect_web_seeds();
m_swarm_last_seen_complete = m_last_seen_complete;
int idx = 0;
for (peer_iterator i = m_connections.begin();
@ -9918,15 +9925,13 @@ namespace libtorrent
if (ec) return;
int now = m_ses.session_time();
int delay = settings().get_int(settings_pack::auto_manage_startup);
bool is_inactive = is_inactive_internal();
if (is_inactive == m_inactive) return;
m_inactive = is_inactive;
update_state_list();
update_want_tick();
if (settings().get_bool(settings_pack::dont_count_slow_torrents))
m_ses.trigger_auto_manage();
@ -10024,7 +10029,7 @@ namespace libtorrent
missing_pieces -= 2 * num_seeds;
if (missing_pieces <= 0) return;
// missing_pieces represents our opportunity to download pieces
// and share them more than once each