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

+53
View File
@@ -9,6 +9,9 @@
///|
pub let ecies_protocol_name : Bytes = b"Noise_IKelg2+hs2_25519_ChaChaPoly_SHA256"
///|
pub let router_garlic_protocol_name : Bytes = b"Noise_N_25519_ChaChaPoly_SHA256"
///|
fn r_slice(data : Bytes, start : Int32, len : Int32) -> Bytes {
let out = FixedArray::make(len, b'\x00')
@@ -559,6 +562,56 @@ pub fn decrypt_ecies_lookup_reply(
decode_blocks(pt)
}
///|
/// Encrypts Garlic blocks to a router's static X25519 key using Proposal 144 `Noise_N_25519_ChaChaPoly_SHA256`
/// (canonical `WrapECIESX25519MessageForRouter`: `raw_ephem_pub (32B) || AEAD ciphertext`).
pub fn encrypt_router_garlic(
remote_static_pub : Bytes,
ephemeral : @noise.KeyPair,
blocks : Array[RatchetBlock],
) -> Bytes raise RatchetError {
if remote_static_pub.length() != 32 {
raise InvalidLength("remote_static_pub must be 32 bytes")
}
let sym = @noise.SymmetricState::initialize(router_garlic_protocol_name)
sym.mix_hash(b"") // null prologue
sym.mix_hash(remote_static_pub)
sym.mix_hash(ephemeral.public_key)
let dh = @crypto.x25519(ephemeral.private_key, remote_static_pub) catch {
e => raise Crypto(e)
}
sym.mix_key(dh)
let pt = encode_blocks(blocks)
let ct = sym.encrypt_and_hash(pt) catch { e => raise Noise(e) }
let w = @encoding.Writer::new(capacity=32 + ct.length())
w.write_bytes(ephemeral.public_key)
w.write_bytes(ct)
w.to_bytes()
}
///|
/// Decrypts a router-targeted `Noise_N_25519_ChaChaPoly_SHA256` Garlic message addressed to `local_static`.
pub fn decrypt_router_garlic(
local_static : @noise.KeyPair,
data : Bytes,
) -> Array[RatchetBlock] raise RatchetError {
if data.length() < 48 {
raise InvalidLength("Router Garlic shorter than 48 bytes")
}
let ephem_pub = r_slice(data, 0, 32)
let ct = r_slice(data, 32, data.length() - 32)
let sym = @noise.SymmetricState::initialize(router_garlic_protocol_name)
sym.mix_hash(b"")
sym.mix_hash(local_static.public_key)
sym.mix_hash(ephem_pub)
let dh = @crypto.x25519(local_static.private_key, ephem_pub) catch {
e => raise Crypto(e)
}
sym.mix_key(dh)
let pt = sym.decrypt_and_hash(ct) catch { _ => raise AuthenticationFailed }
decode_blocks(pt)
}
///|
/// High-level session manager handling New Session, New Session Reply, and Existing Session
/// state transitions for a local I2P Destination.