feat: add working native SAMv3 TCP client and CLI with sane defaults
check / check (macos-latest) (push) Failing after 28s
check / check (ubuntu-latest) (push) Failing after 29s
check / check (windows-latest) (push) Failing after 30s

This commit is contained in:
nandi committed 2026-11-27 19:10:01 +00:00
1 parent e527b84bc3
commit 4d79d78f06
13 files changed
+1910 -11

No files matched your search

+40 -7
View File
@@ -12,7 +12,10 @@ moon-i2p/
├── i2np/ # 16-byte standard & 9-byte NTCP2 short headers, SHA-256 checksums, core I2NP messages
├── noise/ # Noise_XK_25519_ChaChaPoly_SHA256 handshake/transport + NTCP2 SipHash-2-4 length masking
├── sam/ # SAMv3 text protocol parser, serializer, and command builders
└── cmd/main/ # Demo CLI entrypoint
├── sam_client/ # Native POSIX TCP SAMv3 client with sane modern I2P defaults
├── cmd/main/ # Pure protocol demo CLI entrypoint
├── cmd/client/ # Native SAMv3 CLI (`keygen`, `lookup`, `http-get`, `dial`, `listen`)
└── scripts/ # Loopback SAMv3 bridge (`mock_sam.py`) and end-to-end test (`e2e_test.py`)
```
### Verified Test Vectors
@@ -24,24 +27,54 @@ Every cryptographic primitive in `crypto/` is verified against official standard
- **X25519**: RFC 7748 Sections 5.2 & 6.1
- **SipHash-2-4**: Official SipHash reference test vector
## Running the SAMv3 Client (Native)
The native client (`cmd/client`) connects to an I2P SAMv3 bridge with sane modern defaults:
- **Bridge:** `127.0.0.1:7656` (override with `--sam <host:port>` or `I2P_SAM_HOST` / `I2P_SAM_PORT`)
- **Protocol:** SAM `3.1`–`3.3`
- **Keys:** `TRANSIENT` destination, `SIGNATURE_TYPE=7` (`EdDSA_SHA512_Ed25519`)
- **I2CP Tunnel Defaults:** `i2cp.leaseSetEncType=4,0` (ECIES-X25519 preferred), 3-hop / 3-tunnel inbound & outbound pools
```bash
# Build the native client binary
moon build --target native cmd/client
# Start an I2P router with SAMv3 enabled (e.g. i2pd --sam.enabled=true)
# or use the bundled local loopback SAMv3 bridge for testing:
# python3 scripts/mock_sam.py
# Generate a new Ed25519 I2P destination
./_build/native/debug/build/cmd/client/client.exe keygen
# Resolve an I2P hostname
./_build/native/debug/build/cmd/client/client.exe lookup stats.i2p
# Fetch an eepsite over a transient STREAM session
./_build/native/debug/build/cmd/client/client.exe http-get stats.i2p /
# Peer-to-peer STREAM listener and dialer
./_build/native/debug/build/cmd/client/client.exe listen "hello back"
./_build/native/debug/build/cmd/client/client.exe dial <listener.b32.i2p> "hello over i2p"
```
## Running Checks & Tests
```bash
moon check
moon test
moon check --target wasm
moon test --target wasm
moon check --target native
moon test --target native
moon run cmd/main
moon build --target native cmd/client && python3 scripts/e2e_test.py
```
## Roadmap
1. **Phase 1–2 (Completed):** Core encoding, pure-MoonBit modern crypto, I2P Common Structures, I2NP messages, `Noise_XK_25519_ChaChaPoly_SHA256` state machine, NTCP2 SipHash length masking, and SAMv3 protocol codec.
1. **Phase 1–2 (Completed):** Core encoding, pure-MoonBit modern crypto, I2P Common Structures, I2NP messages, `Noise_XK_25519_ChaChaPoly_SHA256` state machine, NTCP2 SipHash length masking, SAMv3 protocol codec, and working native SAMv3 TCP client + CLI (`sam_client/`, `cmd/client/`).
2. **Phase 3 (Signatures & Ratchet):**
- Pure-MoonBit **Ed25519** signing & verification (`RouterInfo` & `LeaseSet2` signatures).
- **ECIES-X25519-AEAD-Ratchet** (Proposal 144) for Garlic encryption & end-to-end sessions.
3. **Phase 4 (Transports & Networking):**
3. **Phase 4 (Direct Transports):**
- **NTCP2** full TCP transport (AES-256-CBC ephemeral key obfuscation, options/padding blocks, session manager).
- **SAMv3** live TCP client for interacting with an existing I2P/i2pd router.
4. **Phase 5 (Router Core):**
- **NetDB** & Floodfill DHT (Kademlia XOR routing with daily routing key derivation).
- **Tunnel** builder (`ShortTunnelBuild` Proposal 157), layered tunnel encryption, and tunnel pool management.