Skip to main content

Module clock

Module clock 

Source
Expand description

The time Vector stamps and judges by: this device’s clock, corrected when the account’s relays agree it is off. Every HTTPS answer carries a Date (RFC 9110 §6.6.1), so any relay can tell the time, whether or not it serves NIP-11; their median moves the clock, so one wrong relay can’t, and nothing of Vector’s own is asked.

Structs§

Status
What the clock is doing, for Settings.

Constants§

EVENT
What the UI hears when the clock in force, or what is known about it, changes.
SETTING_KEY
The account setting: "false" keeps the device’s clock, anything else follows the relays.

Functions§

describe_span
A length of time as a person says it: “40 seconds”, “4 minutes”, “2 hours”.
device_clock_reads
Every place under src_root that reads the time off the device rather than this clock, as path:line relative to crate_root: Timestamp::now(), unix time from SystemTime, and signing with bare keys through nostr’s finalize, which stamps the device’s clock. A read that must stay on the device (a file’s age, a log line, an id) says why with // device-clock: <why> on its line or the three above.
is_decentralised
Whether Vector runs on the relays’ clock.
load_setting
Read the live account’s choice. Called as its session starts.
now_ms
Now, in unix ms, on the clock in force.
now_secs
Now, in unix seconds, on the clock in force.
offset_ms
The correction in force, in ms (positive when this device runs behind). Zero on the device clock.
restamp
Move an event nostr stamped with the device’s clock onto the clock in force. A time the caller chose (a backdated wrap, an edition’s own date) is left alone, and so is the id it fixed.
resync_soon
Ask the relays again soon, rather than at the next hourly check: a server said this clock is off.
set_decentralised
Choose the relays’ clock or the device’s, for this account, from now on.
status
sync_with
Ask relays for the time and correct the clock by what they agree on. Leaves it alone when fewer than QUORUM answer alike, the device’s clock is used until they do.
timestamp
Now, as the created_at or filter bound of an event. Use this, never Timestamp::now().