The master server

The master’s own README is the contract (signed envelope, endpoints, errors). This is what ngnet does with it, and what a program can influence.

Identity and signing

The server’s Ed25519 key lives in memory by default: a new one, so a new row id, at every start (the old row is dropped within 90 s, or at once by the leave on shutdown). With key_file set it is made once and kept there as PEM (mode 0600); a file that cannot be written leaves the key in memory with a warning. Its public key (base64) is the server’s identity: the id of its row is the first 16 hex digits of the key’s SHA-256, so the same key keeps the same row across restarts and addresses. Every call is {"key": "<b64 public key>", "body": "<JSON text>", "sig": "<b64 Ed25519 signature of body>"}; the body gets "time" (Unix ms, strictly increasing so two calls in the same millisecond are never a replay). OpenSSL only.

If the master runs with -keys, the server’s key has to be on its allow list (the key is in the log at start and from ngnet_public_key()).

Calls

callwhen
POST /v1/announce announceat start, every 30 s, and when name, map, mode, protocol or the player counts change (at most every 5 s), once over IPv4 and once over IPv6 (CURLOPT_IPRESOLVE; a master given by IPv4 literal is announced to over IPv4 only)
POST /v1/pollone long poll per master (40 s timeout), repeated at once; the offers go to the WebRTC transport
POST /v1/answer answer / rejectwithin 8 s of an offer, over the family the poll came by
POST /v1/announce leaveon ngnet_server_stop() / enet_host_destroy (waits up to 3 s)

Several masters (ngnet_set("master", ...) repeated) are independent: each has its own announce, poll and answers. All calls run on worker threads (libcurl) and never block the caller’s tick.

The announce body

name (clipped to 64 bytes), port (the game’s UDP port), map (32), mode (16) — clipped on a UTF-8 boundary, because the master refuses longer values — protocol (any [0-9A-Za-z._-]{1,16}; other characters become _; omitted when unknown so the master’s default applies), players_current, players_max (0 to 255), country, webrtc_port, dtls_fingerprint, ice_servers (from stun, turn; at most 8), info (the HELLOINFO JSON: ngnet_set_info(info_json) or a small one built from the fields), join_code and unlisted (with join_code). The master lists the request’s source address, never one in the body.

The answer’s join_code (when asked), the connect token key (token_key) and identifier are read; the join code is logged as Join code: XXX-XXX and available from ngnet_join_code().

Reachability probe

The master probes the announced UDP port (HELLOINFO, and over ENet in parallel on current masters). The shim answers HELLOINFO from the intercept; a program with its own intercept can end it with ngnet_intercept(host, event). For local tests run the master with -probe=false and MASTER_ALLOW_PRIVATE_IPS=1.

Join codes

ngnet_set("join_code", "ABC234") (six letters and digits, none of I L O Q 0 1; p2p_code_generate() makes one) and ngnet_set("unlisted", "1"): the master maps the code to this server and relays players that present it; the WebRTC join needs no forwarded port. A match with unlisted and no join_code is not announced.

Connect tokens

The master’s POST /v1/token certificates (a game’s anti flood step) are checked with ngnet_master_token_check(nonce, cert, sig) against this server’s key and the token key from the announce answers; ngnet_master_token_trusted(120) says the key was heard recently (a master that is down must not lock players out). Whether to ask for tokens is the game’s policy.

The server list (client)

GET <master>/serverlist.json: ngnet_list_fetch, or ngnet_list_start / ngnet_list_poll for several masters without blocking, or ngnet_list_parse for a body you fetched yourself. Rows keep the classic file’s ten columns and id, key, webrtc, identifier6, dtls_fingerprint, info, ice_servers; each row’s master is the master that listed it, which is where a WebRTC join (ngnet_endpoint_t.master) goes. A classic 0.75 list URL (a path ending in .json) is read as it is.

The classic announce

A pass-through host that announces to a classic 0.75 master keeps doing it (the shim passes it through): the master takes that ENet announce too. The library additionally sniffs it and sends its own signed announce for the same server, protocol 0.75; the master hides the classic row when a signed row has the same ip and port.