diff --git a/docs/mwp/README.md b/docs/mwp/README.md index 1cecec8..a720496 100644 --- a/docs/mwp/README.md +++ b/docs/mwp/README.md @@ -41,6 +41,17 @@ MWP eliminates all three by having peers **witness each other**: 3. Shared parameters computed from both contributions 4. Simultaneous connection attempt at computed rendezvous time +### Bundled STUN (IP Reflection) + +MWP includes a novel **Bundled STUN** mechanism: every DHT response includes the requester's observed source address. This eliminates STUN servers entirely - peers discover their public IP from normal DHT traffic: + +``` +Alice ── DHT_REQUEST ──> DHT Node (src: 192.0.2.1:54321) +Alice <── DHT_RESPONSE ── DHT Node (observed_addr: 192.0.2.1:54321) + +Now Alice knows her public IP without any STUN server! +``` + ## Quick Start ```zig @@ -86,6 +97,7 @@ defer connection.close(); | 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** | diff --git a/docs/mwp/SPEC.md b/docs/mwp/SPEC.md index be7c684..b2e309f 100644 --- a/docs/mwp/SPEC.md +++ b/docs/mwp/SPEC.md @@ -44,6 +44,7 @@ The Mutual Witness Protocol (MWP) eliminates external infrastructure by having p - Each peer contributes randomness and timing information - Shared connection parameters are derived from both contributions - Neither peer can cheat or bias the outcome +- **Bundled STUN**: DHT responses include the requester's observed IP address, eliminating STUN servers ### 1.3 Requirements @@ -107,6 +108,7 @@ MWP requires: | Synchronized timing | Derived from publication timestamps | | Mutual authentication | Signatures verify peer identity | | NAT traversal | Simultaneous connection attempts | +| IP discovery | Bundled STUN - DHT responses include observed address | --- @@ -335,22 +337,94 @@ def gather_addresses() -> List[Address]: # 1. Local bound address addresses.append(get_local_address()) - # 2. Previously observed external addresses + # 2. DHT-observed external address (Bundled STUN) + # Every DHT response includes the requester's observed IP:port + if dht_observed := get_dht_observed_address(): + addresses.append(dht_observed) + + # 3. Previously observed external addresses # (From successful past connections) addresses.extend(get_observed_addresses()) - # 3. Predicted addresses + # 4. Predicted addresses # (From NAT behavior learning) if predicted := nat_predictor.predict(): addresses.append(predicted) - # 4. UPnP-mapped address (if available) + # 5. UPnP-mapped address (if available) if upnp_addr := get_upnp_address(): addresses.append(upnp_addr) return addresses ``` +### 6.6 Bundled STUN (IP Reflection) + +MWP eliminates the need for external STUN servers through **IP Reflection**: + +``` +┌─────────────────────────────────────────────────────────────┐ +│ BUNDLED STUN │ +│ │ +│ Every DHT response includes the requester's observed │ +│ source address. This is the same information a STUN │ +│ server would provide, but bundled into existing traffic. │ +│ │ +│ Alice ──── DHT_REQUEST ───────────────> DHT Node │ +│ src: 192.0.2.1:54321 │ +│ │ +│ Alice <─── DHT_RESPONSE ─────────────── DHT Node │ +│ observed_addr: 192.0.2.1:54321 │ +│ │ +│ Now Alice knows her public IP:port without any STUN! │ +└─────────────────────────────────────────────────────────────┘ +``` + +**Wire Format:** + +Each DHT response (FIND_NODE_RESPONSE, STORE_RESPONSE, FIND_VALUE_RESPONSE) +includes: + +``` ++--------+--------+--------+--------+--------+--------+ +| observed_addr (18 bytes) | addr_len (1 byte)| ++--------+--------+--------+--------+--------+--------+ + +IPv4: 4 bytes IP + 2 bytes port = 6 bytes (addr_len = 6) +IPv6: 16 bytes IP + 2 bytes port = 18 bytes (addr_len = 18) +``` + +**Benefits:** + +| Aspect | Traditional STUN | Bundled STUN | +|--------|------------------|--------------| +| Extra servers | Required | None | +| Extra round trips | 1-2 | 0 | +| Infrastructure | Must maintain STUN servers | DHT already exists | +| Availability | STUN server must be up | Works if any DHT node responds | +| Privacy | STUN server sees your IP | DHT nodes already see your IP | + +**Implementation:** + +```python +# DHT response handler (server side) +def handle_dht_request(request, source_addr): + response = process_request(request) + + # Bundled STUN: include requester's observed address + response.observed_addr = source_addr.ip + response.observed_addr_port = source_addr.port + + return response + +# MWP address gathering (client side) +def on_dht_response(response): + if response.observed_addr_len > 0: + # We learned our public IP from the DHT response! + my_public_addr = parse_observed_addr(response) + address_cache.update(my_public_addr) +``` + --- ## 7. Edge Cases & Mitigations @@ -553,13 +627,15 @@ STUN + Signaling: 5. Bob sends answer via Server 6. Both attempt connection -MWP: - 1. Alice publishes to DHT (includes addresses) - 2. Bob publishes to DHT (includes addresses) - 3. Both find each other in DHT - 4. Both attempt connection +MWP (with Bundled STUN): + 1. Alice queries DHT → learns public IP from response (bundled STUN) + 2. Bob queries DHT → learns public IP from response (bundled STUN) + 3. Alice publishes to DHT (includes addresses) + 4. Bob publishes to DHT (includes addresses) + 5. Both find each other in DHT + 6. Both attempt connection -Difference: No STUN (addresses from observation), no signaling (DHT is signaling) +Difference: No STUN (bundled into DHT responses), no signaling (DHT is signaling) ``` | Aspect | STUN+Signaling | MWP |