diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 22:56:34 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-25 22:56:34 +0100 |
| commit | 2e5b19945eb03fe4e3fa47562888401c7cbae71d (patch) | |
| tree | 45daefea693c483a943f3f205405b1019fe9e426 | |
| parent | 0e3a2189f65354962fc71af41f5aa52261a782e8 (diff) | |
| -rw-r--r-- | opentracker.c | 8 | ||||
| -rw-r--r-- | ot_http.c | 23 | ||||
| -rw-r--r-- | ot_timeout.h | 39 |
3 files changed, 47 insertions, 23 deletions
diff --git a/opentracker.c b/opentracker.c index 50fff29..60bdceb 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include "ot_random.h" | 35 | #include "ot_random.h" |
| 36 | #include "ot_scan.h" | 36 | #include "ot_scan.h" |
| 37 | #include "ot_socket.h" | 37 | #include "ot_socket.h" |
| 38 | #include "ot_timeout.h" | ||
| 38 | #include "ot_stats.h" | 39 | #include "ot_stats.h" |
| 39 | #include "ot_udp.h" | 40 | #include "ot_udp.h" |
| 40 | #include "trackerlogic.h" | 41 | #include "trackerlogic.h" |
| @@ -204,7 +205,6 @@ static void handle_accept(const int64_t serversocket) { | |||
| 204 | int64_t sock; | 205 | int64_t sock; |
| 205 | ot_ip6 ip; | 206 | ot_ip6 ip; |
| 206 | uint16_t port; | 207 | uint16_t port; |
| 207 | tai6464 t; | ||
| 208 | 208 | ||
| 209 | while ((sock = socket_accept(serversocket, ip, &port)) != -1) { | 209 | while ((sock = socket_accept(serversocket, ip, &port)) != -1) { |
| 210 | 210 | ||
| @@ -223,11 +223,7 @@ static void handle_accept(const int64_t serversocket) { | |||
| 223 | 223 | ||
| 224 | stats_issue_event(EVENT_ACCEPT, FLAG_TCP, (uintptr_t)ip); | 224 | stats_issue_event(EVENT_ACCEPT, FLAG_TCP, (uintptr_t)ip); |
| 225 | 225 | ||
| 226 | /* That breaks taia encapsulation. But there is no way to take system | 226 | timeout_in(sock, OT_CLIENT_TIMEOUT); |
| 227 | time this often in FreeBSD and libowfat does not allow to set unix time */ | ||
| 228 | taia_uint(&t, 0); /* Clear t */ | ||
| 229 | tai_unix(&(t.sec), (g_now_seconds + OT_CLIENT_TIMEOUT)); | ||
| 230 | io_timeout(sock, t); | ||
| 231 | } | 227 | } |
| 232 | io_eagain(serversocket); | 228 | io_eagain(serversocket); |
| 233 | } | 229 | } |
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "ot_mutex.h" | 26 | #include "ot_mutex.h" |
| 27 | #include "ot_scan.h" | 27 | #include "ot_scan.h" |
| 28 | #include "ot_stats.h" | 28 | #include "ot_stats.h" |
| 29 | #include "ot_timeout.h" | ||
| 29 | #include "scan_urlencoded_query.h" | 30 | #include "scan_urlencoded_query.h" |
| 30 | #include "trackerlogic.h" | 31 | #include "trackerlogic.h" |
| 31 | 32 | ||
| @@ -72,7 +73,6 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { | |||
| 72 | 73 | ||
| 73 | if (written_size < ws->reply_size) { | 74 | if (written_size < ws->reply_size) { |
| 74 | char *outbuf; | 75 | char *outbuf; |
| 75 | tai6464 t; | ||
| 76 | 76 | ||
| 77 | if (!(outbuf = malloc(ws->reply_size - written_size))) { | 77 | if (!(outbuf = malloc(ws->reply_size - written_size))) { |
| 78 | buf_reset(&cookie->request); | 78 | buf_reset(&cookie->request); |
| @@ -97,8 +97,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { | |||
| 97 | 97 | ||
| 98 | /* writeable short data sockets just have a tcp timeout */ | 98 | /* writeable short data sockets just have a tcp timeout */ |
| 99 | if (!ws->keep_alive) { | 99 | if (!ws->keep_alive) { |
| 100 | taia_uint(&t, 0); | 100 | timeout_never(sock); |
| 101 | io_timeout(sock, t); | ||
| 102 | io_dontwantread(sock); | 101 | io_dontwantread(sock); |
| 103 | } | 102 | } |
| 104 | io_wantwrite(sock); | 103 | io_wantwrite(sock); |
| @@ -139,7 +138,6 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t | |||
| 139 | char *header; | 138 | char *header; |
| 140 | const char *encoding = ""; | 139 | const char *encoding = ""; |
| 141 | size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); | 140 | size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); |
| 142 | tai6464 t; | ||
| 143 | 141 | ||
| 144 | /* No cookie? Bad socket. Leave. */ | 142 | /* No cookie? Bad socket. Leave. */ |
| 145 | if (!cookie) { | 143 | if (!cookie) { |
| @@ -209,10 +207,7 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t | |||
| 209 | cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; | 207 | cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; |
| 210 | } | 208 | } |
| 211 | 209 | ||
| 212 | /* writeable sockets timeout after 10 minutes */ | 210 | timeout_in(sock, OT_CLIENT_TIMEOUT_SEND); |
| 213 | taia_now(&t); | ||
| 214 | taia_addsec(&t, &t, OT_CLIENT_TIMEOUT_SEND); | ||
| 215 | io_timeout(sock, t); | ||
| 216 | io_wantwrite(sock); | 211 | io_wantwrite(sock); |
| 217 | return 0; | 212 | return 0; |
| 218 | } | 213 | } |
| @@ -291,7 +286,6 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 291 | } | 286 | } |
| 292 | 287 | ||
| 293 | if (mode == TASK_STATS_TPB) { | 288 | if (mode == TASK_STATS_TPB) { |
| 294 | tai6464 t; | ||
| 295 | #ifdef WANT_COMPRESSION_GZIP | 289 | #ifdef WANT_COMPRESSION_GZIP |
| 296 | ws->request[ws->request_size - 1] = 0; | 290 | ws->request[ws->request_size - 1] = 0; |
| 297 | #ifndef WANT_COMPRESSION_GZIP_ALWAYS | 291 | #ifndef WANT_COMPRESSION_GZIP_ALWAYS |
| @@ -307,8 +301,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 307 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; | 301 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; |
| 308 | 302 | ||
| 309 | /* Clients waiting for us should not easily timeout */ | 303 | /* Clients waiting for us should not easily timeout */ |
| 310 | taia_uint(&t, 0); | 304 | timeout_never(sock); |
| 311 | io_timeout(sock, t); | ||
| 312 | fullscrape_deliver(sock, format); | 305 | fullscrape_deliver(sock, format); |
| 313 | io_dontwantread(sock); | 306 | io_dontwantread(sock); |
| 314 | return ws->reply_size = -2; | 307 | return ws->reply_size = -2; |
| @@ -317,13 +310,11 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c | |||
| 317 | 310 | ||
| 318 | /* default format for now */ | 311 | /* default format for now */ |
| 319 | if ((mode & TASK_CLASS_MASK) == TASK_STATS) { | 312 | if ((mode & TASK_CLASS_MASK) == TASK_STATS) { |
| 320 | tai6464 t; | ||
| 321 | 313 | ||
| 322 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | 314 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; |
| 323 | 315 | ||
| 324 | /* Complex stats also include expensive memory debugging tools */ | 316 | /* Complex stats also include expensive memory debugging tools */ |
| 325 | taia_uint(&t, 0); | 317 | timeout_never(sock); |
| 326 | io_timeout(sock, t); | ||
| 327 | stats_deliver(sock, mode); | 318 | stats_deliver(sock, mode); |
| 328 | return ws->reply_size = -2; | 319 | return ws->reply_size = -2; |
| 329 | } | 320 | } |
| @@ -345,7 +336,6 @@ typedef struct { | |||
| 345 | static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct *ws) { | 336 | static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct *ws) { |
| 346 | struct http_data *cookie = io_getcookie(sock); | 337 | struct http_data *cookie = io_getcookie(sock); |
| 347 | int format = 0; | 338 | int format = 0; |
| 348 | tai6464 t; | ||
| 349 | 339 | ||
| 350 | #ifdef WANT_MODEST_FULLSCRAPES | 340 | #ifdef WANT_MODEST_FULLSCRAPES |
| 351 | { | 341 | { |
| @@ -404,8 +394,7 @@ static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct * | |||
| 404 | /* Pass this task to the worker thread */ | 394 | /* Pass this task to the worker thread */ |
| 405 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; | 395 | cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; |
| 406 | /* Clients waiting for us should not easily timeout */ | 396 | /* Clients waiting for us should not easily timeout */ |
| 407 | taia_uint(&t, 0); | 397 | timeout_never(sock); |
| 408 | io_timeout(sock, t); | ||
| 409 | fullscrape_deliver(sock, format); | 398 | fullscrape_deliver(sock, format); |
| 410 | io_dontwantread(sock); | 399 | io_dontwantread(sock); |
| 411 | return ws->reply_size = -2; | 400 | return ws->reply_size = -2; |
diff --git a/ot_timeout.h b/ot_timeout.h new file mode 100644 index 0000000..1027c2e --- /dev/null +++ b/ot_timeout.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /* This software was written by Dirk Engling <erdgeist@erdgeist.org> | ||
| 2 | It is considered beerware. Prost. Skol. Cheers or whatever. | ||
| 3 | |||
| 4 | $id$ */ | ||
| 5 | |||
| 6 | #ifndef OT_TIMEOUT_H__ | ||
| 7 | #define OT_TIMEOUT_H__ | ||
| 8 | |||
| 9 | #include <stdint.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | /* Libowfat */ | ||
| 13 | #include "io.h" | ||
| 14 | |||
| 15 | #include "trackerlogic.h" | ||
| 16 | |||
| 17 | /* io_timeout wants an absolute TAI64 deadline and io_timeouted skips any | ||
| 18 | socket whose deadline is zero, so that is how a socket is told to wait | ||
| 19 | indefinitely. | ||
| 20 | |||
| 21 | The deadline is taken from the cached clock rather than from | ||
| 22 | gettimeofday, which is too expensive to call at this rate on FreeBSD. */ | ||
| 23 | |||
| 24 | static inline void timeout_never(int64_t sock) { | ||
| 25 | tai6464 t; | ||
| 26 | |||
| 27 | memset(&t, 0, sizeof(t)); | ||
| 28 | io_timeout(sock, t); | ||
| 29 | } | ||
| 30 | |||
| 31 | static inline void timeout_in(int64_t sock, unsigned int seconds) { | ||
| 32 | tai6464 t; | ||
| 33 | |||
| 34 | memset(&t, 0, sizeof(t)); | ||
| 35 | tai_unix(&t.sec, g_now_seconds + seconds); | ||
| 36 | io_timeout(sock, t); | ||
| 37 | } | ||
| 38 | |||
| 39 | #endif | ||
