Skip to main content

ActivePeer

Struct ActivePeer 

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

A fully authenticated remote FIPS node.

Created only after successful Noise KK handshake. The identity is cryptographically verified at this point.

Note: ActivePeer intentionally does not implement Clone because it contains NoiseSession, which cannot be safely cloned (cloning would risk nonce reuse, a catastrophic security failure).

Implementations§

Source§

impl ActivePeer

Source

pub fn new( identity: PeerIdentity, link_id: LinkId, authenticated_at: u64, ) -> Self

Create a new active peer from verified identity.

Called after successful authentication handshake. For peers with Noise sessions, use with_session instead.

Source

pub fn with_stats( identity: PeerIdentity, link_id: LinkId, authenticated_at: u64, link_stats: LinkStats, ) -> Self

Create from verified identity with existing link stats.

Used when promoting from PeerConnection, preserving handshake stats. For peers with Noise sessions, use with_session instead.

Source

pub fn with_session( identity: PeerIdentity, link_id: LinkId, authenticated_at: u64, noise_session: NoiseSession, our_index: SessionIndex, their_index: SessionIndex, transport_id: TransportId, current_addr: TransportAddr, link_stats: LinkStats, is_initiator: bool, mmp_config: &MmpConfig, remote_epoch: Option<[u8; 8]>, ) -> Self

Create from verified identity with Noise session and index tracking.

This is the primary constructor for the wire protocol path. The NoiseSession provides encryption/decryption and replay protection.

Source

pub fn identity(&self) -> &PeerIdentity

Get the peer’s verified identity.

Source

pub fn node_addr(&self) -> &NodeAddr

Get the peer’s NodeAddr.

Source

pub fn address(&self) -> &FipsAddress

Get the peer’s FIPS address.

Source

pub fn pubkey(&self) -> XOnlyPublicKey

Get the peer’s public key.

Source

pub fn npub(&self) -> String

Get the peer’s npub string.

Get the link ID.

Source

pub fn connectivity(&self) -> ConnectivityState

Get the connectivity state.

Source

pub fn can_send(&self) -> bool

Check if peer can receive traffic.

Source

pub fn is_healthy(&self) -> bool

Check if peer is fully healthy.

Source

pub fn is_disconnected(&self) -> bool

Check if peer is disconnected.

Source

pub fn has_session(&self) -> bool

Check if this peer has a Noise session.

Source

pub fn noise_session(&self) -> Option<&NoiseSession>

Get the Noise session, if present.

Source

pub fn noise_session_mut(&mut self) -> Option<&mut NoiseSession>

Get mutable access to the Noise session.

Source

pub fn our_index(&self) -> Option<SessionIndex>

Get our session index (they use this to send TO us).

Source

pub fn their_index(&self) -> Option<SessionIndex>

Get their session index (we use this to send TO them).

Source

pub fn set_their_index(&mut self, index: SessionIndex)

Update their session index (used during cross-connection resolution when the losing node keeps its inbound session but needs the peer’s outbound index).

Source

pub fn replace_session( &mut self, new_session: NoiseSession, new_our_index: SessionIndex, new_their_index: SessionIndex, ) -> Option<SessionIndex>

Replace the Noise session and indices during cross-connection resolution.

When both nodes simultaneously initiate, each promotes its inbound handshake first. When the peer’s msg2 arrives, we learn the correct session — the outbound handshake that pairs with the peer’s inbound. This replaces the entire session so both nodes use matching keys.

Returns the old our_index so the caller can update peers_by_index. Also resets the replay suppression counter since the session changed.

Source

pub fn transport_id(&self) -> Option<TransportId>

Get the transport ID for this peer.

Source

pub fn current_addr(&self) -> Option<&TransportAddr>

Get the current transport address.

Source

pub fn set_current_addr( &mut self, transport_id: TransportId, addr: &TransportAddr, ) -> bool

Update the current address (for roaming support).

Called when we receive a valid authenticated packet from a new address. Short-circuits when neither the transport_id nor the TransportAddr bytes changed — at multi-Gbps the same peer’s source 4-tuple is stable per session and the overwhelming majority of inbound packets hit this fast path. Saves both the redundant Option::take + Vec drop on the cached side and the caller’s .clone() allocation on the input side: the caller can pass &TransportAddr and we only .to_owned() when storing.

Returns true iff the stored (transport_id, current_addr) pair actually changed. The caller uses this signal to invalidate derived caches whose validity is bound to the peer’s 5-tuple — in particular the Linux per-peer connect()-ed UDP socket, which is pinned to one kernel route + neighbour entry and goes stale the moment the peer roams. (Clearing it here would force &mut self users into the wrong shape: the policy of when to rebuild the connected socket lives on Node, not on the peer state. Returning a bool keeps that policy where it belongs.)

Source

pub fn set_handshake_msg2(&mut self, msg2: Vec<u8>)

