Session Contracts
On this page
Namespace: Nalix.Abstractions.Networking.Sessions
Assembly: Nalix.Abstractions
Nalix.Abstractions.Networking.Sessions defines the contracts for capturing, storing, and atomically consuming session state to support zero-RTT session resumption (SessionResume).
Source Mapping
src/Nalix.Abstractions/Networking/Sessions/ISessionService.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionFactory.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionStore.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionPersistencePolicy.cssrc/Nalix.Abstractions/Networking/Sessions/SessionEntry.cssrc/Nalix.Abstractions/Networking/Sessions/SessionSnapshot.cssrc/Nalix.Abstractions/Networking/Sessions/SessionScope.cs
Public Members at a Glance
| Type | Kind | Public Members |
|---|---|---|
ISessionService | interface : IDisposable | ValueTask SaveSessionAsync(IConnection, CancellationToken), ValueTask<SessionScope> ConsumeAsync(ulong sessionToken, Func<SessionEntry, bool>? predicate = null, CancellationToken ct = default) |
ISessionStore | interface | ValueTask StoreAsync(SessionEntry, CancellationToken), ValueTask<SessionScope> ConsumeAsync(ulong sessionToken, Func<SessionEntry, bool>? predicate = null, CancellationToken ct = default) |
ISessionFactory | interface | SessionEntry CreateSession(IConnection connection) |
ISessionPersistencePolicy | interface | bool ShouldPersist(IConnection connection) |
SessionScope | readonly struct : IDisposable | SessionEntry? Value { get; }, bool IsValid { get; }, void Dispose(), implicit operator SessionEntry?(SessionScope) |
SessionEntry | class | SessionSnapshot Snapshot, ulong ConnectionId, void Return() |
SessionSnapshot | class | ulong SessionToken, long CreatedAtUnixMilliseconds, long ExpiresAtUnixMilliseconds, Bytes32 Secret, CipherSuiteType Algorithm, PermissionLevel Level, IObjectMap<AttributeKey, object>? Attributes, void ClearSecret(), void Return() |
ISessionService & ISessionStore
Both ISessionService.ConsumeAsync and ISessionStore.ConsumeAsync perform an atomic retrieve-and-remove operation and return a SessionScope:
using SessionScope scope = await sessionService.ConsumeAsync(
sessionToken,
predicate: entry => entry.Snapshot.ExpiresAtUnixMilliseconds > nowMs,
cancellationToken: ct);
if (scope.IsValid)
{
SessionEntry entry = scope.Value!;
// Restore Secret, Algorithm, Level, and sequence counters onto the new connection
}
ISessionFactory & ISessionPersistencePolicy
ISessionFactory.CreateSession(IConnection): Creates aSessionEntryand populates itsSessionSnapshotwith the connection’sConnectionId(SessionToken), 32-byteSecret(Bytes32),Algorithm,Level, andAttributes(including TCP/UDP sequence numbers).ISessionPersistencePolicy.ShouldPersist(IConnection): Evaluates whether a connection’s session should be saved (defaultDefaultSessionPersistencePolicyverifies that a cryptographic handshake was completed andSecretis non-zero).