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

+71 -3
View File
@@ -46,10 +46,14 @@ fn main {
let mut ntcp2_port = 0
let mut floodfill = false
let mut check_clock_skew = true
let mut public_mode = false
let mut tunnel_hops = 1
let mut debug = false
let peer_files : Array[String] = []
let peer_dirs : Array[String] = []
let su3_files : Array[String] = []
let reseed_urls : Array[String] = []
let hosts_files : Array[String] = []
let mut i = 1
while i < args.length() {
@@ -112,6 +116,31 @@ fn main {
} else {
i += 1
}
"--hosts" =>
if i + 1 < args.length() {
hosts_files.push(args[i + 1])
i += 2
} else {
i += 1
}
"--hops" =>
if i + 1 < args.length() {
match parse_port(args[i + 1]) {
Some(h) if h >= 1 && h <= 4 => tunnel_hops = h
_ => println("warning: ignoring invalid --hops \{args[i + 1]}")
}
i += 2
} else {
i += 1
}
"--public" => {
public_mode = true
i += 1
}
"--debug" => {
debug = true
i += 1
}
"--floodfill" => {
floodfill = true
i += 1
@@ -128,6 +157,9 @@ fn main {
{ sam_host, sam_port, ntcp2_host, ntcp2_port, },
floodfill~,
check_clock_skew~,
public_mode~,
tunnel_hops~,
debug~,
) catch {
_ => {
println("error: failed to start moon-i2p router")
@@ -169,12 +201,48 @@ fn main {
}
println(" Reseeded \{n} peer(s) from \{url}")
}
if public_mode &&
reseed_urls.length() == 0 &&
su3_files.length() == 0 &&
peer_files.length() == 0 &&
peer_dirs.length() == 0 {
println("Reseeding from public I2P network...")
let _ = r.auto_reseed()
}
for hf in hosts_files {
let n = r.load_hosts_file(hf) catch {
_ => {
println("warning: failed to load hosts file \{hf}")
continue
}
}
println(" Loaded \{n} host alias(es) from \{hf}")
}
println("moon-i2p router started (transient identity)")
println(" Router Hash: \{r.router_hash().to_base64()}")
println(" Router B32: \{r.router_hash().to_b32_address()}")
println(" NTCP2: \{ntcp2_host}:\{r.ntcp2_port()}")
println(
" NTCP2: \{ntcp2_host}:\{r.ntcp2_port()} (public=\{public_mode}, hops=\{tunnel_hops})",
)
println(" SAMv3: \{sam_host}:\{r.sam_port()}")
println(" NetDB peers: \{r.netdb.router_count()}")
println(
" NetDB peers: \{r.netdb.router_count()} (floodfills=\{r.netdb.floodfill_count()})",
)
@ntcp2_net.flush_stdout()
r.run()
if public_mode {
let mut last_log_ms = @ntcp2_net.unix_time_ms()
while true {
r.step(poll_ms=10)
let now_ms = @ntcp2_net.unix_time_ms()
if now_ms >= last_log_ms + 5000UL {
last_log_ms = now_ms
println(
"[public] peers=\{r.peer_count()} dials=\{r.pending_dial_count()} netdb=\{r.netdb.router_count()}(ff=\{r.netdb.floodfill_count()},ls=\{r.netdb.leaseset_count()}) tunnels=in:\{r.inbound_tunnel_count()}/out:\{r.outbound_tunnel_count()} builds=\{r.pending_build_count()}",
)
@ntcp2_net.flush_stdout()
}
}
} else {
r.run()
}
}