Skip to main content

ClientHandshakeGate

Struct ClientHandshakeGate 

Source
pub struct ClientHandshakeGate { /* private fields */ }
Expand description

Enforces the inbound handshake sequence and frame direction for one client connection.

Record the exact offered version only after the transport successfully sends its handshake. Before that, every inbound frame is unsolicited. An exact acknowledgment completes the handshake; a server connection-terminal error is surfaced without fallback. Every sequence or direction violation closes the gate permanently with an id-less malformed_frame.

Deliberately not Clone: copying an earlier state must not allow a terminal connection to resume. There is no reset or unchecked-completion operation.

Implementations§

Source§

impl ClientHandshakeGate

Source

pub fn new() -> Self

A fresh connection on which no handshake has been sent.

Source

pub fn record_handshake_sent( &mut self, offered: ProtocolVersion, ) -> Result<(), ClientHandshakeStartError>

Record the exact version in the handshake the transport just sent.

The caller constructs, encodes and writes its existing Frame::Handshake first, then records that version before reading inbound frames. This method does no I/O. Preparation, encoding or write failure must not call it; discard the failed connection instead. A local error leaves the state unchanged. The caller selects a version whose grammar it implements, normally crate::CURRENT_VERSION; this gate adds no range negotiation.

Source

pub fn is_complete(&self) -> bool

Whether this connection currently has a completed handshake.

Source

pub fn offered_version(&self) -> Option<ProtocolVersion>

The outstanding offer, before its matching acknowledgment arrives.

Source

pub fn accepted_version(&self) -> Option<ProtocolVersion>

The accepted version while the connection remains completed and usable.

Source

pub fn is_closed(&self) -> bool

Whether a protocol violation or admitted server error permanently closed this gate.

Source

pub fn admit( &mut self, frame: &Frame, ) -> Result<ClientHandshakeOutcome, HandshakeSequenceError>

Admit one already-decoded inbound frame, before the caller handles it.

A fresh gate rejects every kind. With an offer outstanding, only an exact acknowledgment or a connection-terminal server error is admissible. After completion, server application kinds are admitted; another acknowledgment or any client-to-server kind is a violation. An admitted terminal error yields ClientHandshakeOutcome::ServerTerminated, leaving the original frame available to surface before closing the transport.

The codec remains role-agnostic and owns field/grammar validation. Every sequence rejection here is id-less malformed_frame and permanently closes the gate; even a later otherwise-valid frame cannot recover it.

Trait Implementations§

Source§

impl Debug for ClientHandshakeGate

Source§

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

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

impl Default for ClientHandshakeGate

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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.