pub struct Session { /* private fields */ }Expand description
A sans-IO client session. See the module documentation.
Implementations§
Source§impl Session
impl Session
Sourcepub fn hello(&mut self, now_ms: u64) -> Result<RequestId, ClientError>
pub fn hello(&mut self, now_ms: u64) -> Result<RequestId, ClientError>
Sends session.hello with a fresh nonce (§6.2). Call it first, and again after every
reconnect; commands then wait for the new welcome and are resent after it (§6.3).
SPEC: community_id is “unbound only”; it is sent when the session has no binding
and is null otherwise.
§Errors
ClientError::Failed after a failed welcome (§6.2: use a new Session),
ClientError::Rng or a framing error.
Sourcepub fn send<B: Body>(
&mut self,
body: &B,
community: Option<CommunityId>,
channel: Option<ChannelId>,
now_ms: u64,
) -> Result<RequestId, ClientError>
pub fn send<B: Body>( &mut self, body: &B, community: Option<CommunityId>, channel: Option<ChannelId>, now_ms: u64, ) -> Result<RequestId, ClientError>
Sends a command (§7.1) and tracks it for retries with the same request_id and
byte-identical body (§7.3). The body is validated first (§12).
§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.
Sourcepub fn send_behind_hello<B: Body>(
&mut self,
body: &B,
now_ms: u64,
) -> Result<RequestId, ClientError>
pub fn send_behind_hello<B: Body>( &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 (§6.3 “Pipelined
resumption”): 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
As Session::send; ClientError::NotReady for another command, or before a hello
or without a binding.
Sourcepub fn send_signal<B: Body>(
&mut self,
body: &B,
community: Option<CommunityId>,
channel: Option<ChannelId>,
) -> Result<(), ClientError>
pub fn send_signal<B: Body>( &mut self, body: &B, community: Option<CommunityId>, channel: Option<ChannelId>, ) -> Result<(), ClientError>
Sends an ephemeral signal (signal.*): request_id: null, no response, no retry
(§10.5).
§Errors
As Session::send; ClientError::WrongKind for a non-signal body.
Sourcepub fn resume_request(
&mut self,
now_ms: u64,
) -> Result<Vec<RequestId>, ClientError>
pub fn resume_request( &mut self, now_ms: u64, ) -> Result<Vec<RequestId>, ClientError>
Sends sync.resume for every tracked stream (§10.3), in chunks of 100 channels. Call
it after the welcome of a reconnect (§6.3).
§Errors
As Session::send.
Source§impl Session
impl Session
Sourcepub fn send_command(
&mut self,
command: &Command,
community: Option<CommunityId>,
channel: Option<ChannelId>,
now_ms: u64,
) -> Result<Option<RequestId>, ClientError>
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
As Session::send.
Source§impl Session
impl Session
Sourcepub fn receive(&mut self, text: &str, now_ms: u64) -> Vec<ClientEvent>
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 (§10.5) 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: §10.5 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.
Source§impl Session
impl Session
Sourcepub fn poll_timeouts(&mut self, now_ms: u64) -> Vec<ClientEvent>
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.
Source§impl Session
impl Session
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
A session that has sent nothing yet; call Session::hello first.
Sourcepub const fn state(&self) -> &SessionState
pub const fn state(&self) -> &SessionState
The lifecycle state.
Sourcepub const fn welcome(&self) -> Option<&VerifiedWelcome>
pub const fn welcome(&self) -> Option<&VerifiedWelcome>
The verified welcome of the current hello.
Sourcepub fn community(&self) -> Option<&ValidPair>
pub fn community(&self) -> Option<&ValidPair>
The verified descriptor and delegation; persist its state() (§4.3 rule 5).
Sourcepub fn hold_pair(&mut self, pair: (SignedJson, SignedJson))
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 (§6.2). For a
creator, whose welcome carried no pair.
Sourcepub const fn binding(&self) -> Option<Binding>
pub const fn binding(&self) -> Option<Binding>
The connection’s binding, from the welcome or a successful create/redeem/request.
Sourcepub fn negotiated_version(&self) -> Option<u16>
pub fn negotiated_version(&self) -> Option<u16>
The negotiated protocol version.
Sourcepub fn host_challenge(&self) -> Option<Challenge>
pub fn host_challenge(&self) -> Option<Challenge>
The challenge to sign into a MemberKeyRegistration (§4.4).
Sourcepub const fn cursors(&self) -> &CursorTable
pub const fn cursors(&self) -> &CursorTable
The stream cursors (§10).
Sourcepub const fn cursors_mut(&mut self) -> &mut CursorTable
pub const fn cursors_mut(&mut self) -> &mut CursorTable
The stream cursors, for seeding after a snapshot or history paging.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Unanswered requests (hello and commands).
Sourcepub fn poll_transmit(&mut self) -> Option<String>
pub fn poll_transmit(&mut self) -> Option<String>
The next transport text to send, in order.
Sourcepub fn drain_transmit(&mut self) -> Vec<String>
pub fn drain_transmit(&mut self) -> Vec<String>
Every queued transport text, in order.