[repo] Protocol: ENet 1.3 wire from stock ENet narrows U9; video FEC Cauchy matrix from fec-rs settles U14

This commit is contained in:
2026-11-25 12:22:59 +01:00
parent af1df633a1
commit 3bd7ebeaed
+48 -21
View File
@@ -2,7 +2,8 @@
The protocol between a GameStream host (Sunshine, later Lumen) and a client (Arena Domi TV). Written from the Wolf The protocol between a GameStream host (Sunshine, later Lumen) and a client (Arena Domi TV). Written from the Wolf
protocol docs in our own words, completed with facts read in Moonshine (BSD-2). Every fact has a tag; every gap is protocol docs in our own words, completed with facts read in Moonshine (BSD-2). Every fact has a tag; every gap is
marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, Phase A (docs + API, no logic yet). marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, Phase A (docs + API, no logic yet). U9 narrowed and U14 settled from the approved sources the same
day (sections 3.1, 5.3); the rest waits for the lab capture ([LAB_CAPTURE.md](LAB_CAPTURE.md)).
**Tags** (details in the source log, [CLEAN_ROOM.md](CLEAN_ROOM.md)): **Tags** (details in the source log, [CLEAN_ROOM.md](CLEAN_ROOM.md)):
@@ -11,8 +12,9 @@ marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, Phase A (do
| [W1]-[W7] | Wolf docs: index, pairing, RTSP, control, RTP video, RTP Opus, input (S-1 to S-7) | | [W1]-[W7] | Wolf docs: index, pairing, RTSP, control, RTP video, RTP Opus, input (S-1 to S-7) |
| [M] | Moonshine `f184d5e` (S-9). A host implementation: we mirror its behaviour for the client. | | [M] | Moonshine `f184d5e` (S-9). A host implementation: we mirror its behaviour for the client. |
| [M*] | Moonshine, but the value has GPL provenance (Moonshine cites Sunshine or moonlight-common-c). Confirm by measurement before use. | | [M*] | Moonshine, but the value has GPL provenance (Moonshine cites Sunshine or moonlight-common-c). Confirm by measurement before use. |
| [T] | tokio-enet `364628e` (S-10), pending approval as a source | | [T] | tokio-enet `364628e` (S-10), approved 2026-11-25 |
| [F] | fec-rs README (S-13) | | [E] | stock ENet v1.3.18 `2662c0d` (S-17), MIT, approved 2026-11-25 |
| [F] | fec-rs README and source `402f41f` (S-13, S-18), BSD-2, approved 2026-11-25 |
| [RFC n] | the RFC | | [RFC n] | the RFC |
**Not in DomiStream:** sockets, TLS, the clock, video decoding and **Opus decoding**. DomiStream hands the platform **Not in DomiStream:** sockets, TLS, the clock, video decoding and **Opus decoding**. DomiStream hands the platform
@@ -226,25 +228,45 @@ Source: [Wolf: control](https://games-on-whales.github.io/wolf/stable/protocols/
### 3.1 ENet ### 3.1 ENet
The control stream runs over a custom fork of ENet supporting IPv4 and IPv6 [W4]. What is known about the wire, The control stream runs over a custom fork of ENet supporting IPv4 and IPv6 [W4]. The wire is stock ENet 1.3 [E][T]
from stock ENet 1.3 as tokio-enet implements it [T] (all multi-byte fields big-endian): (all multi-byte fields big-endian):
- Datagram = protocol header + up to 32 commands. Header: `peer_id u16` whose top bits are flags (`1<<15` sent time - **Datagram** = protocol header + up to 32 commands [E]. Header: `peer_id u16` whose bits 15 and 14 are flags (`1<<15`
present, `1<<14` compressed) and bits 12-13 the session id; then `sent_time u16` if flagged. sent time present, `1<<14` compressed) and bits 12-13 the session id; then `sent_time u16` (low 16 bits of the
- Command header (4 bytes): `command u8` (low 4 bits type, `0x80` acknowledge wanted, `0x40` unsequenced), sender's millisecond clock) if flagged [E]. Peer id `0xFFF` = "no peer yet" (the connect datagram) [E].
`channel_id u8`, `reliable_sequence u16`. - **Checksum** [E]: optional, a setting of the host on *both* ends; when on, 4 bytes follow the header (crc32 over the
- Commands and total sizes: 1 acknowledge (8), 2 connect (48), 3 verify connect (44), 4 disconnect (8), 5 ping (4), datagram with the field first set to the peer's connect id). **Nothing on the wire says whether it is on**, so both
6 send reliable (6 + data), 7 send unreliable (8 + data), 8 send fragment (24 + data), 9 send unsequenced (8 + data), ends must agree.
10 bandwidth limit (12), 11 throttle configure (16), 12 send unreliable fragment (24 + data). - **Command header** (4 bytes): `command u8` (low 4 bits type, `0x80` acknowledge wanted, `0x40` unsequenced),
- MTU 576-4096, window 4096-65536, channels 1-255, peer id ≤ 0xFFF. `channel_id u8` (`0xFF` for connection-level commands), `reliable_sequence u16` [E].
- **Commands and total sizes** [E]: 1 acknowledge (8: received reliable sequence, received sent time),
2 connect (48), 3 verify connect (44), 4 disconnect (8: data u32), 5 ping (4), 6 send reliable (6 + data),
7 send unreliable (8 + data), 8 send fragment (24 + data: start sequence, data length, fragment count, fragment
number, total length, fragment offset), 9 send unsequenced (8 + data: unsequenced group), 10 bandwidth limit (12),
11 throttle configure (16), 12 send unreliable fragment (24 + data).
- **Connect** fields [E]: outgoing peer id u16, incoming and outgoing session id u8 (a stock client sends `0xFF` for
both, "pick one"), MTU, window size, channel count, incoming and outgoing bandwidth, throttle interval, acceleration,
deceleration, connect id (random), data u32. Verify connect has the same fields without `data`; the connect id must
match [E].
- **Limits** [E]: MTU 576-4096, window 4096-65536, channels 1-255, peer id ≤ 0xFFF, at most 1024 × 1024 fragments.
- **Stock defaults** [E]: MTU 1392; window 65536 when bandwidth is unlimited; ping every 500 ms when idle;
retransmission timeout = RTT + 4 × RTT variance (initial RTT 500 ms), doubling per retry; a peer is dropped when
the oldest unacknowledged command is 30 s old, or after 32 retries once it is at least 5 s old.
How the host uses it [M]: one peer per session; host created with a channel limit of 0x30; every host message is sent How the host uses it [M]: one peer per session; host created with a channel limit of 0x30; every host message is sent
**reliable on channel 0**. Moonshine does this with stock-wire ENet and real Moonlight clients (see **reliable on channel 0**. Moonshine does this with stock-wire ENet and real Moonlight clients (see
[research/open-point-2.md](research/open-point-2.md)). [research/open-point-2.md](research/open-point-2.md)).
UNKNOWN U9: anything Sunshine's ENet sends that stock 1.3 does not (checksum, compression, header or connect field What follows without a capture (our reasoning on [E][T][M]):
differences); the channel count, MTU and `connect data` the client should offer; ping interval and timeouts. - tokio-enet has no checksum and Moonlight clients work with it, so **Moonlight clients run without the checksum**.
Settle: lab capture of one session, decoded with our parser. The checksum must match on both ends, and Sunshine works with the same clients, so **Sunshine runs without it too**.
Same reasoning for compression: a client that compressed would fail against tokio-enet without a compressor.
- So everything a Moonlight client *sends* parses as stock 1.3. What stays open is only what the fork might add on the
host's *sending* side, which the fork-aware client accepts and a stock parser might not.
UNKNOWN U9 (narrowed): anything Sunshine's ENet sends that stock 1.3 does not; the channel count, MTU and `connect
data` a client offers; whether the client sets non-default ping or timeout values. Settle: the lab capture's control
port datagrams, decoded with our parser (LAB_CAPTURE.md). Until then our client offers stock defaults.
### 3.2 Encrypted frame ### 3.2 Encrypted frame
@@ -432,9 +454,14 @@ Reed-Solomon erasure code over GF(2^8), polynomial `0x11D` [F] [W5]:
[W5] and their RTP and NV header fields are written **after** the parity is computed [M], so parity bytes 0-31 are [W5] and their RTP and NV header fields are written **after** the parity is computed [M], so parity bytes 0-31 are
not parity. Consequence for the receiver: a recovered data shard's bytes 0-31 are garbage; use only its payload not parity. Consequence for the receiver: a recovered data shard's bytes 0-31 are garbage; use only its payload
(offset 32 on) and take its place from the shard index. (offset 32 on) and take its place from the shard index.
- UNKNOWN U14: the generator matrix (systematic construction). fec-rs (BSD-2) claims Moonlight compatibility [F]. - **Matrix (U14, settled from [F], to be confirmed by the capture):** systematic: the data shards pass through, and
Settle: approve fec-rs as a source and read its construction, or measure: capture blocks with known losses and parity shard `j` (0..m) is `Σ_i P[j][i] · data_i` with the Cauchy matrix `P[j][i] = 1 / ((m + i) XOR j)` over
check our decoder against them. GF(2^8), polynomial `0x11D`, generator 2 [F]. Nothing in the Wolf docs contradicts this: they only say Reed-Solomon
with parity blocks [W5]. Examples (our own arithmetic): `k = 4, m = 2`:
`P = [[8e f4 47 a7], [f4 8e a7 47]]`; `k = 3, m = 1`: `P = [[01 8e f4]]`.
The capture settles it without any loss: parity packets are always sent, so our encoder must reproduce the
captured parity bytes (offset 32 on) of every block.
- The audio code is **not** this matrix (section 6.4).
### 5.4 Feedback ### 5.4 Feedback
@@ -538,11 +565,11 @@ client and Sunshine on a lab machine, not Mark's PC, his Sunshine or his TV); th
| U6 | ANNOUNCE attributes and values Sunshine requires | B | capture, then vary one at a time | | U6 | ANNOUNCE attributes and values Sunshine requires | B | capture, then vary one at a time |
| U7 | Extra headers in SETUP replies | B | capture | | U7 | Extra headers in SETUP replies | B | capture |
| U8 | UDP ping payload and repeat interval | B | capture | | U8 | UDP ping payload and repeat interval | B | capture |
| U9 | ENet differences from stock 1.3; client's channel count, MTU, connect data; ping/timeouts | B | capture, decode with our parser | | U9 | Narrowed (3.1): only what Sunshine's ENet may add when *sending*; the client's channel count, MTU, connect data | B | capture, decode with our parser |
| U10 | Bodies of START_A, START_B, PERIODIC_PING, LOSS_STATS, FRAME_STATS, IDR request, TERMINATION; ping interval | B | capture, decrypted with the session's `rikey` | | U10 | Bodies of START_A, START_B, PERIODIC_PING, LOSS_STATS, FRAME_STATS, IDR request, TERMINATION; ping interval | B | capture, decrypted with the session's `rikey` |
| U11 | First control sequence number; host's replay rules | | capture | | U11 | First control sequence number; host's replay rules | | capture |
| U13 | Video frame header: Wolf's constant or Moonshine's fields | | capture | | U13 | Video frame header: Wolf's constant or Moonshine's fields | | capture |
| U14 | Video RS generator matrix | B (for FEC; video plays without it at zero loss) | read fec-rs (approval) or capture with loss | | U14 | Video RS matrix: **settled** (5.3, Cauchy from fec-rs) | | capture confirms: our parity = captured parity |
| U15 | Multi-FEC flags `0x10` | | capture | | U15 | Multi-FEC flags `0x10` | | capture |
| U16 | Audio RS parity matrix | (audio plays without it) | capture, solve over GF(2^8) | | U16 | Audio RS parity matrix | (audio plays without it) | capture, solve over GF(2^8) |
| U17 | Audio encryption always or only when negotiated | B | capture | | U17 | Audio encryption always or only when negotiated | B | capture |