Skip to main content

zlayer_types/api/
overlay.rs

1//! Overlay network API DTOs.
2//!
3//! Wire types for the overlay network status endpoints. These are the
4//! response shapes consumed by both the daemon and SDK clients.
5
6use serde::{Deserialize, Serialize};
7use utoipa::ToSchema;
8
9/// Overlay network status response
10#[derive(Debug, Serialize, Deserialize, ToSchema)]
11pub struct OverlayStatusResponse {
12    /// Overlay interface name
13    pub interface: String,
14    /// Whether this node is the cluster leader
15    pub is_leader: bool,
16    /// Node's overlay IP address
17    pub node_ip: String,
18    /// Overlay network CIDR
19    pub cidr: String,
20    /// Overlay listen port (`WireGuard` protocol)
21    pub port: u16,
22    /// Total number of peers
23    pub total_peers: usize,
24    /// Number of healthy peers
25    pub healthy_peers: usize,
26    /// Number of unhealthy peers
27    pub unhealthy_peers: usize,
28    /// Last health check timestamp (unix epoch seconds)
29    pub last_check: u64,
30}
31
32/// Peer information
33#[derive(Debug, Serialize, Deserialize, ToSchema)]
34pub struct PeerInfo {
35    /// Peer's public key
36    pub public_key: String,
37    /// Peer's overlay IP address
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub overlay_ip: Option<String>,
40    /// Whether the peer is healthy
41    pub healthy: bool,
42    /// Seconds since last handshake
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub last_handshake_secs: Option<u64>,
45    /// Last ping latency in milliseconds
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub last_ping_ms: Option<u64>,
48    /// Number of consecutive health check failures
49    pub failure_count: u32,
50    /// Last health check timestamp (unix epoch seconds)
51    pub last_check: u64,
52}
53
54/// Peer list response
55#[derive(Debug, Serialize, Deserialize, ToSchema)]
56pub struct PeerListResponse {
57    /// Total number of peers
58    pub total: usize,
59    /// Number of healthy peers
60    pub healthy: usize,
61    /// List of peer information
62    pub peers: Vec<PeerInfo>,
63}
64
65/// IP allocation status response
66#[derive(Debug, Serialize, Deserialize, ToSchema)]
67pub struct IpAllocationResponse {
68    /// Overlay network CIDR
69    pub cidr: String,
70    /// Total available IPs in the range
71    pub total_ips: u32,
72    /// Number of allocated IPs
73    pub allocated_count: usize,
74    /// Number of available IPs
75    pub available_count: u32,
76    /// Utilization percentage (0.0 - 100.0)
77    pub utilization_percent: f64,
78    /// List of allocated IP addresses (only included if requested)
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub allocated_ips: Option<Vec<String>>,
81}
82
83/// NAT traversal status response
84#[derive(Debug, Serialize, Deserialize, ToSchema)]
85pub struct NatStatusResponse {
86    /// Whether NAT traversal is enabled in the daemon's config
87    pub enabled: bool,
88    /// Configured STUN servers (host:port)
89    pub stun_servers: Vec<String>,
90    /// Configured TURN/relay servers (host:port)
91    pub turn_servers: Vec<String>,
92    /// Address of the locally-bound built-in relay server, if running
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub relay_server_bind: Option<String>,
95    /// Locally gathered ICE candidates
96    pub candidates: Vec<NatCandidateDto>,
97    /// Per-peer NAT connectivity state
98    pub peers: Vec<NatPeerDto>,
99    /// Unix epoch seconds of the last successful STUN refresh
100    pub last_refresh: u64,
101}
102
103/// Locally gathered NAT candidate (`Host` / `ServerReflexive` / `Relay`).
104#[derive(Debug, Serialize, Deserialize, ToSchema)]
105pub struct NatCandidateDto {
106    /// `Host` / `ServerReflexive` / `Relay`
107    pub kind: String,
108    /// Transport (e.g. "udp")
109    pub transport: String,
110    /// Address (host:port)
111    pub address: String,
112    /// Priority (higher = preferred)
113    pub priority: u32,
114}
115
116/// Per-peer NAT connectivity entry.
117#[derive(Debug, Serialize, Deserialize, ToSchema)]
118pub struct NatPeerDto {
119    /// Peer node ID
120    pub node_id: String,
121    /// Direct / `HolePunched` / Relayed / Unreachable
122    pub connection_type: String,
123    /// Selected remote endpoint, if any
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub remote_endpoint: Option<String>,
126}
127
128/// DNS service status response
129#[derive(Debug, Serialize, Deserialize, ToSchema)]
130pub struct DnsStatusResponse {
131    /// Whether DNS service is enabled
132    pub enabled: bool,
133    /// DNS zone name
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub zone: Option<String>,
136    /// DNS server port
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub port: Option<u16>,
139    /// DNS server bind address
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub bind_addr: Option<String>,
142    /// Number of registered services
143    pub service_count: usize,
144    /// List of registered service names
145    pub services: Vec<String>,
146}