`Params::decode` seeded `Params::default()` and overwrote only the tags it saw, so an omitted tag and one explicitly encoded as zero were indistinguishable afterwards. The protocol gives those the same value but not the same meaning, and a server cannot apply its open admission rules without telling them apart: an absent Duration or Interval is accepted as the wire default zero, while one explicitly encoded as zero is invalid. Add `Params::decode_with_presence`, returning the decoded values alongside a `ParamPresence` recording which known tags appeared. `Params::decode` now delegates to it, so there is still exactly one parser and the two cannot diverge. Unknown tags stay ignored and untracked, and repeated known tags keep last-value-wins. Add `Clock::Unspecified = 0` as the default, which is the wire default for an absent Clock tag and what an empty parameter payload decodes to. An explicit Clock tag encoding zero remains an invalid enum value, so `Unspecified` is only ever reached by omission; `encode` omits the tag for it rather than emitting an explicit zero. It selects no clock, so `has_wall`/`has_mono` are false and no timestamp field is laid out. `ClientConfig::clock` is public and therefore now constructible as `Unspecified`, which is a wire default rather than a client mode. Reject it during config validation. The client default stays `Clock::Both`, so normal client-generated params and wire vectors are unchanged.
141 lines
5.0 KiB
Rust
141 lines
5.0 KiB
Rust
use irtt_client::{Client, ClientEvent};
|
|
use irtt_proto::{Clock, ReceivedStats, StampAt};
|
|
|
|
use crate::support::{config_for_params, default_params, params_for_modes, BackendPeer};
|
|
|
|
#[test]
|
|
fn backend_basic_open_echo_close() {
|
|
let params = default_params();
|
|
let peer = BackendPeer::start_open_echo(params.clone(), None);
|
|
let mut client = Client::connect(config_for_params(peer.addr(), ¶ms)).unwrap();
|
|
|
|
let outcome = client.open().unwrap();
|
|
assert!(matches!(outcome, irtt_client::OpenOutcome::Started { .. }));
|
|
|
|
let sent = client.send_probe().unwrap();
|
|
assert_eq!(sent.len(), 1);
|
|
|
|
let events = client.recv_once().unwrap();
|
|
assert_eq!(events.len(), 1);
|
|
assert!(matches!(events[0], ClientEvent::EchoReply { .. }));
|
|
|
|
client.close().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn backend_received_stats_smoke() {
|
|
for mode in [
|
|
ReceivedStats::None,
|
|
ReceivedStats::Count,
|
|
ReceivedStats::Window,
|
|
ReceivedStats::Both,
|
|
] {
|
|
let params = params_for_modes(mode, StampAt::None, Clock::Both);
|
|
let peer = BackendPeer::start_open_echo(params.clone(), None);
|
|
let mut client = Client::connect(config_for_params(peer.addr(), ¶ms)).unwrap();
|
|
|
|
client.open().unwrap();
|
|
client.send_probe().unwrap();
|
|
let events = client.recv_once().unwrap();
|
|
assert_eq!(events.len(), 1);
|
|
assert!(matches!(events[0], ClientEvent::EchoReply { .. }));
|
|
|
|
client.close().unwrap();
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn backend_timestamp_smoke() {
|
|
for mode in [
|
|
StampAt::None,
|
|
StampAt::Send,
|
|
StampAt::Receive,
|
|
StampAt::Both,
|
|
StampAt::Midpoint,
|
|
] {
|
|
let params = params_for_modes(ReceivedStats::None, mode, Clock::Both);
|
|
let peer = BackendPeer::start_open_echo(params.clone(), None);
|
|
let mut client = Client::connect(config_for_params(peer.addr(), ¶ms)).unwrap();
|
|
|
|
client.open().unwrap();
|
|
client.send_probe().unwrap();
|
|
let events = client.recv_once().unwrap();
|
|
assert_eq!(events.len(), 1);
|
|
|
|
match &events[0] {
|
|
ClientEvent::EchoReply {
|
|
server_timing,
|
|
one_way,
|
|
..
|
|
} => match mode {
|
|
StampAt::None => {
|
|
assert!(server_timing.is_none());
|
|
assert!(one_way.is_none());
|
|
}
|
|
StampAt::Send => {
|
|
let st = server_timing.as_ref().unwrap();
|
|
assert!(st.send_wall_ns.is_some() || st.send_mono_ns.is_some());
|
|
}
|
|
StampAt::Receive => {
|
|
let st = server_timing.as_ref().unwrap();
|
|
assert!(st.receive_wall_ns.is_some() || st.receive_mono_ns.is_some());
|
|
}
|
|
StampAt::Both => {
|
|
let st = server_timing.as_ref().unwrap();
|
|
assert!(st.receive_wall_ns.is_some() || st.receive_mono_ns.is_some());
|
|
assert!(st.send_wall_ns.is_some() || st.send_mono_ns.is_some());
|
|
}
|
|
StampAt::Midpoint => {
|
|
let st = server_timing.as_ref().unwrap();
|
|
assert!(st.midpoint_wall_ns.is_some() || st.midpoint_mono_ns.is_some());
|
|
}
|
|
},
|
|
other => panic!("expected EchoReply, got {other:?}"),
|
|
}
|
|
|
|
client.close().unwrap();
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn backend_clock_smoke() {
|
|
for clock in [Clock::Wall, Clock::Monotonic, Clock::Both] {
|
|
let params = params_for_modes(ReceivedStats::None, StampAt::Both, clock);
|
|
let peer = BackendPeer::start_open_echo(params.clone(), None);
|
|
let mut client = Client::connect(config_for_params(peer.addr(), ¶ms)).unwrap();
|
|
|
|
client.open().unwrap();
|
|
client.send_probe().unwrap();
|
|
let events = client.recv_once().unwrap();
|
|
assert_eq!(events.len(), 1);
|
|
|
|
match &events[0] {
|
|
ClientEvent::EchoReply { server_timing, .. } => {
|
|
let st = server_timing.as_ref().unwrap();
|
|
match clock {
|
|
Clock::Wall => {
|
|
assert!(st.receive_wall_ns.is_some());
|
|
assert!(st.send_wall_ns.is_some());
|
|
}
|
|
Clock::Monotonic => {
|
|
assert!(st.receive_mono_ns.is_some());
|
|
assert!(st.send_mono_ns.is_some());
|
|
}
|
|
Clock::Both => {
|
|
assert!(st.receive_wall_ns.is_some());
|
|
assert!(st.receive_mono_ns.is_some());
|
|
assert!(st.send_wall_ns.is_some());
|
|
assert!(st.send_mono_ns.is_some());
|
|
}
|
|
Clock::Unspecified => {
|
|
unreachable!("clients never request an unspecified clock")
|
|
}
|
|
}
|
|
}
|
|
other => panic!("expected EchoReply, got {other:?}"),
|
|
}
|
|
|
|
client.close().unwrap();
|
|
}
|
|
}
|