pub struct Session {
pub id: SessionId,
pub name: String,
pub features: Vec<String>,
pub created_at: Instant,
pub last_activity: RwLock<Instant>,
pub authenticated: bool,
pub token: Option<String>,
pub subject: Option<String>,
/* private fields */
}Expand description
A connected client session
Fields§
§id: SessionIdUnique session ID
name: StringClient name
features: Vec<String>Client features
created_at: InstantSession creation time
last_activity: RwLock<Instant>Last activity time
authenticated: boolIs authenticated
token: Option<String>Permission token (if any)
subject: Option<String>Subject identifier from token (user, device, or service ID)
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(
sender: Arc<dyn TransportSender>,
name: String,
features: Vec<String>,
) -> Self
pub fn new( sender: Arc<dyn TransportSender>, name: String, features: Vec<String>, ) -> Self
Create a new session
Sourcepub fn set_authenticated(
&mut self,
token: String,
subject: Option<String>,
scopes: Vec<Scope>,
)
pub fn set_authenticated( &mut self, token: String, subject: Option<String>, scopes: Vec<Scope>, )
Set authentication info from a validated token
Sourcepub fn has_scope(&self, action: Action, address: &str) -> bool
pub fn has_scope(&self, action: Action, address: &str) -> bool
Check if this session has permission for the given action on the given address
Sourcepub fn has_strict_read_scope(&self, address: &str) -> bool
pub fn has_strict_read_scope(&self, address: &str) -> bool
Check if this session has an explicit read scope for the given address.
Unlike has_scope(Action::Read, ...), this does NOT match write scopes
(which normally imply read via Action::Write.allows(Action::Read)).
Use this for SUBSCRIBE checks to prevent write-only scopes from granting
subscription access to paths they should only write to.
Sourcepub async fn send(&self, data: Bytes) -> Result<(), TransportError>
pub async fn send(&self, data: Bytes) -> Result<(), TransportError>
Send a message to this session
Sourcepub fn try_send(&self, data: Bytes) -> Result<(), TransportError>
pub fn try_send(&self, data: Bytes) -> Result<(), TransportError>
Try to send a message without blocking (for broadcasts) Returns Ok if sent or queued, Err if buffer is full
Sourcepub fn welcome_message(
&self,
server_name: &str,
server_features: &[String],
) -> Message
pub fn welcome_message( &self, server_name: &str, server_features: &[String], ) -> Message
Create welcome message for this session
Sourcepub fn add_subscription(&self, id: u32)
pub fn add_subscription(&self, id: u32)
Add a subscription
Sourcepub fn remove_subscription(&self, id: u32) -> bool
pub fn remove_subscription(&self, id: u32) -> bool
Remove a subscription
Sourcepub fn subscriptions(&self) -> Vec<u32>
pub fn subscriptions(&self) -> Vec<u32>
Get all subscription IDs
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
Sourcepub fn idle_duration(&self) -> Duration
pub fn idle_duration(&self) -> Duration
Get idle duration
Sourcepub fn check_rate_limit(&self, max_per_second: u32) -> bool
pub fn check_rate_limit(&self, max_per_second: u32) -> bool
Check and increment rate limit counter Returns true if within rate limit, false if exceeded
Sourcepub fn messages_per_second(&self) -> u32
pub fn messages_per_second(&self) -> u32
Get current message count for this second
Sourcepub fn record_drop(&self) -> bool
pub fn record_drop(&self) -> bool
Record a dropped message and check if notification is needed. Returns true if a drop notification should be sent to the client.
Sourcepub fn total_drops(&self) -> u64
pub fn total_drops(&self) -> u64
Get the total number of dropped messages for this session
Sourcepub fn drops_in_window(&self) -> u32
pub fn drops_in_window(&self) -> u32
Get the drops in the current window