Store wire-format msg2 for resend on duplicate msg1.

Source

pub fn handshake_msg2(&self) -> Option<&[u8]>

Get stored msg2 bytes for resend.

Source

pub fn clear_handshake_msg2(&mut self)

Clear stored msg2 (no longer needed after handshake window).

Source

pub fn increment_replay_suppressed(&mut self) -> u32

Increment replay suppression counter. Returns the new count.

Source

pub fn reset_replay_suppressed(&mut self) -> u32

Reset replay suppression counter, returning previous count.

Source

pub fn replay_suppressed_count(&self) -> u32

Current replay suppression count.

Source

pub fn increment_decrypt_failures(&mut self) -> u32

Increment consecutive decryption failure counter, returning new count.

Source

pub fn reset_decrypt_failures(&mut self)

Reset consecutive decryption failure counter.

Source

pub fn consecutive_decrypt_failures(&self) -> u32

Current consecutive decryption failure count.

Source

pub fn remote_epoch(&self) -> Option<[u8; 8]>

Get the remote peer’s startup epoch (from handshake).

Source

pub fn coords(&self) -> Option<&TreeCoordinate>

Get the peer’s tree coordinates, if known.

Source

pub fn declaration(&self) -> Option<&ParentDeclaration>

Get the peer’s parent declaration, if known.

Source

pub fn has_tree_position(&self) -> bool

Check if this peer has a known tree position.

Source

pub fn inbound_filter(&self) -> Option<&BloomFilter>

Get the peer’s inbound filter, if known.

Source

pub fn filter_sequence(&self) -> u64

Get the filter sequence number.

Source

pub fn filter_is_stale( &self, current_time_ms: u64, stale_threshold_ms: u64, ) -> bool

Check if this peer’s filter is stale.

Source

pub fn may_reach(&self, node_addr: &NodeAddr) -> bool

Check if a destination might be reachable through this peer.

Source

pub fn needs_filter_update(&self) -> bool

Check if we need to send this peer a filter update.

Get link statistics.

Get mutable link statistics.

Source

pub fn mmp(&self) -> Option<&MmpPeerState>

Get MMP state (None for legacy peers without sessions).

Source

pub fn mmp_mut(&mut self) -> Option<&mut MmpPeerState>

Get mutable MMP state.

Link cost for routing decisions.

Returns a scalar cost where lower is better (1.0 = ideal). Computed as RTT-weighted ETX: etx * (1.0 + srtt_ms / 100.0).

Returns 1.0 (optimistic default) when MMP metrics are not yet available, matching depth-only parent selection behavior.

Source

pub fn has_srtt(&self) -> bool

Whether this peer has at least one MMP RTT measurement.

Source

pub fn authenticated_at(&self) -> u64

When this peer was authenticated.

Source

pub fn last_seen(&self) -> u64

When this peer was last seen.

Source

pub fn idle_time(&self, current_time_ms: u64) -> u64

Time since last activity.

Source

pub fn connection_duration(&self, current_time_ms: u64) -> u64

Connection duration since authentication.

Source

pub fn session_elapsed_ms(&self) -> u32

Session-relative elapsed time in milliseconds (for inner header timestamp).

Returns milliseconds since session establishment, truncated to u32. Wraps at ~49.7 days which is acceptable for session-relative timing.

Source

pub fn session_start(&self) -> Instant

When this peer’s session started (for link-dead fallback timing).

Source

pub fn last_heartbeat_sent(&self) -> Option<Instant>

When we last sent a heartbeat to this peer.

Source

pub fn mark_heartbeat_sent(&mut self, now: Instant)

Record that we sent a heartbeat.

Source

pub fn touch(&mut self, current_time_ms: u64)

Update last seen timestamp.

Source

pub fn mark_stale(&mut self)

Mark peer as stale (no recent traffic).

Source

pub fn mark_reconnecting(&mut self)

Mark peer as reconnecting.

Source

pub fn mark_disconnected(&mut self)

Mark peer as disconnected.

Source

pub fn mark_connected(&mut self, current_time_ms: u64)

Mark peer as connected (e.g., after successful reconnect).

Update the link ID (e.g., on reconnect).

Source

pub fn update_tree_position( &mut self, declaration: ParentDeclaration, ancestry: TreeCoordinate, current_time_ms: u64, )

Update peer’s tree position.

Source

pub fn clear_tree_position(&mut self)

Clear peer’s tree position.

Source

pub fn set_tree_announce_min_interval_ms(&mut self, ms: u64)

Set the minimum interval between TreeAnnounce messages (milliseconds).

Source

pub fn last_tree_announce_sent_ms(&self) -> u64

Get the last tree announce send timestamp (for carrying across reconnection).

Source

pub fn set_last_tree_announce_sent_ms(&mut self, ms: u64)

Set the last tree announce send timestamp (to preserve rate limit across reconnection).

