Skip to content

WebRTC direct: browsers join listed servers with no offer; the master is a list - #42

Merged
itxtoledo merged 1 commit into
feat/p2p-atyhafrom
feat/webrtc-direct
Nov 30, 2026
Merged

itxtoledo merged 1 commit into
feat/p2p-atyhafrom
feat/webrtc-direct

Conversation

@itxtoledo

Copy link
Copy Markdown
Contributor

Stacked on #41 (base feat/p2p-atyha): merge #41 first, then retarget this one to main.

What: a browser joins a listed server by WebRTC direct (libp2p's webrtc-direct technique). It builds this server's SDP answer itself from the master's row (identifier/identifier6, webrtc_port, dtls_fingerprint), with its own ICE ufrag = pwd = a random R; the server recognises the first STUN request (USERNAME R:R) through libdatachannel's IceUdpMuxListener and makes the peer then. No offer goes through the master any more.

  • RtcPeer.cpp: rtcw_direct_listen (the listener, events on the tick as everything else), rtcw_peer_create_direct (synthetic offer from R and the browser's address, answer with R via LocalDescriptionInit, disableFingerprintVerification); peer creation shared with the room's offers.
  • WebRtc.c: bans, server full and a per-address limit are read at the first STUN request, before anything is made (earlier than before); one peer per R however many times the browser repeats.
  • Master.c: the long poll, /v1/answer and master_answer/master_reject are gone (and their two lanes). The master only lists.
  • The log prints the certificate fingerprint.

Security: the browser checks the server's DTLS certificate against the listed fingerprint (a wrong one fails: tested); the server does not authenticate browsers, as before (anyone may join a public server).

Tested locally: Chrome, Safari 27.3, Firefox 153 (open in 56–194 ms, the 1.0 Greeting received), and the game's browser build joining a dedicated server (connect → joined in ~150 ms). Firefox does not use loopback ICE, so its test used the LAN address.

Pairs with the client PR and the master PR (row gets webrtc_port, signalling routes removed). This PR runs CI.

…r is a list

A browser builds this server's answer itself from the master's row
(address, webrtc_port, dtls_fingerprint), the way libp2p's webrtc-direct
does: its offer's ICE username and password are one random string R, and
its first STUN request (USERNAME "R:R") reaches libdatachannel's
IceUdpMuxListener on the WebRTC port (rtcw_direct_listen). Net/WebRtc.c
reads bans, "server full" and the per-address limit (4 joining) on that
request, before anything is made; rtcw_peer_create_direct then answers a
synthetic offer (R as ufrag and password, the browser's address as its
candidate, DTLS client) with R, not checking the browser's certificate
(anyone may join a public server); the browser checks ours against the
listed fingerprint. From there it is the same peer as before.

The master's signalling is gone: no long poll, no /v1/answer, no
master_answer/master_reject, the two lanes they used. Offers now come only
from a match's room (Net/Room.c). The log shows the certificate's
fingerprint. Checked with Chrome, Safari 27.3 and Firefox 153 (connection
open in 56 to 194 ms, the 1.0 Greeting received) and with the game's own
browser build; a wrong fingerprint fails, as it must.
@itxtoledo
itxtoledo merged commit 10f0222 into feat/p2p-atyha Nov 30, 2026
2 checks passed
@itxtoledo
itxtoledo deleted the feat/webrtc-direct branch November 30, 2026 21:39
@itxtoledo
itxtoledo restored the feat/webrtc-direct branch November 30, 2026 21:42
@itxtoledo
itxtoledo deleted the feat/webrtc-direct branch November 30, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant