Files
zigp2p/docs/mwp/COMPARISON.md
2026-02-07 18:01:12 -03:00

18 KiB
Raw Permalink Blame History

MWP vs Existing Solutions: Detailed Comparison

Version: 1.0.0 Created: February 2026


Executive Summary

Solution Infrastructure Latency Success Rate Decentralization
MWP DHT only ~1-2s ~70% Full
DCUtR Relay nodes ~2s ~70% Partial
STUN+Signaling 2 servers ~1-2s ~80% Low
ICE/TURN 3+ servers ~2-5s ~95% Low

1. Protocol Flow Comparison

1.1 DCUtR (libp2p)

┌─────────────────────────────────────────────────────────────┐
│                        DCUtR FLOW                            │
│                                                              │
│  Alice                    Relay                    Bob       │
│    │                        │                        │       │
│    │─── Connect ───────────>│                        │       │
│    │                        │<─── Connect ───────────│       │
│    │                        │                        │       │
│    │─── CONNECT msg ───────>│                        │       │
│    │                        │─── CONNECT msg ───────>│       │
│    │                        │<─── CONNECT msg ───────│       │
│    │<─── CONNECT msg ───────│                        │       │
│    │                        │                        │       │
│    │      (Relay measures RTT between messages)      │       │
│    │                        │                        │       │
│    │─── SYNC msg ──────────>│                        │       │
│    │   (wait RTT/2)         │                        │       │
│    │                        │─── SYNC msg ──────────>│       │
│    │                        │                        │       │
│    │<════════════ hole punch attempt ═══════════════>│       │
│    │                        │                        │       │
│                                                              │
│  Messages: 6 (via relay)                                     │
│  Round trips: 3                                              │
│  Infrastructure: Relay node(s)                               │
└─────────────────────────────────────────────────────────────┘

1.2 STUN + Signaling Server

┌─────────────────────────────────────────────────────────────┐
│                   STUN + SIGNALING FLOW                      │
│                                                              │
│  Alice          STUN      Signaling        STUN      Bob    │
│    │              │           │              │         │    │
│    │─ Binding ───>│           │              │         │    │
│    │<─ Response ──│           │              │         │    │
│    │              │           │              │<─ Bind ─│    │
│    │              │           │              │─ Resp ─>│    │
│    │              │           │              │         │    │
│    │───────── SDP Offer ─────>│              │         │    │
│    │              │           │──── Offer ──────────> │    │
│    │              │           │<─── Answer ───────────│    │
│    │<──────── SDP Answer ─────│              │         │    │
│    │              │           │              │         │    │
│    │<══════════════ hole punch ══════════════════════>│    │
│    │              │           │              │         │    │
│                                                              │
│  Messages: 8 (4 STUN + 4 signaling)                         │
│  Round trips: 3                                              │
│  Infrastructure: STUN server + Signaling server              │
└─────────────────────────────────────────────────────────────┘

1.3 Full ICE with TURN

┌─────────────────────────────────────────────────────────────┐
│                      FULL ICE FLOW                           │
│                                                              │
│  Alice        STUN    TURN    Signal    TURN    STUN   Bob  │
│    │           │       │        │        │       │      │   │
│    │─ Bind ───>│       │        │        │       │      │   │
│    │<─ Resp ───│       │        │        │       │<Bind─│   │
│    │─ Alloc ─────────>│        │        │       │      │   │
│    │<─ Relay ─────────│        │        │       │      │   │
│    │           │       │        │        │<─ Alloc ─────│   │
│    │           │       │        │        │─ Relay ─────>│   │
│    │           │       │        │        │       │      │   │
│    │─────────── SDP Offer ─────>│        │       │      │   │
│    │           │       │        │──────────────────────>│   │
│    │           │       │        │<──────────────────────│   │
│    │<────────── SDP Answer ─────│        │       │      │   │
│    │           │       │        │        │       │      │   │
│    │     (ICE connectivity checks - multiple paths)    │   │
│    │           │       │        │        │       │      │   │
│    │<══════════════ connection (direct or relayed) ═══>│   │
│    │           │       │        │        │       │      │   │
│                                                              │
│  Messages: 10+ (STUN + TURN + Signaling + ICE checks)       │
│  Round trips: 5+                                             │
│  Infrastructure: STUN + TURN + Signaling                     │
└─────────────────────────────────────────────────────────────┘

1.4 Mutual Witness Protocol

