Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions ntp-proto/src/algorithm/kalman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,18 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
}
}

let selection = select::select(
&self.synchronization_config,
&self.algo_config,
self.sources
.iter()
.filter_map(
|(_, (state, usable))| {
if *usable { state.as_ref() } else { None }
},
)
.cloned()
.collect(),
);
let candidates: Vec<_> = self
.sources
.iter()
.filter_map(
|(_, (state, usable))| {
if *usable { state.as_ref() } else { None }
},
)
.cloned()
.collect();
let selection =
select::select(&self.synchronization_config, &self.algo_config, &candidates);

if let Some(combined) = combine(&selection, &self.algo_config) {
info!(
Expand Down
28 changes: 14 additions & 14 deletions ntp-proto/src/algorithm/kalman/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ enum BoundType {
pub(super) fn select<Index: Copy>(
synchronization_config: &SynchronizationConfig,
algo_config: &AlgorithmConfig,
candidates: Vec<SourceSnapshot<Index>>,
candidates: &[SourceSnapshot<Index>],
) -> Vec<SourceSnapshot<Index>> {
let mut bounds: Vec<(f64, BoundType)> = Vec::with_capacity(2 * candidates.len());

for snapshot in &candidates {
for snapshot in candidates {
if snapshot.period.is_some() {
// Do not let periodic sources be part of the vote for correct time
continue;
Expand Down Expand Up @@ -156,7 +156,7 @@ mod tests {
..Default::default()
};

let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);

let algconfig = AlgorithmConfig {
Expand All @@ -165,7 +165,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);

let algconfig = AlgorithmConfig {
Expand All @@ -174,7 +174,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates);
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 4);
}

Expand All @@ -197,7 +197,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 3);

let algconfig = AlgorithmConfig {
Expand All @@ -206,7 +206,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 2);

let algconfig = AlgorithmConfig {
Expand All @@ -215,7 +215,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 1);

let algconfig = AlgorithmConfig {
Expand All @@ -224,7 +224,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates);
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);
}

Expand All @@ -249,14 +249,14 @@ mod tests {
minimum_agreeing_sources: 3,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 3);

let sysconfig = SynchronizationConfig {
minimum_agreeing_sources: 4,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates);
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);
}

Expand All @@ -279,7 +279,7 @@ mod tests {
minimum_agreeing_sources: 1,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates);
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);
}

Expand All @@ -299,14 +299,14 @@ mod tests {
minimum_agreeing_sources: 2,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 3);
assert_eq!(result[0].offset(), 0.5);
let sysconfig = SynchronizationConfig {
minimum_agreeing_sources: 3,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates);
let result = select(&sysconfig, &algconfig, &candidates);
assert_eq!(result.len(), 0);
}
}
6 changes: 3 additions & 3 deletions ntp-proto/src/algorithm/kalman/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ mod tests {
D: Debug + Clone + Copy,
N: MeasurementNoiseEstimator<MeasurementDelay = D> + Clone,
>(
noise_estimator: N,
noise_estimator: &N,
delay: D,
) {
let base = NtpTimestamp::from_fixed_int(0);
Expand Down Expand Up @@ -1359,7 +1359,7 @@ mod tests {
#[test]
fn test_offset_steering_and_measurements_normal() {
test_offset_steering_and_measurements(
AveragingBuffer {
&AveragingBuffer {
data: [0.0, 0.0, 0.0, 0.0, 0.875e-6, 0.875e-6, 0.875e-6, 0.875e-6],
next_idx: 0,
},
Expand All @@ -1370,7 +1370,7 @@ mod tests {
#[test]
fn test_offset_steering_and_measurements_constant_noise_estimate() {
test_offset_steering_and_measurements(
FixedMeasurementNoise {
&FixedMeasurementNoise {
precision: 1e-9,
accuracy: 0.0,
},
Expand Down
2 changes: 1 addition & 1 deletion ntp-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#![warn(clippy::needless_bitwise_bool)]
#![warn(clippy::needless_continue)]
#![warn(clippy::needless_for_each)]
//FIXME: Enable #![warn(clippy::needless_pass_by_value)]
#![warn(clippy::needless_pass_by_value)]
#![warn(clippy::needless_raw_string_hashes)]
#![warn(clippy::no_effect_underscore_binding)]
#![warn(clippy::no_mangle_with_rust_abi)]
Expand Down
14 changes: 7 additions & 7 deletions ntp-proto/src/nts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub struct KeyExchangeClient {
}

impl KeyExchangeClient {
pub fn new(config: NtsClientConfig) -> Result<Self, NtsError> {
pub fn new(config: &NtsClientConfig) -> Result<Self, NtsError> {
let builder = tls_utils::client_config_builder_with_protocol_versions(&[&TLS13]);
let verifier =
tls_utils::PlatformVerifier::new_with_extra_roots(config.certificates.iter().cloned())?
Expand Down Expand Up @@ -884,7 +884,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V4,
})
Expand Down Expand Up @@ -946,7 +946,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V5,
})
Expand Down Expand Up @@ -1008,7 +1008,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V4UpgradingToV5 { tries_left: 8 },
})
Expand Down Expand Up @@ -1070,7 +1070,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V4UpgradingToV5 { tries_left: 8 },
})
Expand Down Expand Up @@ -1132,7 +1132,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V5,
})
Expand Down Expand Up @@ -1178,7 +1178,7 @@ mod tests {
)
.collect::<Result<Arc<_>, _>>()
.unwrap();
let kex = KeyExchangeClient::new(NtsClientConfig {
let kex = KeyExchangeClient::new(&NtsClientConfig {
certificates,
protocol_version: ProtocolVersion::V4,
})
Expand Down
Loading
Loading