pub struct Session<I = ()> { /* private fields */ }Expand description
Session state shared between the read loop and every dispatch task
(SRV-010): the auth flag is a lock-free atomic flipped by HELLO/AUTH
and read by the dispatch path without locks.
Implementations§
Source§impl<I> Session<I>
impl<I> Session<I>
Sourcepub fn connection_id(&self) -> u64
pub fn connection_id(&self) -> u64
Listener-scoped connection id, surfaced in the metadata-shape HELLO reply (SRV-014).
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Lock-free read of the auth flag (SRV-010).
Sourcepub fn with_principal<R>(
&self,
read: impl FnOnce(Option<&Principal<I>>) -> R,
) -> R
pub fn with_principal<R>( &self, read: impl FnOnce(Option<&Principal<I>>) -> R, ) -> R
Read the resolved principal without cloning it — the authorization path (SRV-012).
Authorization runs on every privileged command, so it must not pay a
String clone (or a credential-store lookup) to ask one question:
let is_admin = session.with_principal(|p| {
p.map(|p| p.identity.is_admin).unwrap_or(false)
});Sourcepub fn principal_name(&self) -> Option<String>
pub fn principal_name(&self) -> Option<String>
The principal’s name, if one was resolved.
Convenience for the common case; prefer
with_principal on a hot authorization path,
since this clones the name.
Sourcepub fn push_sender(&self) -> Option<&PushSender>
pub fn push_sender(&self) -> Option<&PushSender>
Typed push channel for this connection (SRV-013). Some only under
push = Enabled profiles; under Reserved no push emission is
possible.