feat: add ratchet, streaming, SU3 reseed, and router floodfill
- Add ratchet/ with ECIES-X25519-AEAD-Ratchet (Proposal 144), Garlic cloves, and ECIES DatabaseLookup replies - Add streaming/ with Ed25519-signed I2P Streaming (SYN/ACK/NACK/CLOSE/RESET, retransmit, window) and Repliable/Raw Datagrams - Add common/su3.mbt to parse and verify reseed .su3 bundles - Add Elligator2 encoding in crypto/ and OfflineSignature support in LeaseSet2 (flags bit 0) - Router: NTCP2 peer pool, floodfill NetDB crawl, transit tunnel relay, and Garlic/Streaming bridge - cmd/router: add --peer-dir, --su3, --reseed, --floodfill, --no-clock-skew - cmd/client: add --dest for persistent destination keys - Mark Phase 6 complete in README and document the transport scope (NTCP2 only, no SSU2)
This commit is contained in:
1 parent
8eafa11b22
commit
ae72b00323
54 files changed
+9607
-704
No files matched your search
+36
-5
@@ -301,8 +301,25 @@ pub fn NetDb::closest_peers(
|
||||
}
|
||||
|
||||
///|
|
||||
/// Processes an incoming I2NP `DatabaseStore` payload (type 0 = uncompressed RouterInfo,
|
||||
/// type 3 = LeaseSet2). Returns `true` if stored/updated.
|
||||
/// Encodes a `RouterInfo` in canonical I2P `DatabaseStore` type 0 wire format:
|
||||
/// `2-byte BE gzip length || gzip(RouterInfo)`.
|
||||
pub fn encode_router_info_store_data(
|
||||
ri : @common.RouterInfo,
|
||||
) -> Bytes raise NetDbError {
|
||||
let raw = ri.to_bytes() catch { e => raise Common(e) }
|
||||
let gz = @encoding.gzip_compress(raw)
|
||||
if gz.length() > 65535 {
|
||||
raise InvalidRecord("compressed RouterInfo exceeds 65535 bytes")
|
||||
}
|
||||
let w = @encoding.Writer::new(capacity=2 + gz.length())
|
||||
w.write_u16_be(gz.length().reinterpret_as_uint())
|
||||
w.write_bytes(gz)
|
||||
w.to_bytes()
|
||||
}
|
||||
|
||||
///|
|
||||
/// Processes an incoming I2NP `DatabaseStore` payload (type 0 = gzip-prefixed or
|
||||
/// raw uncompressed RouterInfo, type 3 = LeaseSet2). Returns `true` if stored/updated.
|
||||
pub fn NetDb::handle_database_store(
|
||||
self : NetDb,
|
||||
store_type : Byte,
|
||||
@@ -312,8 +329,22 @@ pub fn NetDb::handle_database_store(
|
||||
) -> Bool raise NetDbError {
|
||||
match store_type.to_int() & 0x0F {
|
||||
0 => {
|
||||
// Uncompressed RouterInfo (if gzipped with 2-byte len prefix, caller decompresses first)
|
||||
let ri = @common.RouterInfo::decode(@encoding.Reader::new(data)) catch {
|
||||
let raw = if data.length() >= 4 &&
|
||||
data[2] == b'\x1f' &&
|
||||
data[3] == b'\x8b' {
|
||||
let gz_len = (data[0].to_int() << 8) | data[1].to_int()
|
||||
if gz_len + 2 != data.length() {
|
||||
raise InvalidRecord(
|
||||
"DatabaseStore gzip length prefix \{gz_len} does not match payload \{data.length() - 2}",
|
||||
)
|
||||
}
|
||||
@encoding.gzip_decompress(data[2:].to_owned()) catch {
|
||||
_ => raise InvalidRecord("DatabaseStore RouterInfo gunzip failed")
|
||||
}
|
||||
} else {
|
||||
data
|
||||
}
|
||||
let ri = @common.RouterInfo::decode(@encoding.Reader::new(raw)) catch {
|
||||
e => raise Common(e)
|
||||
}
|
||||
if ri.identity.hash() != key {
|
||||
@@ -370,7 +401,7 @@ pub fn NetDb::handle_database_lookup(
|
||||
if lookup_type == 0 || lookup_type == 2 {
|
||||
match self.get_router_info(key) {
|
||||
Some(ri) => {
|
||||
let raw = ri.to_bytes() catch { e => raise Common(e) }
|
||||
let raw = encode_router_info_store_data(ri)
|
||||
return DatabaseStore(
|
||||
key~,
|
||||
store_type=b'\x00',
|
||||
|
||||
@@ -128,6 +128,7 @@ test "NetDB LeaseSet2 store, .b32.i2p lookup, and expiration pruning" {
|
||||
published_sec: 1700000000U,
|
||||
expires_offset: 300U,
|
||||
flags: 0U,
|
||||
offline_sig: None,
|
||||
options: @common.Mapping::new(),
|
||||
encryption_keys: [{ key_type: X25519, key_data: x_pub, }],
|
||||
leases: [
|
||||
@@ -151,3 +152,35 @@ test "NetDB LeaseSet2 store, .b32.i2p lookup, and expiration pruning" {
|
||||
assert_eq(db.prune_expired(1700000301U), 1)
|
||||
assert_eq(db.leaseset_count(), 0)
|
||||
}
|
||||
|
||||
///|
|
||||
test "NetDB canonical gzipped DatabaseStore type 0 round-trip" {
|
||||
let src = @netdb.NetDb::new()
|
||||
let dst = @netdb.NetDb::new()
|
||||
let r1 = make_signed_router(b'\x0a', "XfR", 1700000000000UL)
|
||||
let r2 = make_signed_router(b'\x0b', "LR", 1700000000000UL)
|
||||
assert_eq(src.store_router_info(r1), true)
|
||||
assert_eq(src.store_router_info(r2), true)
|
||||
|
||||
let resp = src.handle_database_lookup(
|
||||
r1.identity.hash(),
|
||||
r2.identity.hash(),
|
||||
b'\x08',
|
||||
[],
|
||||
1700000010U,
|
||||
)
|
||||
match resp {
|
||||
DatabaseStore(key~, store_type~, data~, ..) => {
|
||||
assert_eq(store_type, b'\x00')
|
||||
// Canonical DatabaseStore type 0 starts with 2-byte BE length + gzip magic 0x1f 0x8b
|
||||
assert_eq(data[2], b'\x1f')
|
||||
assert_eq(data[3], b'\x8b')
|
||||
assert_eq(
|
||||
dst.handle_database_store(store_type, key, data, 1700000010U),
|
||||
true,
|
||||
)
|
||||
assert_eq(dst.get_router_info(r2.identity.hash()), Some(r2))
|
||||
}
|
||||
_ => fail("expected gzipped DatabaseStore")
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
// Values
|
||||
pub fn compare_distance(Bytes, Bytes) -> Int32
|
||||
|
||||
pub fn encode_router_info_store_data(@common.RouterInfo) -> Bytes raise NetDbError
|
||||
|
||||
pub fn format_utc_date(UInt64) -> String
|
||||
|
||||
pub fn is_floodfill(@common.RouterInfo) -> Bool
|
||||
|
||||
Reference in new issue
Block a user