1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: Apache-2.0
//! Canonical wire timestamp types for NodeDB.
//!
//! All wire-level timestamps use these two concepts:
//!
//! - **Wall-clock instants** — signed 64-bit milliseconds since the Unix epoch
//! (UTC). Negative values represent dates before 1970-01-01. Type alias:
//! [`WallMs`].
//! - **Durations / TTLs** — unsigned 64-bit milliseconds. Always non-negative.
//! Type alias: [`DurMs`].
//!
//! Using these aliases in field declarations makes the intended semantics
//! self-documenting and ensures a single canonical width per concept.
use ;
/// A wall-clock instant expressed as signed milliseconds since the Unix epoch
/// (UTC). Negative values represent dates before 1970-01-01.
///
/// This is the canonical wire type for every "when did this happen?" timestamp.
pub type WallMs = i64;
/// A duration or TTL expressed as unsigned milliseconds. Always ≥ 0.
///
/// This is the canonical wire type for every "how long?" field.
pub type DurMs = u64;
/// Return the current wall-clock time as [`WallMs`] (milliseconds since the
/// Unix epoch, UTC).
///
/// Returns `0` (Unix epoch) on the extremely unlikely event that the system
/// clock is before the Unix epoch — a value of 0 is obviously wrong and
/// easier to detect than `i64::MAX`. Logs the condition once per process via
/// `tracing::error!` to alert operators.
///
/// # TODO(post-launch): funnel direct `SystemTime::now()` callers through this
/// helper so all inline clock-read sites also get the once-per-process log.