┌─────────────────────────────────────────────────────────────┐
│                        MWP FLOW                              │
│                                                              │
│  Alice                      DHT                      Bob    │
│    │                         │                         │    │
│    │─── PUT(key, pub_A) ────>│                         │    │
│    │                         │<─── PUT(key, pub_B) ────│    │
│    │                         │                         │    │
│    │<─── GET(key) ──────────>│<─────── GET(key) ──────>│    │
│    │  (returns pub_A, pub_B) │                         │    │
│    │                         │                         │    │
│    │  (compute shared params locally)                  │    │
│    │  (wait until rendezvous_time)                     │    │
│    │                         │                         │    │
│    │<══════════════ hole punch attempt ═══════════════>│    │
│    │                         │                         │    │
│                                                              │
│  Messages: 4 (2 PUT + 2 GET)                                │
│  Round trips: 1-2                                            │
│  Infrastructure: DHT only (already exists in P2P network)   │
└─────────────────────────────────────────────────────────────┘

2. Infrastructure Comparison

2.1 Required Components

Component DCUtR STUN+Signal ICE/TURN MWP
DHT Yes No No Yes
Relay nodes Yes No Yes (TURN) No
STUN server No Yes Yes No
Signaling server No Yes Yes No
Bootstrap nodes Yes N/A N/A Yes

2.2 Operational Costs

Cost Factor DCUtR STUN+Signal ICE/TURN MWP
Server hosting High (relay BW) Medium High Zero
Bandwidth Relay traffic Minimal Relay traffic Zero
Maintenance Relay health Server uptime All servers DHT only
Scaling Per-user relay Central bottleneck Per-user TURN Distributed

2.3 Who Pays?

Solution Who Runs Infrastructure Who Pays
DCUtR Protocol developers, volunteers Unclear (altruism)
STUN+Signal Application developers Application owner
ICE/TURN Cloud providers (Twilio, etc.) Per-minute fees
MWP P2P participants Nobody (self-sustaining)

3. Performance Comparison

3.1 Latency Breakdown

DCUtR:

Connect to relay:           100-500ms
CONNECT exchange:           2 × RTT to relay (~200ms)
SYNC + wait:                RTT/2 (~100ms)
Hole punch:                 50-200ms
────────────────────────────────────────
Total:                      ~1-2 seconds

STUN + Signaling:

STUN binding (both):        2 × 50ms = 100ms
SDP offer/answer:           2 × RTT to server (~200ms)
Hole punch:                 50-200ms
────────────────────────────────────────
Total:                      ~500ms - 1.5 seconds

MWP:

DHT PUT:                    100-500ms
DHT GET (poll):             100-500ms
Wait for rendezvous:        500ms (configurable)
Hole punch:                 50-200ms
────────────────────────────────────────
Total:                      ~1-2 seconds

3.2 Latency by Scenario

Scenario DCUtR STUN+Signal MWP
Best case (fast network) 800ms 400ms 600ms
Typical 2s 1.5s 1.5s
Slow DHT/relay 5s 3s 3s
Retry needed 4s 3s 3s

3.3 Success Rates

NAT Type DCUtR STUN+Signal ICE/TURN MWP
Full Cone 95% 95% 99% 95%
Restricted Cone 85% 85% 99% 85%
Port Restricted 70% 75% 99% 70%
Symmetric 50%* 30% 99%* 30%

*DCUtR and ICE fall back to relay for symmetric NAT

3.4 Bandwidth Usage

Solution Control Overhead Data Path
DCUtR ~2KB via relay Direct
STUN+Signal ~3KB (SDP) Direct
ICE/TURN ~5KB + relay Direct or relayed
MWP ~500 bytes Direct

4. Security & Privacy Comparison

4.1 Trust Requirements

Solution Who You Trust
DCUtR Relay nodes (see connection metadata)
STUN+Signal STUN server, Signaling server
ICE/TURN All of above + TURN operator
MWP DHT nodes (see meeting key only)

4.2 Metadata Exposure

Data DCUtR STUN+Signal MWP
Your IP Relay sees Servers see DHT sees
Peer's IP Relay sees Servers see DHT sees
Connection timing Relay sees Servers see DHT sees
Who connects to whom Relay knows Signaling knows Hashed (meeting key)
Connection content Encrypted Encrypted Encrypted

4.3 Attack Resistance

Attack DCUtR STUN+Signal MWP
Server compromise Metadata leak Metadata leak N/A
Relay DoS Connection fails N/A N/A
DHT eclipse Works (relay) Works Degraded
Meeting point squat N/A N/A Signatures protect

5. Decentralization Analysis

5.1 Centralization Points

