dig-dht 0.7.0

Kademlia DHT with provider records for the DIG Node peer network — maps DIG content (store / capsule / root / resource) to the peer_ids holding it, so a node can locate which peers have the content it wants and fetch it over the L7 peer RPC. peer_id = SHA-256(TLS SPKI DER), XOR-distance k-buckets, iterative find_node/find_providers, TTL'd + republished provider records, riding dig-nat mTLS transport.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! The crate's one wall-clock reading: absolute Unix seconds.
//!
//! Provider records are TTL'd soft state (`expires_at` in absolute Unix seconds), so admission,
//! expiry, GC, and eviction all need the same notion of "now". Keeping the single `SystemTime` read
//! here means the service and the provider store cannot drift onto different clock sources, and the
//! decision points that need to be testable take `now` as a PARAMETER (`ProviderStore::put_at`,
//! `get`, `gc`) instead of reaching for the system clock themselves.

use std::time::{SystemTime, UNIX_EPOCH};

/// The current time as absolute Unix seconds, saturating to 0 if the system clock predates the epoch.
pub(crate) fn now_secs() -> u64 {
    SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap_or_default()
        .as_secs()
}