MCPcopy Create free account
hub / github.com/aws/clock-bound / create_ntp_source

Method create_ntp_source

clock-bound/src/daemon/io.rs:125–158  ·  view source on GitHub ↗

Initializes the IO task for sampling a specific NTP Server source. # Panics - If not called within the `tokio` runtime. - If socket binding fails.

(&mut self, source: ntp::NTPSourceSender)

Source from the content-addressed store, hash-verified

123 /// - If not called within the `tokio` runtime.
124 /// - If socket binding fails.
125 pub async fn create_ntp_source(&mut self, source: ntp::NTPSourceSender) {
126 let (server_address, event_sender) = source;
127 info!(
128 "Creating IO source from ntp server at {:#?}.",
129 server_address.ip().to_string()
130 );
131
132 if !self.ntp_sources.contains_key(&server_address) {
133 let (ctrl_sender, ctrl_receiver) = mpsc::channel::<ControlRequest>(1);
134 let clock_disruption_receiver = self.clock_disruption_channels.sender.subscribe();
135
136 let socket = UdpSocket::bind(ntp::UNSPECIFIED_SOCKET_ADDRESS)
137 .await
138 .unwrap();
139
140 let ntp_source = NTPSource::construct(
141 socket,
142 server_address,
143 event_sender,
144 ctrl_receiver,
145 clock_disruption_receiver,
146 self.selected_clock.clone(),
147 self.daemon_info.clone(),
148 );
149
150 let source = Source {
151 state: SourceState::Initialized(ntp_source),
152 ctrl_sender,
153 };
154 self.ntp_sources.insert(server_address, source);
155 }
156
157 info!("Source NTP update complete.");
158 }
159
160 /// Initializes the IO task for sampling the PHC source.
161 ///

Callers 2

constructMethod · 0.80
setupFunction · 0.80

Calls 1

InitializedClass · 0.85

Tested by

no test coverage detected