Skip to main content

SessionRuntime

Struct SessionRuntime 

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

The session-type runtime cursor + credit window.

Held by each side of a connection — the server runtime is initialised with the server-role type, the client with the dual. Every transition is local: there is no cross-process synchronisation here; the carrier delivers frames in order and the two cursors stay in lock step because they were initialised from a duality-checked pair.

Serialize + Deserialize — §Fase 41.g sealed-snapshot resume. The serialised form is a stable JSON object containing the schema (so resume can verify the protocol hasn’t been swapped), the residual cursor, and the live credit window. Encoded once via Self::seal into the AAD-bound cognitive_states ciphertext; decoded by Self::resume after the §40.k EnvelopeEncryption::decrypt verifies the (tenant, session, flow) binding.

Implementations§

Source§

impl SessionRuntime

Source

pub fn new(schema: SessionType, budget: Option<u64>) -> Self

Create a runtime for the given role’s session type. budget mirrors the socket’s credit(k); pass None for the unbounded fragment (statically equivalent to omitting backpressure:).

Source

pub fn schema(&self) -> &SessionType

The original session type — useful for error messages and logs.

Source

pub fn cursor(&self) -> &SessionType

The current residual cursor — always head-unfolded.

Source

pub fn credit(&self) -> Option<CreditWindow>

The dynamic credit window snapshot (or None for the unbounded fragment).

Source

pub fn is_complete(&self) -> bool

true once the cursor reaches end — both sides should now close the carrier cleanly. The runtime rejects further actions after this point with ProtocolError::AlreadyComplete.

Source

pub fn seal(&self) -> Option<SealedRuntime>

Serialise the live runtime state into a stable JSON envelope — the plaintext the §40.t cognitive_states AAD-bound ciphertext wraps. Carries the schema (so resume can verify the protocol hasn’t been swapped under the connection), the residual cursor, and the live credit window snapshot.

Symmetric with Self::resume: runtime.seal() then SessionRuntime::resume(sealed, declared_schema) round-trips when the declared schema matches.

Returns None if and only if the cursor is already at End — a completed dialogue has no residual to seal, so no snapshot is issued (the caller should evict() the prior snapshot instead).

Source

pub fn resume( sealed: SealedRuntime, declared_schema: &SessionType, ) -> Result<Self, ResumeError>

Reconstruct a SessionRuntime from a sealed snapshot, validating the schema matches what the route declares now (defence against protocol-swap attacks where an attacker reuses a sealed snapshot against a different socket whose declaration drifted).

On success the returned runtime resumes from the exact cursor + credit window the disconnected one left behind. The carrier driver then runs the producer/consumer loop as usual.

Source

pub fn try_send(&mut self, got: &str) -> Result<(), ProtocolError>

Producer step !A.S → S. Succeeds iff:

  1. the cursor is Send { payload, … } with payload == got;
  2. the credit window (if any) has available > 0 — otherwise the §41.c “no rule at n=0” axiom fires. On success the cursor advances (unfolded) and one credit is consumed (when the window is present).
Source

pub fn try_recv(&mut self, got: &str) -> Result<(), ProtocolError>

Consumer step ?A.S → S. The peer just produced an !A.S frame. Symmetric to [try_send] — payload must match, the cursor advances, and one credit is refilled (if a window is present).

Source

pub fn try_select(&mut self, label: &str) -> Result<(), ProtocolError>

Internal choice () — we select the labelled arm. Cursor must be Select { arms } containing label; on success the cursor advances into that arm’s continuation.

Source

pub fn try_offer(&mut self, label: &str) -> Result<(), ProtocolError>

External choice (&) — the peer selected this label; we accept. Cursor must be Branch { arms } containing label.

Source

pub fn try_end(&mut self) -> Result<(), ProtocolError>

end step — terminates the dialogue. Cursor must already be End; otherwise the peer is signalling termination mid-protocol.

Trait Implementations§

Source§

impl Clone for SessionRuntime

Source§

fn clone(&self) -> SessionRuntime

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 Debug for SessionRuntime

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SessionRuntime

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SessionRuntime

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> Same for T

Source§

type Output = T

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