pub struct Client<R: Read, W: Write> { /* private fields */ }Expand description
Client side of the wire, exchanging encrypted messages over a byte stream.
Client::connect sends a reset and runs the handshake, returning a
Sender for outbound messages. Client::recv decrypts inbound
messages.
An empty frame from the server means it holds no session with this client.
Client::recv then ends the client’s session and returns
Error::SessionReset, after which the caller can reconnect.
Transport checks the shape of the device attestation. A Verifier decides
whether to trust the server presenting it.
Implementations§
Source§impl<R: Read, W: Write> Client<R, W>
impl<R: Read, W: Write> Client<R, W>
Sourcepub fn new(stream: Stream<R, W>) -> Self
pub fn new(stream: Stream<R, W>) -> Self
Creates a client that owns the byte stream and its shutdown operation, without an encrypted session.
Call Client::connect to establish one. Output uses the stream’s
configured write timeout. The stream’s Read and Write adapters
must enforce deadlines and let shutdown cancel blocked I/O.
Sourcepub fn set_handshake_timeout(self, timeout: Duration) -> Self
pub fn set_handshake_timeout(self, timeout: Duration) -> Self
Sets the budget for each later handshake, counted from the call to
Client::connect.
Defaults to DEFAULT_HANDSHAKE_TIMEOUT. Output and peer replies share
one deadline; progress and stale frames do not refresh it. Each outgoing
frame is also limited by the stream’s write timeout. Waiting for locks
and verifier callbacks can extend the call beyond the deadline.
Zero expires attempts immediately. A duration too large to add to an
Instant panics when the next handshake’s deadline is constructed.
Sourcepub fn closer(&self) -> Closer
pub fn closer(&self) -> Closer
Returns a handle that permanently closes the stream from another thread.
Sourcepub fn close(&self)
pub fn close(&self)
Permanently closes the stream and waits for adapter shutdown.
Senders observe closure through write failure, and buffered messages
remain readable. See Closer::close.
Sourcepub fn connect<V: Verifier>(
&mut self,
verifier: &V,
) -> Result<(Sender<W>, V::Info), Error>
pub fn connect<V: Verifier>( &mut self, verifier: &V, ) -> Result<(Sender<W>, V::Info), Error>
Establishes an encrypted session over the stream, ending any previous session first.
Sends a reset and drives the handshake:
1. Client -> Server: HostHello { host_signer, host_crypto } (plain CBOR)
2. Server -> Client: ArkHello { ark_attest, ark_crypto, a2h_encap } (cose::seal)
3. Client -> Server: HostAck { h2a_encap } (cose::seal)The verifier receives the server’s device attestation. Its accepted info is returned alongside the new sender. That sender belongs to this session and cannot send into a replacement established by a later handshake.
Sends reset and hello before draining old input. The adapter must allow that output to finish without concurrent client reads for this attempt to progress. Backpressure can instead fail an outgoing frame on timeout.
The handshake uses one configured deadline, shared by output and peer waits. Waiting for writes already in flight may extend the call. If connecting fails, the client has no session and every sender it issued before is invalid.
§Panics
Panics if the handshake or write timeout is too large to add to an
Instant, or if signing reads a wall time before the Unix epoch from
the stream’s clock.
Sourcepub fn recv(&mut self) -> Result<Vec<u8>, Error>
pub fn recv(&mut self) -> Result<Vec<u8>, Error>
Reads and decrypts the next ark-to-host message.
Invalid or oversized frames end the session, since its encryption
sequence may be lost. Decryption failures also end the session. An empty
frame means the server dropped the session, which ends here too with
Error::SessionReset. Adapter read failures and EOF also end the
session, while idle read timeouts are retried internally. Call
Self::connect to establish a new session after a failure. Without a
session, returns an error without reading the stream.
After decryption, message acceptance is ordered with session ending without waiting for the writer. A concurrent send failure can cause a decrypted message to be discarded before acceptance. An accepted message may reach this caller after another thread ends the session. Returning a receive error does wait for outgoing writes to finish.
Trait Implementations§
Source§impl<R: Read, W: Write> Drop for Client<R, W>
impl<R: Read, W: Write> Drop for Client<R, W>
Source§fn drop(&mut self)
fn drop(&mut self)
Closes the stream to cancel blocked I/O, then ends the binding before releasing the contexts.
Shutdown must come before waiting for the writer, which a blocked write could otherwise hold until its deadline. Idle senders hold weak references and cannot extend the stream’s lifetime.