[domistream] Implementation: HTTP, pairing, RTSP/SDP, ENet, control, input, RTP, FEC, video and audio receivers

Per PROTOCOL.md and the Wolf docs; interop with a real host is unverified. Strict, capped parsers throughout,
shared helpers in util.rs. Where PROTOCOL.md says UNKNOWN the Wolf-documented behaviour is used. The audio
receiver waits for the jitter budget before rebuilding a missing packet, so a late packet beats a rebuilt one.
This commit is contained in:
2026-11-25 14:10:24 +01:00
parent 27b26a992b
commit 30a7b90034
27 changed files with 4175 additions and 406 deletions
+52 -19
View File
@@ -7,6 +7,9 @@
use core::time::Duration;
use crate::Result;
use crate::util::{malformed, percent_encode};
pub mod applist;
pub mod launch;
pub mod serverinfo;
@@ -47,49 +50,79 @@ pub struct HttpRequest {
pub timeout: Option<Duration>,
}
/// Checks a client `uniqueid`: 1..=[`MAX_UNIQUE_ID_BYTES`] of letters, digits, `-` and `_` (our own ids are hex).
pub(crate) fn check_unique_id(unique_id: &str) -> Result<()> {
if unique_id.is_empty()
|| unique_id.len() > MAX_UNIQUE_ID_BYTES
|| !unique_id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
{
return Err(malformed("uniqueid"));
}
Ok(())
}
/// `path?k=v&…` with every value percent-encoded.
pub(crate) fn build(scheme: Scheme, path: &str, params: &[(&str, &str)], timeout: Option<Duration>) -> HttpRequest {
let mut s = String::from(path);
for (i, (k, v)) in params.iter().enumerate() {
s.push(if i == 0 { '?' } else { '&' });
s.push_str(k);
s.push('=');
s.push_str(&percent_encode(v));
}
HttpRequest { scheme, path_and_query: s, timeout }
}
/// Parses `body` as XML after checking it against `max` bytes, and refuses a non-200 status.
pub(crate) fn document(body: &[u8], max: usize, what: &'static str) -> Result<xml::Document> {
crate::util::cap(what, max, body.len())?;
let d = xml::parse(body)?;
if d.status_code != 200 {
return Err(crate::Error::HostStatus { code: d.status_code });
}
Ok(d)
}
/// 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)
/// [`crate::Error::Malformed`] for an empty, oversized or non-alphanumeric `unique_id`.
pub fn server_info_request(scheme: Scheme, unique_id: &str) -> Result<HttpRequest> {
check_unique_id(unique_id)?;
Ok(build(scheme, "/serverinfo", &[("uniqueid", unique_id)], None))
}
/// 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)
pub fn app_list_request(unique_id: &str) -> Result<HttpRequest> {
check_unique_id(unique_id)?;
Ok(build(Scheme::Https, "/applist", &[("uniqueid", unique_id)], None))
}
/// 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)
pub fn cancel_request(unique_id: &str) -> Result<HttpRequest> {
check_unique_id(unique_id)?;
Ok(build(Scheme::Https, "/cancel", &[("uniqueid", unique_id)], None))
}
/// 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)
pub fn unpair_request(unique_id: &str) -> Result<HttpRequest> {
check_unique_id(unique_id)?;
Ok(build(Scheme::Https, "/unpair", &[("uniqueid", unique_id)], None))
}
/// 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)
/// [`crate::Error::HostStatus`] for a non-200 status, parser errors as [`xml::parse`].
pub fn parse_status_response(body: &[u8]) -> Result<()> {
document(body, xml::MAX_XML_BYTES, "status answer").map(|_| ())
}