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
@@ -12,6 +12,12 @@
|
||||
//! performs no additional validation, so callers that build `Params` manually
|
||||
//! are responsible for validating those values before sending them.
|
||||
//!
|
||||
//! Parameters are optional on the wire, and an absent tag takes its wire
|
||||
//! default — zero for every integer field, and [`Clock::Unspecified`] for the
|
||||
//! clock. A receiver that must distinguish an omitted tag from one explicitly
|
||||
//! encoded as zero uses [`Params::decode_with_presence`], which runs the same
|
||||
//! parser and additionally reports a [`ParamPresence`].
|
||||
//!
|
||||
//! The crate also provides packet layout calculation, packet encoding and
|
||||
//! decoding, and optional HMAC placement, computation, and verification
|
||||
//! helpers.
|
||||
@@ -51,7 +57,10 @@ pub use flags::*;
|
||||
pub use hmac::{compute_hmac, compute_hmac_in_place, verify_hmac, verify_packet_hmac};
|
||||
pub use layout::{echo_header_len, echo_packet_len, PacketLayout};
|
||||
pub use open::{decode_open_reply, encode_open_reply, OpenReply};
|
||||
pub use params::{Clock, Params, ReceivedStats, ServerFill, StampAt, MAX_SERVER_FILL_BYTES};
|
||||
pub use params::{
|
||||
Clock, DecodedParams, ParamPresence, Params, ReceivedStats, ServerFill, StampAt,
|
||||
MAX_SERVER_FILL_BYTES,
|
||||
};
|
||||
pub use request::{
|
||||
decode_request, encode_request, DecodedRequest, DecodedRequestKind, RequestToEncode,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user