summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-27 21:32:24 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-27 21:32:24 +0100
commit6cbd21542cf7a751e6f0f38864e7e9eae8fa3b14 (patch)
treeb5416c7e6ad2ac30cfe51559f69c122ed493450d /ot_udp.c
parente1d7b7771e915a01b5f1dd12664a6ac7fb397dfb (diff)
Plug in the new per-thread stats counter, also make sure that the ot_clean sleep does not stall tracker exit
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 19a6c7c..14210c3 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -77,8 +77,8 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
77 return 0; 77 return 0;
78 byte_count = (size_t)result; 78 byte_count = (size_t)result;
79 79
80 stats_issue_event(EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip); 80 stats_issue_event(ws, EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip);
81 stats_issue_event(EVENT_READ, FLAG_UDP, byte_count); 81 stats_issue_event(ws, EVENT_READ, FLAG_UDP, byte_count);
82 82
83 /* Minimum udp tracker packet size, also catches error */ 83 /* Minimum udp tracker packet size, also catches error */
84 if (byte_count < 16) 84 if (byte_count < 16)
@@ -111,7 +111,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
111 outpacket[1] = inpacket[3]; 111 outpacket[1] = inpacket[3];
112 memcpy(&outpacket[2], &err_idmiss[0], s); 112 memcpy(&outpacket[2], &err_idmiss[0], s);
113 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport); 113 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport);
114 stats_issue_event(EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s); 114 stats_issue_event(ws, EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s);
115 return 1; 115 return 1;
116 } 116 }
117 } 117 }
@@ -128,7 +128,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
128 outpacket[3] = connid[1]; 128 outpacket[3] = connid[1];
129 129
130 socket_send(serversocket, ws->outbuf, 16, remoteip, remoteport); 130 socket_send(serversocket, ws->outbuf, 16, remoteip, remoteport);
131 stats_issue_event(EVENT_CONNECT, FLAG_UDP, 16); 131 stats_issue_event(ws, EVENT_CONNECT, FLAG_UDP, 16);
132 break; 132 break;
133 case 1: /* This is an announce action */ 133 case 1: /* This is an announce action */
134 /* Minimum udp announce packet size */ 134 /* Minimum udp announce packet size */
@@ -188,7 +188,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
188 } 188 }
189 189
190 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport); 190 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport);
191 stats_issue_event(EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size); 191 stats_issue_event(ws, EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size);
192 break; 192 break;
193 193
194 case 2: /* This is a scrape action */ 194 case 2: /* This is a scrape action */
@@ -199,7 +199,7 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
199 return_udp_scrape_for_torrent(*(ot_hash *)(((char *)inpacket) + 16 + 20 * scrape_count), ((char *)outpacket) + 8 + 12 * scrape_count); 199 return_udp_scrape_for_torrent(*(ot_hash *)(((char *)inpacket) + 16 + 20 * scrape_count), ((char *)outpacket) + 8 + 12 * scrape_count);
200 200
201 socket_send(serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport); 201 socket_send(serversocket, ws->outbuf, 8 + 12 * scrape_count, remoteip, remoteport);
202 stats_issue_event(EVENT_SCRAPE, FLAG_UDP, scrape_count); 202 stats_issue_event(ws, EVENT_SCRAPE, FLAG_UDP, scrape_count);
203 break; 203 break;
204 } 204 }
205 return 1; 205 return 1;
@@ -210,6 +210,7 @@ static void *udp_worker(void *args) {
210 struct ot_workstruct ws; 210 struct ot_workstruct ws;
211 memset(&ws, 0, sizeof(ws)); 211 memset(&ws, 0, sizeof(ws));
212 212
213 stats_counters_register(&ws);
213 ws.inbuf = malloc(G_INBUF_SIZE); 214 ws.inbuf = malloc(G_INBUF_SIZE);
214 ws.outbuf = malloc(G_OUTBUF_SIZE); 215 ws.outbuf = malloc(G_OUTBUF_SIZE);
215#ifdef _DEBUG_HTTPERROR 216#ifdef _DEBUG_HTTPERROR
@@ -219,6 +220,8 @@ static void *udp_worker(void *args) {
219 while (g_opentracker_running) 220 while (g_opentracker_running)
220 handle_udp6(sock, &ws); 221 handle_udp6(sock, &ws);
221 222
223 stats_counters_retire(&ws);
224
222 free(ws.inbuf); 225 free(ws.inbuf);
223 free(ws.outbuf); 226 free(ws.outbuf);
224#ifdef _DEBUG_HTTPERROR 227#ifdef _DEBUG_HTTPERROR