pub enum ClientMessage {
StreamRequest(StreamRequest),
StreamResponse(StreamResponse),
ChunkData(ChunkData),
Voucher(Voucher),
ChunkPreimage(ChunkPreimage),
StreamEnd,
StreamError(StreamError),
}Expand description
Top-level protocol enum for cdn/client/v1. Variant order is frozen per
ADR 013 — new variants MUST be appended at the end.
⚠️ VARIANT ORDER FROZEN — ADR 013 §Protocol Enums
Postcard encodes each variant as its declaration-order index. Reordering,
inserting, or removing a variant is a wire-breaking change requiring an ALPN
version bump (cdn/client/v2). The discriminant assignments are locked by
the client_message_*_discriminant_is_* tests.
Variants§
StreamRequest(StreamRequest)
discriminant 0 — payer → node, opens a delivery.
StreamResponse(StreamResponse)
discriminant 1 — node → payer, answers a StreamRequest.
ChunkData(ChunkData)
discriminant 2 — node → payer, one sequential blob chunk.
Voucher(Voucher)
discriminant 3 — payer → node, cumulative payment voucher. Acceptance
is implicit — delivery simply continues; only rejection is signalled,
via Self::StreamError.
ChunkPreimage(ChunkPreimage)
discriminant 4 — payer → node, one released hash-chain preimage,
advancing the lane’s claim by one chunk without a signature (ADR 003
§Hash-chain metering (PayWord)). Acceptance is implicit, exactly as for
Self::Voucher.
StreamEnd
discriminant 5 — node → payer: the node delivered the whole requested range, holds payment for every byte of it, and ends the stream.
StreamError(StreamError)
discriminant 6 — node → payer, mid-stream failure (carries
StreamError::VoucherRejected); delivery-side errors instead ride in
StreamResponseExt::error.
Implementations§
Source§impl ClientMessage
impl ClientMessage
Sourcepub const fn validate(&self) -> Result<(), MessageValidationError>
pub const fn validate(&self) -> Result<(), MessageValidationError>
Validate the payload’s requester-side invariants, dispatching to the
per-variant validate(). This is the single decode-then-validate seam a
receive-path handler should call after crate::decode_message so the
zero-rate / signature-length / ok-error checks can’t be silently
skipped (they are not enforced at decode time — see
StreamResponse::validate).
The ok/error agreement is NOT among them: error lives in the trailing
StreamResponseExt, which this method cannot see. Neither extension is
reachable from here — validate StreamRequestExt via its own validate
after parse_stream_request_ext, and StreamResponseExt via
StreamResponseExt::validate with body.ok after
parse_stream_response_ext.
Variants with no value invariants (StreamEnd, StreamError) return
Ok(()).
ChunkData is dispatched here for TOTALITY over the enum, and for nothing more
(#1145 review). Two facts about this method are easy to misread, and either mistake
leads the next reader to rely on a check that is not here:
- No receive loop calls this.
read_client_messagedecodes and returns; onlyStreamResponse::validateruns on the receive path, explicitly, viaverify_response. This aggregate is a convenience, not a load-bearing seam. - The
ChunkDataarm cannot fail. Its field is private behind#[serde(try_from)], which makesChunkData::validatetotal — its own doc says so (“alwaysOkfor a frame that exists”).
The empty-frame floor #1088 needs is enforced by the DECODE GATE, not by this dispatch: an empty frame cannot be constructed or deserialized, so no receive loop has to remember anything. That is what makes the floor structural rather than a convention.
§Errors
Propagates the MessageValidationError from the wrapped payload’s
validate().
Trait Implementations§
Source§impl Clone for ClientMessage
impl Clone for ClientMessage
Source§impl Debug for ClientMessage
impl Debug for ClientMessage
Source§impl<'de> Deserialize<'de> for ClientMessage
impl<'de> Deserialize<'de> for ClientMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ClientMessage
Source§impl PartialEq for ClientMessage
impl PartialEq for ClientMessage
Source§impl Serialize for ClientMessage
impl Serialize for ClientMessage
impl StructuralPartialEq for ClientMessage
Source§impl TopLevelEnum for ClientMessage
impl TopLevelEnum for ClientMessage
Source§const VARIANT_COUNT: u32 = 7
const VARIANT_COUNT: u32 = 7
StreamRequest (0) … StreamError (6). Pinned by
client_message_variant_count_matches_discriminants.