Mutual Witness Protocol (MWP)
Version: 1.0.0 Status: Implemented Created: February 2026
Overview
The Mutual Witness Protocol (MWP) is a novel NAT traversal and peer discovery protocol that requires zero external infrastructure beyond a DHT.
┌─────────────────────────────────────────────────────────────┐
│ MUTUAL WITNESS PROTOCOL │
│ │
│ Two parties who know each other's public keys can │
│ establish a direct P2P connection with: │
│ │
│ - No STUN servers │
│ - No relay servers │
│ - No signaling servers │
│ - No beacon chain │
│ - Only DHT (which P2P networks already have) │
│ │
│ Each party contributes randomness and timing. │
│ Neither can cheat. Neither needs to trust third parties. │
└─────────────────────────────────────────────────────────────┘
Key Innovation
Traditional NAT traversal requires:
- STUN: External server to discover your public IP
- Signaling: Server to exchange connection offers
- Relay: Fallback when direct connection fails
MWP eliminates all three by having peers witness each other:
- Both peers publish to a deterministic DHT meeting point
- Each contributes randomness (nonce) and timing (timestamp)
- Shared parameters computed from both contributions
- Simultaneous connection attempt at computed rendezvous time
Bundled STUN (IP Reflection)
MWP includes a novel Bundled STUN mechanism that eliminates STUN servers entirely:
Unidirectional (Response-based): Every DHT response includes the requester's observed address.
Alice ── DHT_REQUEST ──> DHT Node (src: 192.0.2.1:54321)
Alice <── DHT_RESPONSE ── DHT Node (observed_addr: 192.0.2.1:54321)
Bidirectional (Request-based): Every DHT request includes the target's observed address.
Bob ── DHT_REQUEST ──> Alice (target_observed_addr: 203.0.113.5:18100)
Alice learns her address from Bob's request, even as a pure listener!
This solves the "listener problem" where a peer waiting for connections has no one to query.
Quick Start
const mwp = @import("mwp");
// Your addresses (discovered via IP Reflection or configured)
const our_addresses = [_]mwp.Address{
mwp.Address.initV4(.{192, 168, 1, 100}, 9000),
};
// Initialize with your DHT, keypair, and addresses
var witness = mwp.MutualWitness.init(allocator, dht, keypair, &our_addresses);
// Connect to peer by their public key
const result = witness.connect(target_pubkey, .{
.timeout_ms = 5000,
});
switch (result) {
.success => |info| std.debug.print("Connected to {}:{}\n", .{info.remote_address}),
.timeout => std.debug.print("Timeout\n", .{}),
.peer_not_found => std.debug.print("Peer not found\n", .{}),
else => std.debug.print("Failed\n", .{}),
}
Protocol Flow
Alice DHT Bob
│ │ │
│ 1. meeting_key = hash(sort(A_pk, B_pk)) │
│ │ │
│──────── PUT(key, pub_A) ────>│<──── PUT(key, pub_B) ───────│
│ │ │
│<─────── GET(key) ───────────>│<──────── GET(key) ──────────│
│ returns [pub_A, pub_B] │
│ │ │
│ 2. shared_randomness = hash(sort(nonce_A, nonce_B)) │
│ 3. rendezvous_time = computed from timestamps │
│ │ │
│ 4. Wait until rendezvous_time │
│ │ │
│<──────────── simultaneous connection attempt ──────────────>│
│ │ │
▼ ▼ ▼
CONNECTED (direct P2P)
Comparison
| Metric | DCUtR | STUN+Signaling | MWP |
|---|---|---|---|
| External servers | 1+ relays | 2 servers | 0 |
| IP discovery | STUN servers | STUN servers | Bundled in DHT |
| Latency (typical) | ~2s | ~1-2s | ~1-2s |
| Centralization | Relay operators | Server operators | None |
| Infrastructure | Must run relays | Must run servers | DHT only |
Documentation
- SPEC.md - Complete protocol specification
- COMPARISON.md - Detailed comparison with existing solutions
- IP_REFLECTION_PERFORMANCE.md - Wire format optimization details
- ../ip-reflection-trust.md - Trust model and security analysis
- src/mwp/ - Implementation
Use Cases
- Truly decentralized P2P - No external dependencies
- Censorship-resistant - No servers to block
- Privacy-focused - Only DHT sees metadata
- Resource-constrained - Minimal infrastructure
- Offline-first - Works when peers are online, no always-on servers needed
Limitations
- Requires both peers to know each other's public keys
- Symmetric NAT success rate may be lower than relay-based approaches
- DHT latency affects connection setup time
- Novel/unproven (needs real-world testing)
License
Same as parent zig-p2p project.