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

+62 -7
View File
@@ -66,7 +66,11 @@ pub struct Router {
priv bridges : Array[StreamBridge]
priv remote_bridges : Array[RemoteStreamBridge]
priv aliases : Array[(String, String)] // hostname -> pub_b64
priv b32_aliases : Array[(String, String)] // hostname -> lowercase <52>.b32.i2p
priv failed_peers : Array[(@common.Hash, UInt64)] // (router_hash, retry_after_ms)
priv mut http_proxy_listener : @ntcp2_net.TcpListener?
priv http_proxy_conns : Array[HttpProxyConn]
priv mut http_proxy_session_id : String?
priv mut lease_rr : Int32
priv mut outbound_rr : Int32
priv mut last_bootstrap_ms : UInt64
@@ -225,7 +229,7 @@ pub fn Router::start(
} else {
tunnel_hops
}
{
let r : Router = {
ed_seed,
static_key,
ntcp2_iv,
@@ -254,12 +258,20 @@ pub fn Router::start(
bridges: [],
remote_bridges: [],
aliases: [],
b32_aliases: [],
failed_peers: [],
http_proxy_listener: None,
http_proxy_conns: [],
http_proxy_session_id: None,
lease_rr: 0,
outbound_rr: 0,
last_bootstrap_ms: 0UL,
last_explore_ms: 0UL,
}
if public_mode {
r.register_default_public_aliases()
}
r
}
///|
@@ -297,6 +309,33 @@ pub fn Router::router_hash(self : Router) -> @common.Hash {
self.router_info.identity.hash()
}
///|
fn remove_alias_entry(list : Array[(String, String)], key : String) -> Unit {
let mut i = 0
while i < list.length() {
if list[i].0 == key {
let _ = list.remove(i)
} else {
i += 1
}
}
}
///|
fn upsert_alias_entry(
list : Array[(String, String)],
key : String,
val : String,
) -> Unit {
for i = 0; i < list.length(); i = i + 1 {
if list[i].0 == key {
list[i] = (key, val)
return
}
}
list.push((key, val))
}
///|
pub fn Router::register_alias(
self : Router,
@@ -304,13 +343,13 @@ pub fn Router::register_alias(
dest_pub_b64 : String,
) -> Unit {
let key = hostname.to_lower()
for i = 0; i < self.aliases.length(); i = i + 1 {
if self.aliases[i].0 == key {
self.aliases[i] = (key, dest_pub_b64)
return
}
if parse_b32_hash(dest_pub_b64) is Some(_) {
remove_alias_entry(self.aliases, key)
upsert_alias_entry(self.b32_aliases, key, dest_pub_b64.to_lower())
} else {
remove_alias_entry(self.b32_aliases, key)
upsert_alias_entry(self.aliases, key, dest_pub_b64)
}
self.aliases.push((key, dest_pub_b64))
}
///|
@@ -393,6 +432,19 @@ pub fn Router::reseed_from_url(
///|
pub fn Router::close(self : Router) -> Unit {
for pc in self.http_proxy_conns {
if !pc.closed {
pc.sock.close()
pc.closed = true
}
}
match self.http_proxy_listener {
Some(l) => {
l.close()
self.http_proxy_listener = None
}
None => ()
}
for c in self.sam_clients {
if !c.closed {
c.sock.close()
@@ -509,6 +561,9 @@ pub fn Router::step(self : Router, poll_ms~ : Int32 = 10) -> Unit {
if self.step_sam_clients() {
did_work = true
}
if self.step_http_proxy() {
did_work = true
}
self.poll_netdb_lookups()
self.poll_tunnel_builds()
if self.public_mode {