offline_protocol_services/
payloads.rs1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4pub const DISCOVERY_QUERY_DEDUP_TTL_SECS: u64 = 60;
6pub const DISCOVERY_QUERY_DEFAULT_MAX_HOPS: u8 = 10;
8pub const DISCOVERY_GOSSIP_MAX_FANOUT: usize = 5;
10pub const DISCOVERY_INITIAL_BROADCAST_MAX: usize = 20;
12pub const DISCOVERY_QUERY_MAX_DEDUP_ENTRIES: usize = 10_000;
14
15pub const MAX_SERVICE_PAYLOAD_SIZE: usize = 131_072; pub const MAX_SERVICE_BODY_SIZE: usize = 65_536; pub const MAX_SERVICE_METHOD_LEN: usize = 256;
21
22pub const VALID_SERVICE_STATUSES: &[&str] = &["ok", "not_found", "error"];
24
25pub const SVC_MESSAGE_PREFIX: &str = "__SVC_";
27pub const SVC_DISCOVER_QUERY: &str = "__SVC_DISC_Q__";
29pub const SVC_DISCOVER_RESPONSE: &str = "__SVC_DISC_R__";
31pub const SVC_REQUEST: &str = "__SVC_REQ__";
33pub const SVC_RESPONSE: &str = "__SVC_RESP__";
35
36fn default_discovery_max_hops() -> u8 {
37 DISCOVERY_QUERY_DEFAULT_MAX_HOPS
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub(crate) struct ServiceDiscoveryQueryPayload {
43 pub query_id: String,
44 pub originator: String,
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub service_id: Option<String>,
47 #[serde(default = "default_discovery_max_hops")]
48 pub remaining_hops: u8,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53pub(crate) struct ServiceDiscoveryResponsePayload {
54 pub query_id: String,
55 pub service_id: String,
56 pub version: String,
57 pub provider_peer_id: String,
58 pub capabilities: HashMap<String, String>,
59 pub hop_count: u8,
60 #[serde(default)]
62 pub originator: String,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub(crate) struct ServiceRequestPayload {
68 pub request_id: String,
69 pub service_id: String,
70 pub method: String,
71 pub body: String,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76pub(crate) struct ServiceResponsePayload {
77 pub request_id: String,
78 pub service_id: String,
79 pub status: String,
80 pub body: String,
81}