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

+39 -16
View File
@@ -166,7 +166,7 @@ fn Router::send_i2np_to_peer(
while idx >= 0 {
if self.peers[idx].hash == target_hash {
let ok = try {
self.peers[idx].conn.send_i2np(mid, exp_sec, payload)
self.peers[idx].conn.send_i2np_nb(mid, exp_sec, payload)
true
} catch {
_ => false
@@ -177,6 +177,9 @@ fn Router::send_i2np_to_peer(
}
self.peers[idx].conn.close()
let _ = self.peers.remove(idx)
if self.public_mode {
self.mark_peer_failed(target_hash, 60000UL)
}
}
idx -= 1
}
@@ -246,7 +249,7 @@ fn Router::flush_pending_sends_for(
let ps = self.pending_sends[i]
if ps.target_hash == target_hash {
let ok = try {
peer.conn.send_i2np(ps.msg_id, ps.expiration_sec, ps.payload)
peer.conn.send_i2np_nb(ps.msg_id, ps.expiration_sec, ps.payload)
true
} catch {
_ => false
@@ -456,33 +459,53 @@ fn Router::step_ntcp2_peers(self : Router) -> Bool {
)
}
// 5. Non-blocking read & dispatch on all active NTCP2 peer sessions
// 5. Flush non-blocking outbound frames & read incoming frames on all active NTCP2 peers
let mut pi = 0
while pi < self.peers.length() {
let peer = self.peers[pi]
let mut alive = true
for _frame = 0; _frame < 32; _frame = _frame + 1 {
let recv_opt = peer.conn.try_recv_blocks() catch {
_ => {
alive = false
None
}
let flushed = peer.conn.flush_nonblocking() catch {
_ => {
alive = false
false
}
match recv_opt {
Some(blocks) => {
did_work = true
peer.last_active_ms = now_ms
if self.handle_peer_blocks(peer.hash, blocks) {
}
if flushed {
did_work = true
peer.last_active_ms = now_ms
}
if alive {
for _frame = 0; _frame < 32; _frame = _frame + 1 {
let recv_opt = peer.conn.try_recv_blocks() catch {
_ => {
alive = false
break
None
}
}
None => break
match recv_opt {
Some(blocks) => {
did_work = true
peer.last_active_ms = now_ms
if self.handle_peer_blocks(peer.hash, blocks) {
alive = false
break
}
}
None => break
}
}
}
if !alive || now_ms > peer.last_active_ms + 180000UL {
peer.conn.close()
let _ = self.peers.remove(pi)
if self.public_mode && !alive {
self.mark_peer_failed(peer.hash, 60000UL)
if self.debug {
println(
"[debug] NTCP2 peer closed/stalled: \{peer.hash.to_b32_address()}",
)
}
}
} else {
pi += 1
}