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
impl MeshServices
Sourcepub fn register_service(
&mut self,
descriptor: ServiceDescriptor,
) -> Result<(), ServiceError>
pub fn register_service( &mut self, descriptor: ServiceDescriptor, ) -> Result<(), ServiceError>
Registers a local service.
Sourcepub fn unregister_service(
&mut self,
service_id: &str,
) -> Result<bool, ServiceError>
pub fn unregister_service( &mut self, service_id: &str, ) -> Result<bool, ServiceError>
Unregisters a local service. Returns true if it was found and removed.
Sourcepub fn has_service(&self, service_id: &str) -> bool
pub fn has_service(&self, service_id: &str) -> bool
Returns true if a service with the given ID is registered locally.
Sourcepub fn discover_services(
&mut self,
user_id: &str,
known_peers: &[String],
service_id: Option<&str>,
) -> Result<DiscoverResult, ServiceError>
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.
Sourcepub fn send_service_request(
&self,
provider: &str,
service_id: &str,
method: &str,
body: &str,
) -> Result<SendRequestResult, ServiceError>
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.
Sourcepub fn respond_to_service_request(
&self,
request_id: &str,
requester: &str,
service_id: &str,
status: &str,
body: &str,
) -> Result<SendResponseResult, ServiceError>
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.
Sourcepub fn handle_incoming_message(
&mut self,
content: &str,
sender: &str,
hop_count: u8,
user_id: &str,
known_peers: &[String],
) -> ServiceAction
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.
Sourcepub fn cleanup_expired(&mut self)
pub fn cleanup_expired(&mut self)
Removes expired discovery query dedup entries.
Sourcepub fn seen_discovery_queries(&self) -> &HashMap<String, Instant>
pub fn seen_discovery_queries(&self) -> &HashMap<String, Instant>
Provides read access to seen_discovery_queries for testing / inspection.