From 88d280be8f5faf9b0cc93f6b3d6729fb3d02dc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luukas=20P=C3=B6rtfors?= Date: Mon, 27 May 2024 23:08:33 +0300 Subject: [PATCH] feat(remote): implement idle seeding limits (#2947) --- utils/remote.cc | 93 +++++++++++++++++++++++++++++++++++-- utils/transmission-remote.1 | 16 +++++++ 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/utils/remote.cc b/utils/remote.cc index 096a94351..8859cdc8d 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -212,7 +212,7 @@ enum // --- Command-Line Arguments -auto constexpr Options = std::array{ +static auto constexpr Options = std::array{ { { 'a', "add", "Add torrent files by filename or URL", "a", false, nullptr }, { 970, "alt-speed", "Use the alternate Limits", "as", false, nullptr }, { 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, nullptr }, @@ -307,6 +307,31 @@ auto constexpr Options = std::array{ "GSR", false, nullptr }, + { 955, + "idle-seeding-limit", + "Let the current torrent(s) seed until a specific amount idle time", + "isl", + true, + "" }, + { 956, + "default-idle-seeding-limit", + "Let the current torrent(s) use the default idle seeding settings", + "isld", + false, + nullptr }, + { 957, "no-idle-seeding-limit", "Let the current torrent(s) seed regardless of idle time", "ISL", false, nullptr }, + { 958, + "global-idle-seeding-limit", + "All torrents, unless overridden by a per-torrent setting, should seed until a specific amount of idle time", + "gisl", + true, + "" }, + { 959, + "no-global-idle-seeding-limit", + "All torrents, unless overridden by a per-torrent setting, should seed regardless of idle time", + "GISL", + false, + nullptr }, { 710, "tracker-add", "Add a tracker to a torrent", "td", true, "" }, { 712, "tracker-remove", "Remove a tracker from a torrent", "tr", true, "" }, { 's', "start", "Start the current torrent(s)", "s", false, nullptr }, @@ -436,6 +461,8 @@ enum case 912: /* encryption-tolerated */ case 953: /* global-seedratio */ case 954: /* no-global-seedratio */ + case 958: /* global-idle-seeding-limit */ + case 959: /* no-global-idle-seeding-limit */ case 990: /* start-paused */ case 991: /* no-start-paused */ case 992: /* trash-torrent */ @@ -446,6 +473,9 @@ enum case 950: /* seedratio */ case 951: /* seedratio-default */ case 952: /* no-seedratio */ + case 955: /* idle-seeding-limit */ + case 956: /* default-idle-seeding-limit */ + case 957: /* no-idle-seeding-limit*/ case 984: /* honor-session */ case 985: /* no-honor-session */ return MODE_TORRENT_SET; @@ -704,7 +734,7 @@ auto constexpr FilesKeys = std::array{ TR_KEY_wanted, }; -auto constexpr DetailsKeys = std::array{ +static auto constexpr DetailsKeys = std::array{ TR_KEY_activityDate, TR_KEY_addedDate, TR_KEY_bandwidthPriority, @@ -747,6 +777,8 @@ auto constexpr DetailsKeys = std::array{ TR_KEY_seedRatioMode, TR_KEY_seedRatioLimit, TR_KEY_sequentialDownload, + TR_KEY_seedIdleMode, + TR_KEY_seedIdleLimit, TR_KEY_sizeWhenDone, TR_KEY_source, TR_KEY_startDate, @@ -1212,6 +1244,31 @@ void printDetails(tr_variant* top) } } + if (tr_variantDictFindInt(t, TR_KEY_seedIdleMode, &i)) + { + switch (i) + { + case TR_IDLELIMIT_GLOBAL: + fmt::print(" Idle Limit: Default\n"); + break; + + case TR_IDLELIMIT_SINGLE: + if (tr_variantDictFindInt(t, TR_KEY_seedIdleLimit, &j)) + { + fmt::print(" Idle Limit: {} minutes\n", j); + } + + break; + + case TR_IDLELIMIT_UNLIMITED: + fmt::print(" Idle Limit: Unlimited\n"); + break; + + default: + break; + } + } + if (tr_variantDictFindBool(t, TR_KEY_honorsSessionLimits, &boolVal)) { fmt::print(" Honors Session Limits: {:s}\n", boolVal ? "Yes" : "No"); @@ -1792,6 +1849,7 @@ void printSession(tr_variant* top) bool upEnabled; bool downEnabled; bool seedRatioLimited; + bool seedIdleLimited; int64_t altDown; int64_t altUp; int64_t altBegin; @@ -1800,6 +1858,7 @@ void printSession(tr_variant* top) int64_t upLimit; int64_t downLimit; int64_t peerLimit; + int64_t seedIdleLimit; double seedRatioLimit; if (tr_variantDictFindInt(args, TR_KEY_alt_speed_down, &altDown) && @@ -1815,13 +1874,19 @@ void printSession(tr_variant* top) tr_variantDictFindInt(args, TR_KEY_speed_limit_up, &upLimit) && tr_variantDictFindBool(args, TR_KEY_speed_limit_up_enabled, &upEnabled) && tr_variantDictFindReal(args, TR_KEY_seedRatioLimit, &seedRatioLimit) && - tr_variantDictFindBool(args, TR_KEY_seedRatioLimited, &seedRatioLimited)) + tr_variantDictFindBool(args, TR_KEY_seedRatioLimited, &seedRatioLimited) && + tr_variantDictFindInt(args, TR_KEY_idle_seeding_limit, &seedIdleLimit) && + tr_variantDictFindBool(args, TR_KEY_idle_seeding_limit_enabled, &seedIdleLimited)) { fmt::print("LIMITS\n"); fmt::print(" Peer limit: {:d}\n", peerLimit); fmt::print(" Default seed ratio limit: {:s}\n", seedRatioLimited ? strlratio2(seedRatioLimit) : "Unlimited"); + fmt::print( + " Default idle seeding time limit: {:s}\n", + seedIdleLimited ? (std::to_string(seedIdleLimit) + " minutes").c_str() : "Unlimited"); + std::string effective_up_limit; if (altEnabled) @@ -2767,6 +2832,15 @@ int processArgs(char const* rpcurl, int argc, char const* const* argv, RemoteCon tr_variantDictAddBool(args, TR_KEY_seedRatioLimited, false); break; + case 958: + tr_variantDictAddInt(args, TR_KEY_idle_seeding_limit, atoi(optarg)); + tr_variantDictAddBool(args, TR_KEY_idle_seeding_limit_enabled, true); + break; + + case 959: + tr_variantDictAddBool(args, TR_KEY_idle_seeding_limit_enabled, false); + break; + case 990: tr_variantDictAddBool(args, TR_KEY_start_added_torrents, false); break; @@ -2903,6 +2977,19 @@ int processArgs(char const* rpcurl, int argc, char const* const* argv, RemoteCon tr_variantDictAddInt(args, TR_KEY_seedRatioMode, TR_RATIOLIMIT_UNLIMITED); break; + case 955: + tr_variantDictAddInt(args, TR_KEY_seedIdleLimit, atoi(optarg)); + tr_variantDictAddInt(args, TR_KEY_seedIdleMode, TR_IDLELIMIT_SINGLE); + break; + + case 956: + tr_variantDictAddInt(args, TR_KEY_seedIdleMode, TR_IDLELIMIT_GLOBAL); + break; + + case 957: + tr_variantDictAddInt(args, TR_KEY_seedIdleMode, TR_IDLELIMIT_UNLIMITED); + break; + case 984: tr_variantDictAddBool(args, TR_KEY_honorsSessionLimits, true); break; diff --git a/utils/transmission-remote.1 b/utils/transmission-remote.1 index dabc4b633..8f8c308d2 100644 --- a/utils/transmission-remote.1 +++ b/utils/transmission-remote.1 @@ -28,6 +28,8 @@ and .Op Fl F Ar filter .Op Fl g Ar files .Op Fl G Ar files +.Op Fl gisl Ar number +.Op Fl GISL Ar number .Op Fl gsr Ar ratio .Op Fl GSR .Op Fl h @@ -36,6 +38,9 @@ and .Op Fl ids .Op Fl if .Op Fl ip +.Op Fl isl Ar number +.Op Fl ISL Ar number +.Op Fl isld .Op Fl it .Op Fl j .Op Fl l @@ -176,6 +181,17 @@ All torrents, unless overridden by a per-torrent setting, should seed until a sp .Ar ratio .It Fl GSR Fl -no-global-seedratio All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio +.It Fl isl Fl -idle-seeding-limit Ar minutes +Let the selected torrent(s) seed until a specific amount of idle time +.It Fl isld Fl -default-idle-seeding-limit +Use the default idle-seeding-limit for the selected torrent +.It Fl ISL Fl -no-idle-seeding-limit +Let the selected torrent(s) seed regardless of idle time +.It Fl gisl Fl -global-idle-seeding-limit Ar minutes +All torrents, unless overridden by a per-torrent, should stop seeding after spending the specified time idling +.It Fl GISL Fl -no-global-idle-seeding-limit +All torrents, unless overridden by a per-torrent, should seed regardless of the time spent idle +Let the selected torrent(s) seed regardless of idle time .It Fl h Fl -help Print command-line option descriptions. .It Fl i Fl -info