Skip to main content

TimeClient

Struct TimeClient 

Source
pub struct TimeClient { /* private fields */ }
Expand description

A disciplined view of time for a page or an edge function.

Implementations§

Source§

impl TimeClient

Source

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.

Source

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

Source

pub fn new() -> TimeClient

Source

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.

Source

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.

Source

pub fn now_ms(&mut self, date_now_ms: f64, perf_now_ms: f64) -> f64

Corrected Unix time in milliseconds. Never steps backwards.

Source

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.

Source

pub fn offset_ms(&mut self, perf_now_ms: f64) -> f64

The correction currently applied, in milliseconds.

Source

pub fn is_synchronized(&self) -> bool

Source

pub fn accepted(&self) -> u32

Source

pub fn rejected(&self) -> u32

Trait Implementations§

Source§

impl Default for TimeClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.