Skip to main content

A2ARouter

Struct A2ARouter 

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

Agent-to-agent message router.

Manages per-agent inboxes (bounded mpsc channels), validates IPC scope through the capability checker, and routes messages to their targets (direct PID, topic, broadcast, service).

Implementations§

Source§

impl A2ARouter

Source

pub fn new( process_table: Arc<ProcessTable>, capability_checker: Arc<CapabilityChecker>, topic_router: Arc<TopicRouter>, ) -> Self

Create a new A2A router.

Source

pub fn with_service_registry(self, registry: Arc<ServiceRegistry>) -> Self

Attach a service registry for service-based routing (D1, D19).

Source

pub fn with_gate(self, gate: Arc<dyn GateBackend>) -> Self

Attach a routing-time gate for dual-layer governance (C4).

When set, every message routed through send() is checked against the gate before inbox delivery. A Deny decision blocks the message; Defer still delivers (the handler-time gate decides).

Source

pub fn set_gate(&self, gate: Arc<dyn GateBackend>)

Set the routing-time gate after construction (for boot wiring).

This allows the governance gate to be attached after the router is already wrapped in an Arc, since the OnceLock provides interior mutability for the first (and only) write.

Source

pub fn service_registry(&self) -> Option<&Arc<ServiceRegistry>>

Get the service registry (if configured).

Source

pub fn create_inbox(&self, pid: Pid) -> Receiver<KernelMessage>

Create an inbox for a process.

Returns the receiver half that the agent should poll for incoming messages. The sender half is stored internally for routing.

If an inbox already exists for this PID, the old one is replaced (existing messages are lost).

Source

pub fn remove_inbox(&self, pid: Pid)

Remove an inbox (used during process cleanup).

Source

pub async fn send(&self, msg: KernelMessage) -> KernelResult<()>

Send a message, routing it to the appropriate target.

Validates that the sender exists and is running, checks IPC scope via the capability checker, then delivers the message to the target.

§Routing
  • Process(pid): delivers directly to the target’s inbox
  • Topic(name): publishes to all topic subscribers
  • Broadcast: delivers to all inboxes except the sender
  • Service(name): logs a warning (service routing is a future extension)
  • Kernel: logs a warning (kernel messages are internal)
§Errors

Returns KernelError::ProcessNotFound if the sender PID is not in the process table, or KernelError::CapabilityDenied if the sender’s IPC scope does not permit the target.

Source

pub async fn send_checked( &self, msg: KernelMessage, chain: Option<&ChainManager>, ) -> KernelResult<()>

Send a message with chain-event logging.

This mirrors KernelIpc::send_checked but for the A2ARouter: every routed message is logged as an ipc.send chain event with sender, target, payload type, and message ID — forming a tamper-evident IPC audit trail in the exochain.

When the exochain feature is disabled this is equivalent to a plain send().

Source

pub fn topic_router(&self) -> &Arc<TopicRouter>

Get the topic router.

Source

pub fn inbox_count(&self) -> usize

Get the number of active inboxes.

Source

pub fn has_inbox(&self, pid: Pid) -> bool

Check whether a PID has an inbox.

Source

pub async fn request( &self, msg: KernelMessage, timeout: Duration, ) -> KernelResult<KernelMessage>

Send a request and wait for a correlated response with timeout.

The request message is sent normally, but its id is registered as a pending request. When a response arrives with a matching correlation_id, it is delivered to the returned future instead of the sender’s inbox.

§Errors

Returns KernelError::Timeout if no response arrives within the specified duration, or KernelError::Ipc if the response channel is closed before a response arrives.

Source

pub fn try_complete_request(&self, msg: KernelMessage) -> bool

Try to complete a pending request with a correlated response.

If the message has a correlation_id that matches a pending request, the response is delivered to the waiting future and true is returned. Otherwise returns false.

Source

pub fn pending_request_count(&self) -> usize

Get the number of pending requests.

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> 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: 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: 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, 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