pub struct SessionService { /* private fields */ }connect-server only.Expand description
Runs the session-initiation half of an endpoint.
Almost everything it needs is in the Store and in the bearer the client presented,
including the replacement access token it issued and has not yet seen confirmed — a
server that held that in memory would retire the wrong token after a restart.
The one thing it keeps in memory is the set of communication tokens it has handed out and not yet seen used. Those are deliberately not persisted: each is valid for thirty seconds and one connection, so a server that has restarted has none that are still good, and a client whose upgrade is refused simply initiates again.
Implementations§
Source§impl SessionService
impl SessionService
Sourcepub fn new(store: Arc<dyn Store>, websocket_url: impl Into<String>) -> Self
pub fn new(store: Arc<dyn Store>, websocket_url: impl Into<String>) -> Self
A service answering on websocket_url.
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 initiate_session(
&self,
bearer: &AccessToken,
request: &SessionRequest,
access_entropy: &[u8],
now: Timestamp,
) -> Result<SessionGrant, ConnectError>
pub fn initiate_session( &self, bearer: &AccessToken, request: &SessionRequest, access_entropy: &[u8], now: Timestamp, ) -> Result<SessionGrant, ConnectError>
POST /v1/initiateSession.
The replacement token is stored alongside the presented one, never instead of it: until the client confirms, either must work, or a lost reply destroys the pairing.
Sourcepub fn confirm_access_token(
&self,
bearer: &AccessToken,
communication_entropy: &[u8],
now: Timestamp,
) -> Result<(NodeId, CommunicationDetails), ConnectError>
pub fn confirm_access_token( &self, bearer: &AccessToken, communication_entropy: &[u8], now: Timestamp, ) -> Result<(NodeId, CommunicationDetails), ConnectError>
POST /v1/confirmAccessToken.
The bearer is the confirmation. Every older token is retired here, and not one request earlier.
Whether a bearer presented on a WebSocket upgrade is one this endpoint issued, and which node it belongs to.
The token is consumed: s2-connect-common.yml/CommunicationToken is “valid for a
single connection … for maximum 30 seconds”, so a replay is refused rather than
granted a second session in parallel with the first. Every token is compared in
constant time and the list is swept of expired entries on the way through.
This is what a host mounts its /s2 route on —
websocket_router does it for you.
Sourcepub fn pending_connections(&self) -> usize
pub fn pending_connections(&self) -> usize
How many issued communication tokens are still waiting to be used.
For a health endpoint, and for a test that wants to see one consumed.
Sourcepub fn unpair(
&self,
bearer: &AccessToken,
request: &UnpairRequest,
) -> Result<(), ConnectError>
pub fn unpair( &self, bearer: &AccessToken, request: &UnpairRequest, ) -> Result<(), ConnectError>
POST /v1/unpair.
Sourcepub fn tokens(&self, remote: NodeId) -> Option<TokenStore>
pub fn tokens(&self, remote: NodeId) -> Option<TokenStore>
The tokens of one pairing, for a route that must check a bearer.