From 1e7248b330bde4c70528ccf91535391e19294dc3 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 7 Nov 2026 16:54:36 +0100 Subject: Add a knob to help reducing memory consumption. This time: empty torrents may expire sooner --- src/ot_clean.c | 4 +++- src/ot_config.c | 7 +++++++ src/trackerlogic.h | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ot_clean.c b/src/ot_clean.c index 77cb4ba..9e2186f 100644 --- a/src/ot_clean.c +++ b/src/ot_clean.c @@ -16,6 +16,8 @@ #include "ot_vector.h" #include "trackerlogic.h" +ot_time g_empty_torrent_timeout = OT_TORRENT_TIMEOUT; + /* Returns amount of removed peers */ static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t peer_size, time_t timedout, size_t *removed_seeders) { ot_peer *last_peer, *insert_point; @@ -106,7 +108,7 @@ int clean_single_torrent(ot_torrent *torrent) { /* Already empty and nothing arrived before the peer timeout: keep it only while a down count is worth remembering */ if (timedout > OT_PEER_TIMEOUT && !torrent->peer_list6 && !torrent->peer_list4) - return torrent->down_count ? 0 : 1; + return (torrent->down_count && timedout <= g_empty_torrent_timeout) ? 0 : 1; /* Peers past the peer timeout are gone regardless, which caps how far the lists are aged in this pass */ diff --git a/src/ot_config.c b/src/ot_config.c index 9c5e8f0..8af6cfc 100644 --- a/src/ot_config.c +++ b/src/ot_config.c @@ -192,6 +192,7 @@ typedef enum { CONFIG_UNKNOWN, CONFIG_TRACKER_ROOTDIR, CONFIG_TRACKER_USER, + CONFIG_TRACKER_EMPTY_TIMEOUT, CONFIG_LISTEN_TCP_UDP, CONFIG_LISTEN_TCP, CONFIG_LISTEN_UDP, @@ -223,6 +224,7 @@ typedef struct { static const config_key config_keys[] = { CONFIG_KEY("tracker.rootdir", CONFIG_TRACKER_ROOTDIR), CONFIG_KEY("tracker.user", CONFIG_TRACKER_USER), + CONFIG_KEY("tracker.empty_torrent_timeout", CONFIG_TRACKER_EMPTY_TIMEOUT), CONFIG_KEY("listen.tcp_udp", CONFIG_LISTEN_TCP_UDP), CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), @@ -316,6 +318,11 @@ static int parse_configfile(char *config_filename) { case CONFIG_TRACKER_USER: set_config_option(&g_serveruser, p); break; + case CONFIG_TRACKER_EMPTY_TIMEOUT: + if (!scan_uint(p, &value, UINT_MAX)) + goto parse_error; + g_empty_torrent_timeout = (ot_time)value; + break; case CONFIG_LISTEN_TCP_UDP: case CONFIG_LISTEN_TCP: case CONFIG_LISTEN_UDP: { diff --git a/src/trackerlogic.h b/src/trackerlogic.h index 6b53406..c4b7774 100644 --- a/src/trackerlogic.h +++ b/src/trackerlogic.h @@ -44,6 +44,11 @@ typedef struct { #define OT_TORRENT_TIMEOUT_HOURS 24 #define OT_TORRENT_TIMEOUT (60 * OT_TORRENT_TIMEOUT_HOURS) +/* How long a torrent kept only for its download count, with no peers in either + family, is held, in minutes. Defaults to OT_TORRENT_TIMEOUT and is lowered by + tracker.empty_torrent_timeout. */ +extern ot_time g_empty_torrent_timeout; + #define OT_CLIENT_REQUEST_INTERVAL_RANDOM \ (OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION / 2 + (int)(nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION)) #define OT_CLIENT_REJECT_INTERVAL_RANDOM \ -- cgit v1.3