From 5e86efde052760a53ca92ddd411db095fcf4a970 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 16:37:55 +0100 Subject: Use new fdstate subsystem to store per fd cookie and timeout --- ot_http.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 331a457..6bf343c 100644 --- a/ot_http.c +++ b/ot_http.c @@ -25,8 +25,8 @@ #include "ot_ip.h" #include "ot_mutex.h" #include "ot_scan.h" +#include "ot_fdstate.h" #include "ot_stats.h" -#include "ot_timeout.h" #include "scan_urlencoded_query.h" #include "trackerlogic.h" @@ -39,7 +39,7 @@ ssize_t g_stats_path_len; enum { SUCCESS_HTTP_HEADER_LENGTH = 80, SUCCESS_HTTP_SIZE_OFF = 17 }; static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); ssize_t written_size; if (!cookie) { @@ -97,7 +97,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { /* writeable short data sockets just have a tcp timeout */ if (!ws->keep_alive) { - timeout_never(sock); + fdstate_set_expiry(sock, 0); io_dontwantread(sock); } io_wantwrite(sock); @@ -134,7 +134,7 @@ ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) } ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t iovec_entries, struct iovec *iovector, int is_partial) { - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); char *header; const char *encoding = ""; size_t header_size, size = iovec_length(&iovec_entries, (const struct iovec **)&iovector); @@ -207,7 +207,7 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t cookie->flag &= ~STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER; } - timeout_in(sock, OT_CLIENT_TIMEOUT_SEND); + fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT_SEND); io_wantwrite(sock); return 0; } @@ -243,7 +243,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c {"url", TASK_FULLSCRAPE_TPB_URLENCODED}, {"txt", TASK_FULLSCRAPE_TPB_ASCII}, {"txtp", TASK_FULLSCRAPE_TPB_ASCII_PLUS}, {NULL, -3}}; - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); int mode = TASK_STATS_PEERS, scanon = 1, format = 0; /* A socket without one is a dead socket, which is what http_sendiovecdata @@ -301,7 +301,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; /* Clients waiting for us should not easily timeout */ - timeout_never(sock); + fdstate_set_expiry(sock, 0); fullscrape_deliver(sock, format); io_dontwantread(sock); return ws->reply_size = -2; @@ -314,7 +314,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; /* Complex stats also include expensive memory debugging tools */ - timeout_never(sock); + fdstate_set_expiry(sock, 0); stats_deliver(sock, mode); return ws->reply_size = -2; } @@ -334,7 +334,7 @@ typedef struct { #ifdef WANT_FULLSCRAPE static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct *ws) { - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); int format = 0; #ifdef WANT_MODEST_FULLSCRAPES @@ -394,7 +394,7 @@ static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct * /* Pass this task to the worker thread */ cookie->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK | STRUCT_HTTP_FLAG_CHUNKED; /* Clients waiting for us should not easily timeout */ - timeout_never(sock); + fdstate_set_expiry(sock, 0); fullscrape_deliver(sock, format); io_dontwantread(sock); return ws->reply_size = -2; @@ -486,7 +486,7 @@ static ssize_t http_handle_announce(const int64_t sock, struct ot_workstruct unsigned short port = 0; char *write_ptr; ssize_t len; - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); /* This is to hack around stupid clients that send "announce ?info_hash" */ if (read_ptr[-1] != '?') { @@ -663,7 +663,7 @@ ssize_t http_handle_request(const int64_t sock, struct ot_workstruct *ws) { char *read_ptr = ws->request, *write_ptr; #ifdef WANT_FULLLOG_NETWORKS - struct http_data *cookie = io_getcookie(sock); + struct http_data *cookie = fdstate_cookie(sock); if (loglist_check_address(cookie->ip)) { ot_log *log = malloc(sizeof(ot_log)); if (log) { -- cgit v1.3