Skip to content

Commit ea1c50c

Browse files
davidv1992rnijveld
authored andcommitted
Remove SourceId from ObservableSourceState.
1 parent 06d97ec commit ea1c50c

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

ntp-proto/src/algorithm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct StateUpdate<ControllerMessage> {
3535
}
3636

3737
// Note: this default implementation is necessary since the
38-
// derive only works if SourceId is Default (which it isn't
38+
// derive only works if ControllerMessage is Default (which it isn't
3939
// necessarily)
4040
impl<ControllerMessage> Default for StateUpdate<ControllerMessage> {
4141
fn default() -> Self {

ntp-proto/src/source.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
NtpVersion,
2+
ClockId, NtpVersion,
33
algorithm::Measurement,
44
packet::{
55
ExtensionField, NtpHeader,
@@ -117,12 +117,7 @@ impl<Controller: SourceController<MeasurementDelay = ()>> OneWaySource<Controlle
117117
self.controller.handle_message(message);
118118
}
119119

120-
pub fn observe<SourceId>(
121-
&self,
122-
name: String,
123-
address: String,
124-
id: SourceId,
125-
) -> ObservableSourceState<SourceId> {
120+
pub fn observe(&self, name: String, address: String, id: ClockId) -> ObservableSourceState {
126121
ObservableSourceState {
127122
timedata: self.controller.observe(),
128123
unanswered_polls: 0,
@@ -432,15 +427,15 @@ macro_rules! actions {
432427
}
433428

434429
#[derive(Debug, Serialize, Deserialize, Clone)]
435-
pub struct ObservableSourceState<SourceId> {
430+
pub struct ObservableSourceState {
436431
#[serde(flatten)]
437432
pub timedata: ObservableSourceTimedata,
438433
pub unanswered_polls: u32,
439434
pub poll_interval: PollInterval,
440435
pub nts_cookies: Option<usize>,
441436
pub name: String,
442437
pub address: String,
443-
pub id: SourceId,
438+
pub id: ClockId,
444439
}
445440

446441
impl<Controller: SourceController<MeasurementDelay = NtpDuration>> NtpSource<Controller> {
@@ -482,7 +477,7 @@ impl<Controller: SourceController<MeasurementDelay = NtpDuration>> NtpSource<Con
482477
)
483478
}
484479

485-
pub fn observe<SourceId>(&self, name: String, id: SourceId) -> ObservableSourceState<SourceId> {
480+
pub fn observe(&self, name: String, id: ClockId) -> ObservableSourceState {
486481
ObservableSourceState {
487482
timedata: self.controller.observe(),
488483
unanswered_polls: self.reach.unanswered_polls(),

ntpd/src/daemon/ntp_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct SourceChannels<ControllerMessage, SourceMessage> {
4949
pub msg_for_system_sender: tokio::sync::mpsc::Sender<MsgForSystem<SourceMessage>>,
5050
pub system_update_receiver:
5151
tokio::sync::broadcast::Receiver<SystemSourceUpdate<ControllerMessage>>,
52-
pub source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>>,
52+
pub source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>>,
5353
}
5454

5555
pub(crate) struct SourceTask<

ntpd/src/daemon/observer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
1717
pub struct ObservableState {
1818
pub program: ProgramData,
1919
pub system: SystemSnapshot,
20-
pub sources: Vec<ObservableSourceState<ClockId>>,
20+
pub sources: Vec<ObservableSourceState>,
2121
pub servers: Vec<ObservableServerState>,
2222
}
2323

@@ -70,7 +70,7 @@ impl From<&ServerData> for ObservableServerState {
7070
#[instrument(level = tracing::Level::ERROR, skip_all, name = "Observer", fields(path = debug(config.observation_path.clone())))]
7171
pub fn spawn<C: 'static + NtpClock + Send>(
7272
config: &super::config::ObservabilityConfig,
73-
sources_reader: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>>,
73+
sources_reader: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>>,
7474
server_reader: tokio::sync::watch::Receiver<Vec<ServerData>>,
7575
system_reader: tokio::sync::watch::Receiver<SystemSnapshot>,
7676
clock: C,
@@ -92,7 +92,7 @@ pub fn spawn<C: 'static + NtpClock + Send>(
9292

9393
async fn observer<C: 'static + NtpClock + Send>(
9494
config: super::config::ObservabilityConfig,
95-
sources_reader: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>>,
95+
sources_reader: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>>,
9696
server_reader: tokio::sync::watch::Receiver<Vec<ServerData>>,
9797
system_reader: tokio::sync::watch::Receiver<SystemSnapshot>,
9898
clock: C,
@@ -174,7 +174,7 @@ async fn observer<C: 'static + NtpClock + Send>(
174174
async fn handle_connection(
175175
stream: &mut (impl tokio::io::AsyncWrite + Unpin),
176176
start_time: Instant,
177-
sources_reader: &std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>,
177+
sources_reader: &std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>,
178178
server_reader: tokio::sync::watch::Receiver<Vec<ServerData>>,
179179
system_reader: tokio::sync::watch::Receiver<SystemSnapshot>,
180180
now: NtpTimestamp,

ntpd/src/daemon/system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<T: Wait> Wait for SingleshotSleep<T> {
8585
}
8686

8787
pub struct DaemonChannels {
88-
pub source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>>,
88+
pub source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>>,
8989
pub server_data_receiver: tokio::sync::watch::Receiver<Vec<ServerData>>,
9090
pub system_snapshot_receiver: tokio::sync::watch::Receiver<SystemSnapshot>,
9191
}
@@ -185,7 +185,7 @@ struct SystemTask<C: NtpClock, Controller: TimeSyncController<Clock = C>, T: Wai
185185
system_snapshot_sender: tokio::sync::watch::Sender<SystemSnapshot>,
186186
system_update_sender:
187187
tokio::sync::broadcast::Sender<SystemSourceUpdate<Controller::ControllerMessage>>,
188-
source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState<ClockId>>>>,
188+
source_snapshots: Arc<std::sync::RwLock<HashMap<ClockId, ObservableSourceState>>>,
189189
server_data_sender: tokio::sync::watch::Sender<Vec<ServerData>>,
190190
keyset: tokio::sync::watch::Receiver<Arc<KeySet>>,
191191
ip_list: tokio::sync::watch::Receiver<Arc<[IpAddr]>>,

0 commit comments

Comments
 (0)