Skip to main content

offline_protocol_services/
events.rs

1use std::collections::HashMap;
2
3/// Events emitted by mesh service operations.
4#[derive(Debug, Clone, PartialEq)]
5pub enum ServiceEvent {
6    /// A service was discovered on the mesh in response to a discovery query.
7    ServiceDiscovered {
8        /// The query ID this response corresponds to.
9        query_id: String,
10        /// The discovered service's identifier.
11        service_id: String,
12        /// The discovered service's version.
13        version: String,
14        /// The peer providing this service.
15        provider_peer_id: String,
16        /// Capabilities advertised by the service.
17        capabilities: HashMap<String, String>,
18        /// Number of hops the query traveled to reach the provider.
19        hop_count: u8,
20    },
21
22    /// A service request was received from another peer.
23    ServiceRequestReceived {
24        /// Unique request identifier for correlating the response.
25        request_id: String,
26        /// The requested service's identifier.
27        service_id: String,
28        /// The method being invoked.
29        method: String,
30        /// The request body.
31        body: String,
32        /// The peer that sent the request.
33        sender: String,
34    },
35
36    /// A response to a service request was received.
37    ServiceResponseReceived {
38        /// The request ID this response corresponds to.
39        request_id: String,
40        /// The service's identifier.
41        service_id: String,
42        /// Response status (`"ok"`, `"not_found"`, or `"error"`).
43        status: String,
44        /// The response body.
45        body: String,
46        /// The peer that provided the response.
47        provider_peer_id: String,
48    },
49}