[domistream] Host: session test, fixes, mutation, L1 measurement, 0.2.0 #14
@@ -497,6 +497,53 @@ fn verify_with_wrong_connect_id_does_not_connect() {
|
||||
assert!(link.events().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_session_ids_are_taken_as_stock_enet_takes_them() {
|
||||
// PROTOCOL.md 3.1 [E]: the verify carries both session ids from the client's point of view. Its incoming id is
|
||||
// the host's outgoing one (what the host puts in its headers, so what the client must accept) and its outgoing id
|
||||
// is the host's incoming one (what the client must put in its headers). A fresh host slot answers 0/0, which hides
|
||||
// a swap; after a reconnect stock ENet answers with two different ids, as here.
|
||||
let (mut client, d, params, _, connect_seq) = start();
|
||||
let host = |session_id: u8, sent_time: u16, commands: Vec<Command>| {
|
||||
encode_datagram(&Datagram {
|
||||
peer_id: params.outgoing_peer_id,
|
||||
session_id,
|
||||
sent_time: Some(sent_time),
|
||||
commands,
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
let verify = ConnectParams { outgoing_peer_id: 7, incoming_session_id: 1, outgoing_session_id: 2, ..params };
|
||||
let ack = CommandBody::Acknowledge {
|
||||
received_reliable_sequence: connect_seq,
|
||||
received_sent_time: d.sent_time.unwrap_or(0),
|
||||
};
|
||||
client
|
||||
.handle_datagram(
|
||||
at(1),
|
||||
&host(1, 1, vec![cmd(false, 0xFF, 0, ack), cmd(true, 0xFF, 1, CommandBody::VerifyConnect(verify))]),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(client.poll_event(), Some(EnetEvent::Connected));
|
||||
|
||||
// The client's datagrams carry its outgoing session id: the verify's outgoing id, 2.
|
||||
let sent: Vec<Datagram> =
|
||||
core::iter::from_fn(|| client.poll_transmit(at(1))).map(|d| parse_datagram(&d).unwrap()).collect();
|
||||
assert!(!sent.is_empty(), "the verify is acknowledged");
|
||||
for d in &sent {
|
||||
assert_eq!((d.peer_id, d.session_id), (7, 2), "{d:?}");
|
||||
}
|
||||
|
||||
// The host's datagrams carry the host's outgoing id (the verify's incoming id, 1): taken. Id 2 is not the
|
||||
// client's incoming id: dropped.
|
||||
let wrong = cmd(true, 0, 1, CommandBody::SendReliable(b"wrong session".to_vec()));
|
||||
assert_eq!(client.handle_datagram(at(2), &host(2, 2, vec![wrong])), Ok(()));
|
||||
assert_eq!(client.poll_event(), None, "a datagram with the client's outgoing id is not for it");
|
||||
let right = cmd(true, 0, 1, CommandBody::SendReliable(b"right session".to_vec()));
|
||||
client.handle_datagram(at(3), &host(1, 3, vec![right])).unwrap();
|
||||
assert_eq!(client.poll_event(), Some(EnetEvent::Received { channel: 0, data: b"right session".to_vec() }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn garbage_never_changes_state() {
|
||||
let mut link = connected();
|
||||
|
||||
Reference in New Issue
Block a user