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
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 discovery note on
MeshServices for where the responses go.
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.