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

Method construct

clock-bound/src/daemon.rs:71–172  ·  view source on GitHub ↗

Construct and initialize a new daemon FIXME: Make this function not async. (Currently required for the io.run methods)

(cancellation_token: CancellationToken)

Source from the content-addressed store, hash-verified

69 /// Construct and initialize a new daemon
70 /// FIXME: Make this function not async. (Currently required for the io.run methods)
71 pub async fn construct(cancellation_token: CancellationToken) -> Self {
72 let daemon_info = DaemonInfo {
73 major_version: 2,
74 minor_version: 100,
75 startup_id: rng().next_u64(),
76 };
77
78 let clock_state_cancellation_token = CancellationToken::new();
79
80 let selected_clock = Arc::new(SelectedClockSource::default());
81
82 // Initialize IO components.
83 let mut io_front_end = io::SourceIO::construct(selected_clock.clone(), daemon_info);
84 let clock_disruption_receiver = io_front_end.clock_disruption_receiver();
85
86 // Initialize link-local event buffer and IO component.
87 let (link_local_tx, link_local_rx) = async_ring_buffer::create(2);
88 io_front_end.create_link_local(link_local_tx).await;
89
90 // Initialize ntp source event buffer and IO component.
91 let ntp_sources =
92 clock_sync_algorithm::source::NtpSource::create_time_aws_sources(MAX_DISPERSION_GROWTH);
93 let (ntp_source_event_senders, ntp_source_event_receivers) =
94 Self::init_ntp_source_buffers(2, &ntp_sources);
95 for source in ntp_source_event_senders {
96 io_front_end.create_ntp_source(source).await;
97 }
98
99 // Initialize vmclock IO component.
100 io_front_end.create_vmclock(VMCLOCK_SHM_DEFAULT_PATH).await;
101 #[expect(clippy::redundant_closure_for_method_calls)]
102 let disruption_marker = io_front_end
103 .vmclock()
104 .map(|vmclock| vmclock.last_disruption_marker())
105 .unwrap_or_default();
106 let clock_disruption_support_enabled = io_front_end.vmclock().is_some();
107
108 // Initialize PHC event buffer and IO component.
109 let (phc_tx, phc_rx) = async_ring_buffer::create(2);
110 io_front_end.create_phc(phc_tx).await;
111
112 // Note: Failure to create a PHC IO component here is considered non-fatal,
113 // we will continue without using the device as an clock sync input.
114 let phc = io_front_end.phc().map(|io_phc| {
115 clock_sync_algorithm::source::Phc::new(
116 io_phc.device_path().to_owned(),
117 MAX_DISPERSION_GROWTH,
118 )
119 });
120 let phc_rx = if io_front_end.phc_exists() {
121 Some(phc_rx)
122 } else {
123 None
124 };
125
126 // Initialize clock sync algorithm.
127 let clock_sync_algorithm = ClockSyncAlgorithm::builder()
128 .link_local(clock_sync_algorithm::source::LinkLocal::new(

Callers

nothing calls this directly

Calls 13

createFunction · 0.85
create_link_localMethod · 0.80
create_ntp_sourceMethod · 0.80
create_vmclockMethod · 0.80
vmclockMethod · 0.80
create_phcMethod · 0.80
device_pathMethod · 0.80
phc_existsMethod · 0.80
newFunction · 0.50
phcMethod · 0.45

Tested by

no test coverage detected