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: usizeImplementations§
Source§impl SessionHost
impl SessionHost
pub fn new(program: &ProtocolProgram) -> Result<Self, String>
Sourcepub fn new_gated(
program: &ProtocolProgram,
granted: &[String],
) -> Result<Self, String>
pub fn new_gated( program: &ProtocolProgram, granted: &[String], ) -> Result<Self, String>
§35.6: gated constructor — the environment grants capabilities; missing grants reject session opens.
Sourcepub fn peer_satisfies(
card_capabilities: &[String],
) -> impl Fn(&ProtocolProgram) -> Result<(), String> + '_
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)
Sourcepub fn open(&mut self, id: &str, role: &str) -> Result<(), String>
pub fn open(&mut self, id: &str, role: &str) -> Result<(), String>
open a session — capacity AND capability grants are enforced (§35.6)
pub fn close(&mut self, id: &str) -> Result<(), String>
pub fn is_open(&self, id: &str) -> bool
pub fn session_count(&self) -> usize
Sourcepub fn deliver(&mut self, id: &str, ev: Event) -> Result<Vec<OutEvent>, String>
pub fn deliver(&mut self, id: &str, ev: Event) -> Result<Vec<OutEvent>, String>
deliver an event into a session; outs go to the outbox
Sourcepub fn tick(&mut self, elapsed_ms: i64) -> Vec<(SessionId, OutEvent)>
pub fn tick(&mut self, elapsed_ms: i64) -> Vec<(SessionId, OutEvent)>
host-injected time for ALL sessions — journaled per session (§49)
Sourcepub fn journal(&self) -> &[(SessionId, Event)]
pub fn journal(&self) -> &[(SessionId, Event)]
§35.9: the journal (persistent — this IS the state)
Sourcepub fn replay(
program: &ProtocolProgram,
journal: &[(SessionId, Event)],
) -> Result<Self, String>
👎Deprecated: role inference from senders is unsound; use replay_from
pub fn replay( program: &ProtocolProgram, journal: &[(SessionId, Event)], ) -> Result<Self, String>
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.
Sourcepub fn journal_with_roles(
&self,
) -> (Vec<(String, String)>, Vec<String>, Vec<(SessionId, Event)>)
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)
Sourcepub fn replay_from(
program: &ProtocolProgram,
roles: &[(String, String)],
grants: &[String],
journal: &[(SessionId, Event)],
) -> Result<Self, String>
pub fn replay_from( program: &ProtocolProgram, roles: &[(String, String)], grants: &[String], journal: &[(SessionId, Event)], ) -> Result<Self, String>
rebuild from journal + role header
Sourcepub fn sessions_iter(&self) -> impl Iterator<Item = (&String, &Runtime)>
pub fn sessions_iter(&self) -> impl Iterator<Item = (&String, &Runtime)>
iterate open sessions (for tooling)
Sourcepub fn same_state_as(&self, other: &SessionHost) -> bool
pub fn same_state_as(&self, other: &SessionHost) -> bool
compare two hosts’ observable state (for replay verification)