feat: add HTTP-over-I2P proxy to router daemon
check / check (macos-latest) (push) Failing after 27s
check / check (ubuntu-latest) (push) Failing after 28s
check / check (windows-latest) (push) Failing after 26s

- Add --http-proxy/--proxy [host:port] (default 127.0.0.1:4444) to route .i2p and .b32.i2p HTTP requests over I2P streams
- Block clearnet hosts with 403 and reject CONNECT and https:// with 501
- Support ?i2paddresshelper= jump links that register host aliases
- Add `just proxy` target and -h/--help usage output
- Expire idle ratchet sessions after 300s and add RatchetSessionManager::drop_session for fresh NewSession handshakes
- Add NetDb::remove_lease_set2 and bound the outbound pending queue to 64 entries
This commit is contained in:
nandi committed 2026-11-28 01:46:36 -08:00
1 parent 54cfb2faa9
commit 14eae00f5c
15 files changed
+1941 -41

No files matched your search

+42 -1
View File
@@ -295,6 +295,7 @@ pub struct RatchetPeerSession {
mut local_next_priv : Bytes?
mut local_next_pub : Bytes?
mut remote_next_pub : Bytes?
mut last_used_sec : UInt32
}
///|
@@ -433,6 +434,7 @@ pub fn encrypt_new_session_reply(
local_next_priv: None,
local_next_pub: None,
remote_next_pub: None,
last_used_sec: 0U,
}
sess.refill_recv_window()
(w.to_bytes(), sess)
@@ -505,6 +507,7 @@ pub fn decrypt_new_session_reply(
local_next_priv: None,
local_next_pub: None,
remote_next_pub: None,
last_used_sec: 0U,
}
sess.refill_recv_window()
(blocks, sess)
@@ -642,6 +645,34 @@ fn RatchetSessionManager::find_session(
-1
}
///|
/// Drops any established or pending outbound ratchet state for `remote_static_pub`
/// so subsequent sends start a fresh Bound `NewSession` handshake.
pub fn RatchetSessionManager::drop_session(
self : RatchetSessionManager,
remote_static_pub : Bytes,
) -> Unit {
let mut si = 0
while si < self.sessions.length() {
if @crypto.ct_eq(self.sessions[si].remote_static_pub, remote_static_pub) {
let _ = self.sessions.remove(si)
} else {
si += 1
}
}
let mut pi = 0
while pi < self.outbound_pending.length() {
if @crypto.ct_eq(
self.outbound_pending[pi].1.remote_static_pub,
remote_static_pub,
) {
let _ = self.outbound_pending.remove(pi)
} else {
pi += 1
}
}
}
///|
/// Initiates a DH ratchet step (`NextKey` block type 7) for `remote_static_pub`,
/// returning `Some(NextKey(...))` if a session is established.
@@ -715,7 +746,13 @@ pub fn RatchetSessionManager::encrypt_to_peer(
) -> Bytes raise RatchetError {
let sidx = self.find_session(remote_static_pub)
if sidx >= 0 {
return self.sessions[sidx].encrypt_existing(blocks)
let sess = self.sessions[sidx]
if sess.last_used_sec != 0U && now_sec > sess.last_used_sec + 300U {
let _ = self.sessions.remove(sidx)
} else {
sess.last_used_sec = now_sec
return sess.encrypt_existing(blocks)
}
}
// Check if we owe this peer an NSR
for i = 0; i < self.inbound_pending.length(); i = i + 1 {
@@ -724,6 +761,7 @@ pub fn RatchetSessionManager::encrypt_to_peer(
let _ = self.inbound_pending.remove(i)
let ephem_b = generate_elligator_keypair(next_rand_32)
let (wire, sess) = encrypt_new_session_reply(p, ephem_b, blocks)
sess.last_used_sec = now_sec
self.sessions.push(sess)
return wire
}
@@ -754,6 +792,9 @@ pub fn RatchetSessionManager::encrypt_to_peer(
// Pre-register first 4 NSR tags so any reply matches
for _k = 0; _k < 4; _k = _k + 1 {
let (_n, tag, _k32) = p.nsr_tagset.next_entry()
while self.outbound_pending.length() >= 64 {
let _ = self.outbound_pending.remove(0)
}
self.outbound_pending.push((tag, p))
}
None => ()