bidirectional ip reflection for listener address discovery
This commit is contained in:
@@ -366,9 +366,9 @@ MWP eliminates the need for external STUN servers through **IP Reflection**:
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ BUNDLED STUN │
|
||||
│ │
|
||||
│ UNIDIRECTIONAL (Response-based): │
|
||||
│ 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. │
|
||||
│ source address. │
|
||||
│ │
|
||||
│ Alice ──── DHT_REQUEST ───────────────> DHT Node │
|
||||
│ src: 192.0.2.1:54321 │
|
||||
@@ -376,24 +376,49 @@ MWP eliminates the need for external STUN servers through **IP Reflection**:
|
||||
│ Alice <─── DHT_RESPONSE ─────────────── DHT Node │
|
||||
│ observed_addr: 192.0.2.1:54321 │
|
||||
│ │
|
||||
│ Now Alice knows her public IP:port without any STUN! │
|
||||
│ BIDIRECTIONAL (Request-based): │
|
||||
│ Every DHT request includes the target's observed address. │
|
||||
│ This solves the "listener problem". │
|
||||
│ │
|
||||
│ Bob ──── DHT_REQUEST ────────────────> Alice │
|
||||
│ target_observed_addr: 203.0.113.5:18100 │
|
||||
│ │
|
||||
│ Alice learns her address from Bob's request! │
|
||||
│ No need to query anyone - just receive requests. │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**Wire Format:**
|
||||
**Wire Format (Response - Unidirectional):**
|
||||
|
||||
Each DHT response (FIND_NODE_RESPONSE, STORE_RESPONSE, FIND_VALUE_RESPONSE)
|
||||
includes:
|
||||
includes the requester's observed address:
|
||||
|
||||
```
|
||||
+--------+--------+--------+--------+--------+--------+
|
||||
| observed_addr (18 bytes) | addr_len (1 byte)|
|
||||
+--------+--------+--------+--------+--------+--------+
|
||||
+--------+--------+--------+
|
||||
| addr_len (1 byte) | observed_addr (0-18 bytes, variable) |
|
||||
+--------+--------+--------+
|
||||
|
||||
IPv4: 4 bytes IP + 2 bytes port = 6 bytes (addr_len = 6)
|
||||
IPv6: 16 bytes IP + 2 bytes port = 18 bytes (addr_len = 18)
|
||||
IPv4: addr_len=6, then 4 bytes IP + 2 bytes port
|
||||
IPv6: addr_len=18, then 16 bytes IP + 2 bytes port
|
||||
None: addr_len=0 (no address data follows)
|
||||
```
|
||||
|
||||
**Wire Format (Request - Bidirectional):**
|
||||
|
||||
Each DHT request (FIND_NODE, STORE, FIND_VALUE) includes the target's
|
||||
observed address:
|
||||
|
||||
```
|
||||
+--------+--------+--------+
|
||||
| target_addr_len (1 byte) | target_observed_addr (0-18 bytes) |
|
||||
+--------+--------+--------+
|
||||
|
||||
Same encoding as response observed_addr.
|
||||
```
|
||||
|
||||
This bidirectional approach ensures that listeners (who never send requests)
|
||||
can still discover their public address from incoming requests.
|
||||
|
||||
**Benefits:**
|
||||
|
||||
| Aspect | Traditional STUN | Bundled STUN |
|
||||
@@ -425,6 +450,38 @@ def on_dht_response(response):
|
||||
address_cache.update(my_public_addr)
|
||||
```
|
||||
|
||||
### 6.7 IP Reflection Trust Model
|
||||
|
||||
IP Reflection provides address discovery, not security. Applications should
|
||||
understand the trust implications:
|
||||
|
||||
| Observers | Confidence | Meaning |
|
||||
|-----------|------------|---------|
|
||||
| 0 | `none` | No address discovered yet |
|
||||
| 1 | `single_source` | One peer reported; likely correct but unverified |
|
||||
| 2+ agree | `consensus` | Multiple peers agree; high confidence |
|
||||
| 2+ disagree | `conflict` | Peers disagree; using majority |
|
||||
|
||||
**API Usage:**
|
||||
|
||||
```zig
|
||||
const result = p2p_node.getConsensusAddress();
|
||||
switch (result.confidence) {
|
||||
.none => // Wait for peers
|
||||
.single_source => // Works but unverified
|
||||
.consensus => // High confidence
|
||||
.conflict => // Investigate or use fallback
|
||||
}
|
||||
```
|
||||
|
||||
**Important:** IP Reflection only answers "what address should I advertise?"
|
||||
The Noise protocol handshake provides the actual security - cryptographic
|
||||
proof of identity. Even with a wrong address, an attacker cannot impersonate
|
||||
a peer without their private key.
|
||||
|
||||
See [IP Reflection Trust Model](../ip-reflection-trust.md) for detailed
|
||||
security analysis and application guidance.
|
||||
|
||||
---
|
||||
|
||||
## 7. Edge Cases & Mitigations
|
||||
|
||||
Reference in New Issue
Block a user