59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
//! Native, read-only Chrony + Linux kernel quality observation.
|
|
//! This is a source sample, never a job grant or a clock-setting interface.
|
|
#[cfg(target_os = "linux")]
|
|
mod native;
|
|
#[cfg(any(target_os = "linux", test))]
|
|
mod tracking;
|
|
#[cfg(target_os = "linux")]
|
|
pub use native::NativeTimeSource;
|
|
|
|
use uuid::Uuid;
|
|
|
|
/// Constructible only by the native authenticated observation. Consumers must
|
|
/// account for all further elapsed time before signing a response; no holdover.
|
|
#[derive(Debug)]
|
|
pub struct QualifiedSample {
|
|
captured_utc_ns: i64,
|
|
server_error_ns: u64,
|
|
source_sync_age_ns: u64,
|
|
server_boot_id: Uuid,
|
|
captured_monotonic_ns: u64,
|
|
sampled_boottime_ns: u64,
|
|
kernel_state: i32,
|
|
}
|
|
impl QualifiedSample {
|
|
pub fn captured_utc_ns(&self) -> i64 {
|
|
self.captured_utc_ns
|
|
}
|
|
pub fn server_error_ns(&self) -> u64 {
|
|
self.server_error_ns
|
|
}
|
|
pub fn source_sync_age_ns(&self) -> u64 {
|
|
self.source_sync_age_ns
|
|
}
|
|
pub fn server_boot_id(&self) -> Uuid {
|
|
self.server_boot_id
|
|
}
|
|
pub fn captured_monotonic_ns(&self) -> u64 {
|
|
self.captured_monotonic_ns
|
|
}
|
|
pub fn sampled_boottime_ns(&self) -> u64 {
|
|
self.sampled_boottime_ns
|
|
}
|
|
pub fn kernel_state(&self) -> i32 {
|
|
self.kernel_state
|
|
}
|
|
}
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
pub struct NativeTimeSource;
|
|
#[cfg(not(target_os = "linux"))]
|
|
impl NativeTimeSource {
|
|
pub fn open() -> anyhow::Result<Self> {
|
|
anyhow::bail!("TIME_SOURCE_LINUX_REQUIRED")
|
|
}
|
|
pub fn sample(&mut self) -> anyhow::Result<QualifiedSample> {
|
|
anyhow::bail!("TIME_SOURCE_LINUX_REQUIRED")
|
|
}
|
|
}
|