Skip to main content

pim_core/
debug.rs

1//! Shared runtime debug snapshot models used by the daemon and CLI.
2
3#![allow(missing_docs)]
4
5use serde::{Deserialize, Serialize};
6
7/// Versioned snapshot of live daemon state for debug/inspection commands.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct DebugSnapshot {
10    /// Snapshot schema version.
11    pub version: u32,
12    /// Unix timestamp when the snapshot was generated.
13    pub generated_at_unix_secs: u64,
14    /// Local node runtime information.
15    pub node: DebugNodeSnapshot,
16    /// High-level counters and rates exposed by the daemon.
17    pub stats: DebugStatsSnapshot,
18    /// Live connected peers.
19    pub peers: Vec<DebugPeerSnapshot>,
20    /// Peers observed via discovery, whether connected or not.
21    pub discovered_peers: Vec<DebugDiscoveredPeerSnapshot>,
22    /// Installed routes currently used for forwarding.
23    pub routes: Vec<DebugRouteSnapshot>,
24    /// Known gateways sorted by preference.
25    pub gateways: Vec<DebugGatewaySnapshot>,
26}
27
28/// Local node runtime information.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct DebugNodeSnapshot {
31    pub name: String,
32    pub node_id: String,
33    pub short_id: String,
34    pub is_gateway: bool,
35    pub mesh_ip: String,
36    pub mesh_prefix_len: u8,
37}
38
39/// Common stats for operator-facing debug commands.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct DebugStatsSnapshot {
42    pub peers: usize,
43    pub routes: usize,
44    pub packets_forwarded: u64,
45    pub bytes_forwarded: u64,
46    pub packets_dropped: u64,
47    pub congestion_drops: u64,
48    pub conntrack_size: usize,
49    pub uptime_secs: u64,
50}
51
52/// Live peer session information.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct DebugPeerSnapshot {
55    pub node_id: String,
56    pub short_id: String,
57    pub addr: Option<String>,
58    pub mechanism: Option<String>,
59    pub direct: bool,
60    pub configured: bool,
61    pub discovered: bool,
62    pub last_heartbeat_age_ms: Option<u64>,
63}
64
65/// Discovery-layer peer observation.
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct DebugDiscoveredPeerSnapshot {
68    pub node_id: String,
69    pub short_id: String,
70    pub addr: String,
71    pub is_client: bool,
72    pub is_relay: bool,
73    pub is_gateway: bool,
74    pub last_seen_age_ms: u64,
75}
76
77/// Installed route entry.
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct DebugRouteSnapshot {
80    pub destination_id: String,
81    pub destination_short_id: String,
82    pub next_hop_id: String,
83    pub next_hop_short_id: String,
84    pub learned_from_id: String,
85    pub learned_from_short_id: String,
86    pub hops: u8,
87    pub is_gateway: bool,
88    pub gateway_load: u8,
89    pub rtt_ms: Option<u32>,
90    pub mesh_ip: Option<String>,
91    pub age_ms: u64,
92    pub next_hop_blacklisted: bool,
93}
94
95/// Gateway ranking details derived from installed routes.
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct DebugGatewaySnapshot {
98    pub node_id: String,
99    pub short_id: String,
100    pub next_hop_id: String,
101    pub next_hop_short_id: String,
102    pub hops: u8,
103    pub gateway_load: u8,
104    pub rtt_ms: Option<u32>,
105    pub score: u32,
106    pub selected: bool,
107    pub mesh_ip: Option<String>,
108}