Skip to main content

ClientMessage

Enum ClientMessage 

Source
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

Source

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_message decodes and returns; only StreamResponse::validate runs on the receive path, explicitly, via verify_response. This aggregate is a convenience, not a load-bearing seam.
  • The ChunkData arm cannot fail. Its field is private behind #[serde(try_from)], which makes ChunkData::validate total — its own doc says so (“always Ok for 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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ClientMessage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ClientMessage

Source§

impl PartialEq for ClientMessage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ClientMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ClientMessage

Source§

impl TopLevelEnum for ClientMessage

Source§

const VARIANT_COUNT: u32 = 7

StreamRequest (0) … StreamError (6). Pinned by client_message_variant_count_matches_discriminants.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.