Skip to main content

Session

Struct Session 

Source
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: SessionId

Unique session ID

§name: String

Client name

§features: Vec<String>

Client features

§created_at: Instant

Session creation time

§last_activity: RwLock<Instant>

Last activity time

§authenticated: bool

Is authenticated

§token: Option<String>

Permission token (if any)

§subject: Option<String>

Subject identifier from token (user, device, or service ID)

Implementations§

Source§

impl Session

Source

pub fn new( sender: Arc<dyn TransportSender>, name: String, features: Vec<String>, ) -> Self

Create a new session

Source

pub fn set_authenticated( &mut self, token: String, subject: Option<String>, scopes: Vec<Scope>, )

Set authentication info from a validated token

Source

pub fn has_scope(&self, action: Action, address: &str) -> bool

Check if this session has permission for the given action on the given address

Source

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.

Source

pub fn scopes(&self) -> &[Scope]

Get the scopes for this session

Source

pub async fn send(&self, data: Bytes) -> Result<(), TransportError>

Send a message to this session

Source

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

Source

pub async fn send_message(&self, message: &Message) -> Result<(), Error>

Send a Clasp message

Source

pub fn welcome_message( &self, server_name: &str, server_features: &[String], ) -> Message

Create welcome message for this session

Source

pub fn add_subscription(&self, id: u32)

Add a subscription

Source

pub fn remove_subscription(&self, id: u32) -> bool

Remove a subscription

Source

pub fn subscriptions(&self) -> Vec<u32>

Get all subscription IDs

Source

pub fn is_connected(&self) -> bool

Check if connected

Source

pub fn touch(&self)

Touch to update last activity

Source

pub fn idle_duration(&self) -> Duration

Get idle duration

Source

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

Source

pub fn messages_per_second(&self) -> u32

Get current message count for this second

Source

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.

Source

pub fn total_drops(&self) -> u64

Get the total number of dropped messages for this session

Source

pub fn drops_in_window(&self) -> u32

Get the drops in the current window

Trait Implementations§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more