4.1 KiB
NAT Traversal Testing for MWP
This directory contains a Docker-based NAT simulation environment for testing the Mutual Witness Protocol (MWP) NAT traversal capabilities.
Network Topology
┌─────────────────── public (10.200.0.0/24) ───────────────────┐
│ │
│ bootstrap (10.200.0.10) - Rendezvous/DHT node │
│ │ │
│ ┌────┴────┐ ┌─────────┐ │
│ │ nat1 │ 10.200.0.2 │ nat2 │ 10.200.0.3 │
│ │ gateway │ │ gateway │ │
│ └────┬────┘ └────┬────┘ │
└───────┼────────────────────────────────────┼─────────────────┘
│ │
│ NAT (MASQUERADE) │ NAT (MASQUERADE)
│ │
┌───────┴───────┐ ┌───────┴───────┐
│ private_alice │ │ private_bob │
│ (10.201.0.0) │ │ (10.202.0.0) │
│ │ │ │
│ alice │ │ bob │
│ 10.201.0.10 │ │ 10.202.0.10 │
└───────────────┘ └───────────────┘
Quick Start
# Run the full NAT traversal test
./run-nat-test.sh
Manual Testing
# Build the image
docker-compose build
# Start NAT gateways
docker-compose up -d nat1 nat2
# Start bootstrap node
docker-compose up -d bootstrap
# Get bootstrap DHT ID
docker-compose logs bootstrap | grep "DHT Node ID"
# Start peers with the DHT ID
export BOOTSTRAP_DHT_ID=<id-from-above>
docker-compose up alice bob
# View logs
docker-compose logs -f alice bob
What This Tests
-
DHT Discovery: Can Alice and Bob find each other's publications through the DHT when they're behind different NATs?
-
IP Reflection: Does the bootstrap node correctly report the NAT's public IP:port to each peer?
-
Hole Punching: Can Alice and Bob establish a direct UDP connection through both NATs?
Expected Results
DHT Discovery: Should PASS
Both peers should be able to publish and find each other's MWP publications via the DHT through the bootstrap node.
Hole Punching: May FAIL
Docker's iptables-based NAT typically implements symmetric NAT or port-restricted cone NAT, which makes UDP hole punching difficult or impossible without:
- A relay server (TURN)
- Protocol extensions for symmetric NAT traversal
This is expected behavior and matches real-world scenarios where some NAT types require relay fallback.
NAT Types
| NAT Type | Hole Punch Success Rate |
|---|---|
| Full Cone | ~100% |
| Restricted Cone | ~90% |
| Port-Restricted Cone | ~60% |
| Symmetric | ~10% (needs prediction) |
Docker's NAT is typically port-restricted cone or symmetric.
Troubleshooting
"Cannot connect to bootstrap"
- Check that nat1/nat2 gateways are running and healthy
- Verify routing tables in alice/bob containers:
docker-compose exec alice ip route
"DHT FIND_VALUE not found"
- Ensure bootstrap node has the publications stored
- Check that both peers are using the correct bootstrap DHT ID
- Verify
p2p.update()is being called (see CLAUDE.md)
"Hole punch timeout"
- This is expected for symmetric NAT
- The DHT discovery should still work
- Future: implement relay fallback
Files
Dockerfile- Builds the mwp-demo binarydocker-compose.yml- Defines the network topologyrun-nat-test.sh- Automated test script