pub struct SessionStore { /* private fields */ }Expand description
Thread-safe session store with automatic expiry cleanup.
Implementations§
Source§impl SessionStore
impl SessionStore
pub fn new(session_timeout: Duration, max_sessions: usize) -> Self
Sourcepub fn with_max_lifetime(self, lifetime: Duration) -> Self
pub fn with_max_lifetime(self, lifetime: Duration) -> Self
Set an absolute session lifetime. Sessions older than this duration
are expired regardless of activity. Returns self for chaining.
Sourcepub fn get_or_create(&self, client_session_id: Option<&str>) -> String
pub fn get_or_create(&self, client_session_id: Option<&str>) -> String
Get or create a session. Returns the session ID.
If client_session_id is provided and the session exists, it’s reused.
Otherwise a new session is created. Session IDs are always server-generated
to prevent session fixation attacks.
Sourcepub fn get(&self, session_id: &str) -> Option<Ref<'_, String, SessionState>>
pub fn get(&self, session_id: &str) -> Option<Ref<'_, String, SessionState>>
Get an immutable reference to a session.
Sourcepub fn get_mut(
&self,
session_id: &str,
) -> Option<RefMut<'_, String, SessionState>>
pub fn get_mut( &self, session_id: &str, ) -> Option<RefMut<'_, String, SessionState>>
Get a mutable reference to a session.
Sourcepub fn try_get(
&self,
session_id: &str,
) -> TryResult<Ref<'_, String, SessionState>>
pub fn try_get( &self, session_id: &str, ) -> TryResult<Ref<'_, String, SessionState>>
Non-blocking read access. Returns None if the shard is already locked
or the session doesn’t exist. Use this when the caller may already hold
a get_mut() lock on the same shard to avoid deadlock.
Sourcepub fn try_get_mut(
&self,
session_id: &str,
) -> TryResult<RefMut<'_, String, SessionState>>
pub fn try_get_mut( &self, session_id: &str, ) -> TryResult<RefMut<'_, String, SessionState>>
Non-blocking mutable access. Returns Locked if the shard is already
locked. Use this when the caller may already hold a get_mut() lock on
the same shard to avoid deadlock.
Sourcepub fn evict_expired(&self)
pub fn evict_expired(&self)
Remove expired sessions.
Sourcepub fn remove(&self, session_id: &str) -> bool
pub fn remove(&self, session_id: &str) -> bool
Delete a specific session (e.g., on client disconnect via DELETE).
Sourcepub fn flag_tool_globally(&self, tool_name: String)
pub fn flag_tool_globally(&self, tool_name: String)
Record a tool name in the global flagged-tools registry.
SECURITY (R240-PROXY-1): This ensures rug-pull detections survive session eviction. Even if the session that detected the rug-pull is expired or evicted under capacity pressure, the tool remains blocked globally.
Sourcepub fn is_tool_globally_flagged(&self, tool_name: &str) -> bool
pub fn is_tool_globally_flagged(&self, tool_name: &str) -> bool
Check whether a tool is flagged in the global registry.
SECURITY (R240-PROXY-1): Returns true if the tool was flagged by any session and the flag has not yet expired. This is the fallback check when a session lookup returns None (session evicted).
Sourcepub fn evict_expired_global_flags(&self) -> usize
pub fn evict_expired_global_flags(&self) -> usize
Remove expired entries from the global flagged-tools registry.
Sourcepub fn global_flagged_tools_len(&self) -> usize
pub fn global_flagged_tools_len(&self) -> usize
Number of entries in the global flagged-tools registry.