Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Nov 30, 2023
1 parent 356f8cc commit 27a63c6
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ntpd/src/daemon/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ impl Config {
PeerConfig::Standard(_) => count += 1,
PeerConfig::Nts(_) => count += 1,
PeerConfig::Pool(config) => count += config.max_peers,
#[cfg(feature = "unstable_nts-pool")]
PeerConfig::NtsPool(config) => count += config.max_peers,
}
}
count
Expand Down
37 changes: 37 additions & 0 deletions ntpd/src/daemon/config/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ fn max_peers_default() -> usize {
4
}

#[cfg(feature = "unstable_nts-pool")]
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(deny_unknown_fields)]
pub struct NtsPoolPeerConfig {
#[serde(rename = "address")]
pub addr: NtsKeAddress,
#[serde(
deserialize_with = "deserialize_certificate_authorities",
default = "default_certificate_authorities",
rename = "certificate-authority"
)]
pub certificate_authorities: Arc<[Certificate]>,
#[serde(rename = "count", default = "max_peers_default")]
pub max_peers: usize,
}

#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
#[serde(tag = "mode")]
pub enum PeerConfig {
Expand All @@ -73,6 +89,9 @@ pub enum PeerConfig {
#[serde(rename = "pool")]
Pool(PoolPeerConfig),
// Consul(ConsulPeerConfig),
#[cfg(feature = "unstable_nts-pool")]
#[serde(rename = "nts-pool")]
NtsPool(NtsPoolPeerConfig),
}

/// A normalized address has a host and a port part. However, the host may be
Expand Down Expand Up @@ -312,6 +331,8 @@ mod tests {
PeerConfig::Standard(c) => c.address.to_string(),
PeerConfig::Nts(c) => c.address.to_string(),
PeerConfig::Pool(c) => c.addr.to_string(),
#[cfg(feature = "unstable_nts-pool")]
PeerConfig::NtsPool(c) => c.addr.to_string(),
}
}

Expand Down Expand Up @@ -396,6 +417,22 @@ mod tests {
if let PeerConfig::Nts(config) = test.peer {
assert_eq!(config.address.to_string(), "example.com:4460");
}

#[cfg(feature = "unstable_nts-pool")]
{
let test: TestConfig = toml::from_str(
r#"
[peer]
address = "example.com"
mode = "nts-pool"
"#,
)
.unwrap();
assert!(matches!(test.peer, PeerConfig::NtsPool(_)));
if let PeerConfig::Nts(config) = test.peer {
assert_eq!(config.address.to_string(), "example.com:4460");
}
}
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions ntpd/src/daemon/spawn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use super::config::NormalizedAddress;
#[cfg(test)]
pub mod dummy;
pub mod nts;
#[cfg(feature = "unstable_nts-pool")]
pub mod nts_pool;
pub mod pool;
pub mod standard;

Expand Down
1 change: 1 addition & 0 deletions ntpd/src/daemon/spawn/nts_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

9 changes: 9 additions & 0 deletions ntpd/src/daemon/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ pub async fn spawn(
std::io::Error::new(std::io::ErrorKind::Other, e)
})?;
}
#[cfg(feature = "unstable_nts-pool")]
PeerConfig::NtsPool(cfg) => {
system
.add_spawner(NtsPoolSpawner::new(cfg.clone(), NETWORK_WAIT_PERIOD))
.map_err(|e| {
tracing::error!("Could not spawn peer: {}", e);
std::io::Error::new(std::io::ErrorKind::Other, e)
})?;
}
}
}

Expand Down

0 comments on commit 27a63c6

Please sign in to comment.