pub struct SessionTable<C: Config, const N: usize = 16> { /* private fields */ }rustcrypto only.Expand description
The fixed-capacity set of established sessions.
Implementations§
Source§impl<C: Config, const N: usize> SessionTable<C, N>
impl<C: Config, const N: usize> SessionTable<C, N>
Sourcepub const CHECK: ()
pub const CHECK: ()
Compile-time proof that this table can keep §4.14.2.8’s promise.
A node SHALL support at least 3 CASE session contexts per fabric.
Referenced by SessionTable::new, so a table too small for the node’s Config fails
the build at the first place one is constructed.
Sourcepub fn new(first_id: u16) -> Self
pub fn new(first_id: u16) -> Self
An empty table whose first session id is first_id.
§4.13.2.4 requires a fresh local session id that does not collide with a live one; starting from a random value rather than 1 keeps a node’s ids from being guessable across a reboot.
Sourcepub fn allocate_id(&mut self) -> Result<SessionId>
pub fn allocate_id(&mut self) -> Result<SessionId>
Allocates a local session id that no live session is using (§4.13.2.4).
Session id 0 is never returned: with a unicast session type it means the unsecured session, so handing it out would make a secure session indistinguishable from no session at all.
Sourcepub fn insert(&mut self, session: SecureSession) -> Result<()>
pub fn insert(&mut self, session: SecureSession) -> Result<()>
Installs a session.
Sourcepub fn find(&self, local_session_id: SessionId) -> Option<&SecureSession>
pub fn find(&self, local_session_id: SessionId) -> Option<&SecureSession>
The session a message addressed to local_session_id belongs to.
Sourcepub fn find_mut(
&mut self,
local_session_id: SessionId,
) -> Option<&mut SecureSession>
pub fn find_mut( &mut self, local_session_id: SessionId, ) -> Option<&mut SecureSession>
The session, mutably.
Sourcepub fn remove(&mut self, local_session_id: SessionId) -> bool
pub fn remove(&mut self, local_session_id: SessionId) -> bool
Removes a session, returning whether one was there.
Sourcepub fn remove_fabric(&mut self, fabric: FabricIndex) -> usize
pub fn remove_fabric(&mut self, fabric: FabricIndex) -> usize
Removes every session on a fabric — what RemoveFabric does.
Sourcepub fn least_recently_used(&self) -> Option<SessionId>
pub fn least_recently_used(&self) -> Option<SessionId>
The session that has gone unused longest, which is what §4.11.1.1 evicts when the table is full.
Sourcepub fn iter(&self) -> impl Iterator<Item = &SecureSession>
pub fn iter(&self) -> impl Iterator<Item = &SecureSession>
Every session.
Trait Implementations§
Source§impl<C: Config, const N: usize> Capacity for SessionTable<C, N>
impl<C: Config, const N: usize> Capacity for SessionTable<C, N>
Source§const PER_FABRIC: usize
const PER_FABRIC: usize
§11.1.4.4’s CaseSessionsPerFabric: the sessions this table guarantees each fabric.
The whole table divided among the fabrics, with no rounding up. §4.14.2.8 sets the
floor at three and SessionTable::CHECK refuses a smaller table at compile time, so
this never has to be clamped — and clamping is what would turn a table that is too small
into an attribute that lies about it.