feat: add public I2P network mode to router daemon
check / check (ubuntu-latest) (push) Failing after 26s
check / check (macos-latest) (push) Failing after 28s
check / check (windows-latest) (push) Failing after 29s

- Add `--public`, `--hops`, `--hosts`, and `--debug` router flags; `--public` auto-reseeds from the live network and keeps a status loop running.
- Route NetDB lookups through tunnels with Noise_N garlic wrapping, fan out to two floodfills, and fetch unknown RouterInfos in the background.
- Back off failed NTCP2 peers and fall back to IPv6 addresses when no IPv4 NTCP2 address is available.
- Size session LeaseSet2 expiry from lease end dates and use the destination's X25519 key when present.
- Add canonical Ed25519 Destination KeyCertificate constructors with round-trip tests.
- Fix DatabaseStore gzip handling to honor the length prefix, and send `Wget/1.11.4` as the reseed User-Agent.
This commit is contained in:
nandi committed 2026-11-28 00:11:28 -08:00
1 parent ae72b00323
commit 54cfb2faa9
25 files changed
+2033 -191

No files matched your search

+85 -6
View File
@@ -28,6 +28,46 @@ pub fn Router::peer_count(self : Router) -> Int32 {
self.peers.length()
}
///|
fn Router::mark_peer_failed(
self : Router,
peer_hash : @common.Hash,
cooldown_ms : UInt64,
) -> Unit {
let until = @ntcp2_net.unix_time_ms() + cooldown_ms
for i = 0; i < self.failed_peers.length(); i = i + 1 {
if self.failed_peers[i].0 == peer_hash {
self.failed_peers[i] = (peer_hash, until)
return
}
}
if self.failed_peers.length() >= 512 {
let _ = self.failed_peers.remove(0)
}
self.failed_peers.push((peer_hash, until))
}
///|
fn Router::is_peer_backed_off(
self : Router,
peer_hash : @common.Hash,
now_ms : UInt64,
) -> Bool {
let mut i = 0
let mut backed_off = false
while i < self.failed_peers.length() {
if self.failed_peers[i].1 <= now_ms {
let _ = self.failed_peers.remove(i)
} else {
if self.failed_peers[i].0 == peer_hash {
backed_off = true
}
i += 1
}
}
backed_off
}
///|
fn Router::find_peer_hash_by_static(
self : Router,
@@ -63,14 +103,24 @@ fn Router::has_pending_dial(self : Router, target_hash : @common.Hash) -> Bool {
///|
fn Router::ensure_peer_dial(self : Router, target_hash : @common.Hash) -> Unit {
if target_hash == self.router_hash() || self.has_pending_dial(target_hash) {
let now_ms = @ntcp2_net.unix_time_ms()
if target_hash == self.router_hash() ||
self.has_pending_dial(target_hash) ||
(self.public_mode && self.is_peer_backed_off(target_hash, now_ms)) {
return
}
let ri = match self.netdb.get_router_info(target_hash) {
Some(r) => r
None => return
}
let peer_info = @ntcp2_net.extract_ntcp2_peer(ri) catch { _ => return }
let peer_info = @ntcp2_net.extract_ntcp2_peer(ri) catch {
_ => {
if self.public_mode {
self.mark_peer_failed(target_hash, 120000UL)
}
return
}
}
let dial = @ntcp2_net.PendingNtcp2Dial::start(
peer_info,
self.static_key,
@@ -78,7 +128,12 @@ fn Router::ensure_peer_dial(self : Router, target_hash : @common.Hash) -> Unit {
check_clock_skew=self.check_clock_skew,
remote_ri=Some(ri),
) catch {
_ => return
_ => {
if self.public_mode {
self.mark_peer_failed(target_hash, 60000UL)
}
return
}
}
self.pending_dials.push({ peer_hash: target_hash, dial, })
}
@@ -143,8 +198,11 @@ fn Router::send_routed_i2np(
target_tid : UInt32?,
payload : @i2np.I2npPayload,
) -> Unit {
if self.tunnels.outbound.length() > 0 {
let out_t = self.tunnels.outbound[0]
let out_len = self.tunnels.outbound.length()
if out_len > 0 {
let idx = if self.outbound_rr < 0 { 0 } else { self.outbound_rr % out_len }
self.outbound_rr = (self.outbound_rr + 1) & 0x3FFFFFFF
let out_t = self.tunnels.outbound[idx]
let target : @tunnel.DeliveryTarget = match target_tid {
Some(tid) => Tunnel(tunnel_id=tid, gateway=target_gw)
None => Router(router_hash=target_gw)
@@ -324,6 +382,14 @@ fn Router::step_ntcp2_peers(self : Router) -> Bool {
if now_ms > pd.dial.started_at_ms() + 10000UL {
pd.dial.close()
let _ = self.pending_dials.remove(di)
if self.public_mode {
self.mark_peer_failed(pd.peer_hash, 60000UL)
if self.debug {
println(
"[debug] NTCP2 dial timeout: \{pd.peer_hash.to_b32_address()}",
)
}
}
did_work = true
continue
}
@@ -331,6 +397,14 @@ fn Router::step_ntcp2_peers(self : Router) -> Bool {
if stepped.1 {
pd.dial.close()
let _ = self.pending_dials.remove(di)
if self.public_mode {
self.mark_peer_failed(pd.peer_hash, 60000UL)
if self.debug {
println(
"[debug] NTCP2 dial rejected: \{pd.peer_hash.to_b32_address()}",
)
}
}
did_work = true
continue
}
@@ -344,6 +418,11 @@ fn Router::step_ntcp2_peers(self : Router) -> Bool {
last_active_ms: now_ms,
}
self.peers.push(ps)
if self.debug {
println(
"[debug] NTCP2 connected to \{pd.peer_hash.to_b32_address()} (peers=\{self.peers.length()})",
)
}
let _ = self.flush_pending_sends_for(pd.peer_hash, ps)
}
None => di += 1
@@ -401,7 +480,7 @@ fn Router::step_ntcp2_peers(self : Router) -> Bool {
None => break
}
}
if !alive || now_ms > peer.last_active_ms + 120000UL {
if !alive || now_ms > peer.last_active_ms + 180000UL {
peer.conn.close()
let _ = self.peers.remove(pi)
} else {