pub struct ExpiryManager { /* private fields */ }Expand description
Tracks expired peers and the local-to-control clock delta, and mutates peers to reflect expiry.
Go ipnlocal.expiryManager. One instance per node, owned by whatever holds the peer set (here:
ts_runtime’s peer tracker), and driven from the netmap stream.
Implementations§
Source§impl ExpiryManager
impl ExpiryManager
Sourcepub fn on_control_time(
&mut self,
control_time: DateTime<Utc>,
local_now: DateTime<Utc>,
) -> TimeDelta
pub fn on_control_time( &mut self, control_time: DateTime<Utc>, local_now: DateTime<Utc>, ) -> TimeDelta
Record a MapResponse.ControlTime — Go onControlTime.
Stores the delta between control’s clock and local_now when it exceeds
MIN_CLOCK_DELTA_SECS in either direction, and clears it back to zero when it does
not (control and this node agree; a previously-recorded skew has been corrected). Returns
the delta now in effect.
Sourcepub fn clock_delta(&self) -> TimeDelta
pub fn clock_delta(&self) -> TimeDelta
The stored local-to-control clock offset (Go clockDelta). Zero when control’s clock is
within MIN_CLOCK_DELTA_SECS of this node’s, or before any ControlTime has arrived.
Sourcepub fn control_now(&self, local_now: DateTime<Utc>) -> DateTime<Utc>
pub fn control_now(&self, local_now: DateTime<Utc>) -> DateTime<Utc>
Control’s estimated current time — Go LocalBackend.ControlNow: local_now shifted by the
stored clock_delta. Every expiry comparison is made against this, not
against the raw local clock.
Sourcepub fn flag_expired_peer(
&mut self,
peer: &Node,
local_now: DateTime<Utc>,
) -> Option<FlaggedPeer>
pub fn flag_expired_peer( &mut self, peer: &Node, local_now: DateTime<Utc>, ) -> Option<FlaggedPeer>
Apply the expiry pass to one peer — the body of Go’s flagExpiredPeers loop.
Returns the rewritten peer when it had to be changed, and None when nothing changed — so a
caller walking a large peer set clones only the handful of peers it has to re-install and
re-publish. FlaggedPeer::first_transition separates “this peer just expired” from “this
peer was already expired and control restated it unflagged”, which is the difference between
a log line and a silent rewrite.
On expiry the peer is flagged, never dropped: expired is set, its underlay endpoints
and home DERP are cleared (control does the same for expired nodes), and its node key is
broken with ts_keys::node_public_with_bad_old_prefix so nothing can handshake with it.
Keeping the row is the point — a caller that tries to reach the peer can then answer
PEER_KEY_EXPIRED instead of “no such peer”.
Skipped, returning None:
- a peer with no expiry at all (
node_key_expiryisNone— a tagged node; Go’s zeroKeyExpiry), and a peer whose expiry is still in the future. Either way the peer is not expired, so the pristine key, endpoints and home DERP a previous pass memoized are put back (see the manager’s own docs) and the memo dropped, exactly where Go does itsdelete(em.previouslyExpired, ...). - a peer already marked
Node::expired— by control, or by an earlier pass. Re-flagging would repeat the log and the invalidation on every netmap. - every peer, when the delta-adjusted clock is before
flag_expired_peers_epoch.
Sourcepub fn next_peer_expiry<'a>(
&self,
peers: impl IntoIterator<Item = &'a Node>,
self_node: Option<&Node>,
local_now: DateTime<Utc>,
) -> Option<DateTime<Utc>>
pub fn next_peer_expiry<'a>( &self, peers: impl IntoIterator<Item = &'a Node>, self_node: Option<&Node>, local_now: DateTime<Utc>, ) -> Option<DateTime<Utc>>
The soonest future key expiry across peers and self_node — Go nextPeerExpiry.
The result is in local time (the caller’s clock), so next - local_now is directly the
delay to arm a timer for; see EXPIRY_TIMER_SLACK_SECS for the slack upstream adds on
top. None when nothing is due to expire, i.e. every peer is tagged (no expiry), already
expired, or already past its expiry without having been flagged.
Two guards, both upstream’s:
- the delta-adjusted clock must not precede
flag_expired_peers_epoch, elseNone. - the answer is never before
local_now. A local clock running fast relative to control would otherwise produce a negative delay and a timer that fires immediately in a loop; in that case the answer is floored atlocal_now +CLOCK_SKEW_EXPIRY_FLOOR_SECS.
Trait Implementations§
Source§impl Clone for ExpiryManager
impl Clone for ExpiryManager
Source§fn clone(&self) -> ExpiryManager
fn clone(&self) -> ExpiryManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more