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 samecan_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, theserverfeature, Axum, and the wholesrc/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
GameEngineinengine.rsthat returnsVec<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)
| Role | What it does | Identity |
|---|---|---|
| Host | Owns the GameEngine, answers every request, broadcasts results | Persistent host.secret (node id survives restarts) |
| Desktop peer | Dials the host's node id, renders broadcasts, sends requests | Ephemeral key generated per launch |
| Browser | Cannot open UDP sockets — reaches the mesh via the WebSocket relay (step 2) | n/a (uses the relay's address) |