Skip to content

Struct client::Session

zaun_community_protocol::client::Session · Struct

pub struct Session { … }

A sans-IO client session. See the module documentation.

pub fn hello(&mut self, now_ms: u64) -> Result<RequestId, ClientError>

Sends session.hello with a fresh nonce. Call it first, and again after every reconnect; commands then wait for the new welcome and are resent after it.

SPEC: community_id is “unbound only”; it is sent when the session has no binding and is null otherwise.

ClientError::Failed after a failed welcome, ClientError::Rng or a framing error.

pub fn send<B>(&mut self, body: &B, community: Option<CommunityId>, channel: Option<ChannelId>, now_ms: u64) -> Result<RequestId, ClientError>

Sends a command and tracks it for retries with the same request_id and byte-identical body. The body is validated first.

ClientError::NotReady before a verified welcome, ClientError::Failed after a failed one, ClientError::WrongCommunity, ClientError::WrongKind for a signal, or a body, size, framing or RNG error.

pub fn send_behind_hello<B>(&mut self, body: &B, now_ms: u64) -> Result<RequestId, ClientError>

Sends a read-only sync command (sync.snapshot, sync.resume, sync.events) right behind the hello of a bound session, without waiting for the welcome: the host runs the connection’s commands in order, so it answers after the welcome. The answer is reported only once the welcome verified. After the welcome this is Session::send.

As Session::send; ClientError::NotReady for another command, or before a hello or without a binding.

pub fn send_signal<B>(&mut self, body: &B, community: Option<CommunityId>, channel: Option<ChannelId>) -> Result<(), ClientError>

Sends an ephemeral signal (signal.*): request_id: null, no response, no retry.

As Session::send; ClientError::WrongKind for a non-signal body.

pub fn resume_request(&mut self, now_ms: u64) -> Result<Vec<RequestId>, ClientError>

Sends sync.resume for every tracked stream, in chunks of 100 channels. Call it after the welcome of a reconnect.

As Session::send.

pub fn send_command(&mut self, command: &Command, community: Option<CommunityId>, channel: Option<ChannelId>, now_ms: u64) -> Result<Option<RequestId>, ClientError>

Sends a command known only at run time (a bot’s, an application’s raw command): Session::send, or Session::send_signal for a signal.* (no request id).

As Session::send.

pub fn receive(&mut self, text: &str, now_ms: u64) -> Vec<ClientEvent>

Processes one received transport text at now_ms: reassembles fragments, parses the envelope, correlates responses, orders events by their stream cursors, and queues any sync.resume (after a gap) or sync.ack that became due.

Events are only applied on a verified session; before the welcome (or after a failed one) they are dropped and the resume after the welcome recovers them.

SPEC: the protocol acks what the client has “durably applied”. An ack queued here covers the events returned by this call, so the caller must apply (persist) them before sending the texts it drains next.

pub fn poll_timeouts(&mut self, now_ms: u64) -> Vec<ClientEvent>

Drives timers at now_ms: discards stale fragment reassemblies, resends due requests with the same text (commands only once the welcome is verified), abandons requests after the give-up time, and queues a sync.ack when 30 s passed with unacked frames or when a refused ack’s retry time has come.

pub fn new(config: SessionConfig) -> Self

A session that has sent nothing yet; call Session::hello first.

pub const fn state(&self) -> &SessionState

The lifecycle state.

pub const fn welcome(&self) -> Option<&VerifiedWelcome>

The verified welcome of the current hello.

pub fn community(&self) -> Option<&ValidPair>

The verified descriptor and delegation; persist its state().

pub fn hold_pair(&mut self, pair: (SignedJson, SignedJson))

Holds pair (a verified signed descriptor and delegation) for this connection’s community: the next hello names it, so its welcome may leave it out. For a creator, whose welcome carried no pair.

pub const fn binding(&self) -> Option<Binding>

The connection’s binding, from the welcome or a successful create/redeem/request.

pub fn negotiated_version(&self) -> Option<u16>

The negotiated protocol version.

pub fn host_challenge(&self) -> Option<Challenge>

The challenge to sign into a MemberKeyRegistration.

pub const fn cursors(&self) -> &CursorTable

The stream cursors.

pub const fn cursors_mut(&mut self) -> &mut CursorTable

The stream cursors, for seeding after a snapshot or history paging.

pub fn pending_count(&self) -> usize

Unanswered requests (hello and commands).

pub fn poll_transmit(&mut self) -> Option<String>

The next transport text to send, in order.

pub fn drain_transmit(&mut self) -> Vec<String>

Every queued transport text, in order.

Debug

Full rustdoc page