calibur
Back to Inventory
In ProgressNetworking / Game Tooling

SimpleP2P

Peer-to-peer Minecraft hosting — share a code, no port forwarding, no IP exposure.

Java 21Fabric APIPythonFastAPIWebSocketsUDP Hole PunchingSTUN (RFC 5389)Netty

The Problem

Minecraft multiplayer with friends means renting a server, exposing your real IP via port forwarding, or paying for Realms. Configuration is complex, security risk is real, and dedicated servers are pricey — most casual groups just give up on multiplayer.

The Solution

SimpleP2P is a Fabric mod plus FastAPI signaling server that lets you /host a world, hand a friend a human-readable code (p2p.happy-llama-42), and connect over a direct UDP-tunneled P2P link. Game data never touches the signaling server — it only coordinates the hole punch.

Key Features

  • /host command generates a share code in-game, zero setup
  • TCP-over-reliable-UDP tunneling with sequence numbers and ACKs
  • Hand-rolled STUN (RFC 5389) for true public WAN IP discovery
  • Endpoint racing — tries WAN + LAN endpoints simultaneously
  • Birthday Paradox NAT piercer for symmetric NATs (512 sockets)
  • Optional persistent share codes for recurring hosts
  • 30-second WebSocket heartbeat auto-cleans dead sessions

Technical Challenges

01 · UDP Hole Punching Coordination

NATs block incoming UDP from unknown sources by default. Solution: the signaling server coordinates a simultaneous punch — host and client each send UDP toward the other's endpoint, opening reciprocal pinholes that allow direct P2P traffic thereafter.

02 · Symmetric NAT — The Hardest Case

Symmetric NATs assign a new random port per outgoing destination, defeating standard hole punching. Solution: Birthday Paradox technique — 512 simultaneous UDP sockets bind to random local ports and spray packets across the peer's ephemeral range, achieving collision with high probability.

03 · Minecraft Uses TCP, NAT Traversal Uses UDP

Minecraft's protocol is TCP, but NAT traversal works over UDP. Solution: a reliable UDP layer with sequence numbers, ACKs, and retransmission, plus a TCP bridge that pipes Minecraft client ↔ UDP tunnel ↔ local Minecraft server.

04 · STUN Implementation From Scratch

No STUN libraries are available inside Minecraft's sandboxed JVM. Solution: implemented RFC 5389 binding requests from raw binary packets — sends to Google/Cloudflare STUN servers and parses the binary response for the external mapped address.

Future Scope

  • Persistent world registry for discoverable public servers
  • Relay fallback for networks that block all P2P
  • Cross-version Minecraft compatibility matrix
  • Metrics dashboard for connection success and NAT type