pub struct PeerSessionManager { /* private fields */ }Expand description
Manages authenticated peer sessions with capability negotiation and expiry.
Implementations§
Source§impl PeerSessionManager
impl PeerSessionManager
Sourcepub fn new(config: SessionManagerConfig) -> Self
pub fn new(config: SessionManagerConfig) -> Self
Create a new PeerSessionManager with the given configuration.
Sourcepub fn open_session(
&mut self,
peer_id: String,
capabilities: Vec<SessionCapability>,
now_secs: u64,
) -> Result<u64, String>
pub fn open_session( &mut self, peer_id: String, capabilities: Vec<SessionCapability>, now_secs: u64, ) -> Result<u64, String>
Open a new authenticated session for peer_id with capabilities.
Returns Ok(token_id) on success or Err("session limit reached") when
the maximum number of concurrent sessions has been reached.
Sourcepub fn get_session(&self, token_id: u64) -> Option<&PeerSession>
pub fn get_session(&self, token_id: u64) -> Option<&PeerSession>
Look up an active session by its token_id.
Sourcepub fn record_traffic(&mut self, token_id: u64, sent: u64, received: u64)
pub fn record_traffic(&mut self, token_id: u64, sent: u64, received: u64)
Record traffic for a session: increments bytes_sent, bytes_received,
and message_count by 1 for each call.
Sourcepub fn close_session(&mut self, token_id: u64) -> bool
pub fn close_session(&mut self, token_id: u64) -> bool
Close (remove) a session by token_id. Returns true if a session was removed.
Sourcepub fn evict_expired(&mut self, now_secs: u64) -> usize
pub fn evict_expired(&mut self, now_secs: u64) -> usize
Remove all sessions that have expired relative to now_secs.
Returns the number of sessions that were removed.
Sourcepub fn active_sessions(&self, now_secs: u64) -> Vec<&PeerSession>
pub fn active_sessions(&self, now_secs: u64) -> Vec<&PeerSession>
Return references to all sessions that have not expired.
Sourcepub fn sessions_with_capability(
&self,
cap: SessionCapability,
now_secs: u64,
) -> Vec<&PeerSession>
pub fn sessions_with_capability( &self, cap: SessionCapability, now_secs: u64, ) -> Vec<&PeerSession>
Return references to all non-expired sessions that have the given capability.
Auto Trait Implementations§
impl Freeze for PeerSessionManager
impl RefUnwindSafe for PeerSessionManager
impl Send for PeerSessionManager
impl Sync for PeerSessionManager
impl Unpin for PeerSessionManager
impl UnsafeUnpin for PeerSessionManager
impl UnwindSafe for PeerSessionManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more