Skip to content

[FEAT] Replace custom NAT/LAN implementation with Iroh for reliable P2P connectivity #20

Description

@daniil-verba

🚀 [FEAT] Replace custom NAT/LAN implementation with Iroh for reliable P2P connectivity

📌 Current Limitations

Our current custom NAT/LAN implementation (src/network/lan.rs & src/network/beacon_client.rs) has critical limitations:

  • Fails to reliably establish connections with the Beacon node.
  • Lacks support for IPv6 and modern NAT traversal techniques.
  • Results in frequent connection timeouts in real-world network environments (e.g., behind strict firewalls).

🌟 Proposed Solution

Replace the custom implementation with Iroh — a battle-tested, production-ready P2P networking library.

Why Iroh?

  • ✅ Built-in NAT traversal (UPnP, STUN, TURN, and relay fallbacks).
  • ✅ Zero-config Local Area Network (LAN) discovery.
  • ✅ Production-ready and actively maintained by the team behind n0-computer.

🔧 Implementation Plan

  1. Refactor custom NAT/LAN code:

    • Rewrite/replace logic in src/network/lan.rs
    • Rewrite/replace logic in src/network/beacon_client.rs
  2. Integrate Iroh:

    # Cargo.toml
    [dependencies]
    iroh = "0.21" # (or latest stable version)
  3. Adapt the API:

    • Map undertow-protocol's peer discovery to Iroh's Node API.
    • Implement connection fallbacks.

⚠️ Potential Challenges

  • API Compatibility: Iroh is heavily async/await based, while parts of our current network code are synchronous. We will need to refactor the core networking layer to be fully async.
  • Dependency Size: Iroh adds some overhead to the binary size, but this is an acceptable trade-off for massive gains in reliability.

💡 How You Can Help

This is a great task for a first-time contributor! We need help with:

  • Research/Testing: Test Iroh in different NAT scenarios and provide test cases.
  • Refactoring: Adapt src/network/mod.rs (and related files) to Iroh's API.
  • Documentation: Update README.md with the new connectivity guarantees and setup instructions.

🙏 Why This Matters

This change will solve the #1 pain point of the project. With Iroh, undertow-protocol will finally work reliably in real-world networks, making it truly viable for decentralized applications. Let's build something that just works! 🚀

✅ Checklist Before Merging

  • All connectivity tests pass
  • No breaking changes to the public API (or clearly documented if there are)
  • Documentation updated
  • Benchmark comparison (latency/throughput) completed

💬 Discussion

What do you think about this approach?

  1. Should we fully replace the current implementation, or keep it as a fallback for now?
  2. We can break this down into smaller sub-issues to make it easier to tackle step-by-step!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions