Struct client::Session
zaun_community_protocol::client::Session · Struct
pub struct Session { … }A sans-IO client session. See the module documentation.
Methods
Section titled “Methods”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.
Errors
Section titled “Errors”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.
Errors
Section titled “Errors”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.
send_behind_hello
Section titled “send_behind_hello”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.
Errors
Section titled “Errors”As Session::send; ClientError::NotReady for another command, or before a hello
or without a binding.
send_signal
Section titled “send_signal”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.
Errors
Section titled “Errors”As Session::send; ClientError::WrongKind for a non-signal body.
resume_request
Section titled “resume_request”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.
Errors
Section titled “Errors”As Session::send.
send_command
Section titled “send_command”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).
Errors
Section titled “Errors”As Session::send.
receive
Section titled “receive”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.
poll_timeouts
Section titled “poll_timeouts”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) -> SelfA session that has sent nothing yet; call Session::hello first.
pub const fn state(&self) -> &SessionStateThe lifecycle state.
welcome
Section titled “welcome”pub const fn welcome(&self) -> Option<&VerifiedWelcome>The verified welcome of the current hello.
community
Section titled “community”pub fn community(&self) -> Option<&ValidPair>The verified descriptor and delegation; persist its state().
hold_pair
Section titled “hold_pair”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.
binding
Section titled “binding”pub const fn binding(&self) -> Option<Binding>The connection’s binding, from the welcome or a successful create/redeem/request.
negotiated_version
Section titled “negotiated_version”pub fn negotiated_version(&self) -> Option<u16>The negotiated protocol version.
host_challenge
Section titled “host_challenge”pub fn host_challenge(&self) -> Option<Challenge>The challenge to sign into a MemberKeyRegistration.
cursors
Section titled “cursors”pub const fn cursors(&self) -> &CursorTableThe stream cursors.
cursors_mut
Section titled “cursors_mut”pub const fn cursors_mut(&mut self) -> &mut CursorTableThe stream cursors, for seeding after a snapshot or history paging.
pending_count
Section titled “pending_count”pub fn pending_count(&self) -> usizeUnanswered requests (hello and commands).
poll_transmit
Section titled “poll_transmit”pub fn poll_transmit(&mut self) -> Option<String>The next transport text to send, in order.
drain_transmit
Section titled “drain_transmit”pub fn drain_transmit(&mut self) -> Vec<String>Every queued transport text, in order.
Trait implementations
Section titled “Trait implementations”Debug