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

+114 -2
View File
@@ -31,7 +31,37 @@ pub fn Router::auto_reseed(self : Router) -> Int32 {
}
///|
/// Loads `hostname=base64dest` addressbook aliases from a local `hosts.txt` file.
pub let default_public_b32_aliases : Array[(String, String)] = [
("stats.i2p", "kqypgjpjwrphnzebod5ev3ts2vtii6e5tntrg4rnfijqc7rypldq.b32.i2p"),
("zzz.i2p", "lhbd7ojcaiofbfku7ixh47qj537g572zmhdc4oilvugzxdpdghua.b32.i2p"),
(
"tracker2.postman.i2p", "6a4kxkg5wp33p25qqhgwl6sj4yh4xuf5b3p3qldwgclebchm3eea.b32.i2p",
),
("notbob.i2p", "nytzrhrjjfsutowojvxi7hphesskpqqr65wpistz6wa7cpajhp7a.b32.i2p"),
(
"insulaocculta.i2p", "ls5mvws4ytegkfa2s56lo7wl5h5elocyrfhmufpzq4eyozc3vosa.b32.i2p",
),
(
"tracker.insulaocculta.i2p", "2rv2kch37xsn2fqdz6huyevq76njop4inumscnspklh3ufo7mkwa.b32.i2p",
),
(
"tracker.queke.i2p", "j4nrlimeg2loq5sfslb3c6nmnvbucet4gyrmog66igxrk5l5fxla.b32.i2p",
),
(
"opentracker.dg2.i2p", "w7tpbzncbcocrqtwwm3nezhnnsw4ozadvi2hmvzdhrqzfxfum7wa.b32.i2p",
),
]
///|
/// Registers built-in `.i2p` -> `.b32.i2p` aliases for well-known public eepsites.
pub fn Router::register_default_public_aliases(self : Router) -> Unit {
for entry in default_public_b32_aliases {
self.register_alias(entry.0, entry.1)
}
}
///|
/// Loads `hostname=base64dest` or `hostname=<52char>.b32.i2p` aliases from a local `hosts.txt` file.
pub fn Router::load_hosts_file(
self : Router,
path : String,
@@ -56,7 +86,8 @@ pub fn Router::load_hosts_file(
if eq > 0 && eq + 1 < line.length() {
let host = line[:eq].to_owned().trim().to_owned()
let dest_b64 = line[eq + 1:].to_owned().trim().to_owned()
if host.length() > 0 && dest_b64.length() > 100 {
if host.length() > 0 &&
(dest_b64.length() > 100 || parse_b32_hash(dest_b64) is Some(_)) {
self.register_alias(host, dest_b64)
count += 1
}
@@ -174,6 +205,16 @@ fn Router::pick_connected_hop(
None
}
///|
fn Router::has_connected_peer(self : Router, hash : @common.Hash) -> Bool {
for p in self.peers {
if p.hash == hash {
return true
}
}
false
}
///|
fn Router::step_public_bootstrap(self : Router) -> Unit {
let now_ms = @ntcp2_net.unix_time_ms()
@@ -182,6 +223,77 @@ fn Router::step_public_bootstrap(self : Router) -> Unit {
}
self.last_bootstrap_ms = now_ms
// Keepalive NTCP2 peers carrying active Inbound/Outbound tunnels so long-lived sessions stay reachable
let tunnel_peers : Array[@common.Hash] = []
for t in self.tunnels.inbound {
if t.hops.length() > 0 {
let h = t.hops[t.hops.length() - 1].router_hash
if !is_peer_in_list(h, tunnel_peers) {
tunnel_peers.push(h)
}
}
}
for t in self.tunnels.outbound {
if t.hops.length() > 0 {
let h = t.hops[0].router_hash
if !is_peer_in_list(h, tunnel_peers) {
tunnel_peers.push(h)
}
}
}
let mut pi = 0
while pi < self.peers.length() {
let p = self.peers[pi]
if is_peer_in_list(p.hash, tunnel_peers) &&
now_ms > p.last_active_ms + 90000UL {
let ok = try {
p.conn.send_blocks([@ntcp2.Ntcp2Block::Padding(b"\x00\x00\x00\x00")])
true
} catch {
_ => false
}
if ok {
p.last_active_ms = now_ms
pi += 1
} else {
p.conn.close()
let _ = self.peers.remove(pi)
}
} else {
pi += 1
}
}
// Prune expired, nearly-expired, or disconnected-hop client tunnels so fresh replacements build automatically
let now_sec = (now_ms / 1000UL).to_uint()
let mut inbound_pruned = false
let mut ii = 0
while ii < self.tunnels.inbound.length() {
let t = self.tunnels.inbound[ii]
let dead_last_hop = t.hops.length() > 0 &&
!self.has_connected_peer(t.hops[t.hops.length() - 1].router_hash)
if t.expires_sec <= now_sec + 30U || dead_last_hop {
let _ = self.tunnels.inbound.remove(ii)
inbound_pruned = true
} else {
ii += 1
}
}
let mut oi = 0
while oi < self.tunnels.outbound.length() {
let t = self.tunnels.outbound[oi]
let dead_first_hop = t.hops.length() > 0 &&
!self.has_connected_peer(t.hops[0].router_hash)
if t.expires_sec <= now_sec + 30U || dead_first_hop {
let _ = self.tunnels.outbound.remove(oi)
} else {
oi += 1
}
}
if inbound_pruned && self.tunnels.inbound.length() > 0 {
self.republish_all_sessions()
}
// 1. Keep up to 6 live outbound NTCP2 TCP peer sessions active
let target_peers = 6
if self.peers.length() + self.pending_dials.length() < target_peers {