summaryrefslogtreecommitdiff
path: root/trackerlogic.h
diff options
context:
space:
mode:
Diffstat (limited to 'trackerlogic.h')
-rw-r--r--trackerlogic.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/trackerlogic.h b/trackerlogic.h
index 63abf78..6af5d6a 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -6,6 +6,7 @@
6#ifndef OT_TRACKERLOGIC_H__ 6#ifndef OT_TRACKERLOGIC_H__
7#define OT_TRACKERLOGIC_H__ 7#define OT_TRACKERLOGIC_H__
8 8
9#include <stdatomic.h>
9#include <stdint.h> 10#include <stdint.h>
10#include <stdlib.h> 11#include <stdlib.h>
11#include <sys/time.h> 12#include <sys/time.h>
@@ -68,9 +69,31 @@ typedef struct {
68#define RANDOMTORRENTS (1024 * 1024 * 1) 69#define RANDOMTORRENTS (1024 * 1024 * 1)
69 70
70/* From opentracker.c */ 71/* From opentracker.c */
71extern time_t g_now_seconds; 72/* The kernel already keeps a coarse wall clock, updated every tick and
72extern volatile int g_opentracker_running; 73 published where reading it costs no system call. That is what opentracker
73#define g_now_minutes (g_now_seconds / 60) 74 used to keep a thread for, at five second resolution. */
75#if defined(CLOCK_REALTIME_COARSE)
76#define OT_CLOCK_CHEAP CLOCK_REALTIME_COARSE /* Linux */
77#elif defined(CLOCK_REALTIME_FAST)
78#define OT_CLOCK_CHEAP CLOCK_REALTIME_FAST /* the BSDs */
79#else
80#define OT_CLOCK_CHEAP CLOCK_REALTIME /* macOS and whatever else */
81#endif
82
83static inline ot_time time_now_seconds(void) {
84 struct timespec now;
85 clock_gettime(OT_CLOCK_CHEAP, &now);
86 return (ot_time)now.tv_sec;
87}
88
89static inline ot_time time_now_minutes(void) { return time_now_seconds() / 60; }
90
91/* For the deadlines the tracker sets on itself, which read better as the
92 span they allow than as an addition to the current second */
93static inline ot_time time_future_seconds(int span) { return time_now_seconds() + span; }
94/* Cleared from the interrupt handler and read by every worker */
95extern _Atomic int g_opentracker_running;
96
74 97
75extern uint32_t g_tracker_id; 98extern uint32_t g_tracker_id;
76typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG; 99typedef enum { FLAG_TCP, FLAG_UDP, FLAG_MCA, FLAG_SELFPIPE } PROTO_FLAG;