Skip to main content

MeshServices

Struct MeshServices 

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

Mesh service registry and message handler.

Manages local service registration, discovery query generation and handling, and service request/response routing. All methods return actions (messages to send, events to emit) rather than performing I/O directly.

§Multi-hop discovery

Discovery queries are forwarded across multiple hops via gossip. Discovery responses are sent to the direct sender of the query, never to the originator the payload names, so that a spoofed originator cannot make a provider leak its service list to an arbitrary peer. A node that receives a response it did not originate forwards it as a unicast toward the originator (see try_handle_discover_response) and emits no event of its own; only the originator emits ServiceDiscovered.

Implementations§

Source§

impl MeshServices

Source

pub fn new() -> Self

Creates a new empty service registry.

Source

pub fn register_service( &mut self, descriptor: ServiceDescriptor, ) -> Result<(), ServiceError>

Registers a local service.

Source

pub fn unregister_service( &mut self, service_id: &str, ) -> Result<bool, ServiceError>

Unregisters a local service. Returns true if it was found and removed.

Source

pub fn has_service(&self, service_id: &str) -> bool

Returns true if a service with the given ID is registered locally.

Source

pub fn discover_services( &mut self, user_id: &str, known_peers: &[String], service_id: Option<&str>, ) -> Result<DiscoverResult, ServiceError>

Generates a discovery broadcast to known peers, capped at DISCOVERY_INITIAL_BROADCAST_MAX recipients.

See the multi-hop discovery note on MeshServices for where the responses go.

Source

pub fn send_service_request( &self, provider: &str, service_id: &str, method: &str, body: &str, ) -> Result<SendRequestResult, ServiceError>

Generates a service request message to a specific provider peer.

Source

pub fn respond_to_service_request( &self, request_id: &str, requester: &str, service_id: &str, status: &str, body: &str, ) -> Result<SendResponseResult, ServiceError>

Generates a service response message.

Source

pub fn handle_incoming_message( &mut self, content: &str, sender: &str, hop_count: u8, user_id: &str, known_peers: &[String], ) -> ServiceAction

Handles an incoming message, returning a ServiceAction.

hop_count is the hop count from the incoming message (used in discovery responses). known_peers should exclude the sender.

Source

pub fn cleanup_expired(&mut self)

Removes expired discovery query dedup entries.

Source

pub fn seen_discovery_queries(&self) -> &HashMap<String, Instant>

Provides read access to seen_discovery_queries for testing / inspection.

Trait Implementations§

Source§

impl Default for MeshServices

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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