Skip to main content

dash_runtime/timing/
mod.rs

1//! Pure time arithmetic: UTC clock, HTTP `Date`, availability, live edge and
2//! PeriodStart. Nothing in this module reads a clock; every function takes the
3//! instants it needs as arguments. The `xs:dateTime`, NTP and `UTCTiming`
4//! readers live in [`broadcast_dash::xs_datetime`] and
5//! [`broadcast_dash::utc_timing`] and are re-exported here.
6
7use thiserror::Error;
8
9pub mod availability;
10pub mod clock;
11pub use broadcast_common::http_date;
12pub mod live_edge;
13pub mod period;
14pub mod utc_timing;
15
16pub use broadcast_dash::xs_datetime as datetime;
17
18/// Why a clock sample could not be built.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
20#[non_exhaustive]
21pub enum TimingError {
22    /// The response arrived before the request was sent.
23    #[error("response timestamp precedes the request timestamp")]
24    ExchangeReversed,
25    /// The round trip is too long to trust.
26    #[error("round trip of {rtt_us} us exceeds the {max_us} us limit")]
27    RttTooLarge {
28        /// Measured round trip.
29        rtt_us: u64,
30        /// Limit.
31        max_us: u64,
32    },
33    /// A UTC response body above the cap.
34    #[error("UTC response body exceeds {max} bytes")]
35    BodyTooLarge {
36        /// The cap.
37        max: usize,
38    },
39    /// A UTC response body that is not UTF-8.
40    #[error("UTC response body is not UTF-8")]
41    NotUtf8,
42    /// The scheme has no body time this core can read.
43    #[error("UTCTiming scheme {0} is not sampled from a response body")]
44    SchemeNotSampled(utc_timing::UtcScheme),
45    /// An `xs:dateTime` was not accepted.
46    #[error(transparent)]
47    DateTime(#[from] datetime::DateTimeError),
48    /// An HTTP `Date` value was not accepted.
49    #[error(transparent)]
50    HttpDate(#[from] http_date::HttpDateError),
51}