[domistream] Control host: ControlHost (client frames opened with replay refusal, typed client messages, host messages, stop deadline)
parse_client_message types START_B, PERIODIC_PING, INPUT_DATA (through input::parse_input), IDR, INVALIDATE_REF_FRAMES, LOSS_STATS and FRAME_STATS (raw bodies) and skips anything else as Unknown. encode_host_message sends rumble, trigger rumble, motion, RGB LED and the extended termination; the plain termination (U10) and HDR_MODE (GPL-provenance layout) stay Unsupported. StopDeadline ends a session without PERIODIC_PING (default 60 s).
This commit is contained in:
@@ -130,7 +130,8 @@ fn host_parsers_never_allocate_past_their_caps() {
|
||||
let mut h = ControlHost::accept(config, Instant::ZERO, &connect()).unwrap();
|
||||
let cipher = ControlCipher::new([3; 16]);
|
||||
for seq in 0..64u32 {
|
||||
let frame = cipher.seal(seq, Direction::ClientToHost, &[0x06, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]).unwrap();
|
||||
let frame =
|
||||
cipher.seal(seq, Direction::ClientToHost, &[0x06, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]).unwrap();
|
||||
let mut d = vec![0x80, 0x01, 0x00, 0x02, 0x86, 0x00];
|
||||
d.extend_from_slice(&((seq + 1) as u16).to_be_bytes());
|
||||
d.extend_from_slice(&(frame.len() as u16).to_be_bytes());
|
||||
|
||||
@@ -67,8 +67,12 @@ struct StreamClient {
|
||||
|
||||
impl StreamClient {
|
||||
fn new(seed: u64) -> Self {
|
||||
let config = ControlConfig { enet: enet_client_config(), rikey: KEY, ping_interval: Duration::from_millis(100) };
|
||||
Self { stream: ControlStream::connect(config, Instant::ZERO, &mut common::SeqRng::new(seed)).unwrap(), events: Vec::new() }
|
||||
let config =
|
||||
ControlConfig { enet: enet_client_config(), rikey: KEY, ping_interval: Duration::from_millis(100) };
|
||||
Self {
|
||||
stream: ControlStream::connect(config, Instant::ZERO, &mut common::SeqRng::new(seed)).unwrap(),
|
||||
events: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn drain(&mut self) {
|
||||
@@ -210,8 +214,7 @@ impl Host {
|
||||
|
||||
/// Events after the first `Connected`, without it.
|
||||
fn take(&mut self) -> Vec<ControlHostEvent> {
|
||||
let out: Vec<ControlHostEvent> =
|
||||
self.events.drain(..).filter(|e| *e != ControlHostEvent::Connected).collect();
|
||||
let out: Vec<ControlHostEvent> = self.events.drain(..).filter(|e| *e != ControlHostEvent::Connected).collect();
|
||||
out
|
||||
}
|
||||
|
||||
@@ -334,7 +337,10 @@ fn input_vectors_from_the_wolf_tables() {
|
||||
"06 02 12 00 00 00 00 0E 05 00 00 00 05 B8 02 10 00 00 07 7F 04 37",
|
||||
InputEvent::MouseMoveAbs { x: 1464, y: 528, width: 1919, height: 1079 },
|
||||
),
|
||||
("06 02 09 00 00 00 00 05 08 00 00 00 01", InputEvent::MouseButton { pressed: true, button: MouseButton::Left }),
|
||||
(
|
||||
"06 02 09 00 00 00 00 05 08 00 00 00 01",
|
||||
InputEvent::MouseButton { pressed: true, button: MouseButton::Left },
|
||||
),
|
||||
(
|
||||
"06 02 0E 00 00 00 00 0A 03 00 00 00 00 A4 80 04 00 00",
|
||||
InputEvent::Key { pressed: true, flags: 0, key_code: 0x80A4, modifiers: 0x04 },
|
||||
@@ -448,11 +454,17 @@ fn start_ping_idr_and_stats_over_the_wire() {
|
||||
#[test]
|
||||
fn host_message_layouts() {
|
||||
for (m, hex) in [
|
||||
(HostMessage::Rumble { controller: 1, low_frequency: 0x7FFF, high_frequency: 0x8000 }, "0b010a00 00000000 0100 ff7f 0080"),
|
||||
(
|
||||
HostMessage::Rumble { controller: 1, low_frequency: 0x7FFF, high_frequency: 0x8000 },
|
||||
"0b010a00 00000000 0100 ff7f 0080",
|
||||
),
|
||||
(HostMessage::RumbleTriggers { controller: 2, left: 0x1234, right: 0xABCD }, "00550600 0200 3412 cdab"),
|
||||
(HostMessage::Termination { error_code: Some(TERMINATION_GRACEFUL) }, "09010400 80030023"),
|
||||
(HostMessage::Termination { error_code: Some(1) }, "09010400 00000001"),
|
||||
(HostMessage::MotionEvent { controller: 3, rate_hz: 200, kind: MotionKind::Gyroscope }, "01550500 0300 c800 02"),
|
||||
(
|
||||
HostMessage::MotionEvent { controller: 3, rate_hz: 200, kind: MotionKind::Gyroscope },
|
||||
"01550500 0300 c800 02",
|
||||
),
|
||||
(HostMessage::RgbLed { controller: 3, r: 0x10, g: 0x20, b: 0xFF }, "02550500 0300 1020ff"),
|
||||
] {
|
||||
let bytes = encode_host_message(&m).unwrap();
|
||||
@@ -523,8 +535,8 @@ fn replays_and_forgeries_are_dropped() {
|
||||
c.send_frame(t, c.cipher.seal(3, Direction::ClientToHost, &ping).unwrap()); // older
|
||||
c.send_frame(t, c.cipher.seal(5, Direction::ClientToHost, &ping).unwrap()); // equal, other content
|
||||
let mut bad = c.cipher.seal(6, Direction::ClientToHost, &ping).unwrap();
|
||||
bad[30] ^= 0x10;
|
||||
c.send_frame(t, bad); // bad tag
|
||||
bad[26] ^= 0x10;
|
||||
c.send_frame(t, bad); // bad tag (ciphertext changed)
|
||||
c.send_frame(t, c.cipher.seal(6, Direction::HostToClient, &ping).unwrap()); // reflected host frame
|
||||
c.send_frame(t, ControlCipher::new([0; 16]).seal(6, Direction::ClientToHost, &ping).unwrap()); // wrong key
|
||||
c.send_frame(t, vec![0xFF; 40]); // not a frame
|
||||
@@ -562,7 +574,11 @@ fn malformed_message_inside_a_good_frame_is_skipped() {
|
||||
w.run_for(200);
|
||||
assert_eq!(
|
||||
w.host.take(),
|
||||
vec![ControlHostEvent::Dropped, ControlHostEvent::Dropped, ControlHostEvent::Message(ClientControlMessage::StartB)]
|
||||
vec![
|
||||
ControlHostEvent::Dropped,
|
||||
ControlHostEvent::Dropped,
|
||||
ControlHostEvent::Message(ClientControlMessage::StartB)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -664,7 +680,9 @@ fn lossy_session_delivers_everything_in_order() {
|
||||
assert_eq!(w.host.messages(), inputs.iter().cloned().map(ClientControlMessage::Input).collect::<Vec<_>>());
|
||||
assert_eq!(
|
||||
w.client.messages(),
|
||||
(0..120u16).map(|i| HostMessage::Rumble { controller: 0, low_frequency: i, high_frequency: 0 }).collect::<Vec<_>>()
|
||||
(0..120u16)
|
||||
.map(|i| HostMessage::Rumble { controller: 0, low_frequency: i, high_frequency: 0 })
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
assert!(!w.host.events.contains(&ControlHostEvent::Dropped));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user