diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/opentracker.c | 10 | ||||
| -rw-r--r-- | src/ot_fullscrape.c | 2 | ||||
| -rw-r--r-- | src/trackerlogic.c | 2 | ||||
| -rw-r--r-- | src/trackerlogic.h | 5 |
4 files changed, 14 insertions, 5 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); |
diff --git a/src/ot_fullscrape.c b/src/ot_fullscrape.c index 85be65d..ef39a17 100644 --- a/src/ot_fullscrape.c +++ b/src/ot_fullscrape.c | |||
| @@ -131,7 +131,7 @@ static void fullscrape_write_one( ot_tasktype mode, char **cursor, ot_torrent *t | |||
| 131 | case TASK_FULLSCRAPE_TRACKERSTATE: | 131 | case TASK_FULLSCRAPE_TRACKERSTATE: |
| 132 | hex_from_hash(r, *hash); | 132 | hex_from_hash(r, *hash); |
| 133 | r += 2 * sizeof(ot_hash); | 133 | r += 2 * sizeof(ot_hash); |
| 134 | fmt_append(&r, r_end, ":%zd:%zd\n", (ssize_t)time_since_minutes(torrent->peer_list6->base), down_count); | 134 | fmt_append(&r, r_end, ":%zd:%zd\n", (ssize_t)(time_wall_minutes() - time_since_minutes(torrent->peer_list6->base)), down_count); |
| 135 | break; | 135 | break; |
| 136 | } | 136 | } |
| 137 | *cursor = r; | 137 | *cursor = r; |
diff --git a/src/trackerlogic.c b/src/trackerlogic.c index 9fd6114..2313379 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c | |||
| @@ -45,7 +45,7 @@ void add_torrent_from_saved_state(ot_hash const hash, ot_time age, size_t down_c | |||
| 45 | ot_torrent *torrent; | 45 | ot_torrent *torrent; |
| 46 | ot_vector *torrents_list; | 46 | ot_vector *torrents_list; |
| 47 | 47 | ||
| 48 | if (age < 0 || age > OT_TORRENT_TIMEOUT) | 48 | if (age > OT_TORRENT_TIMEOUT) |
| 49 | return; | 49 | return; |
| 50 | 50 | ||
| 51 | torrents_list = mutex_bucket_lock_by_hash(hash); | 51 | torrents_list = mutex_bucket_lock_by_hash(hash); |
diff --git a/src/trackerlogic.h b/src/trackerlogic.h index d03d3b1..241b6a7 100644 --- a/src/trackerlogic.h +++ b/src/trackerlogic.h | |||
| @@ -114,6 +114,11 @@ static inline ot_time time_since_minutes(ot_time then) { | |||
| 114 | 114 | ||
| 115 | /* Has a deadline the tracker set on itself gone by? */ | 115 | /* Has a deadline the tracker set on itself gone by? */ |
| 116 | static inline int time_is_past(ot_time deadline) { return time_now_seconds() > deadline; } | 116 | static inline int time_is_past(ot_time deadline) { return time_now_seconds() > deadline; } |
| 117 | |||
| 118 | /* The wall clock, which the state file uses and nothing else does: it has to | ||
| 119 | survive a restart, and the clock above counts from boot. */ | ||
| 120 | static inline ot_time time_wall_minutes(void) { return time(NULL) / 60; } | ||
| 121 | |||
| 117 | /* Cleared from the interrupt handler and read by every worker */ | 122 | /* Cleared from the interrupt handler and read by every worker */ |
| 118 | extern _Atomic int g_opentracker_running; | 123 | extern _Atomic int g_opentracker_running; |
| 119 | 124 | ||
