Skip to main content

Mountain/Binary/Build/DnsCommands/
StartupTime.rs

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