Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pedantic linting #1679

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d0327f9
Add lint config and fixes nts-pool-ke
van-sprundel Oct 12, 2024
0733454
Add lint config in ntpd
van-sprundel Oct 12, 2024
13eef4e
Run clippy fix in ntpd
van-sprundel Oct 12, 2024
bbb7b6d
Fix struct_excessive_bools in ntpd
van-sprundel Oct 12, 2024
1105cd6
Use type name instead of `Default`
van-sprundel Oct 12, 2024
ad7078e
cargo fmt
van-sprundel Oct 12, 2024
4932e06
Handle conversion of floats
van-sprundel Oct 12, 2024
a20cb36
Move struct & enum that are made mid-function
van-sprundel Oct 12, 2024
6fba450
Remove unused `Result<_>` in function
van-sprundel Oct 12, 2024
3c0efba
Mark unfinished function with unused_self
van-sprundel Oct 12, 2024
e7a3906
Use reference and mark funtion as `too_many_lines`
van-sprundel Oct 12, 2024
025e03e
Use `let else` instead of `if else`
van-sprundel Oct 12, 2024
47b8f7d
Remove async when not used, split `run` into functions
van-sprundel Oct 12, 2024
46ea772
assert float check should have a limit
van-sprundel Oct 12, 2024
681fbe8
Revert clippy cast_lossless
van-sprundel Oct 12, 2024
5e56bef
Allow truncation for darwin target
van-sprundel Oct 12, 2024
3160bad
run `cargo fix` for ntp-proto
van-sprundel Oct 12, 2024
ab7ed1c
Mark truncation, wrap, float_cmp and sign loss with #[allow]
van-sprundel Oct 13, 2024
2f94665
Update for loop
van-sprundel Oct 13, 2024
6df86fe
Update references usages
van-sprundel Oct 13, 2024
7b6b874
Use specific defaults
van-sprundel Oct 13, 2024
54861e4
Move function result out of Result<> when redundant
van-sprundel Oct 13, 2024
e94b01a
Mark debug impl with finish_non_exhaustive for hidden fields
van-sprundel Oct 13, 2024
77115e5
Add should_panic messages
van-sprundel Oct 13, 2024
c95e170
Add error and panic docs
van-sprundel Oct 13, 2024
17810db
Update references usage
van-sprundel Oct 13, 2024
cf4a964
Update formatting
van-sprundel Oct 13, 2024
f91ec40
Update function to error instead of panic
van-sprundel Oct 13, 2024
123e854
Remove out of else when redundant
van-sprundel Oct 13, 2024
f1e1d2c
Use find_map(..) instead of filter_map(..).next()
van-sprundel Oct 13, 2024
a9ff7ba
Split big functions
van-sprundel Oct 13, 2024
8038217
Use `let .. else` instead of `let if .. else`
van-sprundel Oct 13, 2024
f065a6d
Put v5 imports behind feature flag
van-sprundel Oct 13, 2024
4878655
Fix formatting
van-sprundel Oct 13, 2024
bbbb15c
allow explicit iter loop
van-sprundel Oct 13, 2024
710e3f2
Put nts-pool imports behind feature flag
van-sprundel Oct 13, 2024
ff49a8b
Fix panic message test
van-sprundel Oct 13, 2024
978b528
Remove flag behind mutable variable
van-sprundel Oct 13, 2024
8c44e3f
Rebase with main
van-sprundel Jan 9, 2025
29db988
Cleanup
van-sprundel Jan 9, 2025
1efcbb9
Fix build for rustls vers
van-sprundel Jan 9, 2025
e75d77e
Undo state behind feature
van-sprundel Jan 9, 2025
bf8825f
Undo changes for ntp_source
van-sprundel Jan 9, 2025
e3cdb00
Remove as_bytes for len check
van-sprundel Jan 9, 2025
240d6f8
Bind lifetime to static instead of inner lifetime
van-sprundel Jan 9, 2025
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
2 changes: 1 addition & 1 deletion ntp-proto/src/algorithm/kalman/combiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(super) fn combine<Index: Copy>(
selection.first().map(|first| {
let mut estimate = first.state;
if !algo_config.ignore_server_dispersion {
estimate = estimate.add_server_dispersion(first.source_uncertainty.to_seconds())
estimate = estimate.add_server_dispersion(first.source_uncertainty.to_seconds());
}

let mut used_sources = vec![(first.index, estimate.uncertainty.determinant())];
Expand Down
2 changes: 1 addition & 1 deletion ntp-proto/src/algorithm/kalman/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct AlgorithmConfig {
#[serde(default = "default_poll_interval_low_weight")]
pub poll_interval_low_weight: f64,
/// Amount which a measurement contributes to the state, above
/// which we start decreasing the poll_interval interval. (weight, 0-1)
/// which we start decreasing the `poll_interval` interval. (weight, 0-1)
#[serde(default = "default_poll_interval_high_weight")]
pub poll_interval_high_weight: f64,
/// Amount of hysteresis in changing the poll interval (count, 1+)
Expand Down
30 changes: 16 additions & 14 deletions ntp-proto/src/algorithm/kalman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
next_update: None,
};
}
for (_, (state, _)) in self.sources.iter_mut() {
for (state, _) in self.sources.values_mut() {
if let Some(ref mut snapshot) = state {
snapshot.state = snapshot.state.progress_time(time, snapshot.wander)
snapshot.state = snapshot.state.progress_time(time, snapshot.wander);
}
}

let selection = select::select(
&self.synchronization_config,
&self.algo_config,
self.sources
&self
.sources
.iter()
.filter_map(
|(_, (state, usable))| {
Expand All @@ -131,8 +132,8 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
}
},
)
.cloned()
.collect(),
.copied()
.collect::<Vec<SourceSnapshot<SourceId>>>(),
);

if let Some(combined) = combine(&selection, &self.algo_config) {
Expand Down Expand Up @@ -237,8 +238,7 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
|| self
.synchronization_config
.accumulated_step_panic_threshold
.map(|v| self.timedata.accumulated_steps > v)
.unwrap_or(false)
.is_some_and(|v| self.timedata.accumulated_steps > v)
{
error!("Unusually large clock step suggested, please manually verify system clock and reference clock state and restart if appropriate. If the clock is significantly wrong, you can use `ntp-ctl force-sync` to correct it.");
#[cfg(not(test))]
Expand Down Expand Up @@ -315,10 +315,11 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug> KalmanClockController<C, S
.expect("Cannot adjust clock");
for (state, _) in self.sources.values_mut() {
if let Some(ref mut state) = state {
state.state =
state
.state
.process_frequency_steering(freq_update, actual_change, state.wander)
state.state = state.state.process_frequency_steering(
freq_update,
actual_change,
state.wander,
);
}
}
debug!(
Expand Down Expand Up @@ -581,7 +582,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Threshold exceeded")]
fn jumps_add_absolutely() {
let synchronization_config = SynchronizationConfig {
minimum_agreeing_sources: 1,
Expand Down Expand Up @@ -610,6 +611,7 @@ mod tests {
algo.steer_offset(-1000.0, 0.0);
}

#[allow(clippy::float_cmp)]
#[test]
fn test_jumps_update_state() {
let synchronization_config = SynchronizationConfig::default();
Expand Down Expand Up @@ -700,7 +702,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Threshold exceeded")]
fn test_large_offset_eventually_panics() {
let synchronization_config = SynchronizationConfig {
minimum_agreeing_sources: 1,
Expand Down Expand Up @@ -755,7 +757,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Threshold exceeded")]
fn test_backward_step_panics_before_steer() {
let synchronization_config = SynchronizationConfig {
minimum_agreeing_sources: 1,
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 @@ -19,11 +19,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.iter() {
for snapshot in candidates {
let radius = snapshot.offset_uncertainty() * algo_config.range_statistical_weight
+ snapshot.delay * algo_config.range_delay_weight;
if radius > algo_config.maximum_source_uncertainty
Expand All @@ -42,7 +42,7 @@ pub(super) fn select<Index: Copy>(
let mut maxt: f64 = 0.0;
let mut cur: usize = 0;

for (time, boundtype) in bounds.iter() {
for (time, boundtype) in &bounds {
match boundtype {
BoundType::Start => cur += 1,
BoundType::End => cur -= 1,
Expand All @@ -64,7 +64,7 @@ pub(super) fn select<Index: Copy>(
&& snapshot.offset() + radius >= maxt
&& snapshot.leap_indicator.is_synchronized()
})
.cloned()
.copied()
.collect()
} else {
vec![]
Expand Down Expand Up @@ -125,7 +125,7 @@ mod tests {
..Default::default()
};

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

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

let algconfig = AlgorithmConfig {
Expand All @@ -143,7 +143,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 @@ -166,7 +166,7 @@ mod tests {
range_delay_weight: 1.0,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates.clone());
assert_eq!(result.len(), 3);

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

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

let algconfig = AlgorithmConfig {
Expand All @@ -193,7 +193,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 @@ -218,14 +218,14 @@ mod tests {
minimum_agreeing_sources: 3,
..Default::default()
};
let result = select(&sysconfig, &algconfig, candidates.clone());
let result = select(&sysconfig, &algconfig, &candidates.clone());
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 @@ -248,7 +248,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);
}
}
Loading
Loading