English
ours-clock
libs/clock — the time of the process: the system clock moved by the offset the ntp service measured last.
Design
ClockOffset— a signed offset in nanoseconds (a clock that runs ahead needs a negative one);apply— to a time.Clock— the process time (now,unix_seconds): the system time with the offset last set by thentpservice (set_offset), like sing'sntp.TimeFuncFromContext. Clones share it; one per instance. Beyond ±292 years the offset is clamped.civil_from_days,days_from_civil— days since 1970-01-01 to a Gregorian date and back (Howard Hinnant's algorithms), for whatever writes or reads a date: log timestamps, HTTPDate, certificate validity, DNSRRSIGtimes, the binary's build date.
Who uses it
ours-mod-ntp sets the offset; ours-kernel keeps the instance's clock and ours-config hands it out from the services; certificate verification (ours-tls13, ours-mod-tls), REALITY and Shadowsocks 2022 read it. ours-ntp-wire re-exports ClockOffset for its exchange. The date conversion is used by ours-proto (http1), ours-dns-types, ours-tls13, ours-mod-ntp, ours-mod-hysteria2 and the binary (its log and build.rs).
Specifics
Depends only on ours-atomic64 (64-bit atomics on 32-bit MIPS). Shadowsocks 2022 reads it for every request and UDP packet, so it is built at opt-level = 3 in release.
Tests
Unit tests in src/lib.rs; the clock set by a time server — modules/system/ntp/tests/clock.rs.