bidirectional ip reflection for listener address discovery
This commit is contained in:
@@ -43,30 +43,46 @@ MWP eliminates all three by having peers **witness each other**:
|
||||
|
||||
### 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:
|
||||
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)
|
||||
|
||||
Now Alice knows her public IP without any STUN server!
|
||||
```
|
||||
|
||||
**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
|
||||
|
||||
```zig
|
||||
const mwp = @import("mwp");
|
||||
|
||||
// Initialize with your DHT and keypair
|
||||
var witness = mwp.MutualWitness.init(allocator, dht, keypair);
|
||||
// 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 connection = try witness.connect(target_pubkey, .{
|
||||
const result = witness.connect(target_pubkey, .{
|
||||
.timeout_ms = 5000,
|
||||
});
|
||||
|
||||
// Use connection...
|
||||
defer connection.close();
|
||||
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
|
||||
@@ -106,7 +122,9 @@ defer connection.close();
|
||||
|
||||
- [SPEC.md](./SPEC.md) - Complete protocol specification
|
||||
- [COMPARISON.md](./COMPARISON.md) - Detailed comparison with existing solutions
|
||||
- [src/](./src/) - Implementation
|
||||
- [IP_REFLECTION_PERFORMANCE.md](./IP_REFLECTION_PERFORMANCE.md) - Wire format optimization details
|
||||
- [../ip-reflection-trust.md](../ip-reflection-trust.md) - Trust model and security analysis
|
||||
- [src/mwp/](../../src/mwp/) - Implementation
|
||||
|
||||
## Use Cases
|
||||
|
||||
|
||||
Reference in New Issue
Block a user