Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ff62498c9e | |||
| f72babc5b5 | |||
| ccfcdcc36c |
@@ -10,6 +10,8 @@ Days 1-2 wrap Sunshine; from Day 3 the engine is Lumen (own Rust code). Roadmap:
|
|||||||
### Rules that never bend
|
### Rules that never bend
|
||||||
- Clean room: never open, paste or port GPL code (Sunshine, Moonlight, Apollo, Vibeshine, Rubylight, moonlight-common-c)
|
- Clean room: never open, paste or port GPL code (Sunshine, Moonlight, Apollo, Vibeshine, Rubylight, moonlight-common-c)
|
||||||
into Domi repos. Allowed sources: Wolf protocol docs, Moonshine (BSD-2, attribute), our own measurements.
|
into Domi repos. Allowed sources: Wolf protocol docs, Moonshine (BSD-2, attribute), our own measurements.
|
||||||
|
- Also allowed for the wire format, with attribution (Mark, 2026-11-25): stock ENet (MIT), tokio-enet (BSD-2),
|
||||||
|
fec-rs (BSD-2). GPL code stays off limits.
|
||||||
- Sunshine is never patched, linked or bundled: official release, sha256-pinned, separate program, local API only.
|
- Sunshine is never patched, linked or bundled: official release, sha256-pinned, separate program, local API only.
|
||||||
- Sunshine and Lumen listen only on the Via Domi interface and loopback (home LAN only when Via isn't installed).
|
- Sunshine and Lumen listen only on the Via Domi interface and loopback (home LAN only when Via isn't installed).
|
||||||
- Every device must hold a Tessera identity with a grant from the PC's owner. No PIN shown to the user, ever.
|
- Every device must hold a Tessera identity with a grant from the PC's owner. No PIN shown to the user, ever.
|
||||||
@@ -28,3 +30,7 @@ Days 1-2 wrap Sunshine; from Day 3 the engine is Lumen (own Rust code). Roadmap:
|
|||||||
- Commits: `[<crate>] <Feature>: <description>`, `[repo]` for repo-wide changes. No AI attribution in commits, PRs or tags.
|
- Commits: `[<crate>] <Feature>: <description>`, `[repo]` for repo-wide changes. No AI attribution in commits, PRs or tags.
|
||||||
- No binaries, captures or test videos in git.
|
- No binaries, captures or test videos in git.
|
||||||
- Cargo builds: the machine-wide `CARGO_HOME` config sends the build dir to `D:\cargo-build`. Never set `CARGO_TARGET_DIR`.
|
- Cargo builds: the machine-wide `CARGO_HOME` config sends the build dir to `D:\cargo-build`. Never set `CARGO_TARGET_DIR`.
|
||||||
|
- Never start a build or a test run (cargo, npm/pnpm, Gradle, dotnet, Playwright, e2e, emulator, Fabrica runs) while this
|
||||||
|
PC's CPU, RAM, or any drive the work writes to (D:, E:, F:) is more than 90 % used (Mark, 2026-11-25: "CPU, RAM and
|
||||||
|
disk all 90%"). Check first. If any is above 90 %, don't start; wait and check again later. Don't stop other
|
||||||
|
sessions' work to make room.
|
||||||
|
|||||||
Generated
-574
@@ -1,574 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 4
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aead"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"inout",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aes"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
"cpubits",
|
|
||||||
"cpufeatures",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aes-gcm"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f2b8006a0c83f52b62ba44a97b58bf76fe2f70a329e588f67f89691d93d498f"
|
|
||||||
dependencies = [
|
|
||||||
"aead",
|
|
||||||
"aes",
|
|
||||||
"cipher",
|
|
||||||
"ctr",
|
|
||||||
"ctutils",
|
|
||||||
"ghash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base16ct"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64ct"
|
|
||||||
version = "1.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-buffer"
|
|
||||||
version = "0.12.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa"
|
|
||||||
dependencies = [
|
|
||||||
"hybrid-array",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-padding"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b"
|
|
||||||
dependencies = [
|
|
||||||
"hybrid-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cbc"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce2dc9ee5f88d11e0beb842c88b33c8a5cf0d1329c4b19494af42b07dbfe8896"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cipher"
|
|
||||||
version = "0.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"
|
|
||||||
dependencies = [
|
|
||||||
"block-buffer",
|
|
||||||
"crypto-common",
|
|
||||||
"inout",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cmov"
|
|
||||||
version = "0.5.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const-oid"
|
|
||||||
version = "0.10.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cpubits"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cpufeatures"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-bigint"
|
|
||||||
version = "0.7.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82"
|
|
||||||
dependencies = [
|
|
||||||
"cpubits",
|
|
||||||
"ctutils",
|
|
||||||
"getrandom",
|
|
||||||
"num-traits",
|
|
||||||
"rand_core",
|
|
||||||
"serdect",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-common"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
"hybrid-array",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-primes"
|
|
||||||
version = "0.7.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-bigint",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctr"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baaca1c4b237092596f64d571e9db6ce4109c4ef9742e27590f1709594461f21"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctutils"
|
|
||||||
version = "0.4.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f"
|
|
||||||
dependencies = [
|
|
||||||
"cmov",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "der"
|
|
||||||
version = "0.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"der_derive",
|
|
||||||
"flagset",
|
|
||||||
"pem-rfc7468",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "der_derive"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "59600e2c2d636fde9b65e99cc6445ac770c63d3628195ff39932b8d6d7409903"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "digest"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
|
||||||
dependencies = [
|
|
||||||
"block-buffer",
|
|
||||||
"const-oid",
|
|
||||||
"crypto-common",
|
|
||||||
"ctutils",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "domistream"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"aes",
|
|
||||||
"aes-gcm",
|
|
||||||
"cbc",
|
|
||||||
"rand_core",
|
|
||||||
"rsa",
|
|
||||||
"sha2",
|
|
||||||
"x509-cert",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "flagset"
|
|
||||||
version = "0.4.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getrandom"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"r-efi",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ghash"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
|
|
||||||
dependencies = [
|
|
||||||
"polyval",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hmac"
|
|
||||||
version = "0.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hybrid-array"
|
|
||||||
version = "0.4.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17"
|
|
||||||
dependencies = [
|
|
||||||
"typenum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "inout"
|
|
||||||
version = "0.2.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a580c13f0ffc335ef42dd3f6b1a41b726051c5e1656d9a3aa6fddb3c5dfbbf9"
|
|
||||||
dependencies = [
|
|
||||||
"block-padding",
|
|
||||||
"hybrid-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.191"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pem-rfc7468"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9"
|
|
||||||
dependencies = [
|
|
||||||
"base64ct",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkcs1"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650"
|
|
||||||
dependencies = [
|
|
||||||
"der",
|
|
||||||
"spki",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkcs8"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7"
|
|
||||||
dependencies = [
|
|
||||||
"der",
|
|
||||||
"spki",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "polyval"
|
|
||||||
version = "0.7.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f0fa31d631f2b2cb2a544d0aa321ce847a94764d701ca2becc411138b93d49cd"
|
|
||||||
dependencies = [
|
|
||||||
"cpubits",
|
|
||||||
"cpufeatures",
|
|
||||||
"universal-hash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.107"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "r-efi"
|
|
||||||
version = "6.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_core"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rsa"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "23e77fd77e0dea28b3011fd62d15445b7de7959333b0276d930e03be0f755699"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"crypto-bigint",
|
|
||||||
"crypto-common",
|
|
||||||
"crypto-primes",
|
|
||||||
"digest",
|
|
||||||
"hmac",
|
|
||||||
"pkcs1",
|
|
||||||
"pkcs8",
|
|
||||||
"rand_core",
|
|
||||||
"sha2",
|
|
||||||
"signature",
|
|
||||||
"spki",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
||||||
dependencies = [
|
|
||||||
"serde_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_core"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
||||||
dependencies = [
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_derive"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.10",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serdect"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e"
|
|
||||||
dependencies = [
|
|
||||||
"base16ct",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha1"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha2"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "signature"
|
|
||||||
version = "3.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "spki"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9"
|
|
||||||
dependencies = [
|
|
||||||
"base64ct",
|
|
||||||
"der",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.119"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "3.0.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tls_codec"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0de2e01245e2bb89d6f05801c564fa27624dbd7b1846859876c7dad82e90bf6b"
|
|
||||||
dependencies = [
|
|
||||||
"tls_codec_derive",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tls_codec_derive"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typenum"
|
|
||||||
version = "1.20.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "universal-hash"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"ctutils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "x509-cert"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e9f58ad685a2945c7c063f5d69b5c27105d75bb85c740380d8fc64e79a098417"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"der",
|
|
||||||
"sha1",
|
|
||||||
"signature",
|
|
||||||
"spki",
|
|
||||||
"tls_codec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zeroize"
|
|
||||||
version = "1.9.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
|
|
||||||
dependencies = [
|
|
||||||
"zeroize_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zeroize_derive"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
members = ["crates/domistream"]
|
|
||||||
# fuzz/ is its own workspace (cargo-fuzz layout), never part of this one.
|
|
||||||
exclude = ["fuzz"]
|
|
||||||
resolver = "3"
|
|
||||||
|
|
||||||
[workspace.package]
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
rust-version = "1.89"
|
|
||||||
license = "CPAL-1.0"
|
|
||||||
repository = "https://gitea.marek-novak.cz/mnovak/DomiStream"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[workspace.lints.rust]
|
|
||||||
unsafe_code = "forbid"
|
|
||||||
missing_docs = "warn"
|
|
||||||
unreachable_pub = "warn"
|
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
|
||||||
# No panics on any input: these must never appear in library code.
|
|
||||||
unwrap_used = "deny"
|
|
||||||
expect_used = "deny"
|
|
||||||
panic = "deny"
|
|
||||||
todo = "deny"
|
|
||||||
unimplemented = "deny"
|
|
||||||
indexing_slicing = "warn"
|
|
||||||
@@ -18,13 +18,6 @@ Rubylight or moonlight-common-c was opened, pasted or ported. See [`docs/CLEAN_R
|
|||||||
cargo test --workspace
|
cargo test --workspace
|
||||||
```
|
```
|
||||||
|
|
||||||
| Path | What |
|
|
||||||
| :-- | :-- |
|
|
||||||
| `crates/domistream` | the crate: one module per protocol part (see its rustdoc) |
|
|
||||||
| `fuzz/` | one libFuzzer target per parser, its own workspace (how to run: top of `fuzz/Cargo.toml`) |
|
|
||||||
| `docs/PROTOCOL.md` | the protocol as we speak it, with every UNKNOWN |
|
|
||||||
| `docs/CLEAN_ROOM.md` | allowed and forbidden sources, and the source log |
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
DomiStream is licensed under the **Common Public Attribution License 1.0** (SPDX `CPAL-1.0`); see [LICENSE](LICENSE).
|
DomiStream is licensed under the **Common Public Attribution License 1.0** (SPDX `CPAL-1.0`); see [LICENSE](LICENSE).
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "domistream"
|
|
||||||
description = "Sans-I/O GameStream client protocol for Arena Domi Play remotely"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
rust-version.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
repository.workspace = true
|
|
||||||
publish.workspace = true
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
# Crypto: RustCrypto only, pure Rust, all MIT OR Apache-2.0 (fits CPAL-1.0). Chosen in Phase A, used in Phase B.
|
|
||||||
[dependencies]
|
|
||||||
aes = "0.9" # AES-128 block cipher (pairing ECB)
|
|
||||||
aes-gcm = "0.11" # control and video AES-128-GCM
|
|
||||||
cbc = "0.2" # audio AES-128-CBC
|
|
||||||
sha2 = "0.11" # pairing SHA-256
|
|
||||||
rsa = "0.10" # client key, PKCS#1 v1.5 SHA-256 sign/verify (crypto-bigint, constant time)
|
|
||||||
x509-cert = { version = "0.3", features = ["builder", "pem"] } # client certificate, host certificate parsing
|
|
||||||
rand_core = "0.10" # adapter from our RandomSource to the RustCrypto RNG traits
|
|
||||||
zeroize = "1.8" # wipe keys on drop
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
//! The audio receive path (`docs/PROTOCOL.md` section 6): parse → rebuild lost packets from the 4 + 2 FEC block →
|
|
||||||
//! decrypt (AES-128-CBC) → one Opus packet per RTP packet, in order, for the platform's Opus decoder.
|
|
||||||
//!
|
|
||||||
//! **Opus decoding is not here.** A packet that cannot be rebuilt becomes [`AudioEvent::Lost`]; the platform
|
|
||||||
//! conceals it.
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::{Instant, Result, SessionKeys};
|
|
||||||
|
|
||||||
pub mod packet;
|
|
||||||
|
|
||||||
pub use packet::{AudioFecHeader, AudioPacket, parse_audio_packet};
|
|
||||||
|
|
||||||
/// Data packets per FEC block.
|
|
||||||
pub const DATA_SHARDS: usize = 4;
|
|
||||||
/// Parity packets per FEC block.
|
|
||||||
pub const PARITY_SHARDS: usize = 2;
|
|
||||||
/// Maximum blocks kept while waiting for missing packets.
|
|
||||||
pub const MAX_BLOCKS_IN_FLIGHT: usize = 8;
|
|
||||||
|
|
||||||
/// AES-128-CBC for audio payloads: IV = `u32 BE (rikeyid + sequence) ‖ 12 zero bytes`, PKCS#7 padding.
|
|
||||||
/// `Debug` never prints the key.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct AudioCipher {
|
|
||||||
key: [u8; 16],
|
|
||||||
rikeyid: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AudioCipher {
|
|
||||||
/// A cipher for the session's keys.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn new(keys: &SessionKeys) -> Self {
|
|
||||||
Self { key: keys.rikey, rikeyid: keys.rikeyid }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The IV for RTP sequence number `sequence`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn iv(&self, sequence: u16) -> Result<[u8; 16]> {
|
|
||||||
let _ = (sequence, self.rikeyid);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decrypts one payload.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a length that is not a positive multiple of 16, [`crate::Error::Crypto`] for
|
|
||||||
/// bad padding. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn decrypt(&self, sequence: u16, ciphertext: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = (sequence, ciphertext, &self.key);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for AudioCipher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("AudioCipher(<redacted>)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// How lost audio packets are rebuilt.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum AudioFec {
|
|
||||||
/// Parity packets are ignored; losses go to the platform's concealment.
|
|
||||||
Disabled,
|
|
||||||
/// Rebuild with this 2 × 4 parity matrix (row-major). The GameStream matrix is UNKNOWN U16 until measured.
|
|
||||||
ParityMatrix([u8; PARITY_SHARDS * DATA_SHARDS]),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Settings of the audio receiver.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct AudioConfig {
|
|
||||||
/// Decrypt payloads with this cipher (audio encryption negotiated, or always: UNKNOWN U17).
|
|
||||||
pub cipher: Option<AudioCipher>,
|
|
||||||
/// Packet duration in milliseconds (`x-nv-aqos.packetDuration`).
|
|
||||||
pub packet_duration_ms: u8,
|
|
||||||
/// FEC mode.
|
|
||||||
pub fec: AudioFec,
|
|
||||||
/// How long to wait for a missing packet before reporting it lost (the jitter budget).
|
|
||||||
pub loss_timeout: core::time::Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What the receiver reports, in sequence order.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum AudioEvent {
|
|
||||||
/// One decrypted Opus packet.
|
|
||||||
Packet {
|
|
||||||
/// RTP sequence number.
|
|
||||||
sequence: u16,
|
|
||||||
/// RTP timestamp (milliseconds).
|
|
||||||
timestamp_ms: u32,
|
|
||||||
/// The Opus packet.
|
|
||||||
opus: Vec<u8>,
|
|
||||||
/// Rebuilt by FEC.
|
|
||||||
recovered: bool,
|
|
||||||
},
|
|
||||||
/// The packet with this sequence number is gone; the decoder conceals one packet duration.
|
|
||||||
Lost {
|
|
||||||
/// RTP sequence number.
|
|
||||||
sequence: u16,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Counters for the stats overlay.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct AudioStats {
|
|
||||||
/// Packets accepted.
|
|
||||||
pub packets: u64,
|
|
||||||
/// Packets refused (bad format, bad padding, duplicate, too old).
|
|
||||||
pub packets_dropped: u64,
|
|
||||||
/// Packets rebuilt by FEC.
|
|
||||||
pub recovered: u64,
|
|
||||||
/// Packets reported lost.
|
|
||||||
pub lost: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The audio receiver.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AudioDepacketizer {
|
|
||||||
stats: AudioStats,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AudioDepacketizer {
|
|
||||||
/// A receiver for one stream.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a zero packet duration or a parity matrix that is not MDS. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn new(config: AudioConfig) -> Result<Self> {
|
|
||||||
let _ = config;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds one datagram from the audio port. Bad, duplicate and too-old packets are counted and dropped; only an
|
|
||||||
/// oversized datagram is an error.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`packet::MAX_AUDIO_PACKET_BYTES`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn push(&mut self, now: Instant, datagram: &[u8]) -> Result<()> {
|
|
||||||
let _ = (now, datagram);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next event.
|
|
||||||
pub fn poll_event(&mut self) -> Option<AudioEvent> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When a missing packet times out.
|
|
||||||
#[must_use]
|
|
||||||
pub fn poll_timeout(&self) -> Option<Instant> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reports timed-out packets as lost.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_timeout(&mut self, now: Instant) -> Result<()> {
|
|
||||||
let _ = now;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Counters.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn stats(&self) -> AudioStats {
|
|
||||||
self.stats
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
//! The audio packet layout (`docs/PROTOCOL.md` 6.2): RTP header, then the Opus payload (payload type 97) or a
|
|
||||||
//! 12-byte FEC header plus parity (payload type 127). FEC header fields are big-endian.
|
|
||||||
|
|
||||||
use crate::rtp::RtpHeader;
|
|
||||||
|
|
||||||
/// Payload type of audio data packets.
|
|
||||||
pub const AUDIO_PAYLOAD_TYPE: u8 = 97;
|
|
||||||
/// Payload type of audio parity packets.
|
|
||||||
pub const AUDIO_FEC_PAYLOAD_TYPE: u8 = 127;
|
|
||||||
/// Length of the FEC header in parity packets.
|
|
||||||
pub const AUDIO_FEC_HEADER_LEN: usize = 12;
|
|
||||||
/// Maximum size of one audio packet, in bytes.
|
|
||||||
pub const MAX_AUDIO_PACKET_BYTES: usize = 2048;
|
|
||||||
|
|
||||||
/// The FEC header of a parity packet.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct AudioFecHeader {
|
|
||||||
/// Parity shard index, 0 or 1.
|
|
||||||
pub shard_index: u8,
|
|
||||||
/// Payload type of the protected packets (97).
|
|
||||||
pub payload_type: u8,
|
|
||||||
/// Sequence number of the block's first data packet.
|
|
||||||
pub base_sequence: u16,
|
|
||||||
/// Timestamp of the block's first data packet.
|
|
||||||
pub base_timestamp: u32,
|
|
||||||
/// SSRC.
|
|
||||||
pub ssrc: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One audio packet.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub enum AudioPacket<'a> {
|
|
||||||
/// Opus data (still encrypted when audio encryption is on).
|
|
||||||
Data {
|
|
||||||
/// RTP header.
|
|
||||||
rtp: RtpHeader,
|
|
||||||
/// Payload.
|
|
||||||
payload: &'a [u8],
|
|
||||||
},
|
|
||||||
/// Parity.
|
|
||||||
Parity {
|
|
||||||
/// RTP header.
|
|
||||||
rtp: RtpHeader,
|
|
||||||
/// FEC header.
|
|
||||||
fec: AudioFecHeader,
|
|
||||||
/// Parity bytes.
|
|
||||||
parity: &'a [u8],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one audio packet.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_AUDIO_PACKET_BYTES`], [`crate::Error::Truncated`] for a cut header or an
|
|
||||||
/// empty payload, [`crate::Error::UnexpectedValue`] for another payload type or a parity shard index above 1.
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_audio_packet(packet: &[u8]) -> crate::Result<AudioPacket<'_>> {
|
|
||||||
let _ = packet;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
//! The AES-128-GCM frame around every control message (`docs/PROTOCOL.md` 3.2).
|
|
||||||
//!
|
|
||||||
//! ```text
|
|
||||||
//! 0 2 4 8 24
|
|
||||||
//! | 0x0001 | len | seq (LE) | GCM tag (16) | ciphertext … | len = 4 + 16 + ciphertext
|
|
||||||
//! nonce = seq (LE, 4) ‖ 0 × 6 ‖ direction ('C' client→host, 'H' host→client) ‖ 'C'
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::Result;
|
|
||||||
|
|
||||||
/// Type field of an encrypted frame.
|
|
||||||
pub const ENCRYPTED_FRAME_TYPE: u16 = 0x0001;
|
|
||||||
/// GCM tag length.
|
|
||||||
pub const GCM_TAG_LEN: usize = 16;
|
|
||||||
/// Bytes before the ciphertext (type, length, sequence, tag).
|
|
||||||
pub const FRAME_HEADER_LEN: usize = 2 + 2 + 4 + GCM_TAG_LEN;
|
|
||||||
/// Smallest valid frame: header plus a 4-byte message header inside.
|
|
||||||
pub const MIN_FRAME_BYTES: usize = FRAME_HEADER_LEN + 4;
|
|
||||||
/// Maximum frame size accepted or produced, in bytes.
|
|
||||||
pub const MAX_FRAME_BYTES: usize = 4096;
|
|
||||||
/// GCM nonce length.
|
|
||||||
pub const NONCE_LEN: usize = 12;
|
|
||||||
|
|
||||||
/// Which way a frame travels; selects byte 10 of the nonce.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum Direction {
|
|
||||||
/// Client to host (`'C'`).
|
|
||||||
ClientToHost,
|
|
||||||
/// Host to client (`'H'`).
|
|
||||||
HostToClient,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The nonce for sequence number `sequence` in `direction`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn nonce(sequence: u32, direction: Direction) -> Result<[u8; NONCE_LEN]> {
|
|
||||||
let _ = (sequence, direction);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A frame split into its fields, not yet decrypted.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct EncryptedFrame<'a> {
|
|
||||||
/// Sequence number.
|
|
||||||
pub sequence: u32,
|
|
||||||
/// GCM tag.
|
|
||||||
pub tag: [u8; GCM_TAG_LEN],
|
|
||||||
/// Ciphertext.
|
|
||||||
pub ciphertext: &'a [u8],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Splits a frame (one ENet packet) into its fields. The length field must match the bytes present exactly.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_FRAME_BYTES`], [`crate::Error::Truncated`] under [`MIN_FRAME_BYTES`],
|
|
||||||
/// [`crate::Error::UnexpectedValue`] for a type other than [`ENCRYPTED_FRAME_TYPE`], [`crate::Error::Malformed`]
|
|
||||||
/// for a length that does not match. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_encrypted_frame(frame: &[u8]) -> Result<EncryptedFrame<'_>> {
|
|
||||||
let _ = frame;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AES-128-GCM with the session's `rikey`. `Debug` never prints the key.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ControlCipher {
|
|
||||||
key: [u8; 16],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ControlCipher {
|
|
||||||
/// A cipher for `rikey`.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn new(rikey: [u8; 16]) -> Self {
|
|
||||||
Self { key: rikey }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encrypts one message (plaintext = type, length, body) into a whole frame.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] when the frame would exceed [`MAX_FRAME_BYTES`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn seal(&self, sequence: u32, direction: Direction, plaintext: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = (sequence, direction, plaintext, &self.key);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks and decrypts one frame; returns its sequence number and the plaintext message.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Parser errors as [`parse_encrypted_frame`]; [`crate::Error::Crypto`] when the tag does not verify. Phase A:
|
|
||||||
/// always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn open(&self, direction: Direction, frame: &[u8]) -> Result<(u32, Vec<u8>)> {
|
|
||||||
let _ = (direction, frame);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for ControlCipher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("ControlCipher(<redacted>)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
//! Control messages inside the encrypted frame (`docs/PROTOCOL.md` 3.3): `type u16 LE`, `length u16 LE`, body.
|
|
||||||
|
|
||||||
use crate::Result;
|
|
||||||
use crate::input::InputEvent;
|
|
||||||
|
|
||||||
/// Length of the message header (type + length).
|
|
||||||
pub const MESSAGE_HEADER_LEN: usize = 4;
|
|
||||||
/// Maximum size of one decrypted message, in bytes.
|
|
||||||
pub const MAX_MESSAGE_BYTES: usize = super::frame::MAX_FRAME_BYTES - super::frame::FRAME_HEADER_LEN;
|
|
||||||
/// Length of the HDR metadata block in `HDR_MODE` (15 × u16).
|
|
||||||
pub const HDR_METADATA_LEN: usize = 30;
|
|
||||||
|
|
||||||
/// Known message type codes.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
#[repr(u16)]
|
|
||||||
pub enum MessageType {
|
|
||||||
/// Start, part A (client → host).
|
|
||||||
StartA = 0x0305,
|
|
||||||
/// Start, part B (client → host); the host starts video and audio on it.
|
|
||||||
StartB = 0x0307,
|
|
||||||
/// Reference frame invalidation request (client → host).
|
|
||||||
InvalidateRefFrames = 0x0301,
|
|
||||||
/// IDR frame request (client → host).
|
|
||||||
IdrFrame = 0x0302,
|
|
||||||
/// Loss statistics (client → host).
|
|
||||||
LossStats = 0x0201,
|
|
||||||
/// Frame statistics (client → host).
|
|
||||||
FrameStats = 0x0204,
|
|
||||||
/// Input (client → host).
|
|
||||||
InputData = 0x0206,
|
|
||||||
/// Keep-alive (client → host).
|
|
||||||
PeriodicPing = 0x0200,
|
|
||||||
/// Termination (host → client).
|
|
||||||
Termination = 0x0100,
|
|
||||||
/// Termination with a 32-bit error code (host → client).
|
|
||||||
TerminationExtended = 0x0109,
|
|
||||||
/// HDR mode change (host → client).
|
|
||||||
HdrMode = 0x010e,
|
|
||||||
/// Rumble (host → client).
|
|
||||||
RumbleData = 0x010b,
|
|
||||||
/// Trigger rumble (host → client).
|
|
||||||
RumbleTriggers = 0x5500,
|
|
||||||
/// Start or stop motion events (host → client).
|
|
||||||
MotionEvent = 0x5501,
|
|
||||||
/// Controller LED colour (host → client).
|
|
||||||
RgbLed = 0x5502,
|
|
||||||
/// Adaptive trigger effect (host → client), layout UNKNOWN.
|
|
||||||
TriggerEffect = 0x5503,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<u16> for MessageType {
|
|
||||||
type Error = crate::Error;
|
|
||||||
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::UnexpectedValue`] for an unknown code. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
fn try_from(code: u16) -> Result<Self> {
|
|
||||||
let _ = code;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A message split into type and body, not interpreted.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct RawMessage<'a> {
|
|
||||||
/// Type code (possibly unknown).
|
|
||||||
pub message_type: u16,
|
|
||||||
/// Body, exactly `length` bytes.
|
|
||||||
pub body: &'a [u8],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Splits a decrypted message. The length field must equal the bytes after the header.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_MESSAGE_BYTES`], [`crate::Error::Truncated`] under
|
|
||||||
/// [`MESSAGE_HEADER_LEN`], [`crate::Error::Malformed`] for a length that does not match. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_message(message: &[u8]) -> Result<RawMessage<'_>> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Motion sensor kinds of `MOTION_EVENT`.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum MotionKind {
|
|
||||||
/// Accelerometer (1).
|
|
||||||
Accelerometer,
|
|
||||||
/// Gyroscope (2).
|
|
||||||
Gyroscope,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// HDR mastering metadata as sent in `HDR_MODE` (15 little-endian u16 fields, layout `[M*]`, unconfirmed).
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct HdrMetadata {
|
|
||||||
/// Display primaries x/y for R, G, B.
|
|
||||||
pub display_primaries: [(u16, u16); 3],
|
|
||||||
/// White point x/y.
|
|
||||||
pub white_point: (u16, u16),
|
|
||||||
/// Maximum display luminance, nits.
|
|
||||||
pub max_display_luminance: u16,
|
|
||||||
/// Minimum display luminance, 1/10000 nit.
|
|
||||||
pub min_display_luminance: u16,
|
|
||||||
/// Maximum content light level, nits.
|
|
||||||
pub max_content_light_level: u16,
|
|
||||||
/// Maximum frame-average light level, nits.
|
|
||||||
pub max_frame_average_light_level: u16,
|
|
||||||
/// Maximum full-frame luminance, nits.
|
|
||||||
pub max_full_frame_luminance: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A message from the host.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum HostMessage {
|
|
||||||
/// Rumble a controller.
|
|
||||||
Rumble {
|
|
||||||
/// Controller number.
|
|
||||||
controller: u16,
|
|
||||||
/// Low-frequency motor.
|
|
||||||
low_frequency: u16,
|
|
||||||
/// High-frequency motor.
|
|
||||||
high_frequency: u16,
|
|
||||||
},
|
|
||||||
/// Rumble the triggers.
|
|
||||||
RumbleTriggers {
|
|
||||||
/// Controller number.
|
|
||||||
controller: u16,
|
|
||||||
/// Left trigger.
|
|
||||||
left: u16,
|
|
||||||
/// Right trigger.
|
|
||||||
right: u16,
|
|
||||||
},
|
|
||||||
/// Start (rate > 0) or stop (rate 0) sending motion events.
|
|
||||||
MotionEvent {
|
|
||||||
/// Controller number.
|
|
||||||
controller: u16,
|
|
||||||
/// Report rate, Hz.
|
|
||||||
rate_hz: u16,
|
|
||||||
/// Sensor.
|
|
||||||
kind: MotionKind,
|
|
||||||
},
|
|
||||||
/// Set a controller's LED colour.
|
|
||||||
RgbLed {
|
|
||||||
/// Controller number.
|
|
||||||
controller: u16,
|
|
||||||
/// Red.
|
|
||||||
r: u8,
|
|
||||||
/// Green.
|
|
||||||
g: u8,
|
|
||||||
/// Blue.
|
|
||||||
b: u8,
|
|
||||||
},
|
|
||||||
/// HDR turned on or off.
|
|
||||||
HdrMode {
|
|
||||||
/// HDR on.
|
|
||||||
enabled: bool,
|
|
||||||
/// Mastering metadata, if the body carries it.
|
|
||||||
metadata: Option<HdrMetadata>,
|
|
||||||
},
|
|
||||||
/// The host ended the session.
|
|
||||||
Termination {
|
|
||||||
/// Error code (extended form), `None` for the plain form. `0x80030023` = graceful.
|
|
||||||
error_code: Option<u32>,
|
|
||||||
},
|
|
||||||
/// A known or unknown type this client does not interpret; kept for stats and logs.
|
|
||||||
Other {
|
|
||||||
/// Type code.
|
|
||||||
message_type: u16,
|
|
||||||
/// Body length (the body itself is not kept).
|
|
||||||
body_len: usize,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Interprets a decrypted message from the host.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`parse_message`]; [`crate::Error::Malformed`] when a known type's body has the wrong length;
|
|
||||||
/// [`crate::Error::UnexpectedValue`] for an unknown motion kind. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_host_message(message: &[u8]) -> Result<HostMessage> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A message to the host.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum ClientMessage {
|
|
||||||
/// `START_A` (body UNKNOWN U10).
|
|
||||||
StartA,
|
|
||||||
/// `START_B` (body UNKNOWN U10): the host starts video and audio.
|
|
||||||
StartB,
|
|
||||||
/// Keep-alive (body UNKNOWN U10).
|
|
||||||
PeriodicPing,
|
|
||||||
/// Ask for an IDR frame (body UNKNOWN U10).
|
|
||||||
RequestIdrFrame,
|
|
||||||
/// Ask the host to stop referencing frames `first..=last`.
|
|
||||||
InvalidateRefFrames {
|
|
||||||
/// First lost frame index.
|
|
||||||
first: u32,
|
|
||||||
/// Last lost frame index.
|
|
||||||
last: u32,
|
|
||||||
},
|
|
||||||
/// User input.
|
|
||||||
Input(InputEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializes a message to the host (type, length, body), ready for [`super::ControlCipher::seal`].
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Unsupported`] for a message whose body is still UNKNOWN; input errors as
|
|
||||||
/// [`crate::input::encode_input`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn encode_client_message(message: &ClientMessage) -> Result<Vec<u8>> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
//! The control stream (`docs/PROTOCOL.md` section 3): ENet underneath, AES-GCM frames, control messages.
|
|
||||||
//!
|
|
||||||
//! [`ControlStream`] ties them together: it connects the ENet peer, seals every [`ClientMessage`] with an
|
|
||||||
//! increasing sequence number, opens every host frame (dropping replays and frames that fail the tag), and reports
|
|
||||||
//! [`HostMessage`]s.
|
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
use crate::enet::EnetConfig;
|
|
||||||
use crate::{Instant, RandomSource, Result};
|
|
||||||
|
|
||||||
pub mod frame;
|
|
||||||
pub mod message;
|
|
||||||
|
|
||||||
pub use frame::{ControlCipher, Direction, EncryptedFrame, parse_encrypted_frame};
|
|
||||||
pub use message::{ClientMessage, HostMessage, MessageType, parse_host_message, parse_message};
|
|
||||||
|
|
||||||
/// Settings of one control stream. `Debug` never prints the key.
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
|
||||||
pub struct ControlConfig {
|
|
||||||
/// The ENet connection to offer.
|
|
||||||
pub enet: EnetConfig,
|
|
||||||
/// The session's `rikey`.
|
|
||||||
pub rikey: [u8; 16],
|
|
||||||
/// Send `PERIODIC_PING` this often (UNKNOWN U10).
|
|
||||||
pub ping_interval: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl core::fmt::Debug for ControlConfig {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
f.debug_struct("ControlConfig")
|
|
||||||
.field("enet", &self.enet)
|
|
||||||
.field("rikey", &"<redacted>")
|
|
||||||
.field("ping_interval", &self.ping_interval)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What happened on the control stream.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum ControlEvent {
|
|
||||||
/// ENet connected; the client sends `START_A`/`START_B` next.
|
|
||||||
Connected,
|
|
||||||
/// A message from the host.
|
|
||||||
Message(HostMessage),
|
|
||||||
/// A host frame failed its tag or came out of order and was dropped (counted, never fatal).
|
|
||||||
Dropped,
|
|
||||||
/// The host closed the stream.
|
|
||||||
Disconnected,
|
|
||||||
/// The host stopped answering.
|
|
||||||
TimedOut,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One control stream.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ControlStream {
|
|
||||||
next_sequence: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ControlStream {
|
|
||||||
/// Starts connecting.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`crate::enet::EnetClient::connect`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn connect(config: ControlConfig, now: Instant, rng: &mut dyn RandomSource) -> Result<Self> {
|
|
||||||
let _ = (config, now, rng);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds one datagram from the control port.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`crate::enet::EnetClient::handle_datagram`]. Bad frames inside a good datagram are not errors; they
|
|
||||||
/// become [`ControlEvent::Dropped`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_datagram(&mut self, now: Instant, datagram: &[u8]) -> Result<()> {
|
|
||||||
let _ = (now, datagram);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Seals and queues a message (reliable, channel 0 unless measurement says otherwise).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`message::encode_client_message`] and [`crate::enet::EnetClient::send`]; [`crate::Error::Closed`] once
|
|
||||||
/// the sequence space is used up (2^32 messages). Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn send(&mut self, now: Instant, message: &ClientMessage) -> Result<()> {
|
|
||||||
let _ = (now, message, self.next_sequence);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next datagram to send.
|
|
||||||
pub fn poll_transmit(&mut self, now: Instant) -> Option<Vec<u8>> {
|
|
||||||
let _ = now;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next event.
|
|
||||||
pub fn poll_event(&mut self) -> Option<ControlEvent> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When [`Self::handle_timeout`] is due.
|
|
||||||
#[must_use]
|
|
||||||
pub fn poll_timeout(&self) -> Option<Instant> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advances timers (ENet, periodic ping).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_timeout(&mut self, now: Instant) -> Result<()> {
|
|
||||||
let _ = now;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Closes the stream gracefully.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Closed`] when already closed. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn close(&mut self, now: Instant) -> Result<()> {
|
|
||||||
let _ = now;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,175 +0,0 @@
|
|||||||
//! A sans-I/O ENet 1.3 client peer, compatible with GameStream hosts (`docs/PROTOCOL.md` 3.1,
|
|
||||||
//! `docs/research/open-point-2.md`).
|
|
||||||
//!
|
|
||||||
//! One peer, one connection. The caller owns the UDP socket:
|
|
||||||
//!
|
|
||||||
//! ```text
|
|
||||||
//! loop {
|
|
||||||
//! while let Some(d) = peer.poll_transmit(now) { socket.send(&d) }
|
|
||||||
//! wait until a datagram arrives or peer.poll_timeout()
|
|
||||||
//! peer.handle_datagram(now, &d) or peer.handle_timeout(now)
|
|
||||||
//! while let Some(e) = peer.poll_event() { … }
|
|
||||||
//! }
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
use crate::{Instant, RandomSource, Result};
|
|
||||||
|
|
||||||
pub mod protocol;
|
|
||||||
|
|
||||||
/// Maximum size of one reassembled packet, in bytes (control messages are small; this caps fragment memory).
|
|
||||||
pub const MAX_PACKET_BYTES: usize = 64 * 1024;
|
|
||||||
/// Maximum number of packets queued for sending before [`EnetClient::send`] refuses more.
|
|
||||||
pub const MAX_SEND_QUEUE: usize = 1024;
|
|
||||||
/// Maximum number of reliable commands waiting for an acknowledgement.
|
|
||||||
pub const MAX_IN_FLIGHT: usize = 256;
|
|
||||||
|
|
||||||
/// How a packet is delivered.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum Delivery {
|
|
||||||
/// Retransmitted until acknowledged, in order.
|
|
||||||
Reliable,
|
|
||||||
/// In order, may be lost, late packets dropped.
|
|
||||||
Unreliable,
|
|
||||||
/// May be lost, any order.
|
|
||||||
Unsequenced,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Settings of the connection the client offers. All values are UNKNOWN U9 for Sunshine; tests set them
|
|
||||||
/// explicitly.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct EnetConfig {
|
|
||||||
/// Channels to open.
|
|
||||||
pub channel_count: u8,
|
|
||||||
/// MTU to offer (576..=4096).
|
|
||||||
pub mtu: u16,
|
|
||||||
/// The connect command's user data word.
|
|
||||||
pub connect_data: u32,
|
|
||||||
/// Send a ping when nothing was sent for this long.
|
|
||||||
pub ping_interval: Duration,
|
|
||||||
/// Give up when nothing was acknowledged for this long.
|
|
||||||
pub timeout: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Connection state.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum EnetState {
|
|
||||||
/// Connect sent, waiting for verify connect.
|
|
||||||
Connecting,
|
|
||||||
/// Connected.
|
|
||||||
Connected,
|
|
||||||
/// Disconnect sent, waiting for its acknowledgement.
|
|
||||||
Disconnecting,
|
|
||||||
/// Closed (by either side or by timeout).
|
|
||||||
Disconnected,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What happened.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum EnetEvent {
|
|
||||||
/// The host verified the connection.
|
|
||||||
Connected,
|
|
||||||
/// A packet arrived (reassembled, in order for reliable and unreliable delivery).
|
|
||||||
Received {
|
|
||||||
/// Channel.
|
|
||||||
channel: u8,
|
|
||||||
/// The packet.
|
|
||||||
data: Vec<u8>,
|
|
||||||
},
|
|
||||||
/// The host closed the connection.
|
|
||||||
Disconnected {
|
|
||||||
/// The host's disconnect data word.
|
|
||||||
data: u32,
|
|
||||||
},
|
|
||||||
/// The host stopped answering.
|
|
||||||
TimedOut,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The ENet client peer.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct EnetClient {
|
|
||||||
state: EnetState,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EnetClient {
|
|
||||||
/// Starts connecting: queues the connect datagram. The connect id comes from `rng`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a config outside ENet's limits. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn connect(config: EnetConfig, now: Instant, rng: &mut dyn RandomSource) -> Result<Self> {
|
|
||||||
let _ = (config, now, rng);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds one received datagram. Datagrams for another peer id or session are dropped without error.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Parser errors as [`protocol::parse_datagram`]; [`crate::Error::TooLarge`] when a reassembly would exceed
|
|
||||||
/// [`MAX_PACKET_BYTES`]; [`crate::Error::Closed`] after `Disconnected`. A malformed datagram never changes the
|
|
||||||
/// connection state. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_datagram(&mut self, now: Instant, datagram: &[u8]) -> Result<()> {
|
|
||||||
let _ = (now, datagram);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Queues a packet. Packets larger than the MTU are fragmented.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::State`] unless connected, [`crate::Error::UnexpectedValue`] for a channel outside the
|
|
||||||
/// negotiated count, [`crate::Error::TooLarge`] over [`MAX_PACKET_BYTES`] or a full queue. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn send(&mut self, now: Instant, channel: u8, delivery: Delivery, data: &[u8]) -> Result<()> {
|
|
||||||
let _ = (now, channel, delivery, data);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Starts a graceful disconnect.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Closed`] when already disconnected. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn disconnect(&mut self, now: Instant, data: u32) -> Result<()> {
|
|
||||||
let _ = (now, data);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next datagram to send, at most [`protocol::MAX_DATAGRAM_BYTES`] (acknowledgements, retransmissions,
|
|
||||||
/// queued packets, pings).
|
|
||||||
pub fn poll_transmit(&mut self, now: Instant) -> Option<Vec<u8>> {
|
|
||||||
let _ = now;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next event.
|
|
||||||
pub fn poll_event(&mut self) -> Option<EnetEvent> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When [`Self::handle_timeout`] must be called next (retransmission, ping or timeout), if ever.
|
|
||||||
#[must_use]
|
|
||||||
pub fn poll_timeout(&self) -> Option<Instant> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advances timers: retransmits, pings, or gives up with [`EnetEvent::TimedOut`].
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_timeout(&mut self, now: Instant) -> Result<()> {
|
|
||||||
let _ = now;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Connection state.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn state(&self) -> EnetState {
|
|
||||||
self.state
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Smoothed round-trip time, once measured.
|
|
||||||
#[must_use]
|
|
||||||
pub fn round_trip_time(&self) -> Option<Duration> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
//! The ENet 1.3 datagram codec (`docs/PROTOCOL.md` 3.1). Multi-byte fields are big-endian.
|
|
||||||
|
|
||||||
/// Maximum datagram size accepted or produced (ENet's maximum MTU).
|
|
||||||
pub const MAX_DATAGRAM_BYTES: usize = 4096;
|
|
||||||
/// Minimum MTU ENet allows.
|
|
||||||
pub const MIN_MTU: u16 = 576;
|
|
||||||
/// Maximum number of commands in one datagram.
|
|
||||||
pub const MAX_COMMANDS_PER_DATAGRAM: usize = 32;
|
|
||||||
/// Maximum channel count ENet allows.
|
|
||||||
pub const MAX_CHANNEL_COUNT: u8 = 255;
|
|
||||||
/// Maximum peer id ENet allows.
|
|
||||||
pub const MAX_PEER_ID: u16 = 0x0FFF;
|
|
||||||
/// Peer id meaning "no peer yet" (used in the connect datagram).
|
|
||||||
pub const NO_PEER_ID: u16 = MAX_PEER_ID;
|
|
||||||
/// Minimum ENet window size.
|
|
||||||
pub const MIN_WINDOW_SIZE: u32 = 4096;
|
|
||||||
/// Maximum ENet window size.
|
|
||||||
pub const MAX_WINDOW_SIZE: u32 = 65536;
|
|
||||||
|
|
||||||
/// Header flag: the datagram carries `sent_time`.
|
|
||||||
pub const HEADER_FLAG_SENT_TIME: u16 = 1 << 15;
|
|
||||||
/// Header flag: the datagram is compressed (refused by this client).
|
|
||||||
pub const HEADER_FLAG_COMPRESSED: u16 = 1 << 14;
|
|
||||||
/// Command flag: the receiver must acknowledge.
|
|
||||||
pub const COMMAND_FLAG_ACKNOWLEDGE: u8 = 1 << 7;
|
|
||||||
/// Command flag: unsequenced delivery.
|
|
||||||
pub const COMMAND_FLAG_UNSEQUENCED: u8 = 1 << 6;
|
|
||||||
|
|
||||||
/// ENet command numbers (low 4 bits of the command byte).
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum CommandKind {
|
|
||||||
/// Acknowledge a reliable command.
|
|
||||||
Acknowledge = 1,
|
|
||||||
/// Open a connection.
|
|
||||||
Connect = 2,
|
|
||||||
/// Answer to connect.
|
|
||||||
VerifyConnect = 3,
|
|
||||||
/// Close.
|
|
||||||
Disconnect = 4,
|
|
||||||
/// Keep-alive.
|
|
||||||
Ping = 5,
|
|
||||||
/// Reliable data.
|
|
||||||
SendReliable = 6,
|
|
||||||
/// Unreliable sequenced data.
|
|
||||||
SendUnreliable = 7,
|
|
||||||
/// Reliable fragment.
|
|
||||||
SendFragment = 8,
|
|
||||||
/// Unsequenced data.
|
|
||||||
SendUnsequenced = 9,
|
|
||||||
/// Bandwidth limits.
|
|
||||||
BandwidthLimit = 10,
|
|
||||||
/// Throttle parameters.
|
|
||||||
ThrottleConfigure = 11,
|
|
||||||
/// Unreliable fragment.
|
|
||||||
SendUnreliableFragment = 12,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parameters of connect and verify connect.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct ConnectParams {
|
|
||||||
/// Sender's peer id for the receiver to use.
|
|
||||||
pub outgoing_peer_id: u16,
|
|
||||||
/// Session id for incoming traffic.
|
|
||||||
pub incoming_session_id: u8,
|
|
||||||
/// Session id for outgoing traffic.
|
|
||||||
pub outgoing_session_id: u8,
|
|
||||||
/// MTU.
|
|
||||||
pub mtu: u32,
|
|
||||||
/// Reliable window size.
|
|
||||||
pub window_size: u32,
|
|
||||||
/// Channel count.
|
|
||||||
pub channel_count: u32,
|
|
||||||
/// Incoming bandwidth, bytes/s, 0 = unlimited.
|
|
||||||
pub incoming_bandwidth: u32,
|
|
||||||
/// Outgoing bandwidth, bytes/s, 0 = unlimited.
|
|
||||||
pub outgoing_bandwidth: u32,
|
|
||||||
/// Throttle interval, ms.
|
|
||||||
pub packet_throttle_interval: u32,
|
|
||||||
/// Throttle acceleration.
|
|
||||||
pub packet_throttle_acceleration: u32,
|
|
||||||
/// Throttle deceleration.
|
|
||||||
pub packet_throttle_deceleration: u32,
|
|
||||||
/// Random id that ties verify connect to connect.
|
|
||||||
pub connect_id: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fragment fields shared by reliable and unreliable fragments.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct Fragment {
|
|
||||||
/// Sequence number of the first fragment.
|
|
||||||
pub start_sequence: u16,
|
|
||||||
/// Number of fragments.
|
|
||||||
pub fragment_count: u32,
|
|
||||||
/// This fragment's number.
|
|
||||||
pub fragment_number: u32,
|
|
||||||
/// Length of the whole packet.
|
|
||||||
pub total_length: u32,
|
|
||||||
/// This fragment's offset in the whole packet.
|
|
||||||
pub fragment_offset: u32,
|
|
||||||
/// This fragment's bytes.
|
|
||||||
pub data: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One command with its 4-byte header fields.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct Command {
|
|
||||||
/// The receiver must acknowledge (flag bit 7).
|
|
||||||
pub acknowledge: bool,
|
|
||||||
/// Channel id (0xFF for connection-level commands).
|
|
||||||
pub channel_id: u8,
|
|
||||||
/// Reliable sequence number.
|
|
||||||
pub reliable_sequence: u16,
|
|
||||||
/// The command body.
|
|
||||||
pub body: CommandBody,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Command bodies.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum CommandBody {
|
|
||||||
/// Acknowledges `received_reliable_sequence` sent at `received_sent_time`.
|
|
||||||
Acknowledge {
|
|
||||||
/// Acknowledged sequence number.
|
|
||||||
received_reliable_sequence: u16,
|
|
||||||
/// The acknowledged datagram's `sent_time`.
|
|
||||||
received_sent_time: u16,
|
|
||||||
},
|
|
||||||
/// Connect, with its user data word.
|
|
||||||
Connect {
|
|
||||||
/// Connection parameters.
|
|
||||||
params: ConnectParams,
|
|
||||||
/// User data (UNKNOWN U9: what a GameStream host expects here).
|
|
||||||
data: u32,
|
|
||||||
},
|
|
||||||
/// Verify connect.
|
|
||||||
VerifyConnect(ConnectParams),
|
|
||||||
/// Disconnect with a user data word.
|
|
||||||
Disconnect {
|
|
||||||
/// User data.
|
|
||||||
data: u32,
|
|
||||||
},
|
|
||||||
/// Ping.
|
|
||||||
Ping,
|
|
||||||
/// Reliable data.
|
|
||||||
SendReliable(Vec<u8>),
|
|
||||||
/// Unreliable sequenced data.
|
|
||||||
SendUnreliable {
|
|
||||||
/// Unreliable sequence number.
|
|
||||||
unreliable_sequence: u16,
|
|
||||||
/// The data.
|
|
||||||
data: Vec<u8>,
|
|
||||||
},
|
|
||||||
/// Reliable fragment.
|
|
||||||
SendFragment(Fragment),
|
|
||||||
/// Unsequenced data.
|
|
||||||
SendUnsequenced {
|
|
||||||
/// Unsequenced group.
|
|
||||||
unsequenced_group: u16,
|
|
||||||
/// The data.
|
|
||||||
data: Vec<u8>,
|
|
||||||
},
|
|
||||||
/// Bandwidth limits, bytes/s.
|
|
||||||
BandwidthLimit {
|
|
||||||
/// Incoming.
|
|
||||||
incoming: u32,
|
|
||||||
/// Outgoing.
|
|
||||||
outgoing: u32,
|
|
||||||
},
|
|
||||||
/// Throttle parameters.
|
|
||||||
ThrottleConfigure {
|
|
||||||
/// Interval, ms.
|
|
||||||
interval: u32,
|
|
||||||
/// Acceleration.
|
|
||||||
acceleration: u32,
|
|
||||||
/// Deceleration.
|
|
||||||
deceleration: u32,
|
|
||||||
},
|
|
||||||
/// Unreliable fragment.
|
|
||||||
SendUnreliableFragment(Fragment),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One datagram: protocol header plus commands.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct Datagram {
|
|
||||||
/// Receiver's peer id (12 bits).
|
|
||||||
pub peer_id: u16,
|
|
||||||
/// Session id (2 bits).
|
|
||||||
pub session_id: u8,
|
|
||||||
/// `sent_time` (low 16 bits of the sender's ms clock), if present.
|
|
||||||
pub sent_time: Option<u16>,
|
|
||||||
/// The commands, at most [`MAX_COMMANDS_PER_DATAGRAM`].
|
|
||||||
pub commands: Vec<Command>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one datagram strictly: every length checked against the bytes present, unknown command numbers and
|
|
||||||
/// compressed datagrams refused.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_DATAGRAM_BYTES`] or [`MAX_COMMANDS_PER_DATAGRAM`],
|
|
||||||
/// [`crate::Error::Truncated`] for a cut command, [`crate::Error::UnexpectedValue`] for an unknown command or the
|
|
||||||
/// compressed flag, [`crate::Error::Malformed`] for a data length that does not match. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_datagram(datagram: &[u8]) -> crate::Result<Datagram> {
|
|
||||||
let _ = datagram;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializes one datagram.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_DATAGRAM_BYTES`] or [`MAX_COMMANDS_PER_DATAGRAM`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn encode_datagram(datagram: &Datagram) -> crate::Result<Vec<u8>> {
|
|
||||||
let _ = datagram;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Randomness comes in from the caller, so every test is deterministic.
|
|
||||||
|
|
||||||
/// A source of random bytes supplied by the caller.
|
|
||||||
///
|
|
||||||
/// In production this must be a cryptographically secure generator (the OS generator). Tests pass a fixed,
|
|
||||||
/// seeded source. DomiStream never reads randomness any other way: salts, challenges, secrets, the client key,
|
|
||||||
/// `rikey`, ENet connect ids and PINs all come from here.
|
|
||||||
pub trait RandomSource {
|
|
||||||
/// Fills `dest` completely with random bytes.
|
|
||||||
fn fill(&mut self, dest: &mut [u8]);
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
//! The one error type of the crate.
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
/// Result with the crate's [`Error`].
|
|
||||||
pub type Result<T> = core::result::Result<T, Error>;
|
|
||||||
|
|
||||||
/// Everything that can go wrong. Errors never carry key material or decrypted bytes.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
#[non_exhaustive]
|
|
||||||
pub enum Error {
|
|
||||||
/// Phase A: the API exists, the logic does not yet.
|
|
||||||
Unimplemented,
|
|
||||||
/// Input is larger than the parser's `MAX_*` constant. Checked before anything is allocated.
|
|
||||||
TooLarge {
|
|
||||||
/// What was being parsed, e.g. `"rtsp message"`.
|
|
||||||
what: &'static str,
|
|
||||||
/// The cap.
|
|
||||||
max: usize,
|
|
||||||
/// The size that was offered.
|
|
||||||
actual: usize,
|
|
||||||
},
|
|
||||||
/// Input ends before a field it announces.
|
|
||||||
Truncated {
|
|
||||||
/// What was being parsed.
|
|
||||||
what: &'static str,
|
|
||||||
/// Bytes the field needs.
|
|
||||||
needed: usize,
|
|
||||||
/// Bytes that were there.
|
|
||||||
actual: usize,
|
|
||||||
},
|
|
||||||
/// Input does not follow the format (bad syntax, bad length field, wrong constant, bad encoding).
|
|
||||||
Malformed {
|
|
||||||
/// What was being parsed and what was wrong, a fixed string.
|
|
||||||
what: &'static str,
|
|
||||||
},
|
|
||||||
/// A field holds a value this client does not accept (unknown type code, out-of-range number).
|
|
||||||
UnexpectedValue {
|
|
||||||
/// The field.
|
|
||||||
what: &'static str,
|
|
||||||
/// The value seen.
|
|
||||||
value: u64,
|
|
||||||
},
|
|
||||||
/// The host answered with a non-200 `status_code` (HTTP XML) or RTSP status.
|
|
||||||
HostStatus {
|
|
||||||
/// The status code.
|
|
||||||
code: u32,
|
|
||||||
},
|
|
||||||
/// Decryption, tag or signature check failed. Deliberately without detail.
|
|
||||||
Crypto,
|
|
||||||
/// Pairing refused: wrong PIN, failed host proof (possible man in the middle), or `paired=0`.
|
|
||||||
PairingRefused,
|
|
||||||
/// The host does not offer something this client requires (for example control encryption).
|
|
||||||
Unsupported {
|
|
||||||
/// What is missing.
|
|
||||||
what: &'static str,
|
|
||||||
},
|
|
||||||
/// The call is not valid in the current state of the state machine.
|
|
||||||
State {
|
|
||||||
/// The state the call needs, a fixed string.
|
|
||||||
expected: &'static str,
|
|
||||||
},
|
|
||||||
/// The peer stopped answering within its timeout.
|
|
||||||
TimedOut,
|
|
||||||
/// The session is closed; no more calls are accepted.
|
|
||||||
Closed,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::Unimplemented => f.write_str("not implemented yet"),
|
|
||||||
Self::TooLarge { what, max, actual } => {
|
|
||||||
write!(f, "{what}: {actual} bytes is over the {max}-byte limit")
|
|
||||||
}
|
|
||||||
Self::Truncated { what, needed, actual } => {
|
|
||||||
write!(f, "{what}: needs {needed} bytes, got {actual}")
|
|
||||||
}
|
|
||||||
Self::Malformed { what } => write!(f, "malformed {what}"),
|
|
||||||
Self::UnexpectedValue { what, value } => {
|
|
||||||
write!(f, "{what}: unexpected value {value:#x}")
|
|
||||||
}
|
|
||||||
Self::HostStatus { code } => write!(f, "host answered with status {code}"),
|
|
||||||
Self::Crypto => f.write_str("cryptographic check failed"),
|
|
||||||
Self::PairingRefused => f.write_str("pairing refused"),
|
|
||||||
Self::Unsupported { what } => write!(f, "host does not support {what}"),
|
|
||||||
Self::State { expected } => write!(f, "not allowed now: needs state {expected}"),
|
|
||||||
Self::TimedOut => f.write_str("timed out"),
|
|
||||||
Self::Closed => f.write_str("session closed"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for Error {}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
//! Reed-Solomon erasure coding over GF(2^8), polynomial `0x11D` (`docs/PROTOCOL.md` 5.3, 6.4).
|
|
||||||
//!
|
|
||||||
//! Systematic code: `data` shards pass through unchanged, `parity` shards are linear combinations of them, and any
|
|
||||||
//! `data` of the `data + parity` shards rebuild the rest. Every byte position is coded on its own, so all shards of
|
|
||||||
//! a block have the same length.
|
|
||||||
//!
|
|
||||||
//! Two matrices are needed: video (`ReedSolomon::new`, construction UNKNOWN U14) and audio (a fixed 2 × 4 parity
|
|
||||||
//! matrix, UNKNOWN U16, passed in with [`ReedSolomon::with_parity_matrix`] until it is measured).
|
|
||||||
|
|
||||||
/// Maximum shards in one block (data + parity).
|
|
||||||
pub const MAX_SHARDS: usize = 255;
|
|
||||||
/// Maximum length of one shard, in bytes.
|
|
||||||
pub const MAX_SHARD_BYTES: usize = 4096;
|
|
||||||
|
|
||||||
/// Parity shards for `data_shards` at `fec_percentage`: `ceil(data × percentage / 100)`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::UnexpectedValue`] when `data_shards` is 0 or the result would exceed [`MAX_SHARDS`]. Phase A:
|
|
||||||
/// always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parity_count(data_shards: usize, fec_percentage: u8) -> crate::Result<usize> {
|
|
||||||
let _ = (data_shards, fec_percentage);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One code: shard counts and its parity matrix.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct ReedSolomon {
|
|
||||||
data_shards: usize,
|
|
||||||
parity_shards: usize,
|
|
||||||
/// `parity_shards × data_shards` coefficients, row-major.
|
|
||||||
parity_matrix: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ReedSolomon {
|
|
||||||
/// The code GameStream video uses for `data_shards` + `parity_shards` (UNKNOWN U14: construction).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::UnexpectedValue`] when either count is 0 or the sum exceeds [`MAX_SHARDS`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn new(data_shards: usize, parity_shards: usize) -> crate::Result<Self> {
|
|
||||||
let _ = (data_shards, parity_shards);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A code with an explicit parity matrix (`parity_shards × data_shards`, row-major). The matrix must make every
|
|
||||||
/// square submatrix of `[I; P]` invertible, or some loss patterns cannot be rebuilt; this is checked.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`Self::new`]; [`crate::Error::Malformed`] for a matrix of the wrong size or one that is not MDS.
|
|
||||||
pub fn with_parity_matrix(data_shards: usize, parity_shards: usize, parity_matrix: &[u8]) -> crate::Result<Self> {
|
|
||||||
let _ = (data_shards, parity_shards, parity_matrix);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of data shards.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn data_shards(&self) -> usize {
|
|
||||||
self.data_shards
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Number of parity shards.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn parity_shards(&self) -> usize {
|
|
||||||
self.parity_shards
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The parity matrix, row-major.
|
|
||||||
#[must_use]
|
|
||||||
pub fn parity_matrix(&self) -> &[u8] {
|
|
||||||
&self.parity_matrix
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Computes the parity shards from the data shards. `shards` holds `data + parity` buffers of equal length;
|
|
||||||
/// the parity ones are overwritten.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for the wrong shard count or unequal lengths, [`crate::Error::TooLarge`] over
|
|
||||||
/// [`MAX_SHARD_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn encode(&self, shards: &mut [Vec<u8>]) -> crate::Result<()> {
|
|
||||||
let _ = shards;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Rebuilds missing shards in place. `shards` holds `data + parity` entries, `None` for lost ones; on success
|
|
||||||
/// every entry is `Some`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for the wrong count or unequal lengths, [`crate::Error::TooLarge`] over
|
|
||||||
/// [`MAX_SHARD_BYTES`], [`crate::Error::Truncated`] when fewer than `data` shards are present. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn reconstruct(&self, shards: &mut [Option<Vec<u8>>]) -> crate::Result<()> {
|
|
||||||
let _ = shards;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
//! `GET /applist` (`docs/PROTOCOL.md` 1.3).
|
|
||||||
|
|
||||||
/// Maximum size of an applist body, in bytes.
|
|
||||||
pub const MAX_APPLIST_BYTES: usize = 1024 * 1024;
|
|
||||||
/// Maximum number of apps accepted in one list.
|
|
||||||
pub const MAX_APPS: usize = 4096;
|
|
||||||
/// Maximum length of an app title, in bytes.
|
|
||||||
pub const MAX_APP_TITLE_BYTES: usize = 512;
|
|
||||||
|
|
||||||
/// One app the host can launch.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct App {
|
|
||||||
/// `ID`: the value for `appid` in launch.
|
|
||||||
pub id: u32,
|
|
||||||
/// `AppTitle`, unescaped.
|
|
||||||
pub title: String,
|
|
||||||
/// `IsHdrSupported == 1`.
|
|
||||||
pub hdr_supported: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses an applist body. Apps keep the host's order; duplicate ids are refused.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_APPLIST_BYTES`], [`MAX_APPS`] or [`MAX_APP_TITLE_BYTES`],
|
|
||||||
/// [`crate::Error::HostStatus`] for a non-200 answer, [`crate::Error::Malformed`] for an `App` without `ID` or
|
|
||||||
/// `AppTitle`. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_app_list(body: &[u8]) -> crate::Result<Vec<App>> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
//! `GET /launch` and `GET /resume` (`docs/PROTOCOL.md` 1.4).
|
|
||||||
|
|
||||||
use super::HttpRequest;
|
|
||||||
use crate::SessionKeys;
|
|
||||||
|
|
||||||
/// Maximum size of a launch or resume answer, in bytes.
|
|
||||||
pub const MAX_LAUNCH_RESPONSE_BYTES: usize = 16 * 1024;
|
|
||||||
/// Maximum length of `sessionUrl0`, in bytes.
|
|
||||||
pub const MAX_SESSION_URL_BYTES: usize = 256;
|
|
||||||
|
|
||||||
/// Audio channel layouts the client can ask for.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum AudioLayout {
|
|
||||||
/// 2.0.
|
|
||||||
Stereo,
|
|
||||||
/// 5.1.
|
|
||||||
Surround51,
|
|
||||||
/// 7.1.
|
|
||||||
Surround71,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What to launch and how.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct LaunchParams {
|
|
||||||
/// App `ID` from [`super::parse_app_list`].
|
|
||||||
pub app_id: u32,
|
|
||||||
/// Stream width in pixels.
|
|
||||||
pub width: u32,
|
|
||||||
/// Stream height in pixels.
|
|
||||||
pub height: u32,
|
|
||||||
/// Frames per second.
|
|
||||||
pub fps: u32,
|
|
||||||
/// Fresh keys for this session (never reuse; see [`SessionKeys`]).
|
|
||||||
pub keys: SessionKeys,
|
|
||||||
/// Ask for HDR (`hdrMode=1`).
|
|
||||||
pub hdr: bool,
|
|
||||||
/// Audio layout (`surroundAudioInfo`).
|
|
||||||
pub audio: AudioLayout,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What the host answers to launch or resume.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct LaunchResponse {
|
|
||||||
/// `gamesession == 1`.
|
|
||||||
pub game_session: bool,
|
|
||||||
/// `sessionUrl0`, e.g. `rtsp://192.0.2.10:48010`; `None` when missing (UNKNOWN U4).
|
|
||||||
pub session_url: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /launch` (HTTPS).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a zero size or frame rate, or a bad `unique_id`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn launch_request(params: &LaunchParams, unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = (params, unique_id);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /resume` (HTTPS) with fresh keys.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`launch_request`].
|
|
||||||
pub fn resume_request(keys: &SessionKeys, unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = (keys, unique_id);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses a launch or resume answer.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_LAUNCH_RESPONSE_BYTES`] or [`MAX_SESSION_URL_BYTES`],
|
|
||||||
/// [`crate::Error::HostStatus`] for a non-200 answer, [`crate::Error::Malformed`] for a `sessionUrl0` that is not an
|
|
||||||
/// `rtsp://host:port` URL. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_launch_response(body: &[u8]) -> crate::Result<LaunchResponse> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
//! The HTTP/HTTPS side of GameStream (`docs/PROTOCOL.md` section 1): request building and strict parsers of the
|
|
||||||
//! host's XML answers. Pairing has its own module, [`crate::pairing`].
|
|
||||||
//!
|
|
||||||
//! DomiStream builds the path and query of each `GET`; the caller sends it over plain HTTP or over TLS (with the
|
|
||||||
//! client certificate and the pinned host certificate, see [`crate::pairing::ServerCert`]) and hands the response
|
|
||||||
//! body back to the matching `parse_*` function.
|
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
pub mod applist;
|
|
||||||
pub mod launch;
|
|
||||||
pub mod serverinfo;
|
|
||||||
pub mod xml;
|
|
||||||
|
|
||||||
pub use applist::{App, parse_app_list};
|
|
||||||
pub use launch::{LaunchParams, LaunchResponse, parse_launch_response};
|
|
||||||
pub use serverinfo::{ServerInfo, parse_server_info};
|
|
||||||
|
|
||||||
/// Default HTTP port of a GameStream host.
|
|
||||||
pub const DEFAULT_HTTP_PORT: u16 = 47989;
|
|
||||||
/// Default HTTPS port of a GameStream host.
|
|
||||||
pub const DEFAULT_HTTPS_PORT: u16 = 47984;
|
|
||||||
|
|
||||||
/// Maximum length of the client's `uniqueid`, in bytes.
|
|
||||||
pub const MAX_UNIQUE_ID_BYTES: usize = 64;
|
|
||||||
/// Maximum length of the device name sent while pairing, in bytes.
|
|
||||||
pub const MAX_DEVICE_NAME_BYTES: usize = 64;
|
|
||||||
|
|
||||||
/// Plain HTTP or HTTPS.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum Scheme {
|
|
||||||
/// Plain HTTP (port [`DEFAULT_HTTP_PORT`] unless the host says otherwise).
|
|
||||||
Http,
|
|
||||||
/// HTTPS with the client certificate (port from `serverinfo`'s `HttpsPort`).
|
|
||||||
Https,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One `GET` request for the caller to send. Always a `GET`; the body is always empty.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct HttpRequest {
|
|
||||||
/// Which port and transport to use.
|
|
||||||
pub scheme: Scheme,
|
|
||||||
/// Path and percent-encoded query, e.g. `/serverinfo?uniqueid=0123456789ABCDEF`.
|
|
||||||
pub path_and_query: String,
|
|
||||||
/// How long the caller should wait for the answer. `None` = the caller's normal timeout. Pairing step 1 blocks
|
|
||||||
/// on the host until the PIN is entered, so it asks for a long one.
|
|
||||||
pub timeout: Option<Duration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /serverinfo` for this client.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for an empty or oversized `unique_id`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn server_info_request(scheme: Scheme, unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = (scheme, unique_id);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /applist` (HTTPS).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`server_info_request`].
|
|
||||||
pub fn app_list_request(unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = unique_id;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /cancel` (HTTPS): quits the app running on the host.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`server_info_request`].
|
|
||||||
pub fn cancel_request(unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = unique_id;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds `GET /unpair` (HTTPS): the host forgets this client.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`server_info_request`].
|
|
||||||
pub fn unpair_request(unique_id: &str) -> crate::Result<HttpRequest> {
|
|
||||||
let _ = unique_id;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks a plain `<root status_code="200"/>` answer (cancel, unpair).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::HostStatus`] for a non-200 status, parser errors as [`xml::parse`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_status_response(body: &[u8]) -> crate::Result<()> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
//! `GET /serverinfo` (`docs/PROTOCOL.md` 1.2).
|
|
||||||
|
|
||||||
/// Maximum size of a serverinfo body, in bytes.
|
|
||||||
pub const MAX_SERVERINFO_BYTES: usize = 64 * 1024;
|
|
||||||
/// Maximum length of any string field in serverinfo, in bytes.
|
|
||||||
pub const MAX_SERVERINFO_FIELD_BYTES: usize = 256;
|
|
||||||
|
|
||||||
/// What the host says about itself. Optional fields are `None` when the element is missing or empty.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct ServerInfo {
|
|
||||||
/// `hostname`.
|
|
||||||
pub hostname: String,
|
|
||||||
/// `appversion`, e.g. `7.1.431.-1`.
|
|
||||||
pub app_version: String,
|
|
||||||
/// `GfeVersion`.
|
|
||||||
pub gfe_version: Option<String>,
|
|
||||||
/// `uniqueid`: the host's stable id.
|
|
||||||
pub unique_id: String,
|
|
||||||
/// `HttpsPort`.
|
|
||||||
pub https_port: u16,
|
|
||||||
/// `ExternalPort` (the HTTP port).
|
|
||||||
pub http_port: Option<u16>,
|
|
||||||
/// `mac`, for Wake-on-LAN, as `aa:bb:cc:dd:ee:ff`.
|
|
||||||
pub mac: Option<[u8; 6]>,
|
|
||||||
/// `LocalIP`, as the host wrote it.
|
|
||||||
pub local_ip: Option<String>,
|
|
||||||
/// `MaxLumaPixelsHEVC`; 0 = no HEVC.
|
|
||||||
pub max_luma_pixels_hevc: Option<u64>,
|
|
||||||
/// `ServerCodecModeSupport` bitmask (bit meanings UNKNOWN U25).
|
|
||||||
pub codec_mode_support: Option<u32>,
|
|
||||||
/// `PairStatus == 1`. Only meaningful over HTTPS.
|
|
||||||
pub paired: bool,
|
|
||||||
/// `currentgame`: id of the running app, 0 = none.
|
|
||||||
pub current_game: u32,
|
|
||||||
/// `state`, raw (host-specific `…_SERVER_BUSY` / `…_SERVER_FREE`).
|
|
||||||
pub state: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ServerInfo {
|
|
||||||
/// Whether the host reports a running app (`state` ends in `_BUSY` or `currentgame != 0`).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn is_busy(&self) -> crate::Result<bool> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses a serverinfo body.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_SERVERINFO_BYTES`], [`crate::Error::HostStatus`] for a non-200 answer,
|
|
||||||
/// [`crate::Error::Malformed`] for a missing required element (`hostname`, `uniqueid`, `HttpsPort`) or a bad
|
|
||||||
/// number. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_server_info(body: &[u8]) -> crate::Result<ServerInfo> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
//! A small, strict XML reader for the host's answers: one `<root status_code="…">` element with nested
|
|
||||||
//! elements and text. No DTD, no entities beyond the five predefined ones and numeric character references,
|
|
||||||
//! no processing instructions except a leading XML declaration, no namespaces.
|
|
||||||
|
|
||||||
/// Maximum size of any XML body accepted, in bytes.
|
|
||||||
pub const MAX_XML_BYTES: usize = 1024 * 1024;
|
|
||||||
/// Maximum element nesting depth (the root is depth 1).
|
|
||||||
pub const MAX_XML_DEPTH: usize = 8;
|
|
||||||
/// Maximum number of elements in one document.
|
|
||||||
pub const MAX_XML_ELEMENTS: usize = 16 * 1024;
|
|
||||||
/// Maximum length of one element's text, in bytes after unescaping.
|
|
||||||
pub const MAX_XML_TEXT_BYTES: usize = 64 * 1024;
|
|
||||||
/// Maximum number of attributes on one element.
|
|
||||||
pub const MAX_XML_ATTRIBUTES: usize = 8;
|
|
||||||
|
|
||||||
/// One element: its name, attributes, text (concatenated, unescaped, not trimmed) and child elements.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
|
||||||
pub struct Element {
|
|
||||||
/// Tag name, case-sensitive.
|
|
||||||
pub name: String,
|
|
||||||
/// Attributes in document order, values unescaped.
|
|
||||||
pub attributes: Vec<(String, String)>,
|
|
||||||
/// Text content directly inside this element.
|
|
||||||
pub text: String,
|
|
||||||
/// Child elements in document order.
|
|
||||||
pub children: Vec<Element>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A parsed host answer.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct Document {
|
|
||||||
/// The root element's `status_code` attribute (the host's status; 200 = OK).
|
|
||||||
pub status_code: u32,
|
|
||||||
/// The root element's `status_message` attribute, if any (UNKNOWN U27).
|
|
||||||
pub status_message: Option<String>,
|
|
||||||
/// The root element itself.
|
|
||||||
pub root: Element,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses an XML answer. The root element must be `root` and carry a decimal `status_code`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_XML_BYTES`] or any other cap, [`crate::Error::Malformed`] for anything that
|
|
||||||
/// is not well-formed or uses a refused feature. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse(body: &[u8]) -> crate::Result<Document> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
//! Gamepad state, buttons and capabilities (`docs/PROTOCOL.md` section 4, CONTROLLER_MULTI and ARRIVAL).
|
|
||||||
|
|
||||||
/// Data length of `CONTROLLER_MULTI` (26 bytes after the input type).
|
|
||||||
pub const CONTROLLER_MULTI_DATA_LEN: usize = 26;
|
|
||||||
/// Highest controller number accepted (16 controllers, matching a 16-bit active mask).
|
|
||||||
pub const MAX_CONTROLLER_NUMBER: u8 = 15;
|
|
||||||
|
|
||||||
/// Button bits: low 16 bits in the first button field, high 16 bits in the second.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct ButtonFlags(pub u32);
|
|
||||||
|
|
||||||
impl ButtonFlags {
|
|
||||||
/// D-pad up.
|
|
||||||
pub const DPAD_UP: u32 = 0x0001;
|
|
||||||
/// D-pad down.
|
|
||||||
pub const DPAD_DOWN: u32 = 0x0002;
|
|
||||||
/// D-pad left.
|
|
||||||
pub const DPAD_LEFT: u32 = 0x0004;
|
|
||||||
/// D-pad right.
|
|
||||||
pub const DPAD_RIGHT: u32 = 0x0008;
|
|
||||||
/// Start / Menu.
|
|
||||||
pub const START: u32 = 0x0010;
|
|
||||||
/// Back / View.
|
|
||||||
pub const BACK: u32 = 0x0020;
|
|
||||||
/// Left stick press.
|
|
||||||
pub const LEFT_STICK: u32 = 0x0040;
|
|
||||||
/// Right stick press.
|
|
||||||
pub const RIGHT_STICK: u32 = 0x0080;
|
|
||||||
/// Left shoulder.
|
|
||||||
pub const LEFT_BUTTON: u32 = 0x0100;
|
|
||||||
/// Right shoulder.
|
|
||||||
pub const RIGHT_BUTTON: u32 = 0x0200;
|
|
||||||
/// Home / Guide.
|
|
||||||
pub const HOME: u32 = 0x0400;
|
|
||||||
/// A.
|
|
||||||
pub const A: u32 = 0x1000;
|
|
||||||
/// B.
|
|
||||||
pub const B: u32 = 0x2000;
|
|
||||||
/// X.
|
|
||||||
pub const X: u32 = 0x4000;
|
|
||||||
/// Y.
|
|
||||||
pub const Y: u32 = 0x8000;
|
|
||||||
/// Paddle 1.
|
|
||||||
pub const PADDLE1: u32 = 0x01_0000;
|
|
||||||
/// Paddle 2.
|
|
||||||
pub const PADDLE2: u32 = 0x02_0000;
|
|
||||||
/// Paddle 3.
|
|
||||||
pub const PADDLE3: u32 = 0x04_0000;
|
|
||||||
/// Paddle 4.
|
|
||||||
pub const PADDLE4: u32 = 0x08_0000;
|
|
||||||
/// Touchpad click.
|
|
||||||
pub const TOUCHPAD: u32 = 0x10_0000;
|
|
||||||
/// Misc (share / capture).
|
|
||||||
pub const MISC: u32 = 0x20_0000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Controller type in `CONTROLLER_ARRIVAL`.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum ControllerKind {
|
|
||||||
/// Unknown.
|
|
||||||
Unknown = 0x00,
|
|
||||||
/// Xbox-style.
|
|
||||||
Xbox = 0x01,
|
|
||||||
/// PlayStation-style.
|
|
||||||
PlayStation = 0x02,
|
|
||||||
/// Nintendo-style.
|
|
||||||
Nintendo = 0x03,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Capability bits in `CONTROLLER_ARRIVAL`.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct ControllerCapabilities(pub u8);
|
|
||||||
|
|
||||||
impl ControllerCapabilities {
|
|
||||||
/// Analog triggers.
|
|
||||||
pub const ANALOG_TRIGGERS: u8 = 0x01;
|
|
||||||
/// Rumble.
|
|
||||||
pub const RUMBLE: u8 = 0x02;
|
|
||||||
/// Trigger rumble.
|
|
||||||
pub const TRIGGER_RUMBLE: u8 = 0x04;
|
|
||||||
/// Touchpad.
|
|
||||||
pub const TOUCHPAD: u8 = 0x08;
|
|
||||||
/// Accelerometer.
|
|
||||||
pub const ACCELEROMETER: u8 = 0x10;
|
|
||||||
/// Gyroscope.
|
|
||||||
pub const GYRO: u8 = 0x20;
|
|
||||||
/// Battery state.
|
|
||||||
pub const BATTERY: u8 = 0x40;
|
|
||||||
/// RGB LED.
|
|
||||||
pub const RGB_LED: u8 = 0x80;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One `CONTROLLER_MULTI` state.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct GamepadState {
|
|
||||||
/// Controller number, 0..=15.
|
|
||||||
pub controller: u8,
|
|
||||||
/// Bit per connected controller. A cleared bit for `controller` means it was unplugged.
|
|
||||||
pub active_mask: u16,
|
|
||||||
/// Pressed buttons.
|
|
||||||
pub buttons: ButtonFlags,
|
|
||||||
/// Left trigger, 0..=255.
|
|
||||||
pub left_trigger: u8,
|
|
||||||
/// Right trigger, 0..=255.
|
|
||||||
pub right_trigger: u8,
|
|
||||||
/// Left stick X.
|
|
||||||
pub left_stick_x: i16,
|
|
||||||
/// Left stick Y.
|
|
||||||
pub left_stick_y: i16,
|
|
||||||
/// Right stick X.
|
|
||||||
pub right_stick_x: i16,
|
|
||||||
/// Right stick Y.
|
|
||||||
pub right_stick_y: i16,
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
//! Input and gamepad packets (`docs/PROTOCOL.md` section 4).
|
|
||||||
//!
|
|
||||||
//! An `INPUT_DATA` message is `0x0206 (LE) ‖ length (LE) ‖ size (BE) ‖ input type (LE) ‖ data`; see the field
|
|
||||||
//! tables and the test vectors in PROTOCOL.md. [`encode_input`] produces the whole message, ready for the control
|
|
||||||
//! frame; [`parse_input`] is its inverse (for round-trip tests, fuzzing and the Lumen host).
|
|
||||||
|
|
||||||
pub mod gamepad;
|
|
||||||
|
|
||||||
pub use gamepad::{ButtonFlags, ControllerCapabilities, ControllerKind, GamepadState};
|
|
||||||
|
|
||||||
/// Maximum size of one `INPUT_DATA` message, in bytes.
|
|
||||||
pub const MAX_INPUT_MESSAGE_BYTES: usize = 1024;
|
|
||||||
/// Bytes before the input data (message header 4 + size 4 + input type 4).
|
|
||||||
pub const INPUT_HEADER_LEN: usize = 12;
|
|
||||||
|
|
||||||
/// Input type codes (little-endian on the wire).
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
#[repr(u32)]
|
|
||||||
pub enum InputType {
|
|
||||||
/// Key pressed.
|
|
||||||
KeyDown = 0x0000_0003,
|
|
||||||
/// Key released.
|
|
||||||
KeyUp = 0x0000_0004,
|
|
||||||
/// Absolute mouse position.
|
|
||||||
MouseMoveAbs = 0x0000_0005,
|
|
||||||
/// Relative mouse move.
|
|
||||||
MouseMoveRel = 0x0000_0007,
|
|
||||||
/// Mouse button pressed.
|
|
||||||
MouseButtonDown = 0x0000_0008,
|
|
||||||
/// Mouse button released.
|
|
||||||
MouseButtonUp = 0x0000_0009,
|
|
||||||
/// Vertical scroll.
|
|
||||||
MouseScroll = 0x0000_000A,
|
|
||||||
/// Gamepad state.
|
|
||||||
ControllerMulti = 0x0000_000C,
|
|
||||||
/// Haptics (layout UNKNOWN U21).
|
|
||||||
Haptics = 0x0000_000D,
|
|
||||||
/// UTF-8 text (layout UNKNOWN U21).
|
|
||||||
Utf8Text = 0x0000_0017,
|
|
||||||
/// Horizontal scroll.
|
|
||||||
MouseHScroll = 0x5500_0001,
|
|
||||||
/// Touch (layout UNKNOWN U21).
|
|
||||||
Touch = 0x5500_0002,
|
|
||||||
/// Pen (layout UNKNOWN U21).
|
|
||||||
Pen = 0x5500_0003,
|
|
||||||
/// A controller was plugged in.
|
|
||||||
ControllerArrival = 0x5500_0004,
|
|
||||||
/// Controller touchpad (layout UNKNOWN U21).
|
|
||||||
ControllerTouch = 0x5500_0005,
|
|
||||||
/// Controller motion sensors (layout UNKNOWN U21).
|
|
||||||
ControllerMotion = 0x5500_0006,
|
|
||||||
/// Controller battery (layout UNKNOWN U21).
|
|
||||||
ControllerBattery = 0x5500_0007,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<u32> for InputType {
|
|
||||||
type Error = crate::Error;
|
|
||||||
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::UnexpectedValue`] for an unknown code. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
fn try_from(code: u32) -> crate::Result<Self> {
|
|
||||||
let _ = code;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mouse buttons.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum MouseButton {
|
|
||||||
/// Left.
|
|
||||||
Left = 1,
|
|
||||||
/// Middle.
|
|
||||||
Middle = 2,
|
|
||||||
/// Right.
|
|
||||||
Right = 3,
|
|
||||||
/// Side (back).
|
|
||||||
Side = 4,
|
|
||||||
/// Extra (forward).
|
|
||||||
Extra = 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One input event with a known layout.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum InputEvent {
|
|
||||||
/// Relative mouse move.
|
|
||||||
MouseMoveRel {
|
|
||||||
/// Horizontal delta.
|
|
||||||
dx: i16,
|
|
||||||
/// Vertical delta.
|
|
||||||
dy: i16,
|
|
||||||
},
|
|
||||||
/// Absolute mouse position within the client's viewport (the LG Magic Remote pointer).
|
|
||||||
MouseMoveAbs {
|
|
||||||
/// X in the viewport.
|
|
||||||
x: i16,
|
|
||||||
/// Y in the viewport.
|
|
||||||
y: i16,
|
|
||||||
/// Viewport width as the client reports it.
|
|
||||||
width: u16,
|
|
||||||
/// Viewport height as the client reports it.
|
|
||||||
height: u16,
|
|
||||||
},
|
|
||||||
/// Mouse button.
|
|
||||||
MouseButton {
|
|
||||||
/// Pressed (true) or released.
|
|
||||||
pressed: bool,
|
|
||||||
/// Which button.
|
|
||||||
button: MouseButton,
|
|
||||||
},
|
|
||||||
/// Keyboard key.
|
|
||||||
Key {
|
|
||||||
/// Pressed (true) or released.
|
|
||||||
pressed: bool,
|
|
||||||
/// `flags` byte (bit meanings UNKNOWN U20).
|
|
||||||
flags: u8,
|
|
||||||
/// Key code, Windows virtual-key style in the low byte (high byte UNKNOWN U20).
|
|
||||||
key_code: u16,
|
|
||||||
/// `modifiers` byte (bit meanings UNKNOWN U20).
|
|
||||||
modifiers: u8,
|
|
||||||
},
|
|
||||||
/// Vertical scroll (positive = up), in wheel units (120 = one notch).
|
|
||||||
Scroll {
|
|
||||||
/// Amount.
|
|
||||||
amount: i16,
|
|
||||||
},
|
|
||||||
/// Horizontal scroll.
|
|
||||||
HScroll {
|
|
||||||
/// Amount.
|
|
||||||
amount: i16,
|
|
||||||
},
|
|
||||||
/// Full gamepad state.
|
|
||||||
Gamepad(GamepadState),
|
|
||||||
/// A controller appeared.
|
|
||||||
ControllerArrival {
|
|
||||||
/// Controller number.
|
|
||||||
controller: u8,
|
|
||||||
/// What it is.
|
|
||||||
kind: ControllerKind,
|
|
||||||
/// What it can do.
|
|
||||||
capabilities: ControllerCapabilities,
|
|
||||||
/// Which buttons it has.
|
|
||||||
supported_buttons: ButtonFlags,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializes an event into a whole `INPUT_DATA` message.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::UnexpectedValue`] for a controller number above 15. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn encode_input(event: &InputEvent) -> crate::Result<Vec<u8>> {
|
|
||||||
let _ = event;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses a whole `INPUT_DATA` message (inverse of [`encode_input`]).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_INPUT_MESSAGE_BYTES`], [`crate::Error::Truncated`] under
|
|
||||||
/// [`INPUT_HEADER_LEN`], [`crate::Error::Malformed`] when the length or size field does not match, the data length
|
|
||||||
/// is wrong for the type, or a constant differs; [`crate::Error::Unsupported`] for a type whose layout is UNKNOWN.
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_input(message: &[u8]) -> crate::Result<InputEvent> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
//! The per-session stream key handed to the host in `launch` / `resume` (`docs/PROTOCOL.md` 1.4, 7).
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::{RandomSource, Result};
|
|
||||||
|
|
||||||
/// Length of `rikey` in bytes (AES-128).
|
|
||||||
pub const RIKEY_LEN: usize = 16;
|
|
||||||
|
|
||||||
/// The stream key pair of one session: `rikey` (AES-128 key for control, audio and video) and `rikeyid`
|
|
||||||
/// (feeds the audio IV).
|
|
||||||
///
|
|
||||||
/// A fresh pair is generated for every launch and resume, because the GCM nonce counters restart per session.
|
|
||||||
/// `Debug` never prints the key.
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
|
||||||
pub struct SessionKeys {
|
|
||||||
/// AES-128 key, sent hex-encoded as the `rikey` launch parameter.
|
|
||||||
pub rikey: [u8; RIKEY_LEN],
|
|
||||||
/// Key id, sent as the decimal `rikeyid` launch parameter.
|
|
||||||
pub rikeyid: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SessionKeys {
|
|
||||||
/// Draws a fresh key and key id from `rng`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn generate(rng: &mut dyn RandomSource) -> Result<Self> {
|
|
||||||
let _ = rng;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for SessionKeys {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("SessionKeys").field("rikey", &"<redacted>").field("rikeyid", &self.rikeyid).finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
//! DomiStream: a sans-I/O GameStream client (the protocol Sunshine hosts and Moonlight clients speak), for
|
|
||||||
//! Arena Domi TV and the other Play remotely clients.
|
|
||||||
//!
|
|
||||||
//! **Phase A.** This crate holds the public API only. Every function that does protocol work returns
|
|
||||||
//! [`Error::Unimplemented`] (or `None` for `poll_*` functions); QA writes the mandatory tests against these
|
|
||||||
//! signatures before the logic lands. Plain data (constants, enum codes, field structs) is final.
|
|
||||||
//!
|
|
||||||
//! # Shape
|
|
||||||
//!
|
|
||||||
//! Nothing here opens a socket, reads a clock, spawns a thread or touches a file. The caller:
|
|
||||||
//! - feeds received bytes in (`handle_*` / `push` / `parse_*`, always `&[u8]`),
|
|
||||||
//! - passes the current time in as [`Instant`] and randomness as a [`RandomSource`],
|
|
||||||
//! - sends the bytes the state machines hand out (`poll_transmit`, [`http::HttpRequest`]),
|
|
||||||
//! - reacts to events (`poll_event`) and wakes the machine at its deadline (`poll_timeout` / `handle_timeout`).
|
|
||||||
//!
|
|
||||||
//! Every parser has a `MAX_*` constant and refuses larger input before it allocates.
|
|
||||||
//!
|
|
||||||
//! # Modules, in session order
|
|
||||||
//!
|
|
||||||
//! | Module | Protocol (see `docs/PROTOCOL.md`) |
|
|
||||||
//! | :-- | :-- |
|
|
||||||
//! | [`http`] | serverinfo, applist, launch/resume/cancel (section 1) |
|
|
||||||
//! | [`pairing`] | the PIN handshake and the client certificate (section 1.5) |
|
|
||||||
//! | [`rtsp`] | OPTIONS, DESCRIBE, SETUP, ANNOUNCE, PLAY and SDP (section 2) |
|
|
||||||
//! | [`enet`] | the ENet-compatible reliable UDP layer under the control stream (section 3.1) |
|
|
||||||
//! | [`control`] | AES-GCM framing and control messages (sections 3.2, 3.3) |
|
|
||||||
//! | [`input`] | input and gamepad packets (section 4) |
|
|
||||||
//! | [`rtp`] | the RTP header shared by video and audio |
|
|
||||||
//! | [`fec`] | Reed-Solomon erasure coding over GF(2^8) |
|
|
||||||
//! | [`video`] | video depacketizer with FEC recovery and decryption (section 5) |
|
|
||||||
//! | [`audio`] | audio depacketizer with FEC recovery and decryption (section 6) |
|
|
||||||
//!
|
|
||||||
//! Opus and video decoding are not here: they belong to the platform layer (ArenaTV).
|
|
||||||
|
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![deny(missing_docs)]
|
|
||||||
|
|
||||||
pub mod audio;
|
|
||||||
pub mod control;
|
|
||||||
pub mod enet;
|
|
||||||
pub mod entropy;
|
|
||||||
pub mod error;
|
|
||||||
pub mod fec;
|
|
||||||
pub mod http;
|
|
||||||
pub mod input;
|
|
||||||
pub mod keys;
|
|
||||||
pub mod pairing;
|
|
||||||
pub mod rtp;
|
|
||||||
pub mod rtsp;
|
|
||||||
pub mod time;
|
|
||||||
pub mod video;
|
|
||||||
|
|
||||||
pub use entropy::RandomSource;
|
|
||||||
pub use error::{Error, Result};
|
|
||||||
pub use keys::SessionKeys;
|
|
||||||
pub use time::Instant;
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
//! The pure cryptographic steps of pairing (`docs/PROTOCOL.md` 1.5), public so QA can test them against
|
|
||||||
//! independent vectors (for example Python `hashlib` + `cryptography` with fixed test keys).
|
|
||||||
|
|
||||||
use super::{CHALLENGE_LEN, HASH_LEN, Pin, SALT_LEN, SECRET_LEN};
|
|
||||||
use crate::Result;
|
|
||||||
|
|
||||||
/// AES-128 key used for every encrypted pairing value.
|
|
||||||
pub type PairingKey = [u8; 16];
|
|
||||||
|
|
||||||
/// `K = SHA-256(salt ‖ PIN digits)[0..16]`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn derive_key(salt: &[u8; SALT_LEN], pin: &Pin) -> Result<PairingKey> {
|
|
||||||
let _ = (salt, pin);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AES-128-ECB encryption without padding.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] when `data` is not a whole number of 16-byte blocks. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn ecb_encrypt(key: &PairingKey, data: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = (key, data);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// AES-128-ECB decryption without padding.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`ecb_encrypt`].
|
|
||||||
pub fn ecb_decrypt(key: &PairingKey, data: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = (key, data);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `SHA-256(challenge ‖ cert_signature ‖ secret)`: the host's proof `H_s` (with the client challenge, the host
|
|
||||||
/// certificate's signature and the host secret) and the client's proof `H_c` (with the host challenge, the client
|
|
||||||
/// certificate's signature and the client secret).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] for a signature over [`super::MAX_SIGNATURE_BYTES`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn proof_hash(
|
|
||||||
challenge: &[u8; CHALLENGE_LEN],
|
|
||||||
cert_signature: &[u8],
|
|
||||||
secret: &[u8; SECRET_LEN],
|
|
||||||
) -> Result<[u8; HASH_LEN]> {
|
|
||||||
let _ = (challenge, cert_signature, secret);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Splits a decrypted `challengeresponse` (48 bytes) into the host proof `H_s` and the host challenge `S_c`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] unless exactly 48 bytes. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn split_challenge_response(decrypted: &[u8]) -> Result<([u8; HASH_LEN], [u8; CHALLENGE_LEN])> {
|
|
||||||
let _ = decrypted;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Splits a `pairingsecret` into the host secret (16 bytes) and its signature (the rest).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] when shorter than 17 bytes, [`crate::Error::TooLarge`] when the signature is over
|
|
||||||
/// [`super::MAX_SIGNATURE_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn split_pairing_secret(pairing_secret: &[u8]) -> Result<([u8; SECRET_LEN], &[u8])> {
|
|
||||||
let _ = pairing_secret;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
//! The client's certificate and key, and the host certificate learnt while pairing.
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::{RandomSource, Result};
|
|
||||||
|
|
||||||
/// Maximum size of a certificate in PEM form, in bytes.
|
|
||||||
pub const MAX_CERT_PEM_BYTES: usize = 16 * 1024;
|
|
||||||
/// Maximum size of a certificate in DER form, in bytes.
|
|
||||||
pub const MAX_CERT_DER_BYTES: usize = 12 * 1024;
|
|
||||||
/// Maximum size of a PKCS#8 private key in DER form, in bytes.
|
|
||||||
pub const MAX_KEY_DER_BYTES: usize = 8 * 1024;
|
|
||||||
/// RSA modulus size of keys this client generates.
|
|
||||||
pub const CLIENT_KEY_BITS: usize = 2048;
|
|
||||||
|
|
||||||
/// The client's long-lived identity towards GameStream hosts: a self-signed RSA-2048 / SHA-256 X.509 certificate
|
|
||||||
/// and its private key. Generated once per device and kept by the platform layer (never in logs; the key belongs
|
|
||||||
/// in the platform's secret store). `Debug` never prints the key.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ClientIdentity {
|
|
||||||
cert_der: Vec<u8>,
|
|
||||||
key_pkcs8_der: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ClientIdentity {
|
|
||||||
/// Generates a new key and self-signed certificate.
|
|
||||||
///
|
|
||||||
/// `common_name` becomes the subject and issuer CN. `not_before_unix` is the validity start in Unix seconds
|
|
||||||
/// (passed in: no clock reads); validity runs 20 years from it. RSA key generation is slow (hundreds of ms on a
|
|
||||||
/// TV); call it once per device.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for an empty or oversized `common_name`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn generate(rng: &mut dyn RandomSource, common_name: &str, not_before_unix: i64) -> Result<Self> {
|
|
||||||
let _ = (rng, common_name, not_before_unix);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads a stored identity. Checks that the key matches the certificate.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_CERT_DER_BYTES`] / [`MAX_KEY_DER_BYTES`], [`crate::Error::Malformed`]
|
|
||||||
/// for bad DER or a key that does not match. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn from_der(cert_der: &[u8], key_pkcs8_der: &[u8]) -> Result<Self> {
|
|
||||||
let _ = (cert_der, key_pkcs8_der);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The certificate, DER.
|
|
||||||
#[must_use]
|
|
||||||
pub fn cert_der(&self) -> &[u8] {
|
|
||||||
&self.cert_der
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The private key, PKCS#8 DER, for the platform's secret store and its TLS stack.
|
|
||||||
#[must_use]
|
|
||||||
pub fn key_pkcs8_der(&self) -> &[u8] {
|
|
||||||
&self.key_pkcs8_der
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The certificate as PEM text (what pairing step 1 sends, hex-encoded).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn cert_pem(&self) -> Result<String> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The raw `signatureValue` bytes of the certificate (input to the pairing proofs).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn cert_signature(&self) -> Result<Vec<u8>> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// RSASSA-PKCS1-v1_5 / SHA-256 signature over `data` with the client key.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn sign(&self, data: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = data;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for ClientIdentity {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("ClientIdentity")
|
|
||||||
.field("cert_der_len", &self.cert_der.len())
|
|
||||||
.field("key", &"<redacted>")
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The host certificate received as `plaincert` in pairing step 1, kept to pin HTTPS connections.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct ServerCert {
|
|
||||||
der: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ServerCert {
|
|
||||||
/// Parses the PEM the host sent (already hex-decoded). Exactly one `CERTIFICATE` block.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_CERT_PEM_BYTES`], [`crate::Error::Malformed`] for anything that is
|
|
||||||
/// not one well-formed X.509 certificate with an RSA key. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn from_pem(pem: &[u8]) -> Result<Self> {
|
|
||||||
let _ = pem;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads a stored certificate.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_CERT_DER_BYTES`], [`crate::Error::Malformed`] otherwise. Phase A:
|
|
||||||
/// always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn from_der(der: &[u8]) -> Result<Self> {
|
|
||||||
let _ = der;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The certificate, DER.
|
|
||||||
#[must_use]
|
|
||||||
pub fn der(&self) -> &[u8] {
|
|
||||||
&self.der
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The raw `signatureValue` bytes (input to the pairing proofs).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn signature(&self) -> Result<Vec<u8>> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verifies an RSASSA-PKCS1-v1_5 / SHA-256 `signature` over `data` with the certificate's public key.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Crypto`] when it does not verify. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<()> {
|
|
||||||
let _ = (data, signature);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TLS pinning: whether the certificate a host presents over HTTPS (DER) is exactly this one, compared in
|
|
||||||
/// constant time. The platform's TLS verifier calls this and nothing else to accept the host.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_CERT_DER_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn matches(&self, presented_der: &[u8]) -> Result<bool> {
|
|
||||||
let _ = presented_der;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
//! The PIN pairing handshake (`docs/PROTOCOL.md` 1.5), as a sans-I/O state machine.
|
|
||||||
//!
|
|
||||||
//! In Arena Domi the PIN is never shown: Arena Domi TV makes it with [`Pin::generate`], sends it to arena-host over
|
|
||||||
//! its own signed channel, and arena-host submits it to Sunshine. On the GameStream wire the handshake is unchanged.
|
|
||||||
//!
|
|
||||||
//! ```text
|
|
||||||
//! start ─▶ AwaitServerCert ─▶ AwaitChallengeResponse ─▶ AwaitPairingSecret ─▶ AwaitClientSecretAck
|
|
||||||
//! │
|
|
||||||
//! Paired ◀── AwaitPairChallenge (HTTPS) ◀───────────────────────┘
|
|
||||||
//! any step: host says paired=0 / bad proof / bad signature ─▶ Failed
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Each [`PairingSession::handle_response`] consumes one HTTP answer body and returns the next request to send,
|
|
||||||
//! or the finished [`PairedHost`].
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::http::HttpRequest;
|
|
||||||
use crate::{RandomSource, Result};
|
|
||||||
|
|
||||||
pub mod crypto;
|
|
||||||
pub mod identity;
|
|
||||||
|
|
||||||
pub use identity::{ClientIdentity, ServerCert};
|
|
||||||
|
|
||||||
/// Length of the salt sent in step 1.
|
|
||||||
pub const SALT_LEN: usize = 16;
|
|
||||||
/// Length of the client and host challenges.
|
|
||||||
pub const CHALLENGE_LEN: usize = 16;
|
|
||||||
/// Length of the client and host pairing secrets.
|
|
||||||
pub const SECRET_LEN: usize = 16;
|
|
||||||
/// Length of the SHA-256 proofs exchanged in steps 2 and 3.
|
|
||||||
pub const HASH_LEN: usize = 32;
|
|
||||||
/// Number of PIN digits.
|
|
||||||
pub const PIN_LEN: usize = 4;
|
|
||||||
/// Maximum size of one pairing answer body, in bytes.
|
|
||||||
pub const MAX_PAIR_RESPONSE_BYTES: usize = 64 * 1024;
|
|
||||||
/// Maximum size of a signature accepted from the host (RSA-8192), in bytes.
|
|
||||||
pub const MAX_SIGNATURE_BYTES: usize = 1024;
|
|
||||||
|
|
||||||
/// A 4-digit GameStream PIN.
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub struct Pin([u8; PIN_LEN]);
|
|
||||||
|
|
||||||
impl Pin {
|
|
||||||
/// Draws a uniformly random PIN (no modulo bias).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn generate(rng: &mut dyn RandomSource) -> Result<Self> {
|
|
||||||
let _ = rng;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses exactly four ASCII digits.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for anything else. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn from_digits(digits: &str) -> Result<Self> {
|
|
||||||
let _ = digits;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The four ASCII digits.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn as_bytes(&self) -> &[u8; PIN_LEN] {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Pin {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("Pin(<redacted>)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the handshake is.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum PairingState {
|
|
||||||
/// Step 1 sent (`phrase=getservercert`); waiting for `plaincert`. The host holds this answer until the PIN is in.
|
|
||||||
AwaitServerCert,
|
|
||||||
/// Step 2 sent (`clientchallenge`); waiting for `challengeresponse`.
|
|
||||||
AwaitChallengeResponse,
|
|
||||||
/// Step 3 sent (`serverchallengeresp`); waiting for `pairingsecret`.
|
|
||||||
AwaitPairingSecret,
|
|
||||||
/// Step 4 sent (`clientpairingsecret`); waiting for `paired=1`.
|
|
||||||
AwaitClientSecretAck,
|
|
||||||
/// Step 5 sent over HTTPS (`phrase=pairchallenge`); waiting for `paired=1`.
|
|
||||||
AwaitPairChallenge,
|
|
||||||
/// Done.
|
|
||||||
Paired,
|
|
||||||
/// Stopped; see [`PairingFailure`]. No further calls are accepted.
|
|
||||||
Failed(PairingFailure),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Why pairing stopped.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum PairingFailure {
|
|
||||||
/// The host answered `paired=0`.
|
|
||||||
HostRefused,
|
|
||||||
/// The host's proof `H_s` did not match: wrong PIN, or someone in the middle.
|
|
||||||
ProofMismatch,
|
|
||||||
/// The host's signature over its secret did not verify against its certificate.
|
|
||||||
BadHostSignature,
|
|
||||||
/// An answer could not be parsed or missed its element.
|
|
||||||
MalformedAnswer,
|
|
||||||
/// A non-200 HTTP or XML status.
|
|
||||||
HostStatus,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What to do next.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum PairingStep {
|
|
||||||
/// Send this request and feed its answer to [`PairingSession::handle_response`].
|
|
||||||
Send(HttpRequest),
|
|
||||||
/// Pairing finished; store this.
|
|
||||||
Paired(PairedHost),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The result of a successful pairing, to store with the client identity.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct PairedHost {
|
|
||||||
/// The host certificate from step 1; HTTPS connections must present exactly this certificate.
|
|
||||||
pub server_cert: ServerCert,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The fields a pairing answer can carry (`<root status_code="200"><paired>1</paired>…</root>`), hex-decoded.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
|
||||||
pub struct PairResponse {
|
|
||||||
/// `paired == 1`.
|
|
||||||
pub paired: bool,
|
|
||||||
/// `plaincert`: the host certificate PEM (step 1).
|
|
||||||
pub plain_cert: Option<Vec<u8>>,
|
|
||||||
/// `challengeresponse`: `E_K(H_s ‖ S_c)`, 48 bytes (step 2).
|
|
||||||
pub challenge_response: Option<Vec<u8>>,
|
|
||||||
/// `pairingsecret`: `secret_s ‖ signature` (step 3).
|
|
||||||
pub pairing_secret: Option<Vec<u8>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one pairing answer.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_PAIR_RESPONSE_BYTES`], [`crate::Error::HostStatus`] for a non-200
|
|
||||||
/// answer, [`crate::Error::Malformed`] for bad hex or a missing `paired`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_pair_response(body: &[u8]) -> Result<PairResponse> {
|
|
||||||
let _ = body;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One pairing attempt with one host.
|
|
||||||
pub struct PairingSession {
|
|
||||||
state: PairingState,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PairingSession {
|
|
||||||
/// Starts pairing: draws the salt, derives the AES key from salt and PIN, and returns step 1.
|
|
||||||
///
|
|
||||||
/// `unique_id` is this client's id (stable per device), `device_name` is shown on the host.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a bad `unique_id` or `device_name`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn start(
|
|
||||||
identity: &ClientIdentity,
|
|
||||||
unique_id: &str,
|
|
||||||
device_name: &str,
|
|
||||||
pin: Pin,
|
|
||||||
rng: &mut dyn RandomSource,
|
|
||||||
) -> Result<(Self, HttpRequest)> {
|
|
||||||
let _ = (identity, unique_id, device_name, pin, rng);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds the answer to the last request: its HTTP status and body. `identity` must be the one passed to
|
|
||||||
/// [`Self::start`] (it is borrowed per call so the session never holds a copy of the private key). Draws
|
|
||||||
/// randomness for steps 2 and 3.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::PairingRefused`] (the state becomes [`PairingState::Failed`]), parser errors as
|
|
||||||
/// [`parse_pair_response`], [`crate::Error::State`] after `Paired` or `Failed`, [`crate::Error::Malformed`] for
|
|
||||||
/// a different identity than at the start. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_response(
|
|
||||||
&mut self,
|
|
||||||
identity: &ClientIdentity,
|
|
||||||
http_status: u16,
|
|
||||||
body: &[u8],
|
|
||||||
rng: &mut dyn RandomSource,
|
|
||||||
) -> Result<PairingStep> {
|
|
||||||
let _ = (identity, http_status, body, rng);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the handshake is.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn state(&self) -> PairingState {
|
|
||||||
self.state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for PairingSession {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("PairingSession").field("state", &self.state).finish_non_exhaustive()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
//! The 12-byte RTP header shared by video and audio ([RFC 3550] §5.1, `docs/PROTOCOL.md` 5.2, 6.2).
|
|
||||||
//!
|
|
||||||
//! [RFC 3550]: https://www.rfc-editor.org/rfc/rfc3550
|
|
||||||
|
|
||||||
/// Length of the fixed RTP header.
|
|
||||||
pub const RTP_HEADER_LEN: usize = 12;
|
|
||||||
|
|
||||||
/// The fixed RTP header. Fields are big-endian on the wire. The first byte is kept raw (version 2 plus flags:
|
|
||||||
/// `0x90` for video, `0x80` for audio).
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct RtpHeader {
|
|
||||||
/// Byte 0: version, padding, extension, CSRC count.
|
|
||||||
pub flags: u8,
|
|
||||||
/// Byte 1: payload type (video 0, audio 97, audio parity 127).
|
|
||||||
pub payload_type: u8,
|
|
||||||
/// Sequence number.
|
|
||||||
pub sequence: u16,
|
|
||||||
/// Timestamp.
|
|
||||||
pub timestamp: u32,
|
|
||||||
/// SSRC.
|
|
||||||
pub ssrc: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses the first [`RTP_HEADER_LEN`] bytes of `packet` (the rest is ignored here). Refuses a version other
|
|
||||||
/// than 2.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Truncated`] for fewer than 12 bytes, [`crate::Error::UnexpectedValue`] for another RTP version.
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_rtp_header(packet: &[u8]) -> crate::Result<RtpHeader> {
|
|
||||||
let _ = packet;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
//! The RTSP client state machine: OPTIONS → DESCRIBE → SETUP audio → SETUP video → SETUP control → ANNOUNCE →
|
|
||||||
//! PLAY (`docs/PROTOCOL.md` 2.2).
|
|
||||||
//!
|
|
||||||
//! The caller opens TCP to the session URL, writes each request from [`RtspClient::poll_request`], cuts the
|
|
||||||
//! answers with [`super::RtspFramer`], and feeds each whole answer to [`RtspClient::handle_response`] until it
|
|
||||||
//! returns [`RtspProgress::Ready`].
|
|
||||||
|
|
||||||
use super::sdp::{EncryptionFlags, HostCapabilities, OpusConfig};
|
|
||||||
use crate::http::launch::AudioLayout;
|
|
||||||
|
|
||||||
/// Video codecs.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum VideoCodec {
|
|
||||||
/// H.264.
|
|
||||||
H264,
|
|
||||||
/// HEVC (H.265).
|
|
||||||
Hevc,
|
|
||||||
/// AV1.
|
|
||||||
Av1,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What the client asks for in ANNOUNCE.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct StreamConfig {
|
|
||||||
/// Width in pixels.
|
|
||||||
pub width: u32,
|
|
||||||
/// Height in pixels.
|
|
||||||
pub height: u32,
|
|
||||||
/// Frames per second.
|
|
||||||
pub fps: u32,
|
|
||||||
/// Video bitrate in kbit/s.
|
|
||||||
pub bitrate_kbps: u32,
|
|
||||||
/// Video `packetSize` (default 1024).
|
|
||||||
pub packet_size: u16,
|
|
||||||
/// Video codec.
|
|
||||||
pub codec: VideoCodec,
|
|
||||||
/// HDR (10-bit) stream.
|
|
||||||
pub hdr: bool,
|
|
||||||
/// Audio layout.
|
|
||||||
pub audio: AudioLayout,
|
|
||||||
/// Audio packet duration in milliseconds (`x-nv-aqos.packetDuration`).
|
|
||||||
pub audio_packet_duration_ms: u8,
|
|
||||||
/// Minimum video parity packets per FEC block.
|
|
||||||
pub min_fec_packets: u8,
|
|
||||||
/// The client can recover with reference frame invalidation instead of an IDR.
|
|
||||||
pub reference_frame_invalidation: bool,
|
|
||||||
/// Encryption the client wants (Day 1: all three); the ANNOUNCE turns on the intersection with the host.
|
|
||||||
pub encryption: EncryptionFlags,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The three UDP ports from the SETUP answers.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct StreamPorts {
|
|
||||||
/// Audio RTP port.
|
|
||||||
pub audio: u16,
|
|
||||||
/// Video RTP port.
|
|
||||||
pub video: u16,
|
|
||||||
/// Control (ENet) port.
|
|
||||||
pub control: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Everything the stream stage needs once RTSP is done.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct NegotiatedStream {
|
|
||||||
/// UDP ports.
|
|
||||||
pub ports: StreamPorts,
|
|
||||||
/// What the host offered in DESCRIBE.
|
|
||||||
pub host: HostCapabilities,
|
|
||||||
/// Encryption turned on in ANNOUNCE.
|
|
||||||
pub encryption: EncryptionFlags,
|
|
||||||
/// The Opus configuration chosen for `StreamConfig::audio`, for the platform decoder.
|
|
||||||
pub opus: OpusConfig,
|
|
||||||
/// The `Session` id from SETUP, if the host sent one.
|
|
||||||
pub session_id: Option<String>,
|
|
||||||
/// The datagram to send to the video and audio ports before the stream starts (UNKNOWN U8; `PING` for
|
|
||||||
/// Moonshine-like hosts).
|
|
||||||
pub ping_payload: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the negotiation is. Each state names the request just sent.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum RtspClientState {
|
|
||||||
/// OPTIONS sent.
|
|
||||||
Options,
|
|
||||||
/// DESCRIBE sent.
|
|
||||||
Describe,
|
|
||||||
/// SETUP audio sent.
|
|
||||||
SetupAudio,
|
|
||||||
/// SETUP video sent.
|
|
||||||
SetupVideo,
|
|
||||||
/// SETUP control sent.
|
|
||||||
SetupControl,
|
|
||||||
/// ANNOUNCE sent.
|
|
||||||
Announce,
|
|
||||||
/// PLAY sent.
|
|
||||||
Play,
|
|
||||||
/// Done; see [`NegotiatedStream`].
|
|
||||||
Ready,
|
|
||||||
/// A non-200 answer or a bad payload stopped it.
|
|
||||||
Failed,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result of feeding one answer.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum RtspProgress {
|
|
||||||
/// The next request is ready in [`RtspClient::poll_request`].
|
|
||||||
Continue,
|
|
||||||
/// Negotiation finished.
|
|
||||||
Ready(NegotiatedStream),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The RTSP negotiation for one stream session.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct RtspClient {
|
|
||||||
state: RtspClientState,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RtspClient {
|
|
||||||
/// Prepares the negotiation against `session_url` (`sessionUrl0` from launch). The first request (OPTIONS)
|
|
||||||
/// is ready in [`Self::poll_request`].
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a URL that is not `rtsp://host:port`, or a config with zero size, frame
|
|
||||||
/// rate, bitrate or packet size. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn new(session_url: &str, config: StreamConfig) -> crate::Result<Self> {
|
|
||||||
let _ = (session_url, config);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next request to write, if one is due. Each is returned once.
|
|
||||||
pub fn poll_request(&mut self) -> Option<Vec<u8>> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds one whole answer (see [`super::RtspFramer`]).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::HostStatus`] for a non-200 answer, [`crate::Error::Malformed`] for a `CSeq` that does not
|
|
||||||
/// match or a bad payload, [`crate::Error::Unsupported`] when the host lacks something required,
|
|
||||||
/// [`crate::Error::State`] when no request is outstanding. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_response(&mut self, message: &[u8]) -> crate::Result<RtspProgress> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Where the negotiation is.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn state(&self) -> RtspClientState {
|
|
||||||
self.state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
//! RTSP stream negotiation (`docs/PROTOCOL.md` section 2): message codec, a framer for the TCP byte stream, SDP,
|
|
||||||
//! and the client state machine.
|
|
||||||
|
|
||||||
pub mod client;
|
|
||||||
pub mod sdp;
|
|
||||||
|
|
||||||
pub use client::{NegotiatedStream, RtspClient, RtspClientState, RtspProgress, StreamConfig, StreamPorts};
|
|
||||||
pub use sdp::{EncryptionFlags, HostCapabilities, OpusConfig, Sdp};
|
|
||||||
|
|
||||||
/// Default RTSP port.
|
|
||||||
pub const DEFAULT_RTSP_PORT: u16 = 48010;
|
|
||||||
/// Maximum size of one RTSP message (start line + headers + payload), in bytes.
|
|
||||||
pub const MAX_RTSP_MESSAGE_BYTES: usize = 64 * 1024;
|
|
||||||
/// Maximum length of one start or header line, in bytes (without CRLF).
|
|
||||||
pub const MAX_RTSP_LINE_BYTES: usize = 4096;
|
|
||||||
/// Maximum number of header lines in one message.
|
|
||||||
pub const MAX_RTSP_HEADERS: usize = 64;
|
|
||||||
|
|
||||||
/// The methods this client sends.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum Method {
|
|
||||||
/// `OPTIONS`.
|
|
||||||
Options,
|
|
||||||
/// `DESCRIBE`.
|
|
||||||
Describe,
|
|
||||||
/// `SETUP`.
|
|
||||||
Setup,
|
|
||||||
/// `ANNOUNCE`.
|
|
||||||
Announce,
|
|
||||||
/// `PLAY`.
|
|
||||||
Play,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An RTSP request.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct RtspRequest {
|
|
||||||
/// The method.
|
|
||||||
pub method: Method,
|
|
||||||
/// The target, e.g. `rtsp://192.0.2.10:48010` or `streamid=video/0/0`.
|
|
||||||
pub target: String,
|
|
||||||
/// Header lines in order, `CSeq` included.
|
|
||||||
pub headers: Vec<(String, String)>,
|
|
||||||
/// The payload (SDP for ANNOUNCE), possibly empty.
|
|
||||||
pub body: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RtspRequest {
|
|
||||||
/// Serializes the request (CRLF line ends, empty line, payload). Refuses CR or LF inside a target, header
|
|
||||||
/// name or value.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a forbidden character, [`crate::Error::TooLarge`] over
|
|
||||||
/// [`MAX_RTSP_MESSAGE_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn encode(&self) -> crate::Result<Vec<u8>> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An RTSP response.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct RtspResponse {
|
|
||||||
/// Status code, e.g. 200.
|
|
||||||
pub status: u16,
|
|
||||||
/// Reason phrase.
|
|
||||||
pub reason: String,
|
|
||||||
/// Header lines in order.
|
|
||||||
pub headers: Vec<(String, String)>,
|
|
||||||
/// The payload (SDP for DESCRIBE), possibly empty.
|
|
||||||
pub body: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RtspResponse {
|
|
||||||
/// The first header with this name, compared case-insensitively.
|
|
||||||
#[must_use]
|
|
||||||
pub fn header(&self, name: &str) -> Option<&str> {
|
|
||||||
self.headers.iter().find(|(n, _)| n.eq_ignore_ascii_case(name)).map(|(_, v)| v.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one complete response (as cut by [`RtspFramer`]).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_RTSP_MESSAGE_BYTES`], [`MAX_RTSP_LINE_BYTES`] or [`MAX_RTSP_HEADERS`],
|
|
||||||
/// [`crate::Error::Malformed`] for a bad start line, header line or `Content-Length`. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_response(message: &[u8]) -> crate::Result<RtspResponse> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one complete request. Not used by the client; here for the fuzz harness and the Lumen host (Day 3).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// As [`parse_response`], plus [`crate::Error::UnexpectedValue`] for an unknown method.
|
|
||||||
pub fn parse_request(message: &[u8]) -> crate::Result<RtspRequest> {
|
|
||||||
let _ = message;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cuts the TCP byte stream from the host into whole messages.
|
|
||||||
///
|
|
||||||
/// A message ends after its headers plus `Content-Length` payload bytes; without `Content-Length` it ends when
|
|
||||||
/// the host closes the connection ([`RtspFramer::finish`]) (UNKNOWN U5). Never buffers more than
|
|
||||||
/// [`MAX_RTSP_MESSAGE_BYTES`].
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct RtspFramer {
|
|
||||||
buffer: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RtspFramer {
|
|
||||||
/// An empty framer.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn new() -> Self {
|
|
||||||
Self { buffer: Vec::new() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Appends received bytes.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] when the unfinished message would exceed [`MAX_RTSP_MESSAGE_BYTES`]. Phase A:
|
|
||||||
/// always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn push(&mut self, bytes: &[u8]) -> crate::Result<()> {
|
|
||||||
let _ = bytes;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Takes the next complete message, if one is buffered.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a bad `Content-Length`. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn next_message(&mut self) -> crate::Result<Option<Vec<u8>>> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The host closed the connection: returns what is buffered as the last message, if anything.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Truncated`] when a `Content-Length` promised more. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn finish(&mut self) -> crate::Result<Option<Vec<u8>>> {
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bytes buffered but not yet returned.
|
|
||||||
#[must_use]
|
|
||||||
pub fn buffered(&self) -> usize {
|
|
||||||
self.buffer.len()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
//! The SDP-like payloads of DESCRIBE (host → client) and ANNOUNCE (client → host) (`docs/PROTOCOL.md` 2.3, 2.4).
|
|
||||||
|
|
||||||
use super::client::StreamConfig;
|
|
||||||
|
|
||||||
/// Maximum size of an SDP payload, in bytes.
|
|
||||||
pub const MAX_SDP_BYTES: usize = 32 * 1024;
|
|
||||||
/// Maximum number of lines in an SDP payload.
|
|
||||||
pub const MAX_SDP_LINES: usize = 1024;
|
|
||||||
/// Maximum number of Opus configurations a host may advertise.
|
|
||||||
pub const MAX_OPUS_CONFIGS: usize = 16;
|
|
||||||
/// Maximum number of audio channels (7.1).
|
|
||||||
pub const MAX_AUDIO_CHANNELS: usize = 8;
|
|
||||||
|
|
||||||
/// A parsed SDP payload: `a=name:value` attributes plus every other `x=value` line, in order.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
|
||||||
pub struct Sdp {
|
|
||||||
/// `a=` attributes: name and value (value empty for flag attributes).
|
|
||||||
pub attributes: Vec<(String, String)>,
|
|
||||||
/// Other lines: type character and value (e.g. `('v', "0")`), and bare lines such as `sprop-parameter-sets=…`
|
|
||||||
/// with type `'\0'`.
|
|
||||||
pub other: Vec<(char, String)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Sdp {
|
|
||||||
/// The first attribute with this exact name.
|
|
||||||
#[must_use]
|
|
||||||
pub fn attribute(&self, name: &str) -> Option<&str> {
|
|
||||||
self.attributes.iter().find(|(n, _)| n == name).map(|(_, v)| v.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses an SDP payload. Lines end in LF or CRLF.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_SDP_BYTES`] or [`MAX_SDP_LINES`], [`crate::Error::Malformed`] for a line
|
|
||||||
/// that is not UTF-8 or has no `=`. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_sdp(payload: &[u8]) -> crate::Result<Sdp> {
|
|
||||||
let _ = payload;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encryption flag bits of `x-ss-general.encryptionSupported` / `encryptionEnabled`.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct EncryptionFlags(pub u8);
|
|
||||||
|
|
||||||
impl EncryptionFlags {
|
|
||||||
/// Control stream V2 framing with AES-GCM.
|
|
||||||
pub const CONTROL_V2: u8 = 0x01;
|
|
||||||
/// Video AES-GCM.
|
|
||||||
pub const VIDEO: u8 = 0x02;
|
|
||||||
/// Audio AES-CBC.
|
|
||||||
pub const AUDIO: u8 = 0x04;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feature flag bits of `x-ss-general.featureFlags`.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct FeatureFlags(pub u32);
|
|
||||||
|
|
||||||
impl FeatureFlags {
|
|
||||||
/// The host accepts pen and touch events.
|
|
||||||
pub const PEN_TOUCH_EVENTS: u32 = 0x01;
|
|
||||||
/// The host accepts controller touch events.
|
|
||||||
pub const CONTROLLER_TOUCH_EVENTS: u32 = 0x02;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One Opus multistream configuration (RFC 7845 §5.1.1), for the platform's Opus decoder.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct OpusConfig {
|
|
||||||
/// Output channels (2, 6 or 8).
|
|
||||||
pub channels: u8,
|
|
||||||
/// Opus streams per packet.
|
|
||||||
pub streams: u8,
|
|
||||||
/// Of which coupled (stereo) streams.
|
|
||||||
pub coupled_streams: u8,
|
|
||||||
/// Channel mapping, one entry per channel.
|
|
||||||
pub mapping: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one `surround-params` value (single digits: channels, streams, coupled, then one mapping digit per
|
|
||||||
/// channel), e.g. `21101`.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a non-digit, a wrong length, or values that break RFC 7845's rules
|
|
||||||
/// (`coupled ≤ streams`, `streams + coupled ≤ 255`, mapping entries `< streams + coupled`). Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_surround_params(value: &str) -> crate::Result<OpusConfig> {
|
|
||||||
let _ = value;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What the host offers, read from the DESCRIBE payload.
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
|
||||||
pub struct HostCapabilities {
|
|
||||||
/// `x-ss-general.encryptionSupported`.
|
|
||||||
pub encryption_supported: EncryptionFlags,
|
|
||||||
/// `x-ss-general.featureFlags`.
|
|
||||||
pub feature_flags: FeatureFlags,
|
|
||||||
/// `x-nv-video[0].refPicInvalidation:1`.
|
|
||||||
pub reference_frame_invalidation: bool,
|
|
||||||
/// `rtpmap:98 AV1/90000` present.
|
|
||||||
pub av1: bool,
|
|
||||||
/// Every `fmtp:97 surround-params=…`, in order.
|
|
||||||
pub opus_configs: Vec<OpusConfig>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HostCapabilities {
|
|
||||||
/// Reads the capabilities from a DESCRIBE payload.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a present attribute with a bad value, [`crate::Error::TooLarge`] over
|
|
||||||
/// [`MAX_OPUS_CONFIGS`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn from_sdp(sdp: &Sdp) -> crate::Result<Self> {
|
|
||||||
let _ = sdp;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Builds the ANNOUNCE payload for `config`, turning on the encryption flags both sides support.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Unsupported`] when the host lacks control V2 encryption or the requested codec. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn build_announce(config: &StreamConfig, host: &HostCapabilities) -> crate::Result<Vec<u8>> {
|
|
||||||
let _ = (config, host);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//! Time comes in from the caller as an [`Instant`]; DomiStream never reads a clock.
|
|
||||||
|
|
||||||
use core::time::Duration;
|
|
||||||
|
|
||||||
/// A point on the caller's monotonic clock, in microseconds since an epoch the caller chooses.
|
|
||||||
///
|
|
||||||
/// Only differences between instants matter. The caller must never let it go backwards within one session.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct Instant(u64);
|
|
||||||
|
|
||||||
impl Instant {
|
|
||||||
/// The caller's epoch.
|
|
||||||
pub const ZERO: Self = Self(0);
|
|
||||||
|
|
||||||
/// An instant `micros` microseconds after the caller's epoch.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn from_micros(micros: u64) -> Self {
|
|
||||||
Self(micros)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Microseconds since the caller's epoch.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn as_micros(self) -> u64 {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `self + d`, saturating at the end of the clock.
|
|
||||||
#[must_use]
|
|
||||||
pub fn saturating_add(self, d: Duration) -> Self {
|
|
||||||
let micros = u64::try_from(d.as_micros()).unwrap_or(u64::MAX);
|
|
||||||
Self(self.0.saturating_add(micros))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `self - earlier`, or zero when `earlier` is later.
|
|
||||||
#[must_use]
|
|
||||||
pub fn saturating_duration_since(self, earlier: Self) -> Duration {
|
|
||||||
Duration::from_micros(self.0.saturating_sub(earlier.0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
//! The video receive path (`docs/PROTOCOL.md` section 5): decrypt (if negotiated) → parse → group by frame and
|
|
||||||
//! FEC block → rebuild lost data shards → reassemble the frame → hand the Annex-B bitstream to the platform decoder.
|
|
||||||
//!
|
|
||||||
//! Lost frames become [`VideoEvent::FrameLost`], which the caller answers on the control stream with
|
|
||||||
//! `INVALIDATE_REF_FRAMES` (when the host supports it) or an IDR request.
|
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
use crate::{Instant, Result};
|
|
||||||
|
|
||||||
pub mod packet;
|
|
||||||
|
|
||||||
pub use packet::{FecInfo, FrameHeader, FrameType, NvVideoHeader, VideoFlags, VideoPacket, parse_video_packet};
|
|
||||||
|
|
||||||
/// Length of the prefix of an encrypted packet: IV 12 + frame number 4 + tag 16.
|
|
||||||
pub const ENCRYPTION_PREFIX_LEN: usize = 12 + 4 + 16;
|
|
||||||
/// Maximum size of one reassembled frame (frame header + bitstream), in bytes.
|
|
||||||
pub const MAX_FRAME_BYTES: usize = 4 * 1024 * 1024;
|
|
||||||
/// Maximum frames being assembled at once; older ones are declared lost.
|
|
||||||
pub const MAX_FRAMES_IN_FLIGHT: usize = 8;
|
|
||||||
|
|
||||||
/// AES-128-GCM for encrypted video packets (`docs/PROTOCOL.md` 7). `Debug` never prints the key.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct VideoCipher {
|
|
||||||
key: [u8; 16],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoCipher {
|
|
||||||
/// A cipher for `rikey`.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn new(rikey: [u8; 16]) -> Self {
|
|
||||||
Self { key: rikey }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decrypts one encrypted packet (`IV ‖ frame number ‖ tag ‖ ciphertext`) into the plaintext packet.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`packet::MAX_VIDEO_PACKET_BYTES`], [`crate::Error::Truncated`] under the
|
|
||||||
/// prefix, [`crate::Error::Malformed`] for an IV whose byte 11 is not `'V'`, [`crate::Error::Crypto`] for a bad
|
|
||||||
/// tag. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn decrypt(&self, packet: &[u8]) -> Result<Vec<u8>> {
|
|
||||||
let _ = (packet, &self.key);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for VideoCipher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("VideoCipher(<redacted>)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Settings of the video receiver.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct VideoConfig {
|
|
||||||
/// Negotiated `packetSize`.
|
|
||||||
pub packet_size: u16,
|
|
||||||
/// Decrypt packets with this cipher when video encryption was negotiated.
|
|
||||||
pub cipher: Option<VideoCipher>,
|
|
||||||
/// How long to wait for missing shards of a frame before declaring it lost.
|
|
||||||
pub frame_timeout: core::time::Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One complete frame for the decoder.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct VideoFrame {
|
|
||||||
/// Frame index.
|
|
||||||
pub frame_index: u32,
|
|
||||||
/// The frame header.
|
|
||||||
pub header: FrameHeader,
|
|
||||||
/// Annex-B bitstream (start codes included), frame header and padding removed.
|
|
||||||
pub bitstream: Vec<u8>,
|
|
||||||
/// RTP timestamp of its first packet.
|
|
||||||
pub rtp_timestamp: u32,
|
|
||||||
/// When its first packet arrived.
|
|
||||||
pub first_packet_at: Instant,
|
|
||||||
/// When it was completed.
|
|
||||||
pub completed_at: Instant,
|
|
||||||
/// Data shards rebuilt by FEC.
|
|
||||||
pub recovered_shards: u16,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// What the receiver reports.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum VideoEvent {
|
|
||||||
/// A frame is ready, in frame order.
|
|
||||||
Frame(VideoFrame),
|
|
||||||
/// Frames `first..=last` cannot be completed; ask for recovery.
|
|
||||||
FrameLost {
|
|
||||||
/// First lost frame index.
|
|
||||||
first: u32,
|
|
||||||
/// Last lost frame index.
|
|
||||||
last: u32,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Counters for the stats overlay.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VideoStats {
|
|
||||||
/// Packets accepted.
|
|
||||||
pub packets: u64,
|
|
||||||
/// Packets refused (bad format, bad tag, duplicate, too old).
|
|
||||||
pub packets_dropped: u64,
|
|
||||||
/// Data shards rebuilt by FEC.
|
|
||||||
pub shards_recovered: u64,
|
|
||||||
/// Frames delivered.
|
|
||||||
pub frames: u64,
|
|
||||||
/// Frames lost.
|
|
||||||
pub frames_lost: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The video receiver.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct VideoDepacketizer {
|
|
||||||
stats: VideoStats,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoDepacketizer {
|
|
||||||
/// A receiver for one stream.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Malformed`] for a `packet_size` below the NV header size or above what fits in
|
|
||||||
/// [`packet::MAX_VIDEO_PACKET_BYTES`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn new(config: VideoConfig) -> Result<Self> {
|
|
||||||
let _ = config;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Feeds one datagram from the video port. Bad, duplicate and too-old packets are counted and dropped; only
|
|
||||||
/// an oversized datagram is an error.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`packet::MAX_VIDEO_PACKET_BYTES`]. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn push(&mut self, now: Instant, datagram: &[u8]) -> Result<()> {
|
|
||||||
let _ = (now, datagram);
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The next event.
|
|
||||||
pub fn poll_event(&mut self) -> Option<VideoEvent> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When an incomplete frame times out.
|
|
||||||
#[must_use]
|
|
||||||
pub fn poll_timeout(&self) -> Option<Instant> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Declares timed-out frames lost.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn handle_timeout(&mut self, now: Instant) -> Result<()> {
|
|
||||||
let _ = now;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Counters.
|
|
||||||
#[must_use]
|
|
||||||
pub const fn stats(&self) -> VideoStats {
|
|
||||||
self.stats
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
//! The video packet layout (`docs/PROTOCOL.md` 5.2): RTP header, 4 reserved bytes, the 16-byte NV video header,
|
|
||||||
//! payload. NV header fields are little-endian.
|
|
||||||
|
|
||||||
use crate::rtp::RtpHeader;
|
|
||||||
|
|
||||||
/// RTP header plus the 4 reserved bytes.
|
|
||||||
pub const VIDEO_RTP_LEN: usize = 16;
|
|
||||||
/// Length of the NV video header.
|
|
||||||
pub const NV_HEADER_LEN: usize = 16;
|
|
||||||
/// Offset of the payload in a packet.
|
|
||||||
pub const PAYLOAD_OFFSET: usize = VIDEO_RTP_LEN + NV_HEADER_LEN;
|
|
||||||
/// Length of the frame header at the start of each frame's data.
|
|
||||||
pub const FRAME_HEADER_LEN: usize = 8;
|
|
||||||
/// Maximum size of one video packet (plaintext or encrypted), in bytes.
|
|
||||||
pub const MAX_VIDEO_PACKET_BYTES: usize = 4096;
|
|
||||||
/// Maximum FEC blocks per frame (two-bit block index).
|
|
||||||
pub const MAX_FEC_BLOCKS: usize = 4;
|
|
||||||
/// The `packetSize` used when ANNOUNCE does not set one.
|
|
||||||
pub const DEFAULT_PACKET_SIZE: u16 = 1024;
|
|
||||||
|
|
||||||
/// NV video flags.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VideoFlags(pub u8);
|
|
||||||
|
|
||||||
impl VideoFlags {
|
|
||||||
/// The packet carries picture data (0 on parity packets).
|
|
||||||
pub const PICTURE_DATA: u8 = 0x01;
|
|
||||||
/// Last data packet of the frame.
|
|
||||||
pub const END_OF_FRAME: u8 = 0x02;
|
|
||||||
/// First data packet of the frame.
|
|
||||||
pub const START_OF_FRAME: u8 = 0x04;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The FEC fields of one packet, decoded from `fecInfo` and `multiFecBlocks`.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct FecInfo {
|
|
||||||
/// Index in the block: `0..data_shards` data, `data_shards..` parity (`fecInfo` bits 12-21).
|
|
||||||
pub shard_index: u16,
|
|
||||||
/// Data shards in this block (`fecInfo` bits 22-31).
|
|
||||||
pub data_shards: u16,
|
|
||||||
/// FEC percentage of this block (`fecInfo` bits 4-11).
|
|
||||||
pub fec_percentage: u8,
|
|
||||||
/// This block's index in the frame (`multiFecBlocks` bits 4-5).
|
|
||||||
pub block_index: u8,
|
|
||||||
/// The frame's last block index (`multiFecBlocks` bits 6-7).
|
|
||||||
pub last_block_index: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The NV video header.
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
|
||||||
pub struct NvVideoHeader {
|
|
||||||
/// Stream packet index (RTP sequence << 8).
|
|
||||||
pub stream_packet_index: u32,
|
|
||||||
/// Frame index.
|
|
||||||
pub frame_index: u32,
|
|
||||||
/// Flags.
|
|
||||||
pub flags: VideoFlags,
|
|
||||||
/// `multiFecFlags` byte, raw (UNKNOWN U15).
|
|
||||||
pub multi_fec_flags: u8,
|
|
||||||
/// FEC fields.
|
|
||||||
pub fec: FecInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One plaintext video packet.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct VideoPacket<'a> {
|
|
||||||
/// RTP header.
|
|
||||||
pub rtp: RtpHeader,
|
|
||||||
/// NV video header.
|
|
||||||
pub nv: NvVideoHeader,
|
|
||||||
/// Payload (frame data for data shards, parity bytes for parity shards).
|
|
||||||
pub payload: &'a [u8],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses one plaintext video packet. Checks the FEC fields are consistent (`shard_index < data + parity`,
|
|
||||||
/// `block_index <= last_block_index`, `data_shards > 0`).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::TooLarge`] over [`MAX_VIDEO_PACKET_BYTES`], [`crate::Error::Truncated`] under
|
|
||||||
/// [`PAYLOAD_OFFSET`], [`crate::Error::Malformed`] for inconsistent FEC fields. Phase A: always
|
|
||||||
/// [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_video_packet(packet: &[u8]) -> crate::Result<VideoPacket<'_>> {
|
|
||||||
let _ = packet;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Frame types in the frame header.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub enum FrameType {
|
|
||||||
/// Predicted (1).
|
|
||||||
Predicted,
|
|
||||||
/// Key / IDR (2).
|
|
||||||
Key,
|
|
||||||
/// First frame after a reference frame invalidation (5).
|
|
||||||
Recovery,
|
|
||||||
/// Any other value.
|
|
||||||
Other(u8),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The 8-byte header in front of each frame's bitstream (UNKNOWN U13: Wolf shows a constant, Moonshine these
|
|
||||||
/// fields).
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct FrameHeader {
|
|
||||||
/// The 8 bytes as received.
|
|
||||||
pub raw: [u8; FRAME_HEADER_LEN],
|
|
||||||
/// Byte 0.
|
|
||||||
pub header_type: u8,
|
|
||||||
/// Bytes 1-2, LE: host processing latency (unit UNKNOWN).
|
|
||||||
pub processing_latency: u16,
|
|
||||||
/// Byte 3.
|
|
||||||
pub frame_type: FrameType,
|
|
||||||
/// Bytes 4-7, LE: payload bytes in the last data shard.
|
|
||||||
pub last_payload_len: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses the frame header at the start of a frame's data (the rest is ignored here).
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
/// [`crate::Error::Truncated`] under [`FRAME_HEADER_LEN`]. Phase A: always [`crate::Error::Unimplemented`].
|
|
||||||
pub fn parse_frame_header(frame_data: &[u8]) -> crate::Result<FrameHeader> {
|
|
||||||
let _ = frame_data;
|
|
||||||
Err(crate::Error::Unimplemented)
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
# Clean room
|
|
||||||
|
|
||||||
DomiStream is a clean-room implementation of the GameStream protocol (the one Moonlight clients and Sunshine hosts
|
|
||||||
speak). The protocol is written from public protocol notes and our own measurements, never from the code of a
|
|
||||||
GPL-licensed implementation. This file says what may be read, what may not, and logs every source used.
|
|
||||||
|
|
||||||
## Allowed sources
|
|
||||||
|
|
||||||
| Source | Licence | How we may use it |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| [Wolf protocol docs](https://games-on-whales.github.io/wolf/stable/protocols/index.html) and their sub-pages (pairing/HTTP, RTSP, control, RTP video, RTP Opus, input) | Docs site: CC BY-SA 4.0 "except where otherwise noted"; repo: MIT (see [research/open-point-2.md](research/open-point-2.md)) | Read for facts. Restate facts in our own words with a link. Never paste prose or diagrams. The diagram sources (PlantUML, bytefield, wavedrom) are part of the docs pages and may be read the same way. |
|
|
||||||
| [Moonshine](https://github.com/hgaiser/moonshine) | BSD-2-Clause | May be read. Facts taken are logged below. Code is not copied; if a snippet is ever borrowed, it keeps Moonshine's copyright line and licence text in the file that holds it. |
|
|
||||||
| RFCs and standards (RTP RFC 3550, RTSP RFC 2326, SDP RFC 4566, Opus RFC 6716 / RFC 7845, AES FIPS 197, GCM/CBC NIST SP 800-38D/38A, PKCS #1 RFC 8017, X.509 RFC 5280) | open standards | Read freely. |
|
|
||||||
| Crate docs (docs.rs, crates.io, crate READMEs) | per crate | Read freely. |
|
|
||||||
| Our own measurements | ours | Captures between our client and a host on a **lab machine** (never Mark's PC, never Mark's TV, never 192.168.100.217). Captures stay out of git; only the facts and test vectors derived from them go in, with the date and setup. |
|
|
||||||
| READMEs and wikis of forbidden projects | n/a | For facts only (licence, release notes, compatibility statements). Never their source files. |
|
|
||||||
|
|
||||||
### Proposed additions (need the build lead's yes before use)
|
|
||||||
|
|
||||||
| Source | Licence | Why |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| [Stock ENet](https://github.com/lsalzman/enet) (`protocol.h`, `protocol.c`) | MIT | The ENet 1.3 wire format is not documented anywhere else in prose. The Wolf docs do not describe it. |
|
|
||||||
| [tokio-enet](https://github.com/hgaiser/tokio-enet) source | BSD-2-Clause | A pure-Rust ENet 1.3 used by Moonshine to talk to Moonlight clients. Its `src/protocol/` files were read for the command list (logged below, S-10). |
|
|
||||||
| [fec-rs](https://github.com/hgaiser/fec-rs) source | BSD-2-Clause | Its README says its field setup is compatible with Moonlight. Reading its matrix construction would settle UNKNOWN U14 (video FEC). |
|
|
||||||
|
|
||||||
## Forbidden
|
|
||||||
|
|
||||||
Never open, read, paste or port code from: **Sunshine, Moonlight (any client: Qt, Android, iOS, embedded, moonlight-tv),
|
|
||||||
moonlight-common-c, Moonlight's ENet fork, Apollo, Vibeshine, Rubylight, chiaki** (and forks of them). That also
|
|
||||||
means their source files on GitHub. Their READMEs and wikis are fine for facts.
|
|
||||||
|
|
||||||
### Second-hand GPL facts
|
|
||||||
|
|
||||||
Moonshine credits Sunshine for "groundwork" on the host side, and a few Moonshine comments cite Sunshine or
|
|
||||||
moonlight-common-c as the origin of a value. We treat such a value as **GPL-provenance**: it is logged, never
|
|
||||||
copied into DomiStream, and settled by our own measurement instead. Known cases:
|
|
||||||
|
|
||||||
| Where in Moonshine | What | What we do |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| `src/session/stream/audio/encoder.rs` | the fixed 2x4 Reed-Solomon parity matrix for audio FEC; the comment cites a moonlight-common-c file | Not taken. I saw the constant while reading the file; it is not in this repo. U16 in [PROTOCOL.md](PROTOCOL.md) says how to measure it ourselves. |
|
|
||||||
| `src/session/stream/control/mod.rs` | HDR mode payload "matches Sunshine's" struct | Field layout logged as `[M*]`, confirm by measurement before relying on it |
|
|
||||||
| `src/rtsp.rs` | `surround-params` digit packing "matching moonlight-common-c" | The Wolf example `surround-params=21101` gives the same packing independently, so we use the Wolf source |
|
|
||||||
|
|
||||||
## How code gets written
|
|
||||||
|
|
||||||
1. Every fact in [PROTOCOL.md](PROTOCOL.md) carries a source tag that points to the log below.
|
|
||||||
2. A fact without a tag is UNKNOWN until a log entry or a measurement backs it.
|
|
||||||
3. Code comments cite the PROTOCOL.md section, not the outside source directly.
|
|
||||||
4. Anything borrowed (more than a fact) is attributed in the file that holds it and listed here.
|
|
||||||
5. A PR that adds a source adds a row to the log in the same PR.
|
|
||||||
|
|
||||||
## Source log
|
|
||||||
|
|
||||||
All entries by the DomiStream protocol engineer. Pinned commits are the ones read.
|
|
||||||
|
|
||||||
| # | Date | Source | What was taken |
|
|
||||||
| :-- | :-- | :-- | :-- |
|
|
||||||
| S-1 | 2026-11-25 | [Wolf: protocols index](https://games-on-whales.github.io/wolf/stable/protocols/index.html) | The six protocols, their default ports, which are encrypted (control AES-GCM 128, audio AES-CBC 128, video plain), that ports other than HTTP/S are dynamic. Licence footer (CC BY-SA 4.0). |
|
|
||||||
| S-2 | 2026-11-25 | [Wolf: HTTP/S pairing](https://games-on-whales.github.io/wolf/stable/protocols/http-pairing.html) incl. its PlantUML diagram sources | Phases 1-5; AES key from SHA-256(salt + PIN); the hash inputs of phase 2 and phase 4; field names `plaincert`, `challengeresponse`, `serverchallengeresp`, `pairingsecret`, `pairchallenge`, `paired`; phase 5 runs over HTTPS with the client certificate. |
|
|
||||||
| S-3 | 2026-11-25 | [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) incl. diagram | Method order OPTIONS, DESCRIBE, SETUP (audio, video, control), ANNOUNCE, PLAY; message layout (start line, `CSeq`, options, empty line, payload); example `X-GS-ClientVersion: 14`, `a=fmtp:97 surround-params=21101`. |
|
|
||||||
| S-4 | 2026-11-25 | [Wolf: control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html) incl. bytefield sources | ENet fork with IPv4 + IPv6; encrypted frame `type 0x0001 / len / seq / 16-byte tag / payload`, little-endian, seq used for the IV; message type codes; payloads of rumble, rumble triggers, motion event, RGB LED. |
|
|
||||||
| S-5 | 2026-11-25 | [Wolf: RTP video](https://games-on-whales.github.io/wolf/stable/protocols/rtp-video.html) incl. diagrams | PING to the negotiated port; packetSize default 1024 + 16-byte RTP header; 16-byte NV video header layout; flags (picture data 1, EOF 2, SOF 4); 8-byte frame prefix `01 37 63 68 61 72 73 73`; FEC example (4 KB, 1024, 50 % = 4 + 2); parity packets have flags 0; IDR requests over control. |
|
|
||||||
| S-6 | 2026-11-25 | [Wolf: RTP Opus](https://games-on-whales.github.io/wolf/stable/protocols/rtp-opus.html) incl. diagrams | 12-byte RTP header; 12-byte FEC header (shard index, payload type, base seq, base timestamp, SSRC); 4 data + 2 parity; AES-CBC with key and IV from the launch call, same key as control; PING. |
|
|
||||||
| S-7 | 2026-11-25 | [Wolf: input](https://games-on-whales.github.io/wolf/stable/protocols/input-data.html) incl. bytefield sources | INPUT_DATA layout (size BE, type LE); input type codes; layouts and example bytes for mouse move rel/abs, buttons, keys, scroll, hscroll, controller arrival, controller multi; key code table; button flags; controller types and capability bits. |
|
|
||||||
| S-8 | 2026-11-25 | GitHub API for [games-on-whales/wolf](https://github.com/games-on-whales/wolf) (`/repos`, `/git/trees/beta`, `LICENSE`, `docs/README.adoc`) | Repo licence MIT; the docs live in `docs/modules/protocols/pages/*.adoc` of the same repo; latest tag `v2026.11`. No source files of Wolf were read. |
|
|
||||||
| S-9 | 2026-11-25 | [Moonshine](https://github.com/hgaiser/moonshine) at `f184d5e3693e09c3a6ab1025bde6cdb67f36a6bc`: `LICENSE`, `README.md`, `Cargo.toml`, `src/clients.rs`, `src/crypto.rs`, `src/webserver/pairing.rs`, `src/webserver/mod.rs`, `src/rtsp.rs`, `src/session/stream/control/mod.rs`, `src/session/stream/audio/{mod,encoder}.rs`, `src/session/stream/video/{mod,packetizer,shard_batch}.rs` | Facts tagged `[M]` in PROTOCOL.md: pairing query names, AES-128-ECB, key = first 16 bytes of SHA-256(salt + PIN), 16-byte salt/challenge/secret, RSA PKCS#1 v1.5 SHA-256, "certificate signature" = X.509 signatureValue bytes; serverinfo, applist and launch XML and query fields; SDP attribute names, SETUP reply headers, encryption flag bits; control IV layout and direction bytes, START_B starts the streams, INVALIDATE_REF_FRAMES and termination layouts, ENet host settings; audio IV, payload types 97/127, millisecond timestamps; video RTP/NV header byte layout, FEC bit fields and block split, video encryption prefix and IV; `PING` payload. Moonshine depends on `tokio-enet` for the control channel. |
|
|
||||||
| S-10 | 2026-11-25 | [tokio-enet](https://github.com/hgaiser/tokio-enet) at `364628ed754760c99e0df7bcc88e479ad91475c4`: `README.md`, `CHANGELOG.md`, `src/protocol/{mod,header,commands}.rs` | Claims wire compatibility with C ENet 1.3.x, BSD-2; ENet command numbers 1-12, command sizes, header flags (compressed 1<<14, sent time 1<<15, session bits 12-13), 4-byte command header, big-endian fields. Pending approval as an allowed source (see above). |
|
|
||||||
| S-11 | 2026-11-25 | crates.io API for `enet`, `enet-rs`, `nsys-enet`, `rusty_enet`, `tokio-enet`, `enet-sys`, `henet`, `enet-cs-sys`, `fec-rs`, `reed-solomon-erasure` and the RustCrypto crates | Licences, versions, repositories (see research/open-point-2.md and the Cargo manifest). |
|
|
||||||
| S-12 | 2026-11-25 | [docs.rs: rusty_enet](https://docs.rs/rusty_enet/latest/rusty_enet/) | Transpiled from C ENet; caller-supplied `Socket` trait and `HostSettings::time`; optional crc32 checksum; MIT. |
|
|
||||||
| S-13 | 2026-11-25 | [fec-rs README](https://github.com/hgaiser/fec-rs) | GF(2^8) with polynomial 0x1D (0x11D), "compatible with the Moonlight streaming protocol", reconstruction supported, BSD-2. |
|
|
||||||
| S-14 | 2026-11-25 | [moonlight-common-c README](https://github.com/moonlight-stream/moonlight-common-c) (README only) | Needs its bundled ENet; other ENet versions are incompatible; GPL-3.0. |
|
|
||||||
| S-15 | 2026-11-25 | [cgutman/enet](https://github.com/cgutman/enet) repository page (description only) | Forked from lsalzman/enet, has a `moonlight` branch. No files opened. |
|
|
||||||
| S-16 | 2026-11-25 | Roadmap brief §3.2 ([moonlight-android releases](https://github.com/moonlight-stream/moonlight-android/releases)) | Moonlight Android 12.1 added end-to-end stream encryption with Sunshine. |
|
|
||||||
@@ -1,565 +0,0 @@
|
|||||||
# GameStream protocol, as DomiStream speaks it (client side)
|
|
||||||
|
|
||||||
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
|
|
||||||
marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, Phase A (docs + API, no logic yet).
|
|
||||||
|
|
||||||
**Tags** (details in the source log, [CLEAN_ROOM.md](CLEAN_ROOM.md)):
|
|
||||||
|
|
||||||
| Tag | Source |
|
|
||||||
| :-- | :-- |
|
|
||||||
| [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, 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 |
|
|
||||||
| [F] | fec-rs README (S-13) |
|
|
||||||
| [RFC n] | the RFC |
|
|
||||||
|
|
||||||
**Not in DomiStream:** sockets, TLS, the clock, video decoding and **Opus decoding**. DomiStream hands the platform
|
|
||||||
layer (ArenaTV: webOS NDL, Android MediaCodec, Windows D3D11VA) a complete Annex-B access unit per video frame and one
|
|
||||||
Opus packet (or a "lost" marker) per audio packet, plus the Opus multistream configuration. Decoding, packet-loss
|
|
||||||
concealment and output are the platform's job.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 0. Overview
|
|
||||||
|
|
||||||
Six protocols [W1]:
|
|
||||||
|
|
||||||
| Protocol | Default port | Transport | Protection | Purpose |
|
|
||||||
| :-- | :-- | :-- | :-- | :-- |
|
|
||||||
| HTTP | TCP 47989 | plain | none | server info, pairing |
|
|
||||||
| HTTPS | TCP 47984 | TLS, client certificate | TLS | app list, launch/resume/cancel, the last pairing step |
|
|
||||||
| RTSP | TCP 48010 | plain | none | negotiate the three streams |
|
|
||||||
| Control | UDP 47999 | ENet | AES-128-GCM per message | input, feedback, host events |
|
|
||||||
| Video | UDP 47998 | RTP | none by default; optional AES-128-GCM [M] | H.264 / HEVC / AV1 |
|
|
||||||
| Audio | UDP 48000 | RTP | AES-128-CBC | Opus |
|
|
||||||
|
|
||||||
All ports except HTTP/HTTPS can be changed by the host and reach the client through RTSP [W1].
|
|
||||||
|
|
||||||
Session order (client view): `serverinfo` (HTTP) → pair once (HTTP + one HTTPS step) → `applist` (HTTPS) →
|
|
||||||
`launch` (HTTPS, hands over the stream keys) → RTSP OPTIONS, DESCRIBE, SETUP ×3, ANNOUNCE, PLAY → UDP PING to the
|
|
||||||
video and audio ports + ENet connect to the control port → `START_B` on control → video and audio flow [W1][W3][M].
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. HTTP and HTTPS
|
|
||||||
|
|
||||||
Source: [Wolf: HTTP/S pairing](https://games-on-whales.github.io/wolf/stable/protocols/http-pairing.html) [W2], Moonshine `src/webserver/` and `src/clients.rs` [M].
|
|
||||||
|
|
||||||
### 1.1 Common shape
|
|
||||||
|
|
||||||
- Every call is a `GET` with a query string. Every response body is XML with one root:
|
|
||||||
`<root status_code="200">…</root>`; a non-200 `status_code` is an error, possibly with a `status_message`
|
|
||||||
attribute (UNKNOWN U27: attribute names on errors). [M]
|
|
||||||
- Every call carries `uniqueid=<client id>` [M]. Our client id: 16 random hex characters, stored with the pairing
|
|
||||||
(UNKNOWN U1: whether the host requires a particular form).
|
|
||||||
- Binary values travel as hex in both directions [M]. Our parser accepts upper and lower case.
|
|
||||||
- HTTPS: the host presents its certificate (the same one it sends as `plaincert` while pairing [M]); the client
|
|
||||||
presents its own certificate. Only a client certificate that completed pairing may call HTTPS APIs [W2].
|
|
||||||
The client **pins** the host certificate: the TLS certificate must equal the paired `plaincert` byte for byte.
|
|
||||||
TLS itself (version, ciphers) belongs to the platform layer (UNKNOWN U24: TLS versions Sunshine offers).
|
|
||||||
|
|
||||||
### 1.2 serverinfo
|
|
||||||
|
|
||||||
`GET /serverinfo?uniqueid=…` over HTTP (unpaired) or HTTPS (paired). `PairStatus` is 1 only over HTTPS with a
|
|
||||||
paired certificate [M]. Elements under `root` [M]:
|
|
||||||
|
|
||||||
| Element | Meaning |
|
|
||||||
| :-- | :-- |
|
|
||||||
| `hostname` | host name to show |
|
|
||||||
| `appversion` | protocol version string, e.g. `7.1.431.-1`; a negative fourth part marks the Sunshine-era protocol [M] |
|
|
||||||
| `GfeVersion` | compatibility version string |
|
|
||||||
| `uniqueid` | host id (stable across restarts) |
|
|
||||||
| `HttpsPort`, `ExternalPort` | HTTPS and HTTP ports |
|
|
||||||
| `mac` | MAC address for Wake-on-LAN (may be empty) |
|
|
||||||
| `LocalIP` | host's address as it sees it |
|
|
||||||
| `MaxLumaPixelsHEVC` | HEVC capability (0 = none) |
|
|
||||||
| `ServerCodecModeSupport` | codec bitmask (UNKNOWN U25: bit meanings) |
|
|
||||||
| `SupportedDisplayMode` | display modes (may be empty) |
|
|
||||||
| `PairStatus` | 1 = this client is paired |
|
|
||||||
| `currentgame` | running app id, 0 = none |
|
|
||||||
| `state` | busy/free string, host-specific suffix (e.g. `…_SERVER_BUSY`, `…_SERVER_FREE`) |
|
|
||||||
|
|
||||||
### 1.3 applist
|
|
||||||
|
|
||||||
`GET /applist?uniqueid=…` over HTTPS. One `<App>` per app with `<AppTitle>`, `<ID>` (decimal) and
|
|
||||||
`<IsHdrSupported>` (0/1) [M]. Box art: `GET /appasset?appid=<ID>…` returns an image [M] (not used: Arena Domi TV
|
|
||||||
shows Arena's own covers).
|
|
||||||
|
|
||||||
### 1.4 launch, resume, cancel
|
|
||||||
|
|
||||||
`GET /launch?…` over HTTPS. Parameters [M]:
|
|
||||||
|
|
||||||
| Parameter | Value |
|
|
||||||
| :-- | :-- |
|
|
||||||
| `appid` | app `ID` from applist |
|
|
||||||
| `mode` | `<width>x<height>x<fps>`, e.g. `1920x1080x60` |
|
|
||||||
| `rikey` | 16-byte AES key, hex. Used for control, audio and video encryption [W6][M] |
|
|
||||||
| `rikeyid` | integer key id, decimal. Feeds the audio IV (section 6.3) [M] |
|
|
||||||
| `hdrMode` | 0/1 |
|
|
||||||
| `surroundAudioInfo` | `(channel_mask << 16) | channel_count`; stereo default 196610 = `0x30002` [M] |
|
|
||||||
| others | UNKNOWN U4 (e.g. local audio playback, SOPS, gamepad mask, any version field) |
|
|
||||||
|
|
||||||
Response [M]: `<gamesession>1</gamesession>` and `<sessionUrl0>rtsp://<host>:<port></sessionUrl0>`
|
|
||||||
(UNKNOWN U4: what to assume when `sessionUrl0` is missing; we use port 48010 of the same host).
|
|
||||||
|
|
||||||
`GET /resume?rikey=…&rikeyid=…` reattaches to the running app with fresh keys [M]. `GET /cancel` quits the running
|
|
||||||
app [M]. `GET /unpair` forgets this client [M].
|
|
||||||
|
|
||||||
**Key rule (ours):** a fresh random `rikey` and `rikeyid` for every launch and resume. Counters behind the GCM
|
|
||||||
nonces restart with each session (section 7), so a reused key would reuse nonces.
|
|
||||||
|
|
||||||
### 1.5 Pairing
|
|
||||||
|
|
||||||
The host shows nothing to the user in Arena Domi: arena-host submits the PIN to Sunshine locally. On the wire the PIN
|
|
||||||
handshake is unchanged.
|
|
||||||
|
|
||||||
Inputs: `PIN` (4 ASCII digits [M]), the client's RSA certificate and key, randomness. Notation: `‖` concatenation,
|
|
||||||
`E_K` / `D_K` AES-128-ECB with key `K` and no padding (inputs are whole blocks) [M], `sig(cert)` the raw
|
|
||||||
`signatureValue` bytes of an X.509 certificate [M], `Sign`/`Verify` RSASSA-PKCS1-v1_5 with SHA-256 [M][RFC 8017].
|
|
||||||
|
|
||||||
| Step | Client sends | Host answers | Client then |
|
|
||||||
| :-- | :-- | :-- | :-- |
|
|
||||||
| 1 (HTTP) | `/pair?uniqueid&devicename&updateState=1&phrase=getservercert&salt=hex(salt)&clientcert=hex(client cert PEM)`; `salt` 16 random bytes | blocks until the PIN is entered on the host [M], then `paired=1`, `plaincert=hex(host cert PEM)` | derives `K = SHA-256(salt ‖ PIN)[0..16]` [W2][M]; stores the host cert |
|
|
||||||
| 2 (HTTP) | `clientchallenge=hex(E_K(C))`; `C` 16 random bytes | `challengeresponse=hex(E_K(H_s ‖ S_c))`, 48 bytes: `H_s = SHA-256(C ‖ sig(host cert) ‖ secret_s)`, `S_c` the 16-byte host challenge [W2][M] | decrypts, keeps `H_s` and `S_c`; cannot check `H_s` yet |
|
|
||||||
| 3 (HTTP) | `serverchallengeresp=hex(E_K(H_c))`, `H_c = SHA-256(S_c ‖ sig(client cert) ‖ secret_c)`, `secret_c` 16 random bytes | `pairingsecret=hex(secret_s ‖ Sign_host(secret_s))` [W2][M] | checks `Verify_host(secret_s, signature)` **and** `SHA-256(C ‖ sig(host cert) ‖ secret_s) == H_s`. Failure = wrong PIN or man in the middle: stop. |
|
|
||||||
| 4 (HTTP) | `clientpairingsecret=hex(secret_c ‖ Sign_client(secret_c))` | host checks `H_c` and the signature, answers `paired=1` (or `paired=0`) [W2][M] | |
|
|
||||||
| 5 (HTTPS) | `phrase=pairchallenge`, with the client certificate | `paired=1` [W2] | pairing done; store host cert + host `uniqueid` |
|
|
||||||
|
|
||||||
All step responses are `<root status_code="200"><paired>1</paired>…</root>` with the named element inside [M].
|
|
||||||
`paired` is `0` when the host refuses.
|
|
||||||
|
|
||||||
- UNKNOWN U1: whether Sunshine requires `devicename` / `updateState`, and the order of steps 4 and 5 (Wolf's diagram:
|
|
||||||
secret then HTTPS `pairchallenge`; Moonshine's comment lists `pairchallenge` first). We follow Wolf. Settle: lab
|
|
||||||
capture of a pairing against Sunshine.
|
|
||||||
- UNKNOWN U2: what Sunshine checks in the client certificate (key size, validity, subject). Our certificate: RSA-2048,
|
|
||||||
SHA-256, self-signed, long validity, `CN` from the device name. Settle: lab pairing.
|
|
||||||
- UNKNOWN U28: what a client should do after a failed step (call `/unpair`? just stop?). Settle: lab capture.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. RTSP
|
|
||||||
|
|
||||||
Source: [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) [W3], Moonshine `src/rtsp.rs` [M], [RFC 2326].
|
|
||||||
|
|
||||||
### 2.1 Messages
|
|
||||||
|
|
||||||
Plain text over TCP [W3]. A request is a start line `<METHOD> <target> RTSP/1.0`, header lines `Name: value`, an
|
|
||||||
empty line, then an optional payload; lines end in CRLF [W3]. A response starts `RTSP/1.0 <status> <reason>` [W3].
|
|
||||||
`CSeq` is always present and counts requests [W3]. Wolf's example carries `X-GS-ClientVersion: 14` [W3]
|
|
||||||
(UNKNOWN U5: which value Sunshine expects).
|
|
||||||
|
|
||||||
- UNKNOWN U5: framing. Wolf calls the payload "anything after the headers". Our framer uses `Content-Length` when
|
|
||||||
present and otherwise ends the message when the host closes the connection. Settle: lab capture (does Sunshine
|
|
||||||
close the TCP connection after each reply, and does it send `Content-Length`?).
|
|
||||||
- Target: `rtsp://<host>:<port>` from `sessionUrl0` [W3][M].
|
|
||||||
|
|
||||||
### 2.2 Sequence [W3]
|
|
||||||
|
|
||||||
| # | Request | Answer that matters |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 1 | `OPTIONS` | 200 |
|
|
||||||
| 2 | `DESCRIBE` | SDP payload with the host's capabilities (2.3) |
|
|
||||||
| 3 | `SETUP` audio | `Transport: server_port=<audio port>` |
|
|
||||||
| 4 | `SETUP` video | `Transport: server_port=<video port>` |
|
|
||||||
| 5 | `SETUP` control | `Transport: server_port=<control port>` |
|
|
||||||
| 6 | `ANNOUNCE` | SDP payload from the client with the stream settings (2.4); 200 |
|
|
||||||
| 7 | `PLAY` | 200 |
|
|
||||||
|
|
||||||
SETUP details [M]: the target's query is `streamid=<audio|video|control>/…` (Moonshine's example:
|
|
||||||
`streamid=control/13/0`); a `Transport` header must be present (its value is not interpreted by Moonshine); the reply
|
|
||||||
has `Session: <id>;timeout = 90` and `Transport: server_port=<port>`.
|
|
||||||
|
|
||||||
- UNKNOWN U5: the exact SETUP targets and `Transport` value Sunshine expects, whether later requests must echo
|
|
||||||
`Session`, and the PLAY target.
|
|
||||||
- UNKNOWN U7: whether Sunshine's SETUP replies carry extra headers the client must use (for example a payload for the
|
|
||||||
UDP ping or a value for the ENet connect). Settle: lab capture.
|
|
||||||
|
|
||||||
### 2.3 DESCRIBE reply (host → client)
|
|
||||||
|
|
||||||
SDP-like lines, one attribute per line [M][RFC 4566]:
|
|
||||||
|
|
||||||
| Line | Meaning |
|
|
||||||
| :-- | :-- |
|
|
||||||
| `a=x-ss-general.featureFlags:<n>` | bit 0x01 pen/touch events, 0x02 controller touch events [M] |
|
|
||||||
| `a=x-ss-general.encryptionSupported:<n>` | bit 0x01 control V2, 0x02 video, 0x04 audio [M] |
|
|
||||||
| `a=x-nv-video[0].refPicInvalidation:1` | host can invalidate reference frames instead of sending an IDR [M] |
|
|
||||||
| `a=rtpmap:98 AV1/90000` | host can send AV1 [M] |
|
|
||||||
| `a=fmtp:96 packetization-mode=1` | H.264 packetization [M] |
|
|
||||||
| `sprop-parameter-sets=…` | present, value not used [M] |
|
|
||||||
| `a=fmtp:97 surround-params=<digits>` | one line per Opus configuration [W3][M] |
|
|
||||||
|
|
||||||
`surround-params` is a run of single decimal digits: channel count, stream count, coupled-stream count, then one
|
|
||||||
mapping digit per channel. Wolf's example `21101` = 2 channels, 1 stream, 1 coupled stream, mapping `0 1` [W3].
|
|
||||||
These are the Opus multistream parameters of [RFC 7845] §5.1.1 and go straight to the platform's Opus decoder.
|
|
||||||
UNKNOWN U26: the host advertises 5.1/7.1 normal-quality mappings with a channel rotated [M*]; settle by capture.
|
|
||||||
|
|
||||||
### 2.4 ANNOUNCE payload (client → host)
|
|
||||||
|
|
||||||
SDP attribute lines `a=<name>:<value>`. Names the host reads [M]; values and the full required set are UNKNOWN U6:
|
|
||||||
|
|
||||||
| Attribute | What |
|
|
||||||
| :-- | :-- |
|
|
||||||
| `x-nv-video[0].clientViewportWd`, `…clientViewportHt` | resolution |
|
|
||||||
| `x-nv-video[0].maxFPS` | frame rate |
|
|
||||||
| `x-nv-video[0].packetSize` | video packet size (default 1024 [W5]) |
|
|
||||||
| `x-nv-video[0].maxNumReferenceFrames` | 0 = host's choice when the decoder supports invalidation [M*] |
|
|
||||||
| `x-nv-video[0].refPicInvalidation` | client supports invalidation |
|
|
||||||
| `x-nv-video[0].dynamicRangeMode`, `…encoderCscMode` | HDR, colour space |
|
|
||||||
| `x-nv-vqos[0].bitStreamFormat` | codec |
|
|
||||||
| `x-nv-vqos[0].fec.minRequiredFecPackets` | minimum parity packets per block |
|
|
||||||
| `x-nv-vqos[0].qosTrafficType`, `x-nv-aqos.qosTrafficType` | DSCP class |
|
|
||||||
| `x-ml-video.configuredBitrateKbps` | bitrate |
|
|
||||||
| `x-nv-aqos.packetDuration` | audio packet duration in ms |
|
|
||||||
| `x-nv-audio.surround.enable`, `…numChannels`, `…channelMask`, `…AudioQuality` | audio layout |
|
|
||||||
| `x-ss-video[0].chromaSamplingType` | 4:2:0 / 4:4:4 |
|
|
||||||
| `x-ss-general.encryptionEnabled` | encryption flags the client turns on (bits as in 2.3) [M] |
|
|
||||||
|
|
||||||
Settle U6: lab capture of an ANNOUNCE accepted by Sunshine, then vary one attribute at a time.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. Control channel (ENet + AES-GCM)
|
|
||||||
|
|
||||||
Source: [Wolf: control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html) [W4], Moonshine `src/session/stream/control/mod.rs` [M], tokio-enet [T].
|
|
||||||
|
|
||||||
### 3.1 ENet
|
|
||||||
|
|
||||||
The control stream runs over a custom fork of ENet supporting IPv4 and IPv6 [W4]. What is known about the wire,
|
|
||||||
from stock ENet 1.3 as tokio-enet implements it [T] (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
|
|
||||||
present, `1<<14` compressed) and bits 12-13 the session id; then `sent_time u16` if flagged.
|
|
||||||
- Command header (4 bytes): `command u8` (low 4 bits type, `0x80` acknowledge wanted, `0x40` unsequenced),
|
|
||||||
`channel_id u8`, `reliable_sequence u16`.
|
|
||||||
- Commands and total sizes: 1 acknowledge (8), 2 connect (48), 3 verify connect (44), 4 disconnect (8), 5 ping (4),
|
|
||||||
6 send reliable (6 + data), 7 send unreliable (8 + data), 8 send fragment (24 + data), 9 send unsequenced (8 + data),
|
|
||||||
10 bandwidth limit (12), 11 throttle configure (16), 12 send unreliable fragment (24 + data).
|
|
||||||
- MTU 576-4096, window 4096-65536, channels 1-255, peer id ≤ 0xFFF.
|
|
||||||
|
|
||||||
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
|
|
||||||
[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
|
|
||||||
differences); the channel count, MTU and `connect data` the client should offer; ping interval and timeouts.
|
|
||||||
Settle: lab capture of one session, decoded with our parser.
|
|
||||||
|
|
||||||
### 3.2 Encrypted frame
|
|
||||||
|
|
||||||
Every control message is wrapped [W4] (little-endian):
|
|
||||||
|
|
||||||
| Offset | Size | Field |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 0 | 2 | type, always `0x0001` |
|
|
||||||
| 2 | 2 | length of the rest (`4 + 16 + ciphertext`) |
|
|
||||||
| 4 | 4 | sequence number, increasing |
|
|
||||||
| 8 | 16 | GCM tag |
|
|
||||||
| 24 | n | ciphertext |
|
|
||||||
|
|
||||||
- Cipher: AES-128-GCM with the launch `rikey` [W4][W6].
|
|
||||||
- Nonce (12 bytes) [M]: bytes 0-3 the sequence number (LE), bytes 4-9 zero, byte 10 the direction (`'C'` client to
|
|
||||||
host, `'H'` host to client), byte 11 `'C'`. No associated data [M].
|
|
||||||
- Minimum frame: 24 bytes + at least the 4-byte message header [M].
|
|
||||||
- UNKNOWN U11: the first sequence number and whether the host rejects gaps or repeats. Settle: lab capture.
|
|
||||||
We start at 0, never reuse a number, and drop host frames whose number is not greater than the last accepted one
|
|
||||||
(replay protection, ours).
|
|
||||||
- UNKNOWN U10: whether anything is ever sent outside the wrapper once control encryption (V2) is negotiated. Our
|
|
||||||
client refuses to stream with a host that does not offer control V2.
|
|
||||||
|
|
||||||
### 3.3 Messages (decrypted payload)
|
|
||||||
|
|
||||||
`type u16 LE`, `length u16 LE` (bytes that follow, must equal the rest of the payload [M]), then the body [W4].
|
|
||||||
|
|
||||||
| Type | Name | Direction | Body |
|
|
||||||
| :-- | :-- | :-- | :-- |
|
|
||||||
| 0x0305 | START_A | client → host | UNKNOWN U10 |
|
|
||||||
| 0x0307 | START_B | client → host | UNKNOWN U10. The host starts video and audio when it arrives [M] |
|
|
||||||
| 0x0200 | PERIODIC_PING | client → host | UNKNOWN U10. Keeps the session alive; the host stops after a timeout without one [M] |
|
|
||||||
| 0x0201 | LOSS_STATS | client → host | UNKNOWN U10 |
|
|
||||||
| 0x0204 | FRAME_STATS | client → host | UNKNOWN U10 |
|
|
||||||
| 0x0206 | INPUT_DATA | client → host | section 4 |
|
|
||||||
| 0x0302 | IDR_FRAME (request) | client → host | UNKNOWN U10 (Moonshine ignores the body) |
|
|
||||||
| 0x0301 | INVALIDATE_REF_FRAMES | client → host | `first u32`, `reserved u32`, `last u32`, `reserved 12 bytes`, LE [M] |
|
|
||||||
| 0x0100 | TERMINATION | host → client | UNKNOWN U10 |
|
|
||||||
| 0x0109 | TERMINATION (extended) | host → client | `error_code u32 BE`; `0x80030023` = graceful [M] |
|
|
||||||
| 0x010b | RUMBLE_DATA | host → client | `unused 4`, `controller u16`, `low u16`, `high u16` [W4] |
|
|
||||||
| 0x5500 | RUMBLE_TRIGGERS | host → client | `controller u16`, `left u16`, `right u16` [W4] |
|
|
||||||
| 0x5501 | MOTION_EVENT | host → client | `controller u16`, `rate u16`, `type u8` (1 accelerometer, 2 gyroscope) [W4] |
|
|
||||||
| 0x5502 | RGB_LED | host → client | `controller u16`, `r u8`, `g u8`, `b u8` [W4] |
|
|
||||||
| 0x5503 | trigger effect | host → client | UNKNOWN [M] |
|
|
||||||
| 0x010e | HDR_MODE | host → client | `enabled u8` + 30 bytes HDR metadata (15 × u16 LE) [M*] |
|
|
||||||
|
|
||||||
UNKNOWN U23: Wolf states "all data is little-endian" for the frame; we assume LE for the host event bodies too.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. Input and gamepad packets
|
|
||||||
|
|
||||||
Source: [Wolf: input](https://games-on-whales.github.io/wolf/stable/protocols/input-data.html) [W7].
|
|
||||||
|
|
||||||
An INPUT_DATA message (inside the encrypted frame) [W7]:
|
|
||||||
|
|
||||||
| Offset | Size | Field |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 0 | 2 | `0x0206` LE |
|
|
||||||
| 2 | 2 | length LE = 4 + size |
|
|
||||||
| 4 | 4 | **size, big-endian** = 4 + data length |
|
|
||||||
| 8 | 4 | input type, LE |
|
|
||||||
| 12 | n | data |
|
|
||||||
|
|
||||||
Input types [W7]: MOUSE_MOVE_REL `0x07`, MOUSE_MOVE_ABS `0x05`, MOUSE_BUTTON_DOWN `0x08`, MOUSE_BUTTON_UP `0x09`,
|
|
||||||
KEY_DOWN `0x03`, KEY_UP `0x04`, MOUSE_SCROLL `0x0A`, MOUSE_HSCROLL `0x55000001`, TOUCH `0x55000002`,
|
|
||||||
PEN `0x55000003`, CONTROLLER_MULTI `0x0C`, CONTROLLER_ARRIVAL `0x55000004`, CONTROLLER_TOUCH `0x55000005`,
|
|
||||||
CONTROLLER_MOTION `0x55000006`, CONTROLLER_BATTERY `0x55000007`, HAPTICS `0x0D`, UTF8_TEXT `0x17`.
|
|
||||||
|
|
||||||
Data layouts [W7]:
|
|
||||||
|
|
||||||
| Type | Data |
|
|
||||||
| :-- | :-- |
|
|
||||||
| MOUSE_MOVE_REL | `dx i16 BE`, `dy i16 BE` |
|
|
||||||
| MOUSE_MOVE_ABS | `x i16 BE`, `y i16 BE`, `unused 2`, `width u16 BE`, `height u16 BE` (client viewport) |
|
|
||||||
| MOUSE_BUTTON_DOWN/UP | `button u8`: 1 left, 2 middle, 3 right, 4 side, 5 extra |
|
|
||||||
| KEY_DOWN/UP | `flags u8`, `key code u16 LE`, `modifiers u8`, `zero 2` |
|
|
||||||
| MOUSE_SCROLL | `amount1 i16 BE`, `amount2 i16 BE`, `zero 2`; hosts use amount1 |
|
|
||||||
| MOUSE_HSCROLL | `amount i16 BE` |
|
|
||||||
| CONTROLLER_ARRIVAL | `controller u8`, `type u8` (0 unknown, 1 Xbox, 2 PlayStation, 3 Nintendo), `capabilities u8`, `supported buttons u32` |
|
|
||||||
| CONTROLLER_MULTI | below |
|
|
||||||
|
|
||||||
Key codes are Windows virtual-key style (`0x41` A … `0x5A` Z, `0x70` F1 …, `0xA0`/`0xA1` shifts, …) [W7].
|
|
||||||
UNKNOWN U20: the example key packet carries `A4 80` (LE `0x80A4`) for LEFTALT `0xA4`, so the high byte has a flag
|
|
||||||
meaning; also the bit meanings of `flags` and `modifiers` (the example has `modifiers = 0x04` with Alt).
|
|
||||||
|
|
||||||
Controller capability bits [W7]: analog triggers 0x01, rumble 0x02, trigger rumble 0x04, touchpad 0x08,
|
|
||||||
accelerometer 0x10, gyro 0x20, battery 0x40, RGB LED 0x80.
|
|
||||||
|
|
||||||
**CONTROLLER_MULTI** data (26 bytes, LE) [W7]:
|
|
||||||
|
|
||||||
| Offset | Size | Field |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 0 | 2 | `0x001A` |
|
|
||||||
| 2 | 2 | controller number |
|
|
||||||
| 4 | 2 | active mask (bit per connected controller; mask 0 with number 1 = controller 1 unplugged) |
|
|
||||||
| 6 | 2 | `0x0014` |
|
|
||||||
| 8 | 2 | button flags (low 16 bits) |
|
|
||||||
| 10 | 1 | left trigger |
|
|
||||||
| 11 | 1 | right trigger |
|
|
||||||
| 12 | 2 | left stick X, i16 |
|
|
||||||
| 14 | 2 | left stick Y, i16 |
|
|
||||||
| 16 | 2 | right stick X, i16 |
|
|
||||||
| 18 | 2 | right stick Y, i16 |
|
|
||||||
| 20 | 2 | `0x009C` |
|
|
||||||
| 22 | 2 | button flags (high 16 bits; 0 in the legacy format) |
|
|
||||||
| 24 | 2 | `0x0055` |
|
|
||||||
|
|
||||||
Buttons = `low | (high << 16)` [W7]: DPAD_UP 0x0001, DPAD_DOWN 0x0002, DPAD_LEFT 0x0004, DPAD_RIGHT 0x0008,
|
|
||||||
START 0x0010, BACK 0x0020, LEFT_STICK 0x0040, RIGHT_STICK 0x0080, LEFT_BUTTON 0x0100, RIGHT_BUTTON 0x0200,
|
|
||||||
HOME 0x0400, A 0x1000, B 0x2000, X 0x4000, Y 0x8000, PADDLE1-4 0x010000-0x080000, TOUCHPAD 0x100000,
|
|
||||||
MISC 0x200000.
|
|
||||||
|
|
||||||
UNKNOWN U21: layouts of TOUCH, PEN, CONTROLLER_TOUCH, CONTROLLER_MOTION, CONTROLLER_BATTERY, HAPTICS and
|
|
||||||
UTF8_TEXT (Wolf lists them without a layout). Not needed for Day 1 (gamepad + Magic Remote pointer + keys).
|
|
||||||
UNKNOWN U22: meaning of the constants `0x1A`, `0x14`, `0x9C`, `0x55`, and whether the arrival packet has more
|
|
||||||
bytes. Settle: lab capture with a gamepad.
|
|
||||||
|
|
||||||
### Test vectors QA can build from [W7]
|
|
||||||
|
|
||||||
Full INPUT_DATA messages (plaintext, before the encrypted frame), hex:
|
|
||||||
|
|
||||||
| Event | Bytes |
|
|
||||||
| :-- | :-- |
|
|
||||||
| relative move dx = -1, dy = 0 | `06 02 0C 00 00 00 00 08 07 00 00 00 FF FF 00 00` |
|
|
||||||
| absolute move x 1464, y 528, viewport 1919 × 1079 | `06 02 12 00 00 00 00 0E 05 00 00 00 05 B8 02 10 00 00 07 7F 04 37` |
|
|
||||||
| left button down | `06 02 09 00 00 00 00 05 08 00 00 00 01` |
|
|
||||||
| key down, code `0x80A4`, modifiers 0x04 | `06 02 0E 00 00 00 00 0A 03 00 00 00 00 A4 80 04 00 00` |
|
|
||||||
| scroll -120 | `06 02 0E 00 00 00 00 0A 0A 00 00 00 FF 88 FF 88 00 00` |
|
|
||||||
| horizontal scroll 30 | `06 02 0A 00 00 00 00 06 01 00 00 55 00 1E` |
|
|
||||||
| controller 0, active mask 1, right stick Y -104 | `06 02 22 00 00 00 00 1E 0C 00 00 00 1A 00 00 00 01 00 14 00 00 00 00 00 00 00 00 00 00 00 98 FF 9C 00 00 00 55 00` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. RTP video
|
|
||||||
|
|
||||||
Source: [Wolf: RTP video](https://games-on-whales.github.io/wolf/stable/protocols/rtp-video.html) [W5], Moonshine `src/session/stream/video/packetizer.rs` [M], [RFC 3550].
|
|
||||||
|
|
||||||
### 5.1 Ping
|
|
||||||
|
|
||||||
The SETUP port is not where video arrives from: the client sends a PING from its own UDP socket to that port, and
|
|
||||||
the host sends the stream back to the source address of the PING (NAT) [W5]. Moonshine accepts the 4 bytes `PING`
|
|
||||||
[M]. UNKNOWN U8: Sunshine's ping payload and how often to repeat it. Settle: lab capture.
|
|
||||||
|
|
||||||
### 5.2 Packet
|
|
||||||
|
|
||||||
Each packet is `packetSize + 16` bytes, `packetSize` from ANNOUNCE (default 1024) [W5]:
|
|
||||||
|
|
||||||
| Offset | Size | Field |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 0 | 1 | RTP byte 0, `0x90` [M] (version 2, extension bit set) |
|
|
||||||
| 1 | 1 | payload type, 0 [M] |
|
|
||||||
| 2 | 2 | sequence number, BE [W5][RFC 3550] |
|
|
||||||
| 4 | 4 | timestamp, BE (UNKNOWN U29: clock rate, probably 90 kHz) |
|
|
||||||
| 8 | 4 | SSRC, 0 [M] |
|
|
||||||
| 12 | 4 | reserved [W5] |
|
|
||||||
| 16 | 4 | stream packet index, LE (= RTP sequence << 8 [M]) |
|
|
||||||
| 20 | 4 | frame index, LE [W5][M] |
|
|
||||||
| 24 | 1 | flags: 0x01 picture data, 0x02 end of frame, 0x04 start of frame [W5] |
|
|
||||||
| 25 | 1 | reserved [W5] |
|
|
||||||
| 26 | 1 | multi-FEC flags, `0x10` [M] (UNKNOWN U15: meaning) |
|
|
||||||
| 27 | 1 | multi-FEC blocks: bits 4-5 this block's index, bits 6-7 the last block's index [M] |
|
|
||||||
| 28 | 4 | FEC info, LE: bits 4-11 FEC percentage, bits 12-21 shard index in block, bits 22-31 data shards in block [M] |
|
|
||||||
| 32 | n | payload: `packetSize - 16` bytes of frame data |
|
|
||||||
|
|
||||||
A frame's data = an 8-byte frame header + the Annex-B bitstream (start codes `00 00 01` / `00 00 00 01`) [W5].
|
|
||||||
Wolf shows the 8 bytes as the constant `01 37 63 68 61 72 73 73` [W5]; Moonshine fills them as
|
|
||||||
`header type u8 = 0x01`, `processing latency u16 LE`, `frame type u8` (1 predicted, 2 key, 5 first frame after a
|
|
||||||
reference invalidation), `last shard payload length u32 LE` [M]. UNKNOWN U13: which one Sunshine sends. Our parser
|
|
||||||
returns the 8 bytes raw plus the structured reading. The last data shard is zero-padded to full size [M]; the
|
|
||||||
last-payload length (or the Annex-B content) tells where the frame really ends.
|
|
||||||
|
|
||||||
### 5.3 FEC
|
|
||||||
|
|
||||||
Reed-Solomon erasure code over GF(2^8), polynomial `0x11D` [F] [W5]:
|
|
||||||
|
|
||||||
- A frame splits into **blocks** (up to 4 [M]); each block has `k` data shards and
|
|
||||||
`m = ceil(k × percentage / 100)` parity shards, `k + m ≤ 255` [M]. Wolf's example: 4 KB at packetSize 1024 and
|
|
||||||
50 % → 4 data + 2 parity packets [W5].
|
|
||||||
- **Where the receiver gets the parameters:** from every packet of the block: `k` = FEC info bits 22-31, shard index =
|
|
||||||
bits 12-21 (0..k-1 data, k..k+m-1 parity), percentage = bits 4-11, block index and last block index from the
|
|
||||||
multi-FEC byte. `m` follows from `k` and the percentage. The requested percentage and the minimum parity count are
|
|
||||||
set by the client (`x-nv-vqos[0].fec.minRequiredFecPackets`, ANNOUNCE) [M].
|
|
||||||
- Shards are the **whole packets** (all `packetSize + 16` bytes, headers included) [M]. Parity packets have flags 0
|
|
||||||
[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
|
|
||||||
(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].
|
|
||||||
Settle: approve fec-rs as a source and read its construction, or measure: capture blocks with known losses and
|
|
||||||
check our decoder against them.
|
|
||||||
|
|
||||||
### 5.4 Feedback
|
|
||||||
|
|
||||||
On an unrecoverable frame the client asks for an IDR frame or, when the host advertised `refPicInvalidation`, sends
|
|
||||||
INVALIDATE_REF_FRAMES with the lost range (section 3.3) [W5][M].
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. RTP audio (Opus)
|
|
||||||
|
|
||||||
Source: [Wolf: RTP Opus](https://games-on-whales.github.io/wolf/stable/protocols/rtp-opus.html) [W6], Moonshine `src/session/stream/audio/encoder.rs` [M], [RFC 6716].
|
|
||||||
|
|
||||||
### 6.1 Ping
|
|
||||||
|
|
||||||
As for video: the client pings the SETUP audio port and audio comes back to the ping's source address [W6].
|
|
||||||
|
|
||||||
### 6.2 Packets
|
|
||||||
|
|
||||||
RTP header, 12 bytes [W6]: byte 0 `0x80` [M], payload type **97** for audio and **127** for FEC parity [M],
|
|
||||||
sequence BE, timestamp BE, SSRC 0 [M]. The timestamp counts **milliseconds** and advances by the packet duration
|
|
||||||
(`x-nv-aqos.packetDuration`) per packet [M].
|
|
||||||
|
|
||||||
Data packet: RTP header + one Opus packet [RFC 6716], encrypted (6.3).
|
|
||||||
|
|
||||||
Parity packet [W6]: RTP header (sequence continues after the 4 data packets [M]) + a 12-byte FEC header + parity:
|
|
||||||
|
|
||||||
| Offset | Size | Field |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| 12 | 1 | shard index (0 or 1) [W6][M] |
|
|
||||||
| 13 | 1 | payload type of the protected packets, 97 [M] |
|
|
||||||
| 14 | 2 | base sequence number, BE [W6][M] |
|
|
||||||
| 16 | 4 | base timestamp, BE [W6][M] |
|
|
||||||
| 20 | 4 | SSRC [W6] |
|
|
||||||
| 24 | n | parity bytes |
|
|
||||||
|
|
||||||
### 6.3 Encryption
|
|
||||||
|
|
||||||
AES-128-CBC with `rikey` [W6]. IV (16 bytes) [M]: `u32 BE (rikeyid + sequence number)` then 12 zero bytes; PKCS#7
|
|
||||||
padding [M]. UNKNOWN U17: Wolf says audio is always encrypted; Moonshine only when the audio flag is negotiated.
|
|
||||||
Settle: lab capture.
|
|
||||||
|
|
||||||
### 6.4 FEC
|
|
||||||
|
|
||||||
Every 4 data packets are followed by 2 parity packets [W6]. A block is the 4 data packets whose sequence numbers
|
|
||||||
start at a multiple of 4 [M]; the base sequence and timestamp in the FEC header are the first data packet's [M].
|
|
||||||
Shards are the encrypted payloads (all 4 the same length, constant-bitrate Opus) [M]. A lost data packet is rebuilt
|
|
||||||
from any 4 of the 6 packets; its RTP header comes from the base values (sequence = base + index, timestamp = base +
|
|
||||||
index × duration) [M].
|
|
||||||
|
|
||||||
UNKNOWN U16 (blocks audio FEC): the parity matrix. It is a fixed 2 × 4 matrix over GF(2^8), **not** the default
|
|
||||||
construction of the RS library Moonshine uses [M]. The only value we have seen carries GPL provenance and is not
|
|
||||||
used (see CLEAN_ROOM.md). Settle by measurement: capture a few audio blocks from a lab host and solve for the 8
|
|
||||||
coefficients (each parity byte is a linear combination of the 4 data bytes at the same offset: 4 unknowns per
|
|
||||||
parity row, so a handful of byte positions gives a unique solution). Until then, audio loss falls back to the
|
|
||||||
platform's packet-loss concealment.
|
|
||||||
|
|
||||||
### 6.5 Decoding
|
|
||||||
|
|
||||||
**Not DomiStream.** DomiStream outputs each Opus packet (or a "lost" marker) in sequence order plus the multistream
|
|
||||||
configuration from `surround-params` (section 2.3). ArenaTV decodes (NDL or libopus on webOS, MediaCodec on
|
|
||||||
Android) and does concealment.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 7. Stream encryption
|
|
||||||
|
|
||||||
| Stream | When | Cipher | Key | Nonce / IV |
|
|
||||||
| :-- | :-- | :-- | :-- | :-- |
|
|
||||||
| Pairing | always | AES-128-ECB + RSA PKCS#1 v1.5 SHA-256 | SHA-256(salt ‖ PIN)[0..16] | none (ECB) |
|
|
||||||
| HTTPS | after pairing | TLS (platform), pinned host cert, client cert | | |
|
|
||||||
| Control | control V2 flag (0x01) | AES-128-GCM, 16-byte tag, no AAD | `rikey` | seq LE ‖ 6 zero ‖ dir (`C`/`H`) ‖ `C` [M] |
|
|
||||||
| Audio | audio flag (0x04) [M] (always, per [W6]) | AES-128-CBC, PKCS#7 | `rikey` | BE(rikeyid + seq) ‖ 12 zero [M] |
|
|
||||||
| Video | video flag (0x02) [M] | AES-128-GCM, 16-byte tag, no AAD | `rikey` | 8-byte LE counter ‖ 3 zero ‖ `V` [M] |
|
|
||||||
|
|
||||||
Negotiation: the host lists what it supports in DESCRIBE (`x-ss-general.encryptionSupported`), the client turns on
|
|
||||||
what it wants in ANNOUNCE (`x-ss-general.encryptionEnabled`) [M].
|
|
||||||
|
|
||||||
Encrypted video packet [M]: `IV 12 bytes ‖ frame number u32 LE ‖ tag 16 bytes ‖ ciphertext`, where the ciphertext is
|
|
||||||
the whole plaintext packet of section 5.2; FEC is applied before encryption, so the client decrypts first.
|
|
||||||
UNKNOWN U19: whether Sunshine uses this exact layout (Moonlight Android 12.1 added end-to-end encryption with
|
|
||||||
Sunshine, S-16). Settle: lab capture with video encryption on.
|
|
||||||
|
|
||||||
Our policy (Day 1: "stream encryption on"): request every flag the host supports; refuse to stream without control
|
|
||||||
V2; show in the stats overlay whether video is encrypted. A new `rikey`/`rikeyid` per launch and resume, because the
|
|
||||||
three nonce spaces (control `C`/`H`, video `V`) share one key and their counters restart per session. On top of this,
|
|
||||||
traffic goes through the Via Domi tunnel whenever Via is installed (roadmap J6).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 8. UNKNOWNs
|
|
||||||
|
|
||||||
**B** = blocks a Day 1 stream against Sunshine. Almost everything is settled by **one lab capture** (a GameStream
|
|
||||||
client and Sunshine on a lab machine, not Mark's PC, his Sunshine or his TV); the column says what to look at.
|
|
||||||
|
|
||||||
| # | What | B | Settle by |
|
|
||||||
| :-- | :-- | :-- | :-- |
|
|
||||||
| U1 | Pairing query params beyond `uniqueid/phrase/salt/clientcert`; order of steps 4 and 5 | B | capture a pairing |
|
|
||||||
| U2 | Client certificate requirements | B | lab pairing with our certificate |
|
|
||||||
| U4 | Full launch parameter set; default when `sessionUrl0` is missing | B | capture a launch |
|
|
||||||
| U5 | RTSP framing, `X-GS-ClientVersion`, SETUP targets and `Transport`, `Session` echo, PLAY target | B | capture the RTSP exchange |
|
|
||||||
| U6 | ANNOUNCE attributes and values Sunshine requires | B | capture, then vary one at a time |
|
|
||||||
| U7 | Extra headers in SETUP replies | 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 |
|
|
||||||
| 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 |
|
|
||||||
| 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 |
|
|
||||||
| U15 | Multi-FEC flags `0x10` | | capture |
|
|
||||||
| 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 |
|
|
||||||
| U19 | Video encryption layout against Sunshine | | capture with video encryption on |
|
|
||||||
| U20 | Key code high byte, `flags`, `modifiers` bits | | capture with a keyboard |
|
|
||||||
| U21 | TOUCH, PEN, controller touch/motion/battery, HAPTICS, UTF8_TEXT layouts | | capture (Day 5 scope) |
|
|
||||||
| U22 | CONTROLLER_MULTI constants, arrival packet length | | capture with a gamepad |
|
|
||||||
| U23 | Endianness of host event bodies | | capture rumble |
|
|
||||||
| U24 | TLS versions and ciphers | | capture (platform concern) |
|
|
||||||
| U25 | `ServerCodecModeSupport` bits | | serverinfo from hosts with known codecs |
|
|
||||||
| U26 | Surround mapping rotation | | capture 5.1 |
|
|
||||||
| U27 | Error attributes on non-200 XML | | capture a refused call |
|
|
||||||
| U28 | Client behaviour after a failed pairing step | | capture a wrong PIN |
|
|
||||||
| U29 | Video RTP clock rate | | capture |
|
|
||||||
|
|
||||||
## 9. Notes on the Wolf docs
|
|
||||||
|
|
||||||
- The video FEC example sums the overhead as "32 * 6 + 2048 = 2248 bytes"; the arithmetic gives 2240.
|
|
||||||
- The button table lists both HOME and SPECIAL_FLAG as `0x0400`.
|
|
||||||
- The key table prints NUMPAD PLUS as `x6B` (meaning `0x6B`).
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
# Open point 2: Wolf docs licence, Rust ENet crates, and a clean ENet
|
|
||||||
|
|
||||||
Roadmap open point 2 asks three things before Day 1 code: the licence of the Wolf protocol docs, the licences of the
|
|
||||||
Rust ENet crates, and whether Moonlight's ENet changes can be met by a clean Rust implementation.
|
|
||||||
Checked 2026-11-25. Source numbers (S-n) refer to the log in [../CLEAN_ROOM.md](../CLEAN_ROOM.md).
|
|
||||||
|
|
||||||
## 1. Wolf: docs and repo
|
|
||||||
|
|
||||||
| What | Licence | Evidence |
|
|
||||||
| :-- | :-- | :-- |
|
|
||||||
| Docs site `games-on-whales.github.io/wolf` | **CC BY-SA 4.0**, "except where otherwise noted" | Footer of every page: "Copyright © ABeltramo and GOW contributors. Except where otherwise noted, docs are licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)." ([index](https://games-on-whales.github.io/wolf/stable/protocols/index.html), S-1) |
|
|
||||||
| Repo `games-on-whales/wolf` | **MIT** | [`LICENSE`](https://github.com/games-on-whales/wolf/blob/beta/LICENSE), GitHub API reports `MIT` (S-8). The docs sources live in the same repo (`docs/modules/protocols/pages/*.adoc`). |
|
|
||||||
|
|
||||||
The two statements overlap: the `.adoc` files sit in an MIT repo, and the rendered site says CC BY-SA 4.0. We take the
|
|
||||||
stricter one (CC BY-SA 4.0) for the docs.
|
|
||||||
|
|
||||||
What that means for DomiStream (judgment, not legal advice):
|
|
||||||
- **Facts are free.** Port numbers, field layouts, message codes and algorithms are facts and methods. We can
|
|
||||||
implement them under CPAL-1.0.
|
|
||||||
- **Prose and diagrams are not ours to copy.** CC BY-SA content pasted into our docs would make that part
|
|
||||||
share-alike, and CC BY-SA 4.0 is not compatible with CPAL-1.0. So PROTOCOL.md restates the facts in our own words
|
|
||||||
and links each section to its Wolf page (attribution is good practice anyway).
|
|
||||||
- **Example bytes** (the input packet examples) are short functional data needed to interoperate. QA may rebuild
|
|
||||||
them from the documented field layout instead of copying the example lines; both give the same bytes.
|
|
||||||
|
|
||||||
## 2. Rust ENet crates
|
|
||||||
|
|
||||||
| Crate | Version (date) | Licence | What it is | Fits DomiStream? |
|
|
||||||
| :-- | :-- | :-- | :-- | :-- |
|
|
||||||
| [`rusty_enet`](https://github.com/jabuwu/rusty_enet) | 0.4.1 (2026-11-01) | MIT | Stock C ENet transpiled to Rust; caller supplies the `Socket` and a time function (`HostSettings::time`); optional crc32 checksum ([docs.rs](https://docs.rs/rusty_enet/latest/rusty_enet/), S-12) | Licence fits. Socket and time are pluggable, so it can run in memory. But it is transpiled C (pointer-heavy, `unsafe` inside), stock ENet only, and its API is the C host/peer model rather than bytes in/events out. Good as a **test oracle**, weak as the parser of hostile input. |
|
|
||||||
| [`tokio-enet`](https://github.com/hgaiser/tokio-enet) | 0.1.1 (2026-06-14) | BSD-2-Clause | Pure-Rust ENet, "wire-compatible with the C ENet v1.3.x protocol" ([README](https://github.com/hgaiser/tokio-enet), S-10). **Moonshine uses it for its control stream with Moonlight clients** (S-9). | Licence fits. Bound to tokio sockets and the clock, so not sans-I/O; cannot run on webOS without tokio. Its existence is the strongest evidence for the compatibility question below. |
|
|
||||||
| [`enet`](https://github.com/futile/enet-rs) | 0.3.0 (2022-03-30) | MIT OR Apache-2.0 | Bindings to the C library through `enet-sys` | Not pure Rust, not sans-I/O, stock ENet. No. |
|
|
||||||
| [`enet-sys`](https://github.com/ruabmbua/enet-sys) | 1.0.5 (2026-03-16) | MIT | Raw FFI to C ENet | No (C, FFI, stock). |
|
|
||||||
| [`enet-rs`](https://github.com/ZTzTopia/enet-rs) | 1.3.171 (2021-08-29) | ISC | Bindings for C ENet 1.3.17 | No (C, unmaintained). |
|
|
||||||
| [`nsys-enet`](https://github.com/spearman/enet-rs) | 0.2.2 (2026-07-07) | Apache-2.0 | Rust interface to C ENet | No (C). |
|
|
||||||
| [`enet-cs-sys`](https://github.com/Kalkatral/enet-cs-sys) | 0.1.1 (2023-02-25) | MIT | Bindings to ENet-CSharp, a different, incompatible ENet fork | No. |
|
|
||||||
| [`henet`](https://github.com/dehorsed/henet) | 0.1.0 (published 2026-11-25) | MIT OR Apache-2.0 | "Idiomatic Rust implementation of ENet" | Too new to judge; first release today. |
|
|
||||||
|
|
||||||
All licences above (MIT, Apache-2.0, BSD-2-Clause, ISC) are permissive and fit a CPAL-1.0 project as dependencies.
|
|
||||||
None of these crates is GPL. None is a port of Moonlight's ENet fork.
|
|
||||||
|
|
||||||
## 3. Can Moonlight's ENet semantics be met by a clean Rust implementation?
|
|
||||||
|
|
||||||
What is documented:
|
|
||||||
- Wolf: the control stream "runs over UDP via a custom fork of ENET that supports IPV4 and IPV6" and every message
|
|
||||||
inside is AES-GCM framed ([control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html), S-4).
|
|
||||||
Wolf documents nothing else about the fork: no wire change, no extra command.
|
|
||||||
- moonlight-common-c README: the client "requires the specific version of ENet that is bundled" and other versions
|
|
||||||
are "incompatible", with a crash warning against recent GeForce Experience (S-14). It does not say which bytes differ.
|
|
||||||
- IPv6 support is a socket-address change in the C library. It does not appear on the ENet wire: ENet datagrams
|
|
||||||
carry no addresses.
|
|
||||||
|
|
||||||
What is measured by others:
|
|
||||||
- Moonshine (BSD-2) serves real Moonlight clients with `tokio-enet`, a stock ENet 1.3 wire implementation
|
|
||||||
(S-9, S-10): one peer, `channel_limit 0x30`, every host message sent reliable on channel 0. So **whatever the fork
|
|
||||||
changes, a stock-1.3 wire host interoperates with Moonlight clients**.
|
|
||||||
|
|
||||||
What is not known (UNKNOWN U9 in PROTOCOL.md):
|
|
||||||
- whether Sunshine (which ships the fork on the host side) *sends* anything a stock 1.3 peer would reject: a
|
|
||||||
checksum, a different `connect`/`verify connect` field, a different MTU, window or timeout default;
|
|
||||||
- which `connect data` value, channel count and MTU a client must offer.
|
|
||||||
|
|
||||||
Settled by our own measurement: a capture of the control channel between a GameStream client and Sunshine on a
|
|
||||||
lab machine (not Mark's PC), decoded with our own ENet parser. One session is enough to see the handshake fields.
|
|
||||||
|
|
||||||
**Answer: yes.** Nothing documented points at a wire change, and a stock-wire Rust ENet already talks to
|
|
||||||
Moonlight clients. The fork's differences that matter to us can be found by measurement; we do not need its code.
|
|
||||||
|
|
||||||
### What we write ourselves
|
|
||||||
|
|
||||||
A sans-I/O ENet 1.3 **client** subset in `domistream::enet`, `#![forbid(unsafe_code)]`:
|
|
||||||
|
|
||||||
| Part | Scope |
|
|
||||||
| :-- | :-- |
|
|
||||||
| Datagram codec | protocol header (peer id, session bits, compressed flag rejected, optional sent time), command header, all 12 commands; strict lengths, caps (`MAX_DATAGRAM_BYTES` 4096, 32 commands per datagram) |
|
|
||||||
| Connection | connect, verify connect, disconnect (incl. disconnect-later), ping, timeout |
|
|
||||||
| Reliability | reliable sequence numbers per channel, acknowledgements, retransmission with RTT-based timeout, reliable window |
|
|
||||||
| Delivery | reliable, unreliable sequenced, unsequenced, fragments (send + reassembly, capped) |
|
|
||||||
| Throttle | parse `throttle configure` and `bandwidth limit`; honour the window; no bandwidth shaping beyond that (the control channel is tiny) |
|
|
||||||
| Not written | host side, many peers, compression (refused), the crc32 checksum (UNKNOWN whether used; refused until measured) |
|
|
||||||
|
|
||||||
About 1,500-2,500 lines with tests. Tests: our client against `rusty_enet` (MIT) as a **dev-dependency** host over an
|
|
||||||
in-memory socket (no network, deterministic time), plus fuzzing of the datagram codec, plus the lab capture as a
|
|
||||||
recorded vector once it exists.
|
|
||||||
|
|
||||||
## Recommendation
|
|
||||||
|
|
||||||
1. **Write the ENet client ourselves** (`domistream::enet`, sans-I/O, no unsafe). Do not depend on an ENet crate at
|
|
||||||
runtime: the only pure-Rust ones are either tokio-bound (`tokio-enet`) or transpiled C (`rusty_enet`), and this
|
|
||||||
code parses hostile datagrams.
|
|
||||||
2. **Use `rusty_enet` (MIT) as a dev-dependency** for in-memory interop tests only.
|
|
||||||
3. **Approve stock ENet (MIT) and tokio-enet (BSD-2) as reference sources** in CLEAN_ROOM.md, because the ENet wire
|
|
||||||
format is documented nowhere else. Moonlight's fork stays forbidden.
|
|
||||||
4. **Book one lab capture** (client to Sunshine on a lab machine) to settle U9 and the other measurement-only
|
|
||||||
unknowns in PROTOCOL.md in one go. It must not be Mark's PC, his Sunshine install or his TV.
|
|
||||||
5. **Docs licence:** treat the Wolf docs as CC BY-SA 4.0: facts only, our own words, link every section.
|
|
||||||
Generated
-633
@@ -1,633 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 4
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aead"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"inout",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aes"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
"cpubits",
|
|
||||||
"cpufeatures",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aes-gcm"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f2b8006a0c83f52b62ba44a97b58bf76fe2f70a329e588f67f89691d93d498f"
|
|
||||||
dependencies = [
|
|
||||||
"aead",
|
|
||||||
"aes",
|
|
||||||
"cipher",
|
|
||||||
"ctr",
|
|
||||||
"ctutils",
|
|
||||||
"ghash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "arbitrary"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base16ct"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64ct"
|
|
||||||
version = "1.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-buffer"
|
|
||||||
version = "0.12.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa"
|
|
||||||
dependencies = [
|
|
||||||
"hybrid-array",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-padding"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b"
|
|
||||||
dependencies = [
|
|
||||||
"hybrid-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cbc"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce2dc9ee5f88d11e0beb842c88b33c8a5cf0d1329c4b19494af42b07dbfe8896"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
|
|
||||||
dependencies = [
|
|
||||||
"find-msvc-tools",
|
|
||||||
"jobserver",
|
|
||||||
"libc",
|
|
||||||
"shlex",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cipher"
|
|
||||||
version = "0.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"
|
|
||||||
dependencies = [
|
|
||||||
"block-buffer",
|
|
||||||
"crypto-common",
|
|
||||||
"inout",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cmov"
|
|
||||||
version = "0.5.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const-oid"
|
|
||||||
version = "0.10.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cpubits"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cpufeatures"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-bigint"
|
|
||||||
version = "0.7.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "914c195c4d7fbc5ed7f88d14cbf85914d5c664967658d43404b263913a477e82"
|
|
||||||
dependencies = [
|
|
||||||
"cpubits",
|
|
||||||
"ctutils",
|
|
||||||
"getrandom",
|
|
||||||
"num-traits",
|
|
||||||
"rand_core",
|
|
||||||
"serdect",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-common"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
"hybrid-array",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crypto-primes"
|
|
||||||
version = "0.7.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-bigint",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctr"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baaca1c4b237092596f64d571e9db6ce4109c4ef9742e27590f1709594461f21"
|
|
||||||
dependencies = [
|
|
||||||
"cipher",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctutils"
|
|
||||||
version = "0.4.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f"
|
|
||||||
dependencies = [
|
|
||||||
"cmov",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "der"
|
|
||||||
version = "0.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a996a108feb8b427a6e12fcf6af4aa83409b79d72c15337d7741368131ee004"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"der_derive",
|
|
||||||
"flagset",
|
|
||||||
"pem-rfc7468",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "der_derive"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "59600e2c2d636fde9b65e99cc6445ac770c63d3628195ff39932b8d6d7409903"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "digest"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
|
||||||
dependencies = [
|
|
||||||
"block-buffer",
|
|
||||||
"const-oid",
|
|
||||||
"crypto-common",
|
|
||||||
"ctutils",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "domistream"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"aes",
|
|
||||||
"aes-gcm",
|
|
||||||
"cbc",
|
|
||||||
"rand_core",
|
|
||||||
"rsa",
|
|
||||||
"sha2",
|
|
||||||
"x509-cert",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "domistream-fuzz"
|
|
||||||
version = "0.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"domistream",
|
|
||||||
"libfuzzer-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "find-msvc-tools"
|
|
||||||
version = "0.1.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "flagset"
|
|
||||||
version = "0.4.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b7ac824320a75a52197e8f2d787f6a38b6718bb6897a35142d749af3c0e8f4fe"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "getrandom"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"r-efi",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ghash"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
|
|
||||||
dependencies = [
|
|
||||||
"polyval",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hmac"
|
|
||||||
version = "0.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hybrid-array"
|
|
||||||
version = "0.4.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17"
|
|
||||||
dependencies = [
|
|
||||||
"typenum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "inout"
|
|
||||||
version = "0.2.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a580c13f0ffc335ef42dd3f6b1a41b726051c5e1656d9a3aa6fddb3c5dfbbf9"
|
|
||||||
dependencies = [
|
|
||||||
"block-padding",
|
|
||||||
"hybrid-array",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jobserver"
|
|
||||||
version = "0.1.35"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.191"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libfuzzer-sys"
|
|
||||||
version = "0.4.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2"
|
|
||||||
dependencies = [
|
|
||||||
"arbitrary",
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pem-rfc7468"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9"
|
|
||||||
dependencies = [
|
|
||||||
"base64ct",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkcs1"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6250dd7321adbe93d12b750aee0ced159fd13e77f625edcdf1cb6f83cd99f650"
|
|
||||||
dependencies = [
|
|
||||||
"der",
|
|
||||||
"spki",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkcs8"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7"
|
|
||||||
dependencies = [
|
|
||||||
"der",
|
|
||||||
"spki",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "polyval"
|
|
||||||
version = "0.7.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f0fa31d631f2b2cb2a544d0aa321ce847a94764d701ca2becc411138b93d49cd"
|
|
||||||
dependencies = [
|
|
||||||
"cpubits",
|
|
||||||
"cpufeatures",
|
|
||||||
"universal-hash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.107"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "r-efi"
|
|
||||||
version = "6.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_core"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rsa"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "23e77fd77e0dea28b3011fd62d15445b7de7959333b0276d930e03be0f755699"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"crypto-bigint",
|
|
||||||
"crypto-common",
|
|
||||||
"crypto-primes",
|
|
||||||
"digest",
|
|
||||||
"hmac",
|
|
||||||
"pkcs1",
|
|
||||||
"pkcs8",
|
|
||||||
"rand_core",
|
|
||||||
"sha2",
|
|
||||||
"signature",
|
|
||||||
"spki",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
||||||
dependencies = [
|
|
||||||
"serde_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_core"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
||||||
dependencies = [
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_derive"
|
|
||||||
version = "1.0.229"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.10",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serdect"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e"
|
|
||||||
dependencies = [
|
|
||||||
"base16ct",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha1"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sha2"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"cpufeatures",
|
|
||||||
"digest",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shlex"
|
|
||||||
version = "2.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "signature"
|
|
||||||
version = "3.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5"
|
|
||||||
dependencies = [
|
|
||||||
"digest",
|
|
||||||
"rand_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "spki"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7ef958a98b9d5da290cfc78946e9f3e61e1e62a18db0d92cac0b83cc161491a9"
|
|
||||||
dependencies = [
|
|
||||||
"base64ct",
|
|
||||||
"der",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.119"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "3.0.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tls_codec"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0de2e01245e2bb89d6f05801c564fa27624dbd7b1846859876c7dad82e90bf6b"
|
|
||||||
dependencies = [
|
|
||||||
"tls_codec_derive",
|
|
||||||
"zeroize",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tls_codec_derive"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2d2e76690929402faae40aebdda620a2c0e25dd6d3b9afe48867dfd95991f4bd"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typenum"
|
|
||||||
version = "1.20.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "universal-hash"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96"
|
|
||||||
dependencies = [
|
|
||||||
"crypto-common",
|
|
||||||
"ctutils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "x509-cert"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e9f58ad685a2945c7c063f5d69b5c27105d75bb85c740380d8fc64e79a098417"
|
|
||||||
dependencies = [
|
|
||||||
"const-oid",
|
|
||||||
"der",
|
|
||||||
"sha1",
|
|
||||||
"signature",
|
|
||||||
"spki",
|
|
||||||
"tls_codec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zeroize"
|
|
||||||
version = "1.9.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa"
|
|
||||||
dependencies = [
|
|
||||||
"zeroize_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zeroize_derive"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.119",
|
|
||||||
]
|
|
||||||
-157
@@ -1,157 +0,0 @@
|
|||||||
# Fuzz targets: one per DomiStream parser. Its own workspace, built only for fuzzing, never released.
|
|
||||||
#
|
|
||||||
# Linux, nightly, cargo-fuzz:
|
|
||||||
# cargo fuzz run <target> -- -max_total_time=600
|
|
||||||
#
|
|
||||||
# Windows, stable MSVC, no cargo-fuzz, no sanitizer (same setup as Via's via-core/fuzz): build.rs + win_sections.c
|
|
||||||
# give SanitizerCoverage's counters their section bounds, so the targets link without a sanitizer runtime.
|
|
||||||
# cd fuzz
|
|
||||||
# RUSTFLAGS="-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=4
|
|
||||||
# -Cllvm-args=-sanitizer-coverage-inline-8bit-counters -Cllvm-args=-sanitizer-coverage-trace-compares
|
|
||||||
# -Cllvm-args=-simplifycfg-branch-fold-threshold=0 -Ccodegen-units=1 --cfg fuzzing -Cdebug-assertions
|
|
||||||
# -Clink-arg=/include:main" \
|
|
||||||
# cargo build --release --target x86_64-pc-windows-msvc --bin <target>
|
|
||||||
# target/x86_64-pc-windows-msvc/release/<target>.exe -max_total_time=600 corpus/<target>
|
|
||||||
# A plain `cargo build` here does not link on Windows (LNK1561: libFuzzer's `main` needs `/include:main`); use the
|
|
||||||
# RUSTFLAGS above. Checked 2026-11-25: enet_datagram built this way ran 12,183,242 inputs in 11 s.
|
|
||||||
# corpus/ and artifacts/ stay out of git. Never set CARGO_TARGET_DIR.
|
|
||||||
|
|
||||||
[package]
|
|
||||||
name = "domistream-fuzz"
|
|
||||||
version = "0.0.0"
|
|
||||||
edition = "2024"
|
|
||||||
publish = false
|
|
||||||
license = "CPAL-1.0"
|
|
||||||
|
|
||||||
[package.metadata]
|
|
||||||
cargo-fuzz = true
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
cc = "1"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
libfuzzer-sys = "0.4"
|
|
||||||
domistream = { path = "../crates/domistream" }
|
|
||||||
|
|
||||||
# Its own workspace, so the fuzz build never joins the main one (cargo fuzz's layout).
|
|
||||||
[workspace]
|
|
||||||
members = ["."]
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "xml"
|
|
||||||
path = "fuzz_targets/xml.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "server_info"
|
|
||||||
path = "fuzz_targets/server_info.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "app_list"
|
|
||||||
path = "fuzz_targets/app_list.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "launch_response"
|
|
||||||
path = "fuzz_targets/launch_response.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "pair_response"
|
|
||||||
path = "fuzz_targets/pair_response.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "server_cert_pem"
|
|
||||||
path = "fuzz_targets/server_cert_pem.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rtsp_response"
|
|
||||||
path = "fuzz_targets/rtsp_response.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rtsp_request"
|
|
||||||
path = "fuzz_targets/rtsp_request.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "sdp"
|
|
||||||
path = "fuzz_targets/sdp.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rtsp_framer"
|
|
||||||
path = "fuzz_targets/rtsp_framer.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "enet_datagram"
|
|
||||||
path = "fuzz_targets/enet_datagram.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "control_frame"
|
|
||||||
path = "fuzz_targets/control_frame.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "control_message"
|
|
||||||
path = "fuzz_targets/control_message.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "input"
|
|
||||||
path = "fuzz_targets/input.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "rtp_header"
|
|
||||||
path = "fuzz_targets/rtp_header.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "video_packet"
|
|
||||||
path = "fuzz_targets/video_packet.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "audio_packet"
|
|
||||||
path = "fuzz_targets/audio_packet.rs"
|
|
||||||
test = false
|
|
||||||
doc = false
|
|
||||||
bench = false
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// Windows only: give the coverage counters their section bounds (see win_sections.c).
|
|
||||||
fn main() {
|
|
||||||
println!("cargo:rerun-if-changed=win_sections.c");
|
|
||||||
if std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
|
|
||||||
cc::Build::new().file("win_sections.c").compile("win_sections");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes `/applist` answers: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::http::parse_app_list(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes audio packets: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::audio::parse_audio_packet(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes encrypted control frames (outer fields): never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::control::parse_encrypted_frame(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes decrypted control messages from the host: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::control::parse_host_message(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes ENet datagrams: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::enet::protocol::parse_datagram(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes INPUT_DATA messages: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::input::parse_input(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes `/launch` and `/resume` answers: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::http::parse_launch_response(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes pairing answers: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::pairing::parse_pair_response(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes the RTP header: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::rtp::parse_rtp_header(data);
|
|
||||||
});
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
//! Fuzzes the RTSP framer over a chunked byte stream: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
// First byte picks the chunk size, so libFuzzer explores message boundaries across pushes.
|
|
||||||
let Some((&chunk, rest)) = data.split_first() else { return };
|
|
||||||
let chunk = usize::from(chunk).max(1);
|
|
||||||
let mut framer = domistream::rtsp::RtspFramer::new();
|
|
||||||
for piece in rest.chunks(chunk) {
|
|
||||||
if framer.push(piece).is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while let Ok(Some(message)) = framer.next_message() {
|
|
||||||
let _ = domistream::rtsp::parse_response(&message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let _ = framer.finish();
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes RTSP requests: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::rtsp::parse_request(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes RTSP responses: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::rtsp::parse_response(data);
|
|
||||||
});
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
//! Fuzzes SDP payloads and the host capabilities read from them: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
if let Ok(sdp) = domistream::rtsp::sdp::parse_sdp(data) {
|
|
||||||
let _ = domistream::rtsp::HostCapabilities::from_sdp(&sdp);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes the host certificate PEM (`plaincert`): never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::pairing::ServerCert::from_pem(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes `/serverinfo` answers: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::http::parse_server_info(data);
|
|
||||||
});
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
//! Fuzzes video packets and the frame header: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::video::parse_video_packet(data);
|
|
||||||
let _ = domistream::video::packet::parse_frame_header(data);
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Fuzzes the XML reader behind every HTTP answer: never panics, whatever the bytes.
|
|
||||||
//! Phase A: the parser returns `Unimplemented`; QA adds the properties (round trips, caps) with the logic.
|
|
||||||
//! How to run: see the comment at the top of `fuzz/Cargo.toml`.
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use libfuzzer_sys::fuzz_target;
|
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
|
||||||
let _ = domistream::http::xml::parse(data);
|
|
||||||
});
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/* Section bounds for SanitizerCoverage's inline 8-bit counters on Windows (COFF), so the fuzz targets link
|
|
||||||
* without a sanitizer runtime. LLVM puts the counters in ".SCOV$CM"; the linker sorts ".SCOV$CA" before it and
|
|
||||||
* ".SCOV$CZ" after it, and libFuzzer reads everything in between. compiler-rt does the same in
|
|
||||||
* sanitizer_coverage_win_sections.cpp, which only ships inside a sanitizer runtime. Built only for MSVC targets
|
|
||||||
* and only for the fuzz crate, which is never part of a release. */
|
|
||||||
#pragma section(".SCOV$CA", read, write)
|
|
||||||
__declspec(allocate(".SCOV$CA")) unsigned char __start___sancov_cntrs[1] = {0};
|
|
||||||
#pragma section(".SCOV$CZ", read, write)
|
|
||||||
__declspec(allocate(".SCOV$CZ")) unsigned char __stop___sancov_cntrs[1] = {0};
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
max_width = 120
|
|
||||||
use_small_heuristics = "Max"
|
|
||||||
Reference in New Issue
Block a user