Skip to main content

SessionManager

Struct SessionManager 

Source
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

Source

pub fn new() -> Self

Create a new empty SessionManager.

Source

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.

Source

pub fn get_session(&self, nonce: &str) -> Option<&PeerSession>

Get a session by nonce (immutable reference).

Source

pub fn get_session_mut(&mut self, nonce: &str) -> Option<&mut PeerSession>

Get a session by nonce (mutable reference).

Source

pub fn get_sessions_for_identity(&self, identity_key: &str) -> Vec<&PeerSession>

Get all sessions for a given identity key.

Source

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.

Source

pub fn has_session(&self, nonce: &str) -> bool

Check if a session exists for a given nonce.

Source

pub fn has_session_by_identifier(&self, identifier: &str) -> bool

Check if any session exists for a given identifier (nonce or identity key).

Source

pub fn update_session(&mut self, nonce: &str, session: PeerSession)

Replace a session at the given nonce.

Source

pub fn remove_session(&mut self, nonce: &str) -> Option<PeerSession>

Remove a session by nonce. Returns the removed session if found.

Trait Implementations§

Source§

impl Default for SessionManager

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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, 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.