Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

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

Implementations§

Source§

impl Session

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

pub fn new(config: SessionConfig) -> Self

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

Source

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

The lifecycle state.

Source

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

The verified welcome of the current hello.

Source

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

The verified descriptor and delegation; persist its state() (§4.3 rule 5).

Source

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.

Source

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

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

Source

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

The negotiated protocol version.

Source

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

The challenge to sign into a MemberKeyRegistration (§4.4).

Source

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

The stream cursors (§10).

Source

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

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

Source

pub fn pending_count(&self) -> usize

Unanswered requests (hello and commands).

Source

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

The next transport text to send, in order.

Source

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

Every queued transport text, in order.

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Shows no envelope text: pending bodies and queued texts may hold an invitation secret.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.