Skip to main content

Mountain/Binary/Build/DnsCommands/
StartupTime.rs

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