Skip to content

Commit

Permalink
Change measurement noise to f64 instead of NtpDuration
Browse files Browse the repository at this point in the history
Prevents rounding errors when using from_seconds, especially for small values (<1e-9)
  • Loading branch information
michielp1807 committed Jan 10, 2025
1 parent 92e6dff commit dac1cdb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions ntpd/src/daemon/config/ntp_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{
};

use ntp_proto::tls_utils::Certificate;
use ntp_proto::NtpDuration;
#[cfg(feature = "unstable_ntpv5")]
use ntp_proto::NtpVersion;
use serde::{de, Deserialize, Deserializer};
Expand Down Expand Up @@ -114,14 +113,14 @@ pub struct NtsPoolSourceConfig {
#[serde(deny_unknown_fields)]
pub struct SockSourceConfig {
pub path: PathBuf,
pub measurement_noise_estimate: NtpDuration,
pub measurement_noise_estimate: f64,
}

#[derive(Deserialize, Debug, PartialEq, Clone)]
#[serde(deny_unknown_fields)]
pub struct PpsSourceConfig {
pub path: PathBuf,
pub measurement_noise_estimate: NtpDuration,
pub measurement_noise_estimate: f64,
#[serde(default = "default_period")]
pub period: f64,
}
Expand Down
5 changes: 2 additions & 3 deletions ntpd/src/daemon/spawn/pps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Spawner for PpsSpawner {
SpawnAction::Create(SourceCreateParameters::Pps(PpsSourceCreateParameters {
id: SourceId::new(),
path: self.config.path.clone(),
noise_estimate: self.config.measurement_noise_estimate.to_seconds(),
noise_estimate: self.config.measurement_noise_estimate,
period: self.config.period,
})),
))
Expand Down Expand Up @@ -75,7 +75,6 @@ impl Spawner for PpsSpawner {

#[cfg(test)]
mod tests {
use ntp_proto::NtpDuration;
use tokio::sync::mpsc;

use crate::{
Expand All @@ -93,7 +92,7 @@ mod tests {
let noise_estimate = 1e-6;
let mut spawner = PpsSpawner::new(PpsSourceConfig {
path: socket_path.clone(),
measurement_noise_estimate: NtpDuration::from_seconds(noise_estimate),
measurement_noise_estimate: noise_estimate,
period: 1.,
});
let spawner_id = spawner.get_id();
Expand Down
5 changes: 2 additions & 3 deletions ntpd/src/daemon/spawn/sock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Spawner for SockSpawner {
SpawnAction::Create(SourceCreateParameters::Sock(SockSourceCreateParameters {
id: SourceId::new(),
path: self.config.path.clone(),
noise_estimate: self.config.measurement_noise_estimate.to_seconds(),
noise_estimate: self.config.measurement_noise_estimate,
})),
))
.await?;
Expand Down Expand Up @@ -74,7 +74,6 @@ impl Spawner for SockSpawner {

#[cfg(test)]
mod tests {
use ntp_proto::NtpDuration;
use tokio::sync::mpsc;

use crate::{
Expand All @@ -92,7 +91,7 @@ mod tests {
let noise_estimate = 1e-6;
let mut spawner = SockSpawner::new(SockSourceConfig {
path: socket_path.clone(),
measurement_noise_estimate: NtpDuration::from_seconds(noise_estimate),
measurement_noise_estimate: noise_estimate,
});
let spawner_id = spawner.get_id();
let (action_tx, mut action_rx) = mpsc::channel(MESSAGE_BUFFER_SIZE);
Expand Down

0 comments on commit dac1cdb

Please sign in to comment.