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
impl DirectMessaging
Sourcepub async fn register_agent(&self, agent_id: AgentId, machine_id: MachineId)
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.
Sourcepub async fn lookup_agent(&self, machine_id: &MachineId) -> Option<AgentId>
pub async fn lookup_agent(&self, machine_id: &MachineId) -> Option<AgentId>
Look up AgentId from MachineId.
Sourcepub async fn mark_connected(&self, agent_id: AgentId, machine_id: MachineId)
pub async fn mark_connected(&self, agent_id: AgentId, machine_id: MachineId)
Mark an agent as connected.
Sourcepub async fn mark_disconnected(&self, agent_id: &AgentId)
pub async fn mark_disconnected(&self, agent_id: &AgentId)
Mark an agent as disconnected.
Sourcepub async fn is_connected(&self, agent_id: &AgentId) -> bool
pub async fn is_connected(&self, agent_id: &AgentId) -> bool
Check if an agent is currently connected.
Sourcepub async fn get_machine_id(&self, agent_id: &AgentId) -> Option<MachineId>
pub async fn get_machine_id(&self, agent_id: &AgentId) -> Option<MachineId>
Get the MachineId for a connected agent.
Sourcepub async fn connected_agents(&self) -> Vec<AgentId>
pub async fn connected_agents(&self) -> Vec<AgentId>
Get all currently connected agents.
Sourcepub fn subscribe(&self) -> DirectMessageReceiver
pub fn subscribe(&self) -> DirectMessageReceiver
Get a receiver for direct messages.
Sourcepub fn subscriber_count(&self) -> usize
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”.
Sourcepub async fn handle_incoming(
&self,
machine_id: MachineId,
sender_agent_id: AgentId,
payload: Vec<u8>,
verified: bool,
trust_decision: Option<TrustDecision>,
)
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.
Sourcepub async fn recv(&self) -> Option<DirectMessage>
pub async fn recv(&self) -> Option<DirectMessage>
Receive the next direct message (blocking).
Sourcepub fn encode_message(
sender_agent_id: &AgentId,
payload: &[u8],
) -> NetworkResult<Vec<u8>>
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]
Sourcepub fn decode_message(data: &[u8]) -> NetworkResult<(AgentId, Vec<u8>)>
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
impl Debug for DirectMessaging
Auto Trait Implementations§
impl Freeze for DirectMessaging
impl !RefUnwindSafe for DirectMessaging
impl Send for DirectMessaging
impl Sync for DirectMessaging
impl Unpin for DirectMessaging
impl UnsafeUnpin for DirectMessaging
impl !UnwindSafe for DirectMessaging
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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