pub struct Registry { /* private fields */ }Expand description
An in-process address book and router over session mailboxes.
Cloneable and shared: every clone refers to the same registry. There is no
automatic deregistration — a peer that shuts down stays listed, and a delivery
to it fails with RouteError::Closed (a sweep can come later; §10.1 keeps
this minimal).
Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Self
Sourcepub fn register(&self, id: SessionId, handle: SessionHandle)
pub fn register(&self, id: SessionId, handle: SessionHandle)
Register a peer’s mailbox at id; re-registering replaces it.
Sourcepub fn register_remote(&self, id: SessionId, client: Client)
pub fn register_remote(&self, id: SessionId, client: Client)
Register a peer reachable across a socket — a served session this process can message, and which can reach back if it knows us (§8, S4-4).
Sourcepub fn locals(&self) -> Vec<(SessionId, SessionHandle)>
pub fn locals(&self) -> Vec<(SessionId, SessionHandle)>
The local peers — the in-process handles this registry holds, sorted
by address for a deterministic roster. A socket server serves exactly
these (Self::registered sessions: the root and its team); a peer
reached across a socket (Self::register_remote) is not a local handle
and is omitted, so it is never re-served.
Sourcepub fn remove(&self, id: &SessionId)
pub fn remove(&self, id: &SessionId)
Remove id from the address book and every per-session map, then
re-publish the roster.
Drops the id entry from peers (the address book), owners, models,
states, efforts, and windows, then calls Self::refresh_roster
so every Self::subscriber — a socket server, the TUI — pushes the
SHRUNK roster.
§Notes
- The per-session state watcher
registerspawned (tokio::spawnof awhile state_rx.changed() …loop) ends only when the session drops. It can re-insert astatesentry after this returns, but NEVER apeersentry — soSelf::locals(which readspeers) stays clean andSelf::contains/Self::resolvereport the id gone at once. Documented, not fixed (layering: no back-ref). - Removing an unknown
idis a harmless no-op (refresh_rosterstill runs).
Not idempotent-erroring and not socket-routed: this is the ROOT-LOCAL
retire path (no Request ends a served peer’s session).
Sourcepub fn subscribe(&self) -> Receiver<Vec<(SessionId, SessionHandle)>>
pub fn subscribe(&self) -> Receiver<Vec<(SessionId, SessionHandle)>>
A live view of Self::locals: a receiver seeded with the current
local roster and updated whenever it changes (a session is
registered). A socket server serves it, so a session that appears
after the server started is still reachable — see crate::serve.
Sourcepub fn contains(&self, id: &SessionId) -> bool
pub fn contains(&self, id: &SessionId) -> bool
Whether a peer is already registered at id. A plain existence probe —
unlike Self::resolve, it needs no from and enforces no permitted set.
Sourcepub fn set_owner(&self, worker: SessionId, owner: SessionId)
pub fn set_owner(&self, worker: SessionId, owner: SessionId)
Record the report_back_to edge: worker reports to owner (its
orchestrator). This is the whole ownership tree — a star in v1.
Sourcepub fn set_model(&self, id: SessionId, model: impl Into<String>)
pub fn set_model(&self, id: SessionId, model: impl Into<String>)
Record a session’s effective model id, so the roster this registry feeds
(a socket server’s Sessions push) can name it. Mirrors Self::set_owner
— a plain metadata write, no effect on routing; it RE-PUBLISHES the roster.
Sourcepub fn set_state(&self, id: SessionId, state: MemberState)
pub fn set_state(&self, id: SessionId, state: MemberState)
Mirror a session’s run-state. Called by the per-session watcher
register spawns — NOT by the actor, so the registry keeps NO
back-reference into the kernel (layering). Re-publishes the roster, so
the socket server pushes the change without polling.
Sourcepub fn state_of(&self, id: &SessionId) -> MemberState
pub fn state_of(&self, id: &SessionId) -> MemberState
The state last mirrored for id; Idle when unknown (a remote peer the
registry never watched, or an older server).
Sourcepub fn model_of(&self, id: &SessionId) -> Option<String>
pub fn model_of(&self, id: &SessionId) -> Option<String>
The model recorded for id, if any (Self::set_model). None for a
peer registered without one (e.g. a remote reached across a socket).
Sourcepub fn set_effort(&self, id: SessionId, effort: Option<String>)
pub fn set_effort(&self, id: SessionId, effort: Option<String>)
Record a session’s effective effort. A metadata write, no routing effect — but it RE-PUBLISHES the roster, so a socket push reflects it.
Sourcepub fn effort_of(&self, id: &SessionId) -> Option<String>
pub fn effort_of(&self, id: &SessionId) -> Option<String>
The effort last recorded for id; None when unset OR cleared.
Sourcepub fn set_context_window(&self, id: SessionId, window: u64)
pub fn set_context_window(&self, id: SessionId, window: u64)
Record a session’s context window in tokens. RE-PUBLISHES the roster.
Sourcepub fn window_of(&self, id: &SessionId) -> Option<u64>
pub fn window_of(&self, id: &SessionId) -> Option<u64>
The window last recorded for id; None when unknown.
Sourcepub fn set_models(&self, models: Vec<String>)
pub fn set_models(&self, models: Vec<String>)
Record the connection’s model catalog. Does NOT re-publish — the catalog names no session, so it is not roster data.
Sourcepub fn models(&self) -> Vec<String>
pub fn models(&self) -> Vec<String>
The recorded catalog (empty when unset — ListModels then answers []).
Sourcepub fn permitted(&self, from: &SessionId, to: &SessionId) -> bool
pub fn permitted(&self, from: &SessionId, to: &SessionId) -> bool
Whether from may address to (§10.1): the pair must be joined by an
ownership edge in either direction — an orchestrator and one of its
workers. There are no lateral (worker → worker) edges.
Sourcepub fn resolve(
&self,
from: &SessionId,
to: &SessionId,
) -> Result<Backend, RouteError>
pub fn resolve( &self, from: &SessionId, to: &SessionId, ) -> Result<Backend, RouteError>
Resolve to for from, enforcing the permitted set. Fails
RouteError::Unknown if no peer is registered, else
RouteError::NotPermitted if the sender is out of scope.
Sourcepub fn deliver(
&self,
from: &SessionId,
to: &SessionId,
request: Request,
) -> Result<(), RouteError>
pub fn deliver( &self, from: &SessionId, to: &SessionId, request: Request, ) -> Result<(), RouteError>
Deliver a target-side request to to, attributed to from. The
recipient sees it as if from had sent it directly
(SessionHandle::send_from).