[probe] gs-probe: desktop GameStream probe client and the live interop run book
tools/gs-probe (own workspace, never published): `probe serverinfo | pair | apps | launch <app-id> | quit | unpair` against one host address, driving DomiStream's pairing, HTTP, RTSP, ENet, control, video and audio state machines over real sockets. Structured JSONL log per run (requests, answers, timings, the U each record bears on, parser errors with their bytes), secrets redacted (rikey, pairing values; PIN never logged; registered key hex scrubbed from every line). Test-only client key and cert in --out. Video: frames, decode-ready frames, FEC recoveries, losses, elementary-stream dump, live U14 parity check; audio: packets, losses, decrypting vs plain receivers (U17), packet dump and offline U16 solver (`solve-audio-fec`). START_A/START_B/PERIODIC_PING/IDR bodies come from the command line (U10). docs/LIVE-INTEROP.md: the sitting's run book (preparation, sequence S0-S5 with the U each step settles, variants, log reading, where each fact lands in PROTOCOL.md and the code, stop-and-report rule, clean-up, Mark's timeline). Built and unit-tested only (41 tests, clippy -D warnings, fmt); never run against a host.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
//! Packet dumps for offline analysis after the sitting (U14 video parity, U16 audio parity matrix): a magic, then
|
||||
//! one record per datagram: `t_us u64 LE`, `len u16 LE`, the bytes.
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufWriter, Write};
|
||||
use std::path::Path;
|
||||
|
||||
pub const MAGIC: &[u8; 8] = b"GSPROBE1";
|
||||
/// Largest dump file read back.
|
||||
pub const MAX_DUMP_BYTES: usize = 512 * 1024 * 1024;
|
||||
|
||||
pub fn encode_record(t_us: u64, bytes: &[u8]) -> Vec<u8> {
|
||||
let len = u16::try_from(bytes.len()).unwrap_or(u16::MAX);
|
||||
let shown = bytes.get(..usize::from(len)).unwrap_or(bytes);
|
||||
let mut r = Vec::with_capacity(10 + shown.len());
|
||||
r.extend_from_slice(&t_us.to_le_bytes());
|
||||
r.extend_from_slice(&len.to_le_bytes());
|
||||
r.extend_from_slice(shown);
|
||||
r
|
||||
}
|
||||
|
||||
/// Every record of a dump file's contents.
|
||||
pub fn decode(data: &[u8]) -> Result<Vec<(u64, Vec<u8>)>, String> {
|
||||
if data.len() > MAX_DUMP_BYTES {
|
||||
return Err(format!("dump over {MAX_DUMP_BYTES} bytes"));
|
||||
}
|
||||
let mut rest = data.strip_prefix(MAGIC.as_slice()).ok_or("not a gs-probe dump (magic)")?;
|
||||
let mut out = Vec::new();
|
||||
while !rest.is_empty() {
|
||||
let head = rest.get(..10).ok_or("record header cut")?;
|
||||
let mut t = [0u8; 8];
|
||||
t.copy_from_slice(&head[..8]);
|
||||
let len = usize::from(u16::from_le_bytes([head[8], head[9]]));
|
||||
let body = rest.get(10..10 + len).ok_or("record body cut")?;
|
||||
out.push((u64::from_le_bytes(t), body.to_vec()));
|
||||
rest = &rest[10 + len..];
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Writes up to `limit` records.
|
||||
pub struct PacketDump {
|
||||
w: Option<BufWriter<File>>,
|
||||
pub written: u32,
|
||||
limit: u32,
|
||||
}
|
||||
|
||||
impl PacketDump {
|
||||
pub fn create(path: &Path, limit: u32) -> io::Result<Self> {
|
||||
if limit == 0 {
|
||||
return Ok(Self { w: None, written: 0, limit });
|
||||
}
|
||||
let mut w = BufWriter::new(File::options().write(true).create_new(true).open(path)?);
|
||||
w.write_all(MAGIC)?;
|
||||
Ok(Self { w: Some(w), written: 0, limit })
|
||||
}
|
||||
|
||||
pub fn push(&mut self, t_us: u64, bytes: &[u8]) -> io::Result<()> {
|
||||
if self.written >= self.limit {
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(w) = &mut self.w {
|
||||
w.write_all(&encode_record(t_us, bytes))?;
|
||||
self.written += 1;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn finish(&mut self) -> io::Result<()> {
|
||||
if let Some(w) = &mut self.w {
|
||||
w.flush()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn records_round_trip() {
|
||||
let mut file = MAGIC.to_vec();
|
||||
file.extend(encode_record(7, b"abc"));
|
||||
file.extend(encode_record(u64::MAX, b""));
|
||||
assert_eq!(decode(&file).unwrap(), vec![(7, b"abc".to_vec()), (u64::MAX, vec![])]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cut_or_foreign_files_are_refused() {
|
||||
assert!(decode(b"NOTADUMP").is_err());
|
||||
let mut file = MAGIC.to_vec();
|
||||
file.extend(encode_record(1, b"abcd"));
|
||||
assert!(decode(&file[..file.len() - 1]).unwrap_err().contains("body cut"));
|
||||
assert!(decode(&file[..MAGIC.len() + 5]).unwrap_err().contains("header cut"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user