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 --- proxy.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'proxy.c') diff --git a/proxy.c b/proxy.c index 63b4c4f..9486e75 100644 --- a/proxy.c +++ b/proxy.c @@ -19,6 +19,7 @@ /* Opentracker */ #include "ot_batch.h" +#include "ot_fdstate.h" #include "ot_ip.h" #include "ot_mutex.h" #include "ot_random.h" @@ -267,7 +268,7 @@ static void handle_reconnects(void) { continue; /* No socket for you */ io_fd(newfd); io_wantwrite(newfd); /* So we will be informed when it is connected */ - io_setcookie(newfd, g_connections + i); + fdstate_open(newfd, g_connections + i, 0); /* Prepare connection info block */ reset_info_block(g_connections + i); @@ -310,7 +311,7 @@ static void handle_accept(int64_t serversocket) { g_connections[i].port = port; g_connections[i].fd = newfd; - io_setcookie(newfd, g_connections + i); + fdstate_open(newfd, g_connections + i, 0); /* We expect the connecting side to begin with its tracker_id */ io_wantread(newfd); @@ -325,7 +326,7 @@ static void handle_read(int64_t peersocket) { int i; int64_t datalen; uint32_t tracker_id; - proxy_peer *peer = io_getcookie(peersocket); + proxy_peer *peer = fdstate_cookie(peersocket); if (!peer) { /* Can't happen ;) */ @@ -391,7 +392,7 @@ static void handle_read(int64_t peersocket) { /* Can write new sync data to the stream */ static void handle_write(int64_t peersocket) { - proxy_peer *peer = io_getcookie(peersocket); + proxy_peer *peer = fdstate_cookie(peersocket); if (!peer) { /* Can't happen ;) */ @@ -464,7 +465,7 @@ static void server_mainloop() { /* Loop over readable sockets */ while ((sock = io_canread()) != -1) { - const void *cookie = io_getcookie(sock); + const void *cookie = fdstate_cookie(sock); if ((uintptr_t)cookie == FLAG_SERVERSOCKET) handle_accept(sock); else @@ -493,7 +494,7 @@ static int64_t ot_try_bind(ot_ip6 ip, uint16_t port) { if (!io_fd(sock)) panic("io_fd"); - io_setcookie(sock, (void *)FLAG_SERVERSOCKET); + fdstate_open(sock, (void *)FLAG_SERVERSOCKET, 0); io_wantread(sock); return sock; } @@ -535,6 +536,8 @@ int main(int argc, char **argv) { int scanon = 1, lbound = 0, sbound = 0; random_init(); + if (fdstate_init() == -1) + panic("fdstate_init"); g_tracker_id = random_uint32(); while (scanon) { -- cgit v1.3