Skip to main content

SessionHost

Struct SessionHost 

Source
pub struct SessionHost {
    pub program: ProtocolProgram,
    pub capacity: usize,
    /* private fields */
}
Expand description

A multiplexed session host for one protocol program.

Fields§

§program: ProtocolProgram§capacity: usize

Implementations§

Source§

impl SessionHost

Source

pub fn new(program: &ProtocolProgram) -> Result<Self, String>

Source

pub fn new_gated( program: &ProtocolProgram, granted: &[String], ) -> Result<Self, String>

§35.6: gated constructor — the environment grants capabilities; missing grants reject session opens.

Source

pub fn peer_satisfies( card_capabilities: &[String], ) -> impl Fn(&ProtocolProgram) -> Result<(), String> + '_

verify a peer’s capability list against this program’s needs (the AgentCard check, §35.6)

Source

pub fn open(&mut self, id: &str, role: &str) -> Result<(), String>

open a session — capacity AND capability grants are enforced (§35.6)

Source

pub fn close(&mut self, id: &str) -> Result<(), String>

Source

pub fn is_open(&self, id: &str) -> bool

Source

pub fn session_count(&self) -> usize

Source

pub fn deliver(&mut self, id: &str, ev: Event) -> Result<Vec<OutEvent>, String>

deliver an event into a session; outs go to the outbox

Source

pub fn tick(&mut self, elapsed_ms: i64) -> Vec<(SessionId, OutEvent)>

host-injected time for ALL sessions — journaled per session (§49)

Source

pub fn journal(&self) -> &[(SessionId, Event)]

§35.9: the journal (persistent — this IS the state)

Source

pub fn outbox(&self) -> &[(SessionId, OutEvent)]

outbox drain: everything emitted so far

Source

pub fn replay( program: &ProtocolProgram, journal: &[(SessionId, Event)], ) -> Result<Self, String>

👎Deprecated:

role inference from senders is unsound; use replay_from

§35.9: reconstruct a host from a journal — deterministic replay. The replayed host must be indistinguishable from the original. §55: DEPRECATED — role inference from the first sender is UNSOUND (the peer is not the session’s own role). This helper now rebuilds ONLY from journaled opens (the faithful path) and REJECTS legacy journals it cannot reconstruct faithfully; use replay_from.

Source

pub fn journal_with_roles( &self, ) -> (Vec<(String, String)>, Vec<String>, Vec<(SessionId, Event)>)

journal with explicit session→role map (the persistence header) — §49: capability grants are part of the header too (they gate open)

Source

pub fn replay_from( program: &ProtocolProgram, roles: &[(String, String)], grants: &[String], journal: &[(SessionId, Event)], ) -> Result<Self, String>

rebuild from journal + role header

Source

pub fn sessions_iter(&self) -> impl Iterator<Item = (&String, &Runtime)>

iterate open sessions (for tooling)

Source

pub fn same_state_as(&self, other: &SessionHost) -> bool

compare two hosts’ observable state (for replay verification)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

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