pub struct TimeClient { /* private fields */ }Expand description
A disciplined view of time for a page or an edge function.
Implementations§
Source§impl TimeClient
impl TimeClient
Sourcepub fn build_request_with_nonce(
&mut self,
date_now_ms: f64,
nonce: u64,
) -> Vec<u8> ⓘ
pub fn build_request_with_nonce( &mut self, date_now_ms: f64, nonce: u64, ) -> Vec<u8> ⓘ
Build a client request. date_now_ms is the page’s Date.now(), and
nonce must be unpredictable — it is echoed back as the origin
timestamp and is what stops an off-path attacker forging a reply.
Sourcepub fn process_response_inner(
&mut self,
bytes: &[u8],
date_now_ms: f64,
perf_now_ms: f64,
) -> bool
pub fn process_response_inner( &mut self, bytes: &[u8], date_now_ms: f64, perf_now_ms: f64, ) -> bool
Feed a gateway response. Returns true if it was accepted.
date_now_ms is Date.now() at receipt (T4) and perf_now_ms is
performance.now(), which is monotonic and therefore what the estimate
is anchored to — Date.now() can jump under us at any moment.
Source§impl TimeClient
impl TimeClient
pub fn new() -> TimeClient
Sourcepub fn build_request(
&mut self,
date_now_ms: f64,
nonce_hi: u32,
nonce_lo: u32,
) -> Vec<u8> ⓘ
pub fn build_request( &mut self, date_now_ms: f64, nonce_hi: u32, nonce_lo: u32, ) -> Vec<u8> ⓘ
Build a request, drawing the nonce from the caller.
Exposed this way because the page has crypto.getRandomValues and this
crate should not carry a random source into wasm just to duplicate it.
Sourcepub fn process_response(
&mut self,
bytes: &[u8],
date_now_ms: f64,
perf_now_ms: f64,
) -> bool
pub fn process_response( &mut self, bytes: &[u8], date_now_ms: f64, perf_now_ms: f64, ) -> bool
Feed a gateway response; returns true if it was accepted.
Sourcepub fn now_ms(&mut self, date_now_ms: f64, perf_now_ms: f64) -> f64
pub fn now_ms(&mut self, date_now_ms: f64, perf_now_ms: f64) -> f64
Corrected Unix time in milliseconds. Never steps backwards.
Sourcepub fn confidence_ms(&self, perf_now_ms: f64) -> f64
pub fn confidence_ms(&self, perf_now_ms: f64) -> f64
Current error bound in milliseconds; Infinity until the first
accepted exchange. Mesh apps gate CRDT and capability decisions on this
rather than assuming the clock is good.
Sourcepub fn offset_ms(&mut self, perf_now_ms: f64) -> f64
pub fn offset_ms(&mut self, perf_now_ms: f64) -> f64
The correction currently applied, in milliseconds.