Skip to main content

SessionTokenRegistry

Struct SessionTokenRegistry 

Source
pub struct SessionTokenRegistry { /* private fields */ }
Expand description

Thread-safe registry of active session tokens.

Implementations§

Source§

impl SessionTokenRegistry

Source

pub fn new() -> Self

Source

pub fn register( &self, token: String, scope: impl Into<GrantScope>, max_connections: u32, )

Register a new token. Replaces any existing token with the same value.

Source

pub fn register_with_expiry_ms( &self, token: String, scope: impl Into<GrantScope>, max_connections: u32, expires_at_ms: Option<u64>, )

Register a new token with an optional absolute Unix-millisecond expiry.

Source

pub fn validate_and_consume(&self, token: &str) -> Result<GrantScope, String>

Validate a token and increment its use count.

Returns Ok(scope) on success, Err(reason) on failure. If the registry is empty, only a tokenless low-level/manual connection receives the compatibility verdict. A presented bearer token must always match a registered capability; otherwise arbitrary strings could be promoted into trust by higher layers.

Source

pub fn validate_and_consume_for_connection( &self, token: &str, connection_id: Option<&str>, ) -> Result<GrantScope, String>

Validate a token, increment its use count, and optionally record the connection_id so revoke_by_scope can return affected connections.

Source

pub fn validate_and_consume_for_connection_with_payload( &self, token: &str, connection_id: Option<&str>, payload_suffix: Option<&str>, ) -> Result<GrantScope, String>

Validate a raw session token with optional compact payload metadata.

Legacy callers may omit payload_suffix; modern compound-ticket callers should provide it so the host can enforce the payload audience, expiry, token binding, and nonce replay checks instead of seeing only the raw bearer token.

Source

pub fn validate_with_cached_response( &self, token: &str, connection_id: &str, ) -> Result<GrantScope, String>

Phase 1 verdict-only API. Returns the deterministic admission verdict for (token, connection_id) without running any post-admission side effects (no accept_replacement_peer, no WebRTC recovery, no transport replacement). Callers must:

  1. Call this to compute the verdict.
  2. Write + flush the response to the wire.
  3. Then run their post-admission side effects (e.g. via Client::run_post_session_token_admission_side_effects).

This separation is what eliminates the 0 bytes read race where the host’s lifecycle hooks would retire the very transport the response writer was using before it could flush.

Source

pub fn validate_with_cached_response_and_payload( &self, token: &str, connection_id: &str, payload_suffix: Option<&str>, ) -> Result<GrantScope, String>

Source

pub fn begin_admission_response( &self, connection_id: &str, ) -> AdmissionResponseGuard

Mark a session-token response writer as in-flight for connection_id. Returns a guard whose Drop decrements the counter. While any guard is alive for a given connection, the transport must not be closed/retired by lifecycle code (see is_session_token_admission_in_flight).

Source

pub fn try_begin_admission_response( &self, connection_id: &str, ) -> Option<AdmissionResponseGuard>

Atomically begin a response writer unless terminal retirement already owns this connection.

Source

pub fn try_begin_admission_presentation( &self, connection_id: &str, ) -> Option<AdmissionPresentationGuard>

Atomically acquire the sole outbound presenter for one connection. Host response writers may coexist because they operate in the opposite direction, while duplicate outbound attempts and retirement are fenced.

Source

pub fn try_begin_transport_retirement( &self, connection_id: &str, ) -> Option<AdmissionRetirementGuard>

Atomically acquire transport retirement unless a response writer or outbound presenter already owns the connection.

Physical health replacement and terminal admission timeout share this fence. Both must serialize teardown against an in-flight protocol exchange; the guard itself does not decide whether logical admission is retained or forgotten.

Source

pub fn try_begin_admission_retirement( &self, connection_id: &str, ) -> Option<AdmissionRetirementGuard>

Admission-timeout spelling retained for the terminal caller.

Source

pub fn is_session_token_admission_in_flight(&self, connection_id: &str) -> bool

True while a session-token response writer or the sole outbound presenter is mid-flight for connection_id. Lifecycle code must defer transport teardown while this returns true.

Source

pub fn is_session_token_presentation_in_flight( &self, connection_id: &str, ) -> bool

Source

pub fn admission_fingerprint(&self, connection_id: &str) -> Option<String>

Source

pub fn admission_epoch(&self, connection_id: &str) -> Option<u64>

Source

pub fn revoke(&self, token: &str) -> Vec<String>

Revoke a specific token.

Source

pub fn revoke_by_scope(&self, scope: impl AsRef<str>) -> Vec<String>

Revoke all tokens and logical admissions with the given scope.

validated_connections records tokens this runtime validated from a peer. admissions also records the opposite direction after a remote host approves this runtime’s token. Scope revocation is a logical-session boundary, so both directions must be returned to the lifecycle owner.

Source

pub fn clear(&self)

Remove all tokens and validated connection bindings.

Source

pub fn is_empty(&self) -> bool

True if no restricted session tokens are registered.

Source

pub fn admission(&self, connection_id: &str) -> SessionAdmission

Source

pub fn is_session_token_admitted_for_connection( &self, connection_id: &str, ) -> bool

True when this runtime validated a token presented by the remote peer.

Used to detect duplicate token frames on the same logical connection (e.g. new iroh substreams re-sending the compound ticket) — those must not re-trigger native WebRTC upgrade recovery, which is only appropriate for the first token presentation.

Source

pub fn mark_rejected(&self, connection_id: &str, reason: impl Into<String>)

Source

pub fn mark_accepted( &self, connection_id: &str, mechanism: SessionAdmissionMechanism, scope: Option<GrantScope>, authoritative_device_id: Option<String>, )

Source

pub fn bind_connection_scope( &self, connection_id: &str, scope: impl Into<GrantScope>, authoritative_device_id: Option<String>, )

Source

pub fn forget_connection(&self, connection_id: &str)

Source

pub fn set_native_trusted_connection_verifier( &self, verifier: Option<NativeTrustedConnectionVerifier>, )

Source

pub fn evaluate_trusted_native_connection( &self, context: &NativeTrustedConnectionContext, ) -> Option<String>

Trait Implementations§

Source§

impl Clone for SessionTokenRegistry

Source§

fn clone(&self) -> SessionTokenRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SessionTokenRegistry

Source§

fn default() -> SessionTokenRegistry

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SendSyncBound for T
where T: Send + Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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