Files
moon-i2p/i2np/i2np_test.mbt
T
nandi ae72b00323
check / check (windows-latest) (push) Failing after 27s
check / check (ubuntu-latest) (push) Failing after 29s
check / check (macos-latest) (push) Failing after 27s
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)
2026-11-27 22:23:46 -08:00

130 lines
4.4 KiB
MoonBit

///|
test "I2NP standard header checksum and Data message round-trip" {
let msg = @i2np.I2npPayload::Data(data=b"hello invisible internet")
let wire = @i2np.encode_standard_message(12345U, 1700000000000UL, msg)
// 16-byte header + 4-byte length + 24-byte payload = 44 bytes
assert_eq(wire.length(), 44)
let (hdr, decoded) = @i2np.decode_standard_message(
@encoding.Reader::new(wire),
)
assert_eq(hdr.msg_type, Data)
assert_eq(hdr.msg_id, 12345U)
assert_eq(hdr.expiration_ms, 1700000000000UL)
assert_eq(decoded, msg)
}
///|
test "I2NP standard header detects corrupted checksum" {
let msg = @i2np.I2npPayload::DeliveryStatus(
msg_id=99U,
timestamp_ms=1700000000123UL,
)
let wire = @i2np.encode_standard_message(77U, 1700000010000UL, msg)
// Flip a bit in the payload
let tampered = FixedArray::make(wire.length(), b'\x00')
for i = 0; i < wire.length(); i = i + 1 {
tampered[i] = wire[i]
}
tampered[16] = (tampered[16].to_int() ^ 0xFF).to_byte()
let mut failed = false
try {
let _ = @i2np.decode_standard_message(
@encoding.Reader::new(Bytes::from_array(tampered)),
)
} catch {
@i2np.I2npError::ChecksumMismatch(_, _) => failed = true
_ => ()
}
assert_true(failed)
}
///|
test "I2NP NTCP2 short 9-byte header round-trip for DatabaseStore and ShortTunnelBuild" {
let key = @common.Hash::from_bytes(Bytes::make(32, b'\x42'))
let gw = @common.Hash::from_bytes(Bytes::make(32, b'\x99'))
let store = @i2np.I2npPayload::DatabaseStore(
key~,
store_type=b'\x03',
reply_token=555U,
reply_tunnel_id=777U,
reply_gateway=Some(gw),
data=b"leaseset2-bytes",
)
let wire = @i2np.encode_short_message(42U, 1700000500U, store)
let (hdr, decoded) = @i2np.decode_short_message(@encoding.Reader::new(wire))
assert_eq(hdr.msg_type, DatabaseStore)
assert_eq(hdr.msg_id, 42U)
assert_eq(hdr.expiration_sec, 1700000500U)
assert_eq(decoded, store)
// ShortTunnelBuild (Proposal 157: 218-byte records)
let stb = @i2np.I2npPayload::ShortTunnelBuild(records=[
Bytes::make(218, b'\x01'),
Bytes::make(218, b'\x02'),
])
let stb_wire = @i2np.encode_short_message(101U, 1700000600U, stb)
let (stb_hdr, stb_dec) = @i2np.decode_short_message(
@encoding.Reader::new(stb_wire),
)
assert_eq(stb_hdr.msg_type, ShortTunnelBuild)
assert_eq(stb_dec, stb)
}
///|
test "I2NP TunnelData and DatabaseSearchReply round-trip" {
let td = @i2np.I2npPayload::TunnelData(
tunnel_id=0x11223344U,
data=Bytes::make(1024, b'\x7e'),
)
let td_wire = @i2np.encode_short_message(5U, 1700000900U, td)
let (_, td_dec) = @i2np.decode_short_message(@encoding.Reader::new(td_wire))
assert_eq(td_dec, td)
let dsr = @i2np.I2npPayload::DatabaseSearchReply(
key=@common.Hash::from_bytes(Bytes::make(32, b'\x01')),
peer_hashes=[
@common.Hash::from_bytes(Bytes::make(32, b'\x02')),
@common.Hash::from_bytes(Bytes::make(32, b'\x03')),
],
from=@common.Hash::from_bytes(Bytes::make(32, b'\x04')),
)
let dsr_wire = @i2np.encode_standard_message(6U, 1700000900000UL, dsr)
let (_, dsr_dec) = @i2np.decode_standard_message(
@encoding.Reader::new(dsr_wire),
)
assert_eq(dsr_dec, dsr)
}
///|
test "I2NP DatabaseLookup ECIES (0x10) and AES (0x02) reply key/tags round-trip" {
let key = @common.Hash::from_bytes(Bytes::make(32, b'\x11'))
let from = @common.Hash::from_bytes(Bytes::make(32, b'\x22'))
let ecies_dbl = @i2np.I2npPayload::DatabaseLookup(
key~,
from~,
flags=b'\x11', // tunnel delivery (0x01) + ECIES reply (0x10)
reply_tunnel_id=Some(445566U),
excluded_peers=[@common.Hash::from_bytes(Bytes::make(32, b'\x33'))],
reply_key=Some(Bytes::make(32, b'\x44')),
reply_tags=[Bytes::make(8, b'\x55')],
)
let ecies_wire = @i2np.encode_short_message(11U, 1700000900U, ecies_dbl)
let (_, ecies_dec) = @i2np.decode_short_message(
@encoding.Reader::new(ecies_wire),
)
assert_eq(ecies_dec, ecies_dbl)
let aes_dbl = @i2np.I2npPayload::DatabaseLookup(
key~,
from~,
flags=b'\x0a', // RouterInfo lookup (0x08) + AES encryption (0x02)
reply_tunnel_id=None,
excluded_peers=[],
reply_key=Some(Bytes::make(32, b'\x66')),
reply_tags=[Bytes::make(32, b'\x77')],
)
let aes_wire = @i2np.encode_short_message(12U, 1700000900U, aes_dbl)
let (_, aes_dec) = @i2np.decode_short_message(@encoding.Reader::new(aes_wire))
assert_eq(aes_dec, aes_dbl)
}