feat: add non-blocking NTCP2 sends and Firefox settings sync
check / check (macos-latest) (push) Failing after 26s
check / check (ubuntu-latest) (push) Failing after 27s
check / check (windows-latest) (push) Failing after 30s

- NTCP2: queue outbound data frames and flush them without blocking (send_blocks_nb, send_i2np_nb, flush_nonblocking)
- NTCP2: bound write_all with a deadline and set TCP keepalive and user timeout on peer sockets
- Firefox extension 0.1.3: save settings as a patch, keep unsaved form fields from being overwritten on refresh, add timeouts to router API calls, and honor the interceptTorrents toggle in the content script
This commit is contained in:
nandi committed 2026-11-28 18:39:32 -08:00
1 parent 82aaa9f11e
commit 9aa15f9ae8
18 files changed
+1323 -239

No files matched your search

+26 -1
View File
@@ -10,6 +10,7 @@
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <signal.h>
#include <stdint.h>
@@ -30,6 +31,10 @@
#define MSG_NOSIGNAL 0
#endif
#ifndef MSG_DONTWAIT
#define MSG_DONTWAIT 0
#endif
static char g_net_last_error[256] = {0};
static void net_set_error(const char *msg) {
@@ -329,7 +334,7 @@ int32_t moon_i2p_net_tcp_send(
moonbit_bytes_t data,
int32_t offset,
int32_t len) {
ssize_t n = send((int)fd, data + offset, (size_t)len, MSG_NOSIGNAL);
ssize_t n = send((int)fd, data + offset, (size_t)len, MSG_NOSIGNAL | MSG_DONTWAIT);
if (n < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return -2;
@@ -340,6 +345,26 @@ int32_t moon_i2p_net_tcp_send(
return (int32_t)n;
}
MOONBIT_FFI_EXPORT
int32_t moon_i2p_net_tcp_set_peer_timeouts(int32_t fd, int32_t user_timeout_ms) {
(void)user_timeout_ms;
int keepalive = 1;
if (setsockopt((int)fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) < 0) {
net_set_error(strerror(errno));
return -1;
}
#ifdef TCP_USER_TIMEOUT
if (user_timeout_ms > 0) {
unsigned int uto = (unsigned int)user_timeout_ms;
if (setsockopt((int)fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &uto, sizeof(uto)) < 0) {
net_set_error(strerror(errno));
return -1;
}
}
#endif
return 0;
}
MOONBIT_FFI_EXPORT
int32_t moon_i2p_net_tcp_poll_writable(int32_t fd, int32_t timeout_ms) {
struct pollfd pfd;