From 34dd2ee5d22b5ab26efd28c38676b5fb84fe4f11 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Tue, 28 Apr 2026 16:15:26 +0700 Subject: [PATCH] refactor(proto): Remove Clock::None and default to Clock::Both Simplify clock parameter negotiation by rejecting the ambiguous 'None' value. --- crates/irtt-proto/src/layout.rs | 12 +++++++++++- crates/irtt-proto/src/params.rs | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/irtt-proto/src/layout.rs b/crates/irtt-proto/src/layout.rs index e8460f4..9a61623 100644 --- a/crates/irtt-proto/src/layout.rs +++ b/crates/irtt-proto/src/layout.rs @@ -139,7 +139,7 @@ mod tests { assert_eq!( echo_header_len( false, - ¶ms(ReceivedStats::None, StampAt::None, Clock::None) + ¶ms(ReceivedStats::None, StampAt::None, Clock::Both) ), 16 ); @@ -180,6 +180,16 @@ mod tests { ); } + #[test] + fn no_timestamp_layout_ignores_clock() { + for clock in [Clock::Wall, Clock::Monotonic, Clock::Both] { + assert_eq!( + echo_header_len(false, ¶ms(ReceivedStats::None, StampAt::None, clock)), + 16 + ); + } + } + #[test] fn negotiated_length_never_smaller_than_header() { let mut p = params(ReceivedStats::Both, StampAt::Both, Clock::Both); diff --git a/crates/irtt-proto/src/params.rs b/crates/irtt-proto/src/params.rs index 500dcf8..e957da5 100644 --- a/crates/irtt-proto/src/params.rs +++ b/crates/irtt-proto/src/params.rs @@ -151,10 +151,9 @@ impl TryFrom for StampAt { #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[repr(i64)] pub enum Clock { - #[default] - None = 0, Wall = 1, Monotonic = 2, + #[default] Both = 3, } @@ -173,7 +172,6 @@ impl TryFrom for Clock { fn try_from(value: i64) -> Result { match value { - 0 => Ok(Self::None), 1 => Ok(Self::Wall), 2 => Ok(Self::Monotonic), 3 => Ok(Self::Both), @@ -232,4 +230,19 @@ mod tests { let params = Params::decode(&encoded).unwrap(); assert_eq!(params.protocol_version, 1); } + + #[test] + fn explicit_clock_zero_is_rejected() { + let mut encoded = Vec::new(); + varint::encode_uvarint(7, &mut encoded); + varint::encode_varint(0, &mut encoded); + + assert_eq!( + Params::decode(&encoded), + Err(ProtoError::InvalidEnum { + name: "Clock", + value: 0, + }) + ); + } }