Source

pub fn can_send_tree_announce(&self, now_ms: u64) -> bool

Check if we can send a TreeAnnounce now (rate limiting).

Source

pub fn record_tree_announce_sent(&mut self, now_ms: u64)

Record that we sent a TreeAnnounce to this peer.

Source

pub fn mark_tree_announce_pending(&mut self)

Mark that a tree announce is pending (deferred due to rate limit).

Source

pub fn has_pending_tree_announce(&self) -> bool

Check if a deferred tree announce is waiting to be sent.

Source

pub fn update_filter( &mut self, filter: BloomFilter, sequence: u64, current_time_ms: u64, )

Update peer’s inbound filter.

Source

pub fn clear_filter(&mut self)

Clear peer’s inbound filter.

Source

pub fn mark_filter_update_needed(&mut self)

Mark that we need to send this peer a filter update.

Source

pub fn clear_filter_update_needed(&mut self)

Clear the pending filter update flag.

Source

pub fn session_established_at(&self) -> Instant

When the current Noise session was established.

Source

pub fn current_k_bit(&self) -> bool

Current K-bit epoch value.

Source

pub fn rekey_in_progress(&self) -> bool

Whether a rekey is currently in progress.

Source

pub fn set_rekey_in_progress(&mut self)

Mark that a rekey has been initiated.

Source

pub fn is_rekey_dampened(&self, dampening_secs: u64) -> bool

Check if rekey initiation is dampened (peer recently sent us msg1).

Source

pub fn record_peer_rekey(&mut self)

Record that the peer initiated a rekey (for dampening).

Source

pub fn pending_our_index(&self) -> Option<SessionIndex>

Get the pending new session’s our_index.

Source

pub fn pending_their_index(&self) -> Option<SessionIndex>

Get the pending new session’s their_index.

Source

pub fn previous_our_index(&self) -> Option<SessionIndex>

Get the previous session’s our_index (during drain).

Source

pub fn previous_session(&self) -> Option<&NoiseSession>

Get the previous session for decryption fallback.

Source

pub fn previous_session_mut(&mut self) -> Option<&mut NoiseSession>

Get mutable access to the previous session for decryption.

Source

pub fn pending_new_session(&self) -> Option<&NoiseSession>

Get the pending new session (completed rekey, not yet cut over).

Source

pub fn set_pending_session( &mut self, session: NoiseSession, our_index: SessionIndex, their_index: SessionIndex, )

Store a completed rekey session and its indices.

Called when the rekey handshake completes. The session is held as pending until the initiator flips the K-bit on the next outbound packet.

Source

pub fn cutover_to_new_session(&mut self) -> Option<SessionIndex>

Cut over to the pending new session (initiator side).

Moves current session to previous (for drain), promotes pending to current, flips the K-bit. Returns the old our_index that should remain in peers_by_index during the drain window.

Source

pub fn handle_peer_kbit_flip(&mut self) -> Option<SessionIndex>

Handle receiving a K-bit flip from the peer (responder side).

Promotes pending_new_session to current, demotes current to previous. Returns the old our_index for drain tracking.

Source

pub fn drain_expired(&self, drain_secs: u64) -> bool

Check if the drain window has expired.

Source

pub fn is_draining(&self) -> bool

Whether a drain is in progress.

Source

pub fn complete_drain(&mut self) -> Option<SessionIndex>

Complete the drain: drop previous session and free its index.

Returns the previous our_index so the caller can remove it from peers_by_index and free it from the IndexAllocator.

Source

pub fn abandon_rekey(&mut self) -> Option<SessionIndex>

Abandon an in-progress rekey.

Returns the rekey our_index so the caller can free it. Also clears any pending session state if the handshake was completed but not yet cut over.

Source

pub fn set_rekey_state( &mut self, handshake: NoiseHandshakeState, our_index: SessionIndex, wire_msg1: Vec<u8>, next_resend_ms: u64, )

Store rekey handshake state after sending msg1.

Source

pub fn rekey_our_index(&self) -> Option<SessionIndex>

Get the rekey our_index (for msg2 dispatch lookup).

Source

pub fn complete_rekey_msg2( &mut self, msg2_bytes: &[u8], ) -> Result<NoiseSession, NoiseError>

Complete the rekey by processing msg2 (initiator side).

Takes the stored handshake state, reads msg2, and returns the completed NoiseSession. Clears the handshake-related fields but leaves rekey_our_index for set_pending_session to use.

Source

pub fn needs_msg1_resend(&self, now_ms: u64) -> bool

Check if msg1 needs resending.

Source

pub fn rekey_msg1(&self) -> Option<&[u8]>

Get msg1 bytes for resend (without consuming).

Source

pub fn set_msg1_next_resend(&mut self, next_ms: u64)

Update next resend timestamp.

Trait Implementations§

Source§

impl Debug for ActivePeer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more