From 355c8ae57d582974f4f6a4ba42f635f2253b84a7 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 6 Nov 2026 14:24:04 +0100 Subject: Add a wall clock helper so that statedumps can be written and re-read --- src/opentracker.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/opentracker.c') diff --git a/src/opentracker.c b/src/opentracker.c index e467ce6..123f20a 100644 --- a/src/opentracker.c +++ b/src/opentracker.c @@ -300,9 +300,13 @@ void load_state(const char *const state_filename) { FILE *state_filehandle; char inbuf[512]; ot_hash infohash; - uint64_t age, downcount; + uint64_t touched, downcount; int consumed; + /* The file records the minute a torrent was last touched, by the clock that + survives a restart */ + uint64_t now = (uint64_t)time_wall_minutes(); + state_filehandle = fopen(state_filename, "r"); if (state_filehandle == NULL) { @@ -318,12 +322,12 @@ void load_state(const char *const state_filename) { continue; i = 2 * sizeof(ot_hash); - if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &age, OT_TORRENT_TIMEOUT))) + if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &touched, now))) continue; i += consumed; if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &downcount, SIZE_MAX))) continue; - add_torrent_from_saved_state(infohash, (ot_time)age, (size_t)downcount); + add_torrent_from_saved_state(infohash, (ot_time)(now - touched), (size_t)downcount); } fclose(state_filehandle); -- cgit v1.3