Skip to content

Rooms by code over Atyha: no master for a join code, optional password - #41

Closed
itxtoledo wants to merge 8 commits into
mainfrom
feat/p2p-atyha
Closed

itxtoledo wants to merge 8 commits into
mainfrom
feat/p2p-atyha

Conversation

@itxtoledo

Copy link
Copy Markdown
Contributor

A listen server's join code no longer goes through the master: it opens the match's room on public Nostr relays with Atyha (MIT, vendored in common/atyha until it becomes a submodule), and friends join over WebRTC as browsers already did.

What changes

  • --join-code is 8 symbols, XXXX-XXXX (25-symbol alphabet, no look-alikes; netlib's p2p.c follows Atyha's rule).
  • Net/Room.c: the room (Atyha host), polled on the tick. Offers go to Net/WebRtc.c as the master's do; answers and refusals go back through the room. The log says Room <code> open (the client reads it).
  • SP_JOIN_PASSWORD: an optional room password (CPace: relays cannot test guesses; a host answers 20 hellos a minute).
  • The master is never told the code. A private listen server is not announced at all; --public lists it as before.
  • A room's friend has no address until ICE finds it: its own key meanwhile (the per-address limit no longer counts every friend as one), and the real address from the selected candidate at connect, where bans and the limit read it.
  • The relays' WebSocket is libdatachannel's own (NO_WEBSOCKET OFF).
  • New dependency: libsodium. CI (Ubuntu, macOS), the Alpine and MSYS2 release builds and tools/server_deps_macos.sh (1.0.20 static, SHA-256 checked) install it.

Checked locally (macOS)

  • make server (Release, -Werror), and the client against it (paired client PR).
  • Native server room with a password: TypeScript, Go, C# and Godot joiners connect over the real relays and get the 1.0 Greeting; a wrong password is refused; the desktop client joins (wrong password → password screen → right one → in the match).
  • Not checked: the Alpine static build (the local container could not reach Alpine's package mirror) and MSYS2; this PR's CI covers Ubuntu and macOS.

This PR runs CI (ci.yml runs on pull_request).

…word

A listen server's join code (--join-code, now 8 symbols XXXX-XXXX) opens
the match's room on public Nostr relays through Atyha (common/atyha, MIT,
github.com/ngspades/atyha), Net/Room.c. A friend's offer comes from the
room, Net/WebRtc.c answers it as it answers the master's, and the answer
goes back through the relays. SP_JOIN_PASSWORD gives the room a password
(CPace: the relays cannot test guesses, a host answers 20 hellos a minute).
The log says "Room <code> open" once a relay confirmed it.

The master is no longer told the code: a private listen server is not
announced at all, a public one is listed as before. A room's friend has no
address until ICE finds it: a key of its own until then (the per-address
limit no longer lumps every friend under 0), the real address from the
selected candidate at "connect", where bans and the limit read it.

netlib's p2p.c follows Atyha's code rule (8 symbols, the 25-symbol
alphabet, white space trimmed); transport.h carries the room's password and
the wrong-password flag for the client. The WebSocket to the relays is
libdatachannel's own (NO_WEBSOCKET off). libsodium is a new dependency:
CI (Ubuntu, macOS), the Alpine and MSYS2 release builds and
server_deps_macos.sh (1.0.20, static, SHA-256 checked) install it.
…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.
p2p_code_norm takes a room link, ngspades://HK4M-7TRW in any case and with
the trailing slash a browser may add: the game's desktop builds register
the scheme. sadcode:// (Shoot and Destroy's) is gone.
WebRTC direct: browsers join listed servers with no offer; the master is a list
Join codes: ngspades:// links in place of sadcode://
common/atyha is the Atyha repository at c96b71d (its main), the C library
in its c/; the copy it replaces was the same files. CI and the releases
already check submodules out recursively.
@itxtoledo

Copy link
Copy Markdown
Contributor Author

Superseded by the PR that ports these features onto ngnet (the server moved to ngnet in #38).

@itxtoledo itxtoledo closed this Nov 30, 2026
@itxtoledo
itxtoledo deleted the feat/p2p-atyha branch November 30, 2026 22:34
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