pub struct MeshClockSync {
pub offset_us: i64,
pub authority_id: Option<String>,
pub authority_source: ClockSource,
pub local_source: ClockSource,
pub sync_count: u64,
pub uncertainty_us: u64,
/* private fields */
}Expand description
Mesh time synchronization state for a node.
Fields§
§offset_us: i64Current clock offset from authority (microseconds, signed).
ID of the current time authority node.
Clock source of the authority.
local_source: ClockSourceOur own clock source.
sync_count: u64Number of sync samples received.
uncertainty_us: u64Estimated clock uncertainty (microseconds).
Implementations§
Source§impl MeshClockSync
impl MeshClockSync
Sourcepub fn new(local_source: ClockSource) -> Self
pub fn new(local_source: ClockSource) -> Self
Create a new clock sync state.
Sourcepub fn mesh_time_us(&self) -> u64
pub fn mesh_time_us(&self) -> u64
Get the current mesh-synchronized time in microseconds since epoch.
Uses RealClock. Prefer Self::mesh_time_us_with when a
Clock is available (tests / DI).
Sourcepub fn mesh_time_us_with(&self, clock: &dyn Clock) -> u64
pub fn mesh_time_us_with(&self, clock: &dyn Clock) -> u64
Mesh-synchronized time using an injectable Clock.
Sourcepub fn process_sync(
&mut self,
sender_id: &str,
sender_time_us: u64,
sender_source: ClockSource,
local_receive_time_us: u64,
)
pub fn process_sync( &mut self, sender_id: &str, sender_time_us: u64, sender_source: ClockSource, local_receive_time_us: u64, )
Process a time sync sample from a heartbeat.
If the sender has a better clock source, update our offset. Uses exponential moving average to smooth jitter.
Check if this node should be the time authority.
Sourcepub fn is_better_source(&self, other: ClockSource) -> bool
pub fn is_better_source(&self, other: ClockSource) -> bool
Whether we have a better clock source than the given source.
Trait Implementations§
Source§impl Clone for MeshClockSync
impl Clone for MeshClockSync
Auto Trait Implementations§
impl Freeze for MeshClockSync
impl RefUnwindSafe for MeshClockSync
impl Send for MeshClockSync
impl Sync for MeshClockSync
impl Unpin for MeshClockSync
impl UnsafeUnpin for MeshClockSync
impl UnwindSafe for MeshClockSync
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more