← All Workshops

MudEngine Part 11: Peer-to-Peer with iroh

From Fullstack to P2P

In Parts 6–10 the MudEngine always had a server. First it was Axum fullstack (dx serve); from Part 10 onwards a native Blitz client dialed that server over a WebSocket. Some process somewhere owned the GameState, validated moves, and broadcast updates — and in every case that process was a server you had to start and deploy.

This part deletes the server entirely. Instead the game lives on the host's own desktop app and travels to the other players over a peer-to-peer mesh built on iroh. If you want to understand the mesh pieces, the iroh docs and iroh-gossip are the best deep dives.

For the iroh APIs used here, the crate docs at docs.rs/iroh and docs.rs/iroh-gossip are the best references.

How the mesh works

  • The host's desktop app runs the authoritative GameEngine — the same can_move(), quest, inventory, and save logic from Parts 7–9, now transport- agnostic. It is a referee, not a player: it never joins under a player name.
  • Each process is an iroh Endpoint — a QUIC endpoint identified by a node id (the public half of an Ed25519 key).
  • Everyone subscribes to one gossip topic. The host's engine answers every player's request and broadcasts the resulting ServerMessages to the mesh. Players just render whatever the host broadcasts.
  • Desktop peers find the host without a hardcoded address: the client dials the host's node id, mDNS resolves its LAN address, and iroh's relay network is the fallback when direct dialing fails (NATs, VPNs, different networks).

No central server. No fullstack. No dx serve for the desktop app — it runs with plain cargo run.

What changes from Part 10

  • dioxus/fullstack, dioxus-fullstack, the server feature, Axum, and the whole src/game/server/ module are removed
  • iroh is added — Endpoint (QUIC), Gossip (plumtree pub-sub), mDNS address lookup
  • The game handlers move from the server module into a transport-agnostic GameEngine in engine.rs that returns Vec<ServerMessage> instead of writing to sockets
  • A join handshake (ClientMessage::Join) is added so the host knows who each gossiper is
  • Browsers still build, behind a cfg(target_arch = "wasm32") stub — the WebSocket relay that would connect them to the mesh is a step 2 of this part (see the relay step)
"💻 Host (desktop, owns the world)" "Player (desktop)" "Player (browser) — step 2" "QUIC + gossip" "step 2 bridge" "WebSocket" Dioxus UI (Blitz) GameEngine can_move / quest / save iroh Endpoint + gossip topic Dioxus UI (Blitz) iroh Endpoint + gossip topic Dioxus UI (web) WebSocket relay
🔍 Roles on the mesh
RoleWhat it doesIdentity
HostOwns the GameEngine, answers every request, broadcasts resultsPersistent host.secret (node id survives restarts)
Desktop peerDials the host's node id, renders broadcasts, sends requestsEphemeral key generated per launch
BrowserCannot open UDP sockets — reaches the mesh via the WebSocket relay (step 2)n/a (uses the relay's address)