DCUtR:
├── Relay nodes (must be online)
├── Relay selection (could be gamed)
└── Relay operators (trust required)

STUN+Signaling:
├── STUN server (Google's, etc.)
├── Signaling server (you run)
└── Single point of failure each

ICE/TURN:
├── STUN servers
├── TURN servers (expensive, central)
├── Signaling server
└── Maximum centralization

MWP:
└── DHT (distributed among all participants)
    └── No single point of failure

5.2 Censorship Resistance

Solution Blocking Difficulty
DCUtR Block relay IPs
STUN+Signal Block server IPs
ICE/TURN Block any server
MWP Must block all DHT nodes

5.3 Failure Modes

If This Fails... DCUtR STUN+Signal MWP
One relay Use another N/A N/A
All relays Total failure N/A N/A
STUN server N/A Total failure N/A
Signaling server N/A Total failure N/A
Some DHT nodes Works Works Works
DHT partitioned Works (relay) Works Degraded

6. Implementation Complexity

6.1 Lines of Code (Estimated)

Component DCUtR STUN+Signal MWP
Core protocol 2000 1500 1000
Server/relay 3000 2000 0
DHT integration 500 0 500
NAT detection 500 1000 300
Total 6000 4500 1800

6.2 Dependencies

Solution External Dependencies
DCUtR libp2p, relay protocol
STUN+Signal STUN lib, WebSocket, SDP parser
ICE/TURN libnice/pion, full ICE stack
MWP DHT (already in P2P stack)

6.3 Testing Complexity

Aspect DCUtR STUN+Signal MWP
Unit testing Medium Medium Easy
Integration testing Hard (relay) Hard (servers) Medium
E2E testing Hard Hard Medium
Reproducing NAT Hard Hard Hard

7. Use Case Suitability

7.1 When to Use Each

Use DCUtR when:

  • Already using libp2p
  • Have relay infrastructure
  • Need proven solution
  • 70% success rate acceptable

Use STUN+Signaling when:

  • Building WebRTC application
  • Have server infrastructure
  • Need browser support
  • Can run signaling server

Use ICE/TURN when:

  • Need 95%+ success rate
  • Can pay for TURN servers
  • Symmetric NAT support critical
  • Browser + native interop needed

Use MWP when:

  • Zero infrastructure requirement
  • True decentralization priority
  • Building censorship-resistant app
  • Already have DHT
  • Privacy important (minimal metadata)

7.2 Application Fit

Application Best Solution
Video calling ICE/TURN
WebRTC P2P STUN+Signaling
libp2p apps DCUtR
Decentralized apps MWP
Censorship-resistant MWP
Zero-server P2P MWP
IoT mesh MWP

8. Migration Path

8.1 From STUN+Signaling to MWP

Step 1: Add DHT to your stack
Step 2: Implement MWP alongside existing
Step 3: Try MWP first, fall back to STUN
Step 4: Gradually remove STUN dependency
Step 5: Pure MWP (optional)

8.2 From DCUtR to MWP

Step 1: Already have DHT (libp2p includes it)
Step 2: Implement MWP
Step 3: Try MWP first, fall back to DCUtR
Step 4: Keep DCUtR for symmetric NAT fallback
fn connect(target: PeerId) !*Connection {
    // 1. Try MWP (no infrastructure needed)
    if (mwp.connect(target)) |conn| return conn;

    // 2. Fall back to DCUtR (if relays available)
    if (dcutr.connect(target)) |conn| return conn;

    // 3. Last resort: TURN relay (if configured)
    if (turn.connect(target)) |conn| return conn;

    return error.AllMethodsFailed;
}

9. Conclusion

9.1 Summary Matrix

Criterion DCUtR STUN+Signal ICE/TURN MWP
No servers No No No Yes
Decentralized Partial No No Yes
Success rate 70% 80% 95% 70%
Latency 2s 1.5s 2-5s 1.5s
Complexity Medium Medium High Low
Battle-tested Yes Yes Yes No
Privacy Medium Low Low High

9.2 Recommendation

For new decentralized P2P applications:

  1. Implement MWP as primary connection method
  2. Add DCUtR fallback for symmetric NAT
  3. Consider TURN only if 95%+ success required

For existing applications:

  1. Add MWP alongside existing solution
  2. Use MWP when both peers support it
  3. Fall back to existing method otherwise

9.3 Future Work

Enhancement Impact
Symmetric NAT prediction Higher success rate
DHT privacy (onion routing) Better privacy
Multi-path probing Faster connection
Machine learning NAT prediction Better port guessing

End of Comparison Document