refactor(proto): preserve open parameter presence
`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.
This commit is contained in:
10 files changed
+325
-16
No files matched your search
@@ -139,6 +139,16 @@ fn params_from_config_rejects_invalid_values() {
|
||||
},
|
||||
"dscp",
|
||||
),
|
||||
(
|
||||
// The unspecified clock is the absent-tag wire default, not a
|
||||
// client mode; a client that needs timestamps must name a clock.
|
||||
"unspecified clock",
|
||||
ClientConfig {
|
||||
clock: Clock::Unspecified,
|
||||
..ClientConfig::default()
|
||||
},
|
||||
"clock must be wall, monotonic, or both",
|
||||
),
|
||||
(
|
||||
"empty server fill",
|
||||
ClientConfig {
|
||||
|
||||
@@ -77,6 +77,10 @@ pub struct ClientConfig {
|
||||
/// Requested timestamp placement in echo replies.
|
||||
pub stamp_at: StampAt,
|
||||
/// Requested server clock sources for timestamp fields.
|
||||
///
|
||||
/// [`Clock::Unspecified`] is the wire default meaning "no clock tag was
|
||||
/// sent" and is not a client mode; opening a session with it is rejected.
|
||||
/// Request [`Clock::Wall`], [`Clock::Monotonic`], or [`Clock::Both`].
|
||||
pub clock: Clock,
|
||||
/// Requested DSCP codepoint.
|
||||
///
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use irtt_proto::{
|
||||
decode_echo_reply, echo_packet_len, encode_request, flags, EchoReply, OpenReply, Params,
|
||||
decode_echo_reply, echo_packet_len, encode_request, flags, Clock, EchoReply, OpenReply, Params,
|
||||
RequestToEncode, ServerFill, TimestampFields, PROTOCOL_VERSION,
|
||||
};
|
||||
|
||||
@@ -989,6 +989,11 @@ fn validate_protocol_config(config: &ClientConfig) -> Result<(), ClientError> {
|
||||
reason: "interval must be greater than zero".to_owned(),
|
||||
});
|
||||
}
|
||||
if config.clock == Clock::Unspecified {
|
||||
return Err(ClientError::InvalidConfig {
|
||||
reason: "clock must be wall, monotonic, or both".to_owned(),
|
||||
});
|
||||
}
|
||||
if config.dscp > MAX_DSCP_CODEPOINT {
|
||||
return Err(ClientError::InvalidConfig {
|
||||
reason: format!("dscp must be <= {MAX_DSCP_CODEPOINT}"),
|
||||
|
||||
Reference in new issue
Block a user