Skip to main content

SessionInitClient

Struct SessionInitClient 

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

The communication client’s half of session initiation.

use s2_kit::connect::proto::{AccessToken, NodeId, SessionInitClient, TokenStore};

let store = TokenStore::new(AccessToken::from_entropy(&[1u8; 32])?);
let mut client = SessionInitClient::new(NodeId::parse("rm-1")?, NodeId::parse("cem-1")?, store);

let (bearer, body) = client.initiate()?;
assert_eq!(body.client_node_id.to_string(), "rm-1");

Implementations§

Source§

impl SessionInitClient

Source

pub fn new( client_node_id: NodeId, server_node_id: NodeId, tokens: TokenStore, ) -> Self

A client for one pairing.

Source

pub fn allowing_insecure_websocket(self) -> Self

Accept a plaintext ws:// websocketUrl — for a loopback test and nothing else.

S2C §Encrypted connection: “S2 MUST NOT be sent over unencrypted channels. Therefore a wss connection … must be used.” The communication token is a bearer; over ws:// anyone on the path can read it and the session it opens.

Source

pub fn with_s2_message_versions(self, versions: Vec<ProtocolVersion>) -> Self

Offer a different set of S2 JSON message versions, newest first.

Source

pub fn initiate( &mut self, ) -> Result<(AccessToken, SessionRequest), ConnectError>

Build initiateSession, with the bearer to send it under.

A completed initiation is a legitimate place to start another: every reconnection needs fresh credentials, because a communication token authorises exactly one connection and lives thirty seconds. Requiring Self::restart in between would make the common path the one a caller forgets.

Source

pub fn unauthorized(&mut self) -> Result<(), ConnectError>

Handle a 401 on initiateSession by moving to the next stored token.

S2C §Recovery: “It should try all the accessTokens sequentially.” When they are exhausted the pairing really is gone, and this returns ConnectError::NotPaired — which is a call to a human, not a retry.

Source

pub fn accept( &mut self, grant: SessionGrant, now: Timestamp, ) -> Result<(), ConnectError>

Take the grant and store the replacement token.

Storing before confirming is the order the specification requires, and the reason the two requests exist at all: a client that confirmed first and stored afterwards has a window in which a crash loses the replacement for good.

now starts the PENDING_TOKEN_LIFETIME clock on this side too, so a client that was suspended between the two requests declines to retire the token it already had rather than retiring it against a server that never activated the replacement.

Source

pub fn confirm(&mut self) -> Result<AccessToken, ConnectError>

The bearer for confirmAccessToken: the new token.

Presenting it is the confirmation, which is why there is no body.

Source

pub fn connected( &mut self, details: CommunicationDetails, now: Timestamp, ) -> Result<SessionCredentials, ConnectError>

Take the communication details the confirmation returned.

The old tokens are retired here and not before: the server has just proved it accepted the new one.

Source

pub fn restart(&mut self)

Start again after a failure, keeping whatever tokens survived.

This is what makes the two-phase commit worth having: after any failure at all, the store still holds a token the server will accept.

Source

pub fn unpaired(&mut self) -> UnpairRequest

Forget the pairing. What a NoLongerPaired means.

Source

pub fn tokens(&self) -> &TokenStore

The tokens, to persist.

Trait Implementations§

Source§

impl Debug for SessionInitClient

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more