pub struct ClockGuard { /* private fields */ }Expand description
The latest sample of each peer. A delayed sample looks like a slow peer, so it can pause decisions but never approve a wrong clock: the median needs a majority of the clocks within the tolerance.
Implementations§
Source§impl ClockGuard
impl ClockGuard
Sourcepub fn new(
peers: impl IntoIterator<Item = NodeId>,
tolerance_millis: u64,
) -> Self
pub fn new( peers: impl IntoIterator<Item = NodeId>, tolerance_millis: u64, ) -> Self
Compare with peers, allowing tolerance_millis of disagreement.
Sourcepub fn observe(
&mut self,
peer: NodeId,
peer_wall_millis: u64,
local_wall_millis: u64,
now: Duration,
)
pub fn observe( &mut self, peer: NodeId, peer_wall_millis: u64, local_wall_millis: u64, now: Duration, )
Keep peer’s sample: its wall time as sent, the local wall time at
receipt, and the local monotonic time. Unconfigured peers are ignored.
Sourcepub fn forget(&mut self)
pub fn forget(&mut self)
Drop every sample. Their offsets were measured against a clock that has since stepped.
Sourcepub fn offsets(
&self,
now: Duration,
) -> impl Iterator<Item = (NodeId, Option<i64>)> + '_
pub fn offsets( &self, now: Duration, ) -> impl Iterator<Item = (NodeId, Option<i64>)> + '_
Each peer’s fresh offset in milliseconds, peer minus local.
Sourcepub fn verdict(&self, now: Duration) -> ClockVerdict
pub fn verdict(&self, now: Duration) -> ClockVerdict
Take the median of zero (this clock) and the fresh offsets. With two clocks both count, because neither can outvote the other.
Trait Implementations§
Source§impl Clone for ClockGuard
impl Clone for ClockGuard
Auto Trait Implementations§
impl Freeze for ClockGuard
impl RefUnwindSafe for ClockGuard
impl Send for ClockGuard
impl Sync for ClockGuard
impl Unpin for ClockGuard
impl UnsafeUnpin for ClockGuard
impl UnwindSafe for ClockGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more