diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-06 14:24:04 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-06 14:24:04 +0100 |
| commit | 355c8ae57d582974f4f6a4ba42f635f2253b84a7 (patch) | |
| tree | 81536ae109b37242217c818ae3a6b2c193fb8ff3 /src/opentracker.c | |
| parent | 367ff65242ca88fd6435d04a577a43cec5de92fe (diff) | |
Add a wall clock helper so that statedumps can be written and re-read
Diffstat (limited to 'src/opentracker.c')
| -rw-r--r-- | src/opentracker.c | 10 |
1 files changed, 7 insertions, 3 deletions
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) { | |||
| 300 | FILE *state_filehandle; | 300 | FILE *state_filehandle; |
| 301 | char inbuf[512]; | 301 | char inbuf[512]; |
| 302 | ot_hash infohash; | 302 | ot_hash infohash; |
| 303 | uint64_t age, downcount; | 303 | uint64_t touched, downcount; |
| 304 | int consumed; | 304 | int consumed; |
| 305 | 305 | ||
| 306 | /* The file records the minute a torrent was last touched, by the clock that | ||
| 307 | survives a restart */ | ||
| 308 | uint64_t now = (uint64_t)time_wall_minutes(); | ||
| 309 | |||
| 306 | state_filehandle = fopen(state_filename, "r"); | 310 | state_filehandle = fopen(state_filename, "r"); |
| 307 | 311 | ||
| 308 | if (state_filehandle == NULL) { | 312 | if (state_filehandle == NULL) { |
| @@ -318,12 +322,12 @@ void load_state(const char *const state_filename) { | |||
| 318 | continue; | 322 | continue; |
| 319 | i = 2 * sizeof(ot_hash); | 323 | i = 2 * sizeof(ot_hash); |
| 320 | 324 | ||
| 321 | if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &age, OT_TORRENT_TIMEOUT))) | 325 | if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &touched, now))) |
| 322 | continue; | 326 | continue; |
| 323 | i += consumed; | 327 | i += consumed; |
| 324 | if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &downcount, SIZE_MAX))) | 328 | if (inbuf[i++] != ':' || !(consumed = scan_uint(inbuf + i, &downcount, SIZE_MAX))) |
| 325 | continue; | 329 | continue; |
| 326 | add_torrent_from_saved_state(infohash, (ot_time)age, (size_t)downcount); | 330 | add_torrent_from_saved_state(infohash, (ot_time)(now - touched), (size_t)downcount); |
| 327 | } | 331 | } |
| 328 | 332 | ||
| 329 | fclose(state_filehandle); | 333 | fclose(state_filehandle); |
