Mountain/Binary/Build/DnsCommands/StartupTime.rs
1//! DNS server startup-time storage. The wall-clock instant the
2//! Hickory server bound its UDP socket is captured once and
3//! returned to the webview via `dns_get_server_info`.
4//!
5//! Two siblings live here for cohesion: `init_dns_startup_time`
6//! (fire-and-forget setter called from the bind path) and
7//! private `Get` (read accessor used by `dns_get_server_info`).
8
9use std::time::{SystemTime, UNIX_EPOCH};
10
11use once_cell::sync::OnceCell;
12
13static DNS_STARTUP_TIME:OnceCell<String> = OnceCell::new();
14
15/// Records the moment the DNS server starts. Idempotent - the
16/// `OnceCell` swallows subsequent calls.
17pub fn init_dns_startup_time() {
18 let now_iso = SystemTime::now()
19 .duration_since(UNIX_EPOCH)
20 .map(|d| {
21 let secs = d.as_secs();
22 let hh = (secs % 86400) / 3600;
23 let mm = (secs % 3600) / 60;
24 let ss = secs % 60;
25 format!("T{:02}:{:02}:{:02}Z", hh, mm, ss)
26 })
27 .unwrap_or_else(|_| "unknown".to_string());
28
29 let _ = DNS_STARTUP_TIME.set(now_iso);
30}
31
32pub(super) fn Get() -> String { DNS_STARTUP_TIME.get().cloned().unwrap_or_else(|| "unknown".to_string()) }