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 limitation

Discovery queries are forwarded across multiple hops via gossip. However, discovery responses are currently sent only to the direct sender of the query (one hop back) rather than being relayed all the way to the original querier. In practice this means that services more than one hop away will generate responses that reach intermediate forwarders but not the node that initiated the query. Multi-hop response relay is planned for a future release.

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 limitation note on MeshServices.

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