pub struct SessionManager { /* private fields */ }Expand description
Manages authenticated peer sessions with dual-index tracking.
Sessions are indexed by:
- Session nonce (primary key, unique per session)
- Identity key (secondary index, one-to-many)
This allows lookup by either nonce or identity key, with the identity key lookup returning the “best” session (preferring authenticated ones).
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn add_session(&mut self, session: PeerSession)
pub fn add_session(&mut self, session: PeerSession)
Add a session to the manager.
Indexes by session_nonce (primary) and peer_identity_key (secondary). Does NOT overwrite existing sessions for the same identity key, allowing multiple concurrent sessions per peer.
Sourcepub fn get_session(&self, nonce: &str) -> Option<&PeerSession>
pub fn get_session(&self, nonce: &str) -> Option<&PeerSession>
Get a session by nonce (immutable reference).
Sourcepub fn get_session_mut(&mut self, nonce: &str) -> Option<&mut PeerSession>
pub fn get_session_mut(&mut self, nonce: &str) -> Option<&mut PeerSession>
Get a session by nonce (mutable reference).
Sourcepub fn get_sessions_for_identity(&self, identity_key: &str) -> Vec<&PeerSession>
pub fn get_sessions_for_identity(&self, identity_key: &str) -> Vec<&PeerSession>
Get all sessions for a given identity key.
Sourcepub fn get_session_by_identifier(
&self,
identifier: &str,
) -> Option<&PeerSession>
pub fn get_session_by_identifier( &self, identifier: &str, ) -> Option<&PeerSession>
Get the “best” session for an identity key (prefers authenticated).
Matches TS SDK SessionManager.getSession() behavior: if the identifier is a session nonce, returns that exact session. If it is an identity key, returns the best (authenticated preferred) session.
Sourcepub fn has_session(&self, nonce: &str) -> bool
pub fn has_session(&self, nonce: &str) -> bool
Check if a session exists for a given nonce.
Sourcepub fn has_session_by_identifier(&self, identifier: &str) -> bool
pub fn has_session_by_identifier(&self, identifier: &str) -> bool
Check if any session exists for a given identifier (nonce or identity key).
Sourcepub fn update_session(&mut self, nonce: &str, session: PeerSession)
pub fn update_session(&mut self, nonce: &str, session: PeerSession)
Replace a session at the given nonce.
Sourcepub fn remove_session(&mut self, nonce: &str) -> Option<PeerSession>
pub fn remove_session(&mut self, nonce: &str) -> Option<PeerSession>
Remove a session by nonce. Returns the removed session if found.