pub struct SessionInitServer { /* private fields */ }Expand description
The communication server’s half of session initiation.
It owns the token store for one pairing and never hands out a communication token without having accepted an access token first.
Implementations§
Source§impl SessionInitServer
impl SessionInitServer
Sourcepub fn new(
node_id: NodeId,
peer_node_id: NodeId,
tokens: TokenStore,
websocket_url: impl Into<String>,
) -> Self
pub fn new( node_id: NodeId, peer_node_id: NodeId, tokens: TokenStore, websocket_url: impl Into<String>, ) -> Self
A server for one pairing.
Sourcepub fn with_s2_message_versions(self, versions: Vec<ProtocolVersion>) -> Self
pub fn with_s2_message_versions(self, versions: Vec<ProtocolVersion>) -> Self
Offer a different set of S2 JSON message versions, newest first.
Sourcepub fn authenticates(&self, bearer: &AccessToken) -> bool
pub fn authenticates(&self, bearer: &AccessToken) -> bool
Whether a bearer presented on either endpoint is one we would accept.
A false is a 401.
Sourcepub fn initiate_session(
&mut self,
bearer: &AccessToken,
request: &SessionRequest,
access_entropy: &[u8],
now: Timestamp,
) -> Result<SessionGrant, ConnectError>
pub fn initiate_session( &mut self, bearer: &AccessToken, request: &SessionRequest, access_entropy: &[u8], now: Timestamp, ) -> Result<SessionGrant, ConnectError>
Handle initiateSession.
access_entropy is a parameter for the same reason it is in
pairing: a test needs it pinned, and this layer has no business
knowing where a system keeps its randomness.
§Errors
ConnectError::NotPaired is a 401; a SessionRefused carried in
ConnectError::SessionRefused is a 400 with that body.
Sourcepub fn confirm_access_token(
&mut self,
bearer: &AccessToken,
communication_entropy: &[u8],
now: Timestamp,
) -> Result<CommunicationDetails, ConnectError>
pub fn confirm_access_token( &mut self, bearer: &AccessToken, communication_entropy: &[u8], now: Timestamp, ) -> Result<CommunicationDetails, ConnectError>
Handle confirmAccessToken, retiring every older token.
The bearer is the confirmation: a client that can present the new token has stored it, so there is nothing else to check and nothing to take on trust.
Sourcepub fn unpair(
&mut self,
bearer: &AccessToken,
request: &UnpairRequest,
) -> Result<(), ConnectError>
pub fn unpair( &mut self, bearer: &AccessToken, request: &UnpairRequest, ) -> Result<(), ConnectError>
Handle unpair.
Sourcepub fn accepts_connection(&mut self, presented: &str, now: Timestamp) -> bool
pub fn accepts_connection(&mut self, presented: &str, now: Timestamp) -> bool
Whether a bearer presented on a WebSocket handshake is the one this server issued, and still inside its thirty seconds.
Takes &mut self and consumes the token on success, because
s2-connect-common.yml/CommunicationToken says it is “valid for a single
connection”: a second upgrade with the same bearer is refused rather than
silently granted a parallel session.
Sourcepub fn tokens(&self) -> &TokenStore
pub fn tokens(&self) -> &TokenStore
The tokens, to persist.