From 166cd9b591464417600035e88993ca4d7e8cd44b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 20:29:22 +0100 Subject: Prepare having each thread keep their own stats to avoid data races --- trackerlogic.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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 { on startup */ #define RANDOMTORRENTS (1024 * 1024 * 1) -/* From opentracker.c */ -/* The kernel already keeps a coarse wall clock, updated every tick and - published where reading it costs no system call. That is what opentracker - used to keep a thread for, at five second resolution. */ #if defined(CLOCK_REALTIME_COARSE) #define OT_CLOCK_CHEAP CLOCK_REALTIME_COARSE /* Linux */ #elif defined(CLOCK_REALTIME_FAST) @@ -152,8 +148,56 @@ struct ot_peerlist { }; #define OT_PEERLIST_HASBUCKETS(peer_list) ((peer_list)->peers.size > (peer_list)->peers.space) +/* The http replies the tracker counts when it has to refuse a request. */ +enum { + CODE_HTTPERROR_302, + CODE_HTTPERROR_400, + CODE_HTTPERROR_400_PARAM, + CODE_HTTPERROR_400_COMPACT, + CODE_HTTPERROR_402_NOTMODEST, + CODE_HTTPERROR_402_PAYMENT_REQUIRED, + CODE_HTTPERROR_403_IP, + CODE_HTTPERROR_404, + CODE_HTTPERROR_500, + + CODE_HTTPERROR_COUNT +}; + +/* One statistic. Used when workers report stats to their workstruct */ +typedef _Atomic unsigned long long ot_counter; + +/* What each thread counts for itself. The two runs at the end are indexed by + the http error code and by the age in minutes of a renewed peer */ +typedef enum { + OT_COUNTER_TCP_CONNECTIONS, + OT_COUNTER_UDP_CONNECTIONS, + OT_COUNTER_TCP_ANNOUNCES, + OT_COUNTER_UDP_ANNOUNCES, + OT_COUNTER_TCP_SCRAPES, + OT_COUNTER_UDP_SCRAPES, + OT_COUNTER_TCP_CONNECTS, + OT_COUNTER_UDP_CONNECTS, + OT_COUNTER_UDP_CONNID_MISSMATCH, + OT_COUNTER_COMPLETED, + OT_COUNTER_FULLSCRAPES, + OT_COUNTER_FULLSCRAPE_REQUESTS, + OT_COUNTER_FULLSCRAPE_BYTES, + OT_COUNTER_SYNCS, + OT_COUNTER_STALLS, + + OT_COUNTER_FAILED, /* CODE_HTTPERROR_COUNT of them */ + OT_COUNTER_RENEWED = OT_COUNTER_FAILED + CODE_HTTPERROR_COUNT, /* OT_PEER_TIMEOUT of them */ + + OT_COUNTER_COUNT = OT_COUNTER_RENEWED + OT_PEER_TIMEOUT +} ot_counter_index; + struct ot_workstruct { /* Thread specific, static */ + + /* This thread's own statistics, and the link ot_stats keeps them on */ + ot_counter counters[OT_COUNTER_COUNT]; + struct ot_workstruct *counters_next; + char *inbuf; #define G_INBUF_SIZE 8192 char *outbuf; -- cgit v1.3