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
impl ClientHandshakeGate
Sourcepub fn record_handshake_sent(
&mut self,
offered: ProtocolVersion,
) -> Result<(), ClientHandshakeStartError>
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.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Whether this connection currently has a completed handshake.
Sourcepub fn offered_version(&self) -> Option<ProtocolVersion>
pub fn offered_version(&self) -> Option<ProtocolVersion>
The outstanding offer, before its matching acknowledgment arrives.
Sourcepub fn accepted_version(&self) -> Option<ProtocolVersion>
pub fn accepted_version(&self) -> Option<ProtocolVersion>
The accepted version while the connection remains completed and usable.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether a protocol violation or admitted server error permanently closed this gate.
Sourcepub fn admit(
&mut self,
frame: &Frame,
) -> Result<ClientHandshakeOutcome, HandshakeSequenceError>
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.