summaryrefslogtreecommitdiff
path: root/src/trackerlogic.h
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-05 13:52:17 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-05 13:52:17 +0100
commit47293a4f116e04a88b0797bafad0c98b4393b744 (patch)
treeb71d19aa8637382a6d3b453614a6a52a2c1b3245 /src/trackerlogic.h
parent9a3a01643fc78bf544a1e6f5ca5c7529e2026b25 (diff)
Clamp every elapsed time span at zero, using a set of helper functions
Diffstat (limited to 'src/trackerlogic.h')
-rw-r--r--src/trackerlogic.h24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/trackerlogic.h b/src/trackerlogic.h
index 692b6af..c8d859c 100644
--- a/src/trackerlogic.h
+++ b/src/trackerlogic.h
@@ -61,10 +61,10 @@ typedef struct {
61#define OT_PEER_TIMEOUT 45 61#define OT_PEER_TIMEOUT 45
62 62
63/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs 63/* We maintain a list of 1024 pointers to sorted list of ot_torrent structs
64 Sort key is, of course, its hash */ 64 Sort key is, of course, its hash.
65/* Set from the Makefile, 8 to 16. More buckets means shorter vectors and a 65 Can be tweked from the Makefile, sensible values are between 8 in 16. More
66 cheaper insert, which only pays for a tracker carrying millions of 66 buckets means shorter vectors and a cheaper insert, which only pays for a
67 torrents; see DESIGN. */ 67 tracker carrying millions of torrents. Consult the DESIGN document. */
68#ifndef OT_BUCKET_COUNT_BITS 68#ifndef OT_BUCKET_COUNT_BITS
69#define OT_BUCKET_COUNT_BITS 10 69#define OT_BUCKET_COUNT_BITS 10
70#endif 70#endif
@@ -95,6 +95,22 @@ static inline ot_time time_now_minutes(void) { return time_now_seconds() / 60; }
95/* For the deadlines the tracker sets on itself, which read better as the 95/* For the deadlines the tracker sets on itself, which read better as the
96 span they allow than as an addition to the current second */ 96 span they allow than as an addition to the current second */
97static inline ot_time time_future_seconds(int span) { return time_now_seconds() + span; } 97static inline ot_time time_future_seconds(int span) { return time_now_seconds() + span; }
98
99/* How long ago a stamp was taken. */
100_Static_assert((ot_time)-1 < 0, "ot_time has to be signed for time_since_* to clamp");
101
102static inline ot_time time_since_seconds(ot_time then) {
103 ot_time now = time_now_seconds();
104 return now > then ? now - then : 0;
105}
106
107static inline ot_time time_since_minutes(ot_time then) {
108 ot_time now = time_now_minutes();
109 return now > then ? now - then : 0;
110}
111
112/* Has a deadline the tracker set on itself gone by? */
113static inline int time_is_past(ot_time deadline) { return time_now_seconds() > deadline; }
98/* Cleared from the interrupt handler and read by every worker */ 114/* Cleared from the interrupt handler and read by every worker */
99extern _Atomic int g_opentracker_running; 115extern _Atomic int g_opentracker_running;
100 116