Skip to main content

DirectMessaging

Struct DirectMessaging 

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

Tracks connections and mappings for direct messaging.

This maintains the MachineId → AgentId reverse lookup needed to identify message senders, since ant-quic only knows about MachineIds.

Implementations§

Source§

impl DirectMessaging

Source

pub fn new() -> Self

Create a new DirectMessaging instance.

Source

pub async fn register_agent(&self, agent_id: AgentId, machine_id: MachineId)

Register a mapping from MachineId to AgentId.

Called when an agent is discovered or connected.

Source

pub async fn lookup_agent(&self, machine_id: &MachineId) -> Option<AgentId>

Look up AgentId from MachineId.

Source

pub async fn mark_connected(&self, agent_id: AgentId, machine_id: MachineId)

Mark an agent as connected.

Source

pub async fn mark_disconnected(&self, agent_id: &AgentId)

Mark an agent as disconnected.

Source

pub async fn is_connected(&self, agent_id: &AgentId) -> bool

Check if an agent is currently connected.

Source

pub async fn get_machine_id(&self, agent_id: &AgentId) -> Option<MachineId>

Get the MachineId for a connected agent.

Source

pub async fn connected_agents(&self) -> Vec<AgentId>

Get all currently connected agents.

Source

pub fn subscribe(&self) -> DirectMessageReceiver

Get a receiver for direct messages.

Source

pub fn subscriber_count(&self) -> usize

Current number of live broadcast subscribers.

Used by diagnostics to distinguish “message dispatched to N SSE/WS consumers” from “message silently dropped because no one is listening”.

Source

pub async fn handle_incoming( &self, machine_id: MachineId, sender_agent_id: AgentId, payload: Vec<u8>, verified: bool, trust_decision: Option<TrustDecision>, )

Process an incoming direct message from the network.

Called by the network layer when a direct message is received. The verified and trust_decision fields are populated by the caller based on the identity discovery cache and contact store.

Source

pub async fn recv(&self) -> Option<DirectMessage>

Receive the next direct message (blocking).

Source

pub fn encode_message( sender_agent_id: &AgentId, payload: &[u8], ) -> NetworkResult<Vec<u8>>

Encode a direct message for transmission.

Format: [0x10][sender_agent_id: 32 bytes][payload]

Source

pub fn decode_message(data: &[u8]) -> NetworkResult<(AgentId, Vec<u8>)>

Decode a direct message from the wire.

Returns (sender_agent_id, payload) on success.

Trait Implementations§

Source§

impl Debug for DirectMessaging

Source§

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

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

impl Default for DirectMessaging

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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