Build and fix the web UI flow for Polytoria: a local web server that lets users browse local .poly game files, host/join game servers, and discover remote Polytoria nodes over a global DHT network.
- Serialization fix: Added
PropertyNamingPolicy = JsonNamingPolicy.CamelCasetoBroadcastWsMessageandget_servershandler soServerInfomatches frontend's camelCase. - WebSocket upgrade fix: Replaced custom 101 handshake with
HttpListenerContext.AcceptWebSocketAsync(null). RefactoredWebSocketConnectionto wrapSystem.Net.WebSockets.WebSocket. - Recursive loop fix:
SignalClient.JoinServerwas calling HTTP POST →HandleJoinServer→ServerJoinRequested→P2PManager.JoinServer→SignalClient.JoinServer. Changed to read DHT directly. - Missing Ip/Port: DHT entry was stored before
CreateP2Pset Ip/Port. Added DHT update afterStartGameAsHost→CreateP2P. - UI restructure: Removed standalone Servers tab; merged into Games tab as "Created" (local
.poly) and "Other" (DHT-discovered servers). - KRPC (BitTorrent Mainline DHT): Added
Bencode.csfor bencoding, KRPC handlers (ping,find_node,get_peers,announce_peer) inKademliaDHT.cs. Node announces onSHA1("polytoria-dht-v1")info_hash and discovers other Polytoria nodes viaget_peers→ token →announce_peerexchange. Discovered nodes stored asserver:dht:<ip>:<port>entries so they appear in the "Other" section. - Build script: Created
build.shfor exporting standalone executables for Linux and Windows.
- Local-only for now: DHT only reads from local in-memory storage. Full network DHT lookup via KRPC is implemented but relies on the BitTorrent Mainline DHT for peer discovery.
- Web UI as Godot overlay: Web UI runs on localhost:24222, served by a
HttpListenerembedded in the Godot process. - Hybrid architecture: KRPC (BitTorrent DHT protocol) for public peer discovery on a fixed info_hash; custom binary protocol for private server listing/game communication between discovered peers.
- Token exchange: Proper
get_peers→ token →announce_peerflow per BitTorrent DHT spec.
Polytoria/scripts/network/p2p/WebServer.cs— HTTP API and WebSocket serverPolytoria/scripts/network/p2p/KademliaDHT.cs— DHT node with KRPC supportPolytoria/scripts/network/p2p/Bencode.cs— Bencoding encoder/decoderPolytoria/scripts/network/p2p/SignalClient.cs— HTTP client for server operationsPolytoria/scripts/network/p2p/P2PManager.cs— Orchestrates DHT, WebServer, SignalClientPolytoria/scripts/network/p2p/WebUIEntry.cs— React SPA entry point with webviewPolytoria/scripts/network/p2p/userdata/webui/— React frontend sourcePolytoria/export_presets.cfg— Export presets for Linux/Windowsbuild.sh— Build script for standalone executables
- Export requires Godot 4.6.2 mono + export templates installed locally
- DHT bootstrap will error if no internet or UDP port is blocked
- Token secret rotates hourly; in-flight announce_peer queries between rotation may fail (graceful)
- "Other" section only shows discovered nodes with
(DHT)as hostname — real server names require querying the discovered node's binary protocol endpoint