Retain Windows signed sync responses across transient clock failures
Rust development slice / linux (push) Failing after 8s

This commit is contained in:
2026-11-16 12:09:52 +01:00
parent 2d5126876f
commit c7a69d9409
7 changed files with 399 additions and 22 deletions
+79
View File
@@ -29,6 +29,8 @@ pub struct Observation {
pub clock_failure: &'static str,
pub needs_sync: bool,
pub prepared: bool,
pub deferred_sync: &'static str,
pub deferred_sync_wait_ms: u64,
pub helper_control: &'static str,
pub helper_apply_unconfirmed: bool,
pub signed_gate_present: bool,
@@ -154,3 +156,80 @@ mod tests {
));
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ResponseWindow {
WaitForClock,
WithinWindow,
Expired,
}
/// Only scheduling of an independently authenticated, already bound control
/// reply. It cannot qualify a clock or turn this reply into an authorization.
pub fn response_window(
issued: chrono::DateTime<chrono::Utc>,
until: chrono::DateTime<chrono::Utc>,
held: std::time::Duration,
reading: Option<(chrono::DateTime<chrono::Utc>, chrono::DateTime<chrono::Utc>)>,
) -> ResponseWindow {
if held >= std::time::Duration::from_secs(60) || until <= issued {
return ResponseWindow::Expired;
}
let Some((wall, upper)) = reading else {
return ResponseWindow::WaitForClock;
};
if upper < wall || upper >= until {
return ResponseWindow::Expired;
}
if wall < issued {
return ResponseWindow::WaitForClock;
}
ResponseWindow::WithinWindow
}
#[cfg(test)]
mod response_tests {
use super::*;
#[test]
fn signed_response_waits_for_fresh_clock_and_issued_at_without_extending_its_deadline() {
let issued = chrono::DateTime::from_timestamp(100, 0).unwrap();
let until = issued + chrono::Duration::seconds(30);
let short = std::time::Duration::from_millis(20);
assert_eq!(
response_window(issued, until, short, None),
ResponseWindow::WaitForClock
);
assert_eq!(
response_window(
issued,
until,
short,
Some((
issued - chrono::Duration::milliseconds(500),
issued + chrono::Duration::milliseconds(100)
))
),
ResponseWindow::WaitForClock
);
assert_eq!(
response_window(
issued,
until,
short,
Some((issued, issued + chrono::Duration::milliseconds(100)))
),
ResponseWindow::WithinWindow
);
assert_eq!(
response_window(
issued,
until,
short,
Some((until - chrono::Duration::milliseconds(1), until))
),
ResponseWindow::Expired
);
assert_eq!(
response_window(issued, until, std::time::Duration::from_secs(60), None),
ResponseWindow::Expired
);
}
}