diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-27 20:29:22 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-27 20:29:22 +0100 |
| commit | 166cd9b591464417600035e88993ca4d7e8cd44b (patch) | |
| tree | 375473c03539c223d64abf0322b5c194011984a9 /trackerlogic.h | |
| parent | 6b0069ba013236a74be22b30229162b6bfb917b2 (diff) | |
Prepare having each thread keep their own stats to avoid data races
Diffstat (limited to 'trackerlogic.h')
| -rw-r--r-- | trackerlogic.h | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/trackerlogic.h b/trackerlogic.h index 6af5d6a..ad6c911 100644 --- a/trackerlogic.h +++ b/trackerlogic.h | |||
| @@ -68,10 +68,6 @@ typedef struct { | |||
| 68 | on startup */ | 68 | on startup */ |
| 69 | #define RANDOMTORRENTS (1024 * 1024 * 1) | 69 | #define RANDOMTORRENTS (1024 * 1024 * 1) |
| 70 | 70 | ||
| 71 | /* From opentracker.c */ | ||
| 72 | /* The kernel already keeps a coarse wall clock, updated every tick and | ||
| 73 | published where reading it costs no system call. That is what opentracker | ||
| 74 | used to keep a thread for, at five second resolution. */ | ||
| 75 | #if defined(CLOCK_REALTIME_COARSE) | 71 | #if defined(CLOCK_REALTIME_COARSE) |
| 76 | #define OT_CLOCK_CHEAP CLOCK_REALTIME_COARSE /* Linux */ | 72 | #define OT_CLOCK_CHEAP CLOCK_REALTIME_COARSE /* Linux */ |
| 77 | #elif defined(CLOCK_REALTIME_FAST) | 73 | #elif defined(CLOCK_REALTIME_FAST) |
| @@ -152,8 +148,56 @@ struct ot_peerlist { | |||
| 152 | }; | 148 | }; |
| 153 | #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) | 149 | #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) |
| 154 | 150 | ||
| 151 | /* The http replies the tracker counts when it has to refuse a request. */ | ||
| 152 | enum { | ||
| 153 | CODE_HTTPERROR_302, | ||
| 154 | CODE_HTTPERROR_400, | ||
| 155 | CODE_HTTPERROR_400_PARAM, | ||
| 156 | CODE_HTTPERROR_400_COMPACT, | ||
| 157 | CODE_HTTPERROR_402_NOTMODEST, | ||
| 158 | CODE_HTTPERROR_402_PAYMENT_REQUIRED, | ||
| 159 | CODE_HTTPERROR_403_IP, | ||
| 160 | CODE_HTTPERROR_404, | ||
| 161 | CODE_HTTPERROR_500, | ||
| 162 | |||
| 163 | CODE_HTTPERROR_COUNT | ||
| 164 | }; | ||
| 165 | |||
| 166 | /* One statistic. Used when workers report stats to their workstruct */ | ||
| 167 | typedef _Atomic unsigned long long ot_counter; | ||
| 168 | |||
| 169 | /* What each thread counts for itself. The two runs at the end are indexed by | ||
| 170 | the http error code and by the age in minutes of a renewed peer */ | ||
| 171 | typedef enum { | ||
| 172 | OT_COUNTER_TCP_CONNECTIONS, | ||
| 173 | OT_COUNTER_UDP_CONNECTIONS, | ||
| 174 | OT_COUNTER_TCP_ANNOUNCES, | ||
| 175 | OT_COUNTER_UDP_ANNOUNCES, | ||
| 176 | OT_COUNTER_TCP_SCRAPES, | ||
| 177 | OT_COUNTER_UDP_SCRAPES, | ||
| 178 | OT_COUNTER_TCP_CONNECTS, | ||
| 179 | OT_COUNTER_UDP_CONNECTS, | ||
| 180 | OT_COUNTER_UDP_CONNID_MISSMATCH, | ||
| 181 | OT_COUNTER_COMPLETED, | ||
| 182 | OT_COUNTER_FULLSCRAPES, | ||
| 183 | OT_COUNTER_FULLSCRAPE_REQUESTS, | ||
| 184 | OT_COUNTER_FULLSCRAPE_BYTES, | ||
| 185 | OT_COUNTER_SYNCS, | ||
| 186 | OT_COUNTER_STALLS, | ||
| 187 | |||
| 188 | OT_COUNTER_FAILED, /* CODE_HTTPERROR_COUNT of them */ | ||
| 189 | OT_COUNTER_RENEWED = OT_COUNTER_FAILED + CODE_HTTPERROR_COUNT, /* OT_PEER_TIMEOUT of them */ | ||
| 190 | |||
| 191 | OT_COUNTER_COUNT = OT_COUNTER_RENEWED + OT_PEER_TIMEOUT | ||
| 192 | } ot_counter_index; | ||
| 193 | |||
| 155 | struct ot_workstruct { | 194 | struct ot_workstruct { |
| 156 | /* Thread specific, static */ | 195 | /* Thread specific, static */ |
| 196 | |||
| 197 | /* This thread's own statistics, and the link ot_stats keeps them on */ | ||
| 198 | ot_counter counters[OT_COUNTER_COUNT]; | ||
| 199 | struct ot_workstruct *counters_next; | ||
| 200 | |||
| 157 | char *inbuf; | 201 | char *inbuf; |
| 158 | #define G_INBUF_SIZE 8192 | 202 | #define G_INBUF_SIZE 8192 |
| 159 | char *outbuf; | 203 | char *outbuf; |
