From 14d085f607da33e14c0352a939a8b9ae639cc3b6 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 1 Jun 2016 01:05:32 -0400 Subject: [PATCH] rename allow_peers to paused (#773) --- include/libtorrent/torrent.hpp | 9 +++-- src/session_impl.cpp | 16 ++++----- src/torrent.cpp | 61 +++++++++++++++++----------------- 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 29791d157..ba710edc6 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -223,7 +223,7 @@ namespace libtorrent bool m_abort:1; // is true if this torrent has allows having peers - bool m_allow_peers:1; + bool m_paused:1; // this is set when the torrent is in share-mode bool m_share_mode:1; @@ -237,7 +237,7 @@ namespace libtorrent // set to true when this torrent has been paused but // is waiting to finish all current download requests // before actually closing all connections, When in graceful pause mode, - // m_allow_peers is also false. + // m_paused is also true. bool m_graceful_pause_mode:1; // state subscription. If set, a pointer to this torrent @@ -458,7 +458,7 @@ namespace libtorrent flag_graceful_pause = 1, flag_clear_disk_cache = 2 }; - void set_allow_peers(bool b, int flags = flag_clear_disk_cache); + void set_paused(bool b, int flags = flag_clear_disk_cache); void set_announce_to_dht(bool b) { m_announce_to_dht = b; } void set_announce_to_trackers(bool b) { m_announce_to_trackers = b; } void set_announce_to_lsd(bool b) { m_announce_to_lsd = b; } @@ -475,8 +475,7 @@ namespace libtorrent int seeding_time() const; bool is_paused() const; - bool allows_peers() const { return m_allow_peers; } - bool is_torrent_paused() const { return !m_allow_peers || m_graceful_pause_mode; } + bool is_torrent_paused() const { return m_paused || m_graceful_pause_mode; } void force_recheck(); void save_resume_data(int flags); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index ef6819b8a..b62341e27 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2799,7 +2799,7 @@ namespace aux { for (torrent_map::iterator i = m_torrents.begin() , end(m_torrents.end()); i != end; ++i) { - if (i->second->allows_peers()) + if (!i->second->is_torrent_paused()) { has_active_torrent = true; break; @@ -3661,10 +3661,10 @@ namespace aux { --hard_limit; #ifndef TORRENT_DISABLE_LOGGING - if (!t->allows_peers()) + if (t->is_torrent_paused()) t->log_to_all_peers("auto manager starting (inactive) torrent"); #endif - t->set_allow_peers(true); + t->set_paused(false); t->update_gauge(); t->update_want_peers(); continue; @@ -3679,21 +3679,21 @@ namespace aux { --hard_limit; --type_limit; #ifndef TORRENT_DISABLE_LOGGING - if (!t->allows_peers()) + if (t->is_torrent_paused()) t->log_to_all_peers("auto manager starting torrent"); #endif - t->set_allow_peers(true); + t->set_paused(false); t->update_gauge(); t->update_want_peers(); continue; } #ifndef TORRENT_DISABLE_LOGGING - if (t->allows_peers()) + if (!t->is_torrent_paused()) t->log_to_all_peers("auto manager pausing torrent"); #endif // use graceful pause for auto-managed torrents - t->set_allow_peers(false, torrent::flag_graceful_pause + t->set_paused(true, torrent::flag_graceful_pause | torrent::flag_clear_disk_cache); t->set_announce_to_dht(false); t->set_announce_to_trackers(false); @@ -4056,7 +4056,7 @@ namespace aux { } TORRENT_ASSERT(t->want_peers()); - TORRENT_ASSERT(t->allows_peers()); + TORRENT_ASSERT(!t->is_torrent_paused()); TORRENT_TRY { diff --git a/src/torrent.cpp b/src/torrent.cpp index 2860f2b25..29ca94acd 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -174,7 +174,7 @@ namespace libtorrent , m_upload_mode((p.flags & add_torrent_params::flag_upload_mode) != 0) , m_connections_initialized(false) , m_abort(false) - , m_allow_peers((p.flags & add_torrent_params::flag_paused) == 0) + , m_paused((p.flags & add_torrent_params::flag_paused) != 0) , m_share_mode((p.flags & add_torrent_params::flag_share_mode) != 0) , m_have_all(false) , m_graceful_pause_mode(false) @@ -560,7 +560,7 @@ namespace libtorrent if (m_abort) return counters::num_checking_torrents + no_gauge_state; if (has_error()) return counters::num_error_torrents; - if (!m_allow_peers || m_graceful_pause_mode) + if (m_paused || m_graceful_pause_mode) { if (!is_auto_managed()) return counters::num_stopped_torrents; if (is_seed()) return counters::num_queued_seeding_torrents; @@ -822,7 +822,7 @@ namespace libtorrent if (!m_ses.dht()) return false; if (m_torrent_file->is_valid() && !m_files_checked) return false; if (!m_announce_to_dht) return false; - if (!m_allow_peers) return false; + if (m_paused) return false; #ifndef TORRENT_NO_DEPRECATE // deprecated in 1.2 @@ -2669,7 +2669,7 @@ namespace libtorrent // managed logic runs again (which is triggered further down) // setting flags to 0 prevents the disk cache from being evicted as a // result of this - set_allow_peers(false, 0); + set_paused(true, 0); } // we're done checking! (this should cause a call to trigger_auto_manage) @@ -2771,7 +2771,7 @@ namespace libtorrent if (!m_announce_to_dht) debug_log("DHT: queueing disabled DHT announce"); - if (!m_allow_peers) + if (m_paused) debug_log("DHT: torrent paused, no DHT announce"); #ifndef TORRENT_NO_DEPRECATE @@ -2797,7 +2797,7 @@ namespace libtorrent return; } - TORRENT_ASSERT(m_allow_peers); + TORRENT_ASSERT(!m_paused); #ifdef TORRENT_USE_OPENSSL int port = is_ssl_torrent() ? m_ses.ssl_listen_port() : m_ses.listen_port(); @@ -2891,15 +2891,15 @@ namespace libtorrent } // if we're not allowing peers, there's no point in announcing - if (e != tracker_request::stopped && !m_allow_peers) + if (e != tracker_request::stopped && m_paused) { #ifndef TORRENT_DISABLE_LOGGING - debug_log("*** announce: event != stopped && !m_allow_peers"); + debug_log("*** announce: event != stopped && m_paused"); #endif return; } - TORRENT_ASSERT(m_allow_peers || e == tracker_request::stopped); + TORRENT_ASSERT(!m_paused || e == tracker_request::stopped); if (e == tracker_request::none && is_finished() && !is_seed()) e = tracker_request::paused; @@ -4756,7 +4756,7 @@ namespace libtorrent m_apply_ip_filter = true; } - m_allow_peers = false; + m_paused = false; m_auto_managed = false; update_state_list(); for (int i = 0; i < aux::session_interface::num_torrent_lists; ++i) @@ -5691,7 +5691,7 @@ namespace libtorrent if (k - m_trackers.begin() < m_last_working_tracker) ++m_last_working_tracker; k = m_trackers.insert(k, url); if (k->source == 0) k->source = announce_entry::source_client; - if (m_allow_peers && !m_trackers.empty()) announce_with_tracker(); + if (!m_paused && !m_trackers.empty()) announce_with_tracker(); return true; } @@ -5936,7 +5936,7 @@ namespace libtorrent TORRENT_ASSERT(is_paused()); // this will post torrent_paused alert - set_allow_peers(false); + set_paused(true); } update_want_peers(); @@ -7516,7 +7516,7 @@ namespace libtorrent return true; // if we don't get ticks we won't become inactive - if (m_allow_peers && !m_inactive) return true; + if (!m_paused && !m_inactive) return true; return false; } @@ -7617,7 +7617,7 @@ namespace libtorrent void torrent::update_want_scrape() { update_list(aux::session_interface::torrent_want_scrape - , !m_allow_peers && m_auto_managed && !m_abort); + , m_paused && m_auto_managed && !m_abort); } namespace { @@ -7668,7 +7668,7 @@ namespace libtorrent void torrent::disconnect_all(error_code const& ec, operation_t op) { -// doesn't work with the !m_allow_peers -> m_num_peers == 0 condition +// doesn't work with the m_paused -> m_num_peers == 0 condition // INVARIANT_CHECK; while (!m_connections.empty()) @@ -8253,10 +8253,10 @@ namespace libtorrent case counters::num_seeding_torrents: TORRENT_ASSERT(is_seed()); break; case counters::num_upload_only_torrents: TORRENT_ASSERT(is_upload_only()); break; case counters::num_stopped_torrents: TORRENT_ASSERT(!is_auto_managed() - && (!m_allow_peers || m_graceful_pause_mode)); + && (m_paused || m_graceful_pause_mode)); break; case counters::num_queued_seeding_torrents: - TORRENT_ASSERT((!m_allow_peers || m_graceful_pause_mode) && is_seed()); break; + TORRENT_ASSERT((m_paused || m_graceful_pause_mode) && is_seed()); break; } if (m_torrent_file) @@ -8280,7 +8280,7 @@ namespace libtorrent TORRENT_ASSERT(want_peers_download() == m_links[aux::session_interface::torrent_want_peers_download].in_list()); TORRENT_ASSERT(want_peers_finished() == m_links[aux::session_interface::torrent_want_peers_finished].in_list()); TORRENT_ASSERT(want_tick() == m_links[aux::session_interface::torrent_want_tick].in_list()); - TORRENT_ASSERT((!m_allow_peers && m_auto_managed && !m_abort) == m_links[aux::session_interface::torrent_want_scrape].in_list()); + TORRENT_ASSERT((m_paused && m_auto_managed && !m_abort) == m_links[aux::session_interface::torrent_want_scrape].in_list()); bool is_checking = false; bool is_downloading = false; @@ -8936,9 +8936,8 @@ namespace libtorrent bool torrent::should_check_files() const { TORRENT_ASSERT(is_single_thread()); - // #error should m_allow_peers really affect checking? return m_state == torrent_status::checking_files - && m_allow_peers + && !m_paused && !has_error() && !m_abort && !m_graceful_pause_mode @@ -8973,7 +8972,7 @@ namespace libtorrent bool torrent::is_paused() const { - return !m_allow_peers || m_ses.is_paused() || m_graceful_pause_mode; + return m_paused || m_ses.is_paused() || m_graceful_pause_mode; } void torrent::pause(bool graceful) @@ -8981,14 +8980,14 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; - if (m_allow_peers) + if (!m_paused) { // we need to save this new state set_need_save_resume(); } int const flags = graceful ? flag_graceful_pause : 0; - set_allow_peers(false, flags | flag_clear_disk_cache); + set_paused(true, flags | flag_clear_disk_cache); } void torrent::do_pause(bool const clear_disk_cache) @@ -9147,7 +9146,7 @@ namespace libtorrent set_need_save_resume(); } - void torrent::set_allow_peers(bool b, int flags) + void torrent::set_paused(bool b, int flags) { TORRENT_ASSERT(is_single_thread()); @@ -9159,12 +9158,12 @@ namespace libtorrent if (m_connections.empty()) flags &= ~flag_graceful_pause; - if (m_allow_peers == b) + if (m_paused == b) { // there is one special case here. If we are // currently in graceful pause mode, and we just turned into regular // paused mode, we need to actually pause the torrent properly - if (m_allow_peers == false + if (m_paused == true && m_graceful_pause_mode == true && (flags & flag_graceful_pause) == 0) { @@ -9175,11 +9174,11 @@ namespace libtorrent return; } - m_allow_peers = b; + m_paused = b; if (!m_ses.is_paused()) m_graceful_pause_mode = (flags & flag_graceful_pause) ? true : false; - if (!b) + if (b) { m_announce_to_dht = false; m_announce_to_trackers = false; @@ -9192,7 +9191,7 @@ namespace libtorrent update_state_list(); state_updated(); - if (!b) + if (b) { do_pause((flags & flag_clear_disk_cache) != 0); } @@ -9208,7 +9207,7 @@ namespace libtorrent TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; - if (m_allow_peers + if (!m_paused && m_announce_to_dht && m_announce_to_trackers && m_announce_to_lsd) return; @@ -9216,7 +9215,7 @@ namespace libtorrent m_announce_to_dht = true; m_announce_to_trackers = true; m_announce_to_lsd = true; - m_allow_peers = true; + m_paused = false; if (!m_ses.is_paused()) m_graceful_pause_mode = false; update_gauge();