From 21e50d290a4dcf9be370025ddf213c78f5220308 Mon Sep 17 00:00:00 2001 From: Elegant Date: Mon, 15 May 2023 02:33:25 +0900 Subject: [PATCH] Add trackers.delay_scrape Based on https://github.com/rakshasa/rtorrent/pull/1210 and https://github.com/jesec/rtorrent/pull/31 --- include/core/download_factory.h | 8 ++++++++ src/command_tracker.cc | 1 + src/core/download_factory.cc | 4 ++++ src/main.cc | 2 ++ 4 files changed, 15 insertions(+) diff --git a/include/core/download_factory.h b/include/core/download_factory.h index 23c2623b..0d73c9de 100644 --- a/include/core/download_factory.h +++ b/include/core/download_factory.h @@ -60,6 +60,13 @@ class DownloadFactory { m_start = v; } + bool get_init_load() const { + return m_initLoad; + } + void set_init_load(bool v) { + m_initLoad = v; + } + bool print_log() const { return m_printLog; } @@ -103,6 +110,7 @@ class DownloadFactory { bool m_printLog{ true }; bool m_immediate{ false }; bool m_isFile{ false }; + bool m_initLoad{ false }; command_list_type m_commands; torrent::Object::map_type m_variables; diff --git a/src/command_tracker.cc b/src/command_tracker.cc index 59d46dd7..adeedbd9 100644 --- a/src/command_tracker.cc +++ b/src/command_tracker.cc @@ -222,6 +222,7 @@ initialize_command_tracker() { CMD2_ANY_VALUE("trackers.disable", [](const auto&, const auto&) { return apply_enable_trackers(int64_t(0)); }); + CMD2_VAR_BOOL("trackers.delay_scrape", false); CMD2_VAR_VALUE("trackers.numwant", -1); CMD2_VAR_BOOL("trackers.use_udp", true); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index c330a0e2..81d363eb 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -298,6 +298,10 @@ DownloadFactory::receive_success() { if (!rpc::call_command_value("trackers.use_udp")) download->enable_udp_trackers(false); + // Skip forcing trackers to scrape when rtorrent starts + if (m_initLoad && rpc::call_command_value("trackers.delay_scrape")) + download->set_resume_flags(torrent::Download::start_skip_tracker); + // Check first if we already have these values set in the session // torrent, so that it is safe to change the values. // diff --git a/src/main.cc b/src/main.cc index 57937c6e..8b7e1c13 100644 --- a/src/main.cc +++ b/src/main.cc @@ -155,6 +155,7 @@ load_session_torrents() { // Replace with session torrent flag. f->set_session(true); + f->set_init_load(true); f->set_immediate(true); f->slot_finished([f, &progress_bar, entries_size]() { if (control->is_shutdown_received()) { @@ -199,6 +200,7 @@ load_arg_torrents(char** first, char** last) { // Replace with session torrent flag. f->set_start(true); + f->set_init_load(true); f->slot_finished([f]() { delete f; }); f->load(*first); f->commit();