From 2d6b6d4da1d9732b2b02989a4374d356ff840d1b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 20:03:22 +0100 Subject: Replace libowfat's event waiter with our own abstraction It's with a heavy heart that I remove libowfat as my event library from opentracker. libowfat is what taught opentracker to walk and then fly. The tracker was literally standing on the shoulder of giants when I started writing it in 2006. For its time, the event abstraction was unparalleled and it has held up for many years, and it served the bittorrent community greatly. https://erdgeist.org/gitweb/opentracker/commit/?id=ad472597c569568bad0526d116b601dfcb36638c Unfortunately, it is very likely that libowfat will not be maintained anymore for the foreseeable future, it is already not easy to get its source from upstream and opentracker started receiving bug reports that I can not reasonably answer or patch. Before the project gets more dependent on the limitations of libowfat's current state, I need to teach opentracker to stand on its own feet and fly by itself. I've learned a great deal in the process and have even more respect now for what libowfat pioneered. The path for opentracker is cleared now. Ground work has already been laid in the migration process to support multi threaded http processing while keeping the aggressive reduction of syscalls alive that made the libowfat+opentracker combo so scalable. Here be some dragons, though: Even though there is a unit test suite now, the event loop's rewrite has not been battle tested yet. So you might want to hold up for a bit before jumping on the solo band wagon. What awaits at the end will be a long overdue v1.0, which will be named in honour of Felix. --- ot_http.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index 3c135cb..5e10d59 100644 --- a/ot_http.c +++ b/ot_http.c @@ -14,9 +14,6 @@ #include #include -/* Libowfat */ -#include "io.h" - /* Opentracker */ #include "ot_accesslist.h" #include "ot_fullscrape.h" @@ -25,6 +22,7 @@ #include "ot_ip.h" #include "ot_mutex.h" #include "ot_scan.h" +#include "ot_event.h" #include "ot_fdstate.h" #include "ot_stats.h" #include "ot_urlencoded.h" @@ -43,7 +41,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { ssize_t written_size; if (!cookie) { - io_close(sock); + event_del((int)sock), close((int)sock); return; } @@ -67,7 +65,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { if ((written_size < 0) || ((written_size == ws->reply_size) && !ws->keep_alive)) { buf_reset(&cookie->request); free(cookie); - io_close(sock); + event_del((int)sock), close((int)sock); return; } @@ -77,7 +75,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { if (!(outbuf = malloc(ws->reply_size - written_size))) { buf_reset(&cookie->request); free(cookie); - io_close(sock); + event_del((int)sock), close((int)sock); return; } @@ -88,7 +86,7 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { free(outbuf); buf_reset(&cookie->request); free(cookie); - io_close(sock); + event_del((int)sock), close((int)sock); return; } } @@ -98,9 +96,9 @@ 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) { fdstate_set_expiry(sock, 0); - io_dontwantread(sock); + http_interest_drop(sock, cookie, EVENT_IN); } - io_wantwrite(sock); + http_interest_add(sock, cookie, EVENT_OUT); } } @@ -113,6 +111,21 @@ static void http_senddata(const int64_t sock, struct ot_workstruct *ws) { #define HTTPERROR_403_IP return http_issue_error(sock, ws, CODE_HTTPERROR_403_IP) #define HTTPERROR_404 return http_issue_error(sock, ws, CODE_HTTPERROR_404) #define HTTPERROR_500 return http_issue_error(sock, ws, CODE_HTTPERROR_500) +static void http_interest(const int64_t sock, struct http_data *cookie, int what) { + if (cookie->interest == what) + return; + cookie->interest = what; + event_modify((int)sock, what, fdstate_generation((int)sock)); +} + +void http_interest_add(const int64_t sock, struct http_data *cookie, int what) { + http_interest(sock, cookie, cookie->interest | what); +} + +void http_interest_drop(const int64_t sock, struct http_data *cookie, int what) { + http_interest(sock, cookie, cookie->interest & ~what); +} + ssize_t http_issue_error(const int64_t sock, struct ot_workstruct *ws, int code) { const char *error_code[] = {"302 Found", "400 Invalid Request", "400 Invalid Request", "400 Invalid Request", "402 Payment Required", "403 Not Modest", "403 Access Denied", "404 Not Found", "500 Internal Server Error"}; @@ -157,7 +170,7 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t /* If we came here, wait for the answer is over */ if (cookie->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK) { - io_dontwantread(sock); + http_interest_drop(sock, cookie, EVENT_IN); cookie->flag &= ~STRUCT_HTTP_FLAG_WAITINGFORTASK; } @@ -208,7 +221,7 @@ ssize_t http_sendiovecdata(const int64_t sock, struct ot_workstruct *ws, size_t } fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT_SEND); - io_wantwrite(sock); + http_interest_add(sock, cookie, EVENT_OUT); return 0; } @@ -303,7 +316,7 @@ static ssize_t http_handle_stats(const int64_t sock, struct ot_workstruct *ws, c /* Clients waiting for us should not easily timeout */ fdstate_set_expiry(sock, 0); fullscrape_deliver(sock, format); - io_dontwantread(sock); + http_interest_drop(sock, cookie, EVENT_IN); return ws->reply_size = -2; } #endif @@ -396,7 +409,7 @@ static ssize_t http_handle_fullscrape(const int64_t sock, struct ot_workstruct * /* Clients waiting for us should not easily timeout */ fdstate_set_expiry(sock, 0); fullscrape_deliver(sock, format); - io_dontwantread(sock); + http_interest_drop(sock, cookie, EVENT_IN); return ws->reply_size = -2; } #endif -- cgit v1.3