diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 16:54:36 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 16:54:36 +0100 |
| commit | 1e7248b330bde4c70528ccf91535391e19294dc3 (patch) | |
| tree | f650bc5090227578602de43b3f1ea6dfa3c8e5b5 /src | |
| parent | cfbe53da5d9ef8dad1bb3276c0b33ec2ab6e974b (diff) | |
Add a knob to help reducing memory consumption. This time: empty torrents may expire sooner
Diffstat (limited to 'src')
| -rw-r--r-- | src/ot_clean.c | 4 | ||||
| -rw-r--r-- | src/ot_config.c | 7 | ||||
| -rw-r--r-- | src/trackerlogic.h | 5 |
3 files changed, 15 insertions, 1 deletions
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 @@ | |||
| 16 | #include "ot_vector.h" | 16 | #include "ot_vector.h" |
| 17 | #include "trackerlogic.h" | 17 | #include "trackerlogic.h" |
| 18 | 18 | ||
| 19 | ot_time g_empty_torrent_timeout = OT_TORRENT_TIMEOUT; | ||
| 20 | |||
| 19 | /* Returns amount of removed peers */ | 21 | /* Returns amount of removed peers */ |
| 20 | static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t peer_size, time_t timedout, size_t *removed_seeders) { | 22 | static ssize_t clean_single_bucket(ot_peer *peers, size_t peer_count, size_t peer_size, time_t timedout, size_t *removed_seeders) { |
| 21 | ot_peer *last_peer, *insert_point; | 23 | ot_peer *last_peer, *insert_point; |
| @@ -106,7 +108,7 @@ int clean_single_torrent(ot_torrent *torrent) { | |||
| 106 | /* Already empty and nothing arrived before the peer timeout: keep it only | 108 | /* Already empty and nothing arrived before the peer timeout: keep it only |
| 107 | while a down count is worth remembering */ | 109 | while a down count is worth remembering */ |
| 108 | if (timedout > OT_PEER_TIMEOUT && !torrent->peer_list6 && !torrent->peer_list4) | 110 | if (timedout > OT_PEER_TIMEOUT && !torrent->peer_list6 && !torrent->peer_list4) |
| 109 | return torrent->down_count ? 0 : 1; | 111 | return (torrent->down_count && timedout <= g_empty_torrent_timeout) ? 0 : 1; |
| 110 | 112 | ||
| 111 | /* Peers past the peer timeout are gone regardless, which caps how far the | 113 | /* Peers past the peer timeout are gone regardless, which caps how far the |
| 112 | lists are aged in this pass */ | 114 | 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 { | |||
| 192 | CONFIG_UNKNOWN, | 192 | CONFIG_UNKNOWN, |
| 193 | CONFIG_TRACKER_ROOTDIR, | 193 | CONFIG_TRACKER_ROOTDIR, |
| 194 | CONFIG_TRACKER_USER, | 194 | CONFIG_TRACKER_USER, |
| 195 | CONFIG_TRACKER_EMPTY_TIMEOUT, | ||
| 195 | CONFIG_LISTEN_TCP_UDP, | 196 | CONFIG_LISTEN_TCP_UDP, |
| 196 | CONFIG_LISTEN_TCP, | 197 | CONFIG_LISTEN_TCP, |
| 197 | CONFIG_LISTEN_UDP, | 198 | CONFIG_LISTEN_UDP, |
| @@ -223,6 +224,7 @@ typedef struct { | |||
| 223 | static const config_key config_keys[] = { | 224 | static const config_key config_keys[] = { |
| 224 | CONFIG_KEY("tracker.rootdir", CONFIG_TRACKER_ROOTDIR), | 225 | CONFIG_KEY("tracker.rootdir", CONFIG_TRACKER_ROOTDIR), |
| 225 | CONFIG_KEY("tracker.user", CONFIG_TRACKER_USER), | 226 | CONFIG_KEY("tracker.user", CONFIG_TRACKER_USER), |
| 227 | CONFIG_KEY("tracker.empty_torrent_timeout", CONFIG_TRACKER_EMPTY_TIMEOUT), | ||
| 226 | CONFIG_KEY("listen.tcp_udp", CONFIG_LISTEN_TCP_UDP), | 228 | CONFIG_KEY("listen.tcp_udp", CONFIG_LISTEN_TCP_UDP), |
| 227 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), | 229 | CONFIG_KEY("listen.tcp", CONFIG_LISTEN_TCP), |
| 228 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), | 230 | CONFIG_KEY("listen.udp", CONFIG_LISTEN_UDP), |
| @@ -316,6 +318,11 @@ static int parse_configfile(char *config_filename) { | |||
| 316 | case CONFIG_TRACKER_USER: | 318 | case CONFIG_TRACKER_USER: |
| 317 | set_config_option(&g_serveruser, p); | 319 | set_config_option(&g_serveruser, p); |
| 318 | break; | 320 | break; |
| 321 | case CONFIG_TRACKER_EMPTY_TIMEOUT: | ||
| 322 | if (!scan_uint(p, &value, UINT_MAX)) | ||
| 323 | goto parse_error; | ||
| 324 | g_empty_torrent_timeout = (ot_time)value; | ||
| 325 | break; | ||
| 319 | case CONFIG_LISTEN_TCP_UDP: | 326 | case CONFIG_LISTEN_TCP_UDP: |
| 320 | case CONFIG_LISTEN_TCP: | 327 | case CONFIG_LISTEN_TCP: |
| 321 | case CONFIG_LISTEN_UDP: { | 328 | 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 { | |||
| 44 | #define OT_TORRENT_TIMEOUT_HOURS 24 | 44 | #define OT_TORRENT_TIMEOUT_HOURS 24 |
| 45 | #define OT_TORRENT_TIMEOUT (60 * OT_TORRENT_TIMEOUT_HOURS) | 45 | #define OT_TORRENT_TIMEOUT (60 * OT_TORRENT_TIMEOUT_HOURS) |
| 46 | 46 | ||
| 47 | /* How long a torrent kept only for its download count, with no peers in either | ||
| 48 | family, is held, in minutes. Defaults to OT_TORRENT_TIMEOUT and is lowered by | ||
| 49 | tracker.empty_torrent_timeout. */ | ||
| 50 | extern ot_time g_empty_torrent_timeout; | ||
| 51 | |||
| 47 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM \ | 52 | #define OT_CLIENT_REQUEST_INTERVAL_RANDOM \ |
| 48 | (OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION / 2 + (int)(nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION)) | 53 | (OT_CLIENT_REQUEST_INTERVAL - OT_CLIENT_REQUEST_VARIATION / 2 + (int)(nrand48(ws->rand48_state) % OT_CLIENT_REQUEST_VARIATION)) |
| 49 | #define OT_CLIENT_REJECT_INTERVAL_RANDOM \ | 54 | #define OT_CLIENT_REJECT_INTERVAL_RANDOM \ |
