ConnectionStateGraph

Struct ConnectionStateGraph 

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

Connection state graph for tracking all peer connection states

Provides a queryable view of all known peers and their connection lifecycle state. Apps can use this to display appropriate UI indicators and associate data with connection state at time of receipt.

§Example

let graph = mesh.get_connection_graph();

// Show connected peers with green indicator
for peer in graph.get_connected() {
    ui.show_peer_connected(&peer);
}

// Show recently disconnected peers with yellow indicator
for peer in graph.get_recently_disconnected(30_000) {
    ui.show_peer_stale(&peer, peer.time_since_disconnected(now));
}

// Show lost peers with gray indicator
for peer in graph.get_lost() {
    ui.show_peer_lost(&peer);
}

Implementations§

Source§

impl ConnectionStateGraph

Source

pub fn new() -> Self

Create a new empty connection state graph

Source

pub fn with_config(rssi_degraded_threshold: i8, lost_timeout_ms: u64) -> Self

Create with custom thresholds

Source

pub fn get_all(&self) -> Vec<&PeerConnectionState>

Get all tracked peers

Source

pub fn get_all_owned(&self) -> Vec<PeerConnectionState>

Get all peers as owned values

Source

pub fn get_peer(&self, node_id: NodeId) -> Option<&PeerConnectionState>

Get a specific peer’s state

Source

pub fn get_peer_mut( &mut self, node_id: NodeId, ) -> Option<&mut PeerConnectionState>

Get a mutable reference to a peer’s state

Source

pub fn get_connected(&self) -> Vec<&PeerConnectionState>

Get all currently connected peers (Connected or Degraded state)

Source

pub fn get_degraded(&self) -> Vec<&PeerConnectionState>

Get all peers in Degraded state

Source

pub fn get_recently_disconnected( &self, within_ms: u64, now_ms: u64, ) -> Vec<&PeerConnectionState>

Get peers disconnected within the specified time window

Source

pub fn get_lost(&self) -> Vec<&PeerConnectionState>

Get all peers in Lost state

Source

pub fn get_with_history(&self) -> Vec<&PeerConnectionState>

Get peers that were previously connected (have connection history)

Source

pub fn state_counts(&self) -> StateCountSummary

Count of peers in each state

Source

pub fn len(&self) -> usize

Total number of tracked peers

Source

pub fn is_empty(&self) -> bool

Check if graph is empty

Source

pub fn on_discovered( &mut self, node_id: NodeId, identifier: String, name: Option<String>, mesh_id: Option<String>, rssi: i8, now_ms: u64, ) -> &PeerConnectionState

Register a newly discovered peer

Source

pub fn on_connecting(&mut self, node_id: NodeId, now_ms: u64)

Handle connection start

Source

pub fn on_connected(&mut self, node_id: NodeId, now_ms: u64)

Handle successful connection

Source

pub fn on_disconnected( &mut self, node_id: NodeId, reason: DisconnectReason, now_ms: u64, )

Handle disconnection

Source

pub fn update_rssi(&mut self, node_id: NodeId, rssi: i8, now_ms: u64) -> bool

Update RSSI for a peer, checking for degradation

Returns true if peer transitioned to Degraded state

Source

pub fn record_transfer( &mut self, node_id: NodeId, bytes_received: u64, bytes_sent: u64, )

Record data transfer for a peer

Source

pub fn record_sync(&mut self, node_id: NodeId)

Record a document sync for a peer

Source

pub fn tick(&mut self, now_ms: u64) -> Vec<NodeId>

Run periodic maintenance (transition Disconnected → Lost)

Returns list of peers that transitioned to Lost state

Source

pub fn cleanup_lost(&mut self, older_than_ms: u64, now_ms: u64) -> Vec<NodeId>

Remove peers that have been lost for longer than the specified duration

Source

pub fn import_peer(&mut self, peer: &HivePeer, now_ms: u64)

Import state from a HivePeer

Source

pub fn on_relay_received( &mut self, source_peer: NodeId, origin_node: NodeId, hop_count: u8, now_ms: u64, ) -> bool

Record that we received a relay message with given origin

This updates the indirect peer graph when we receive a relay message where the origin differs from the immediate sender.

§Arguments
  • source_peer - The direct peer we received the relay from
  • origin_node - The original sender (from relay envelope)
  • hop_count - Current hop count from the relay envelope
  • now_ms - Current timestamp
§Returns

true if this is a newly discovered indirect peer

Source

pub fn get_indirect_peers(&self) -> Vec<&IndirectPeer>

Get all indirect peers

Source

pub fn get_indirect_peers_owned(&self) -> Vec<IndirectPeer>

Get all indirect peers as owned values

Source

pub fn get_indirect_peer(&self, node_id: NodeId) -> Option<&IndirectPeer>

Get a specific indirect peer

Source

pub fn get_peers_by_degree(&self, degree: PeerDegree) -> Vec<NodeId>

Get peers by degree

Source

pub fn peer_degree(&self, node_id: NodeId) -> Option<PeerDegree>

Get the degree of a specific peer (direct or indirect)

Source

pub fn get_paths_to(&self, node_id: NodeId) -> Vec<(NodeId, u8)>

Get all paths to reach an indirect peer

Returns Vec of (via_peer_id, hop_count) pairs

Source

pub fn is_known(&self, node_id: NodeId) -> bool

Check if a node is known (either direct or indirect)

Source

pub fn cleanup_indirect(&mut self, now_ms: u64) -> Vec<NodeId>

Cleanup stale indirect peers

Returns list of removed peer IDs

Source

pub fn remove_via_peer(&mut self, via_peer: NodeId)

Remove a via_peer path from all indirect peers

Called when a direct peer disconnects - the indirect paths through that peer may no longer be valid.

Source

pub fn full_state_counts(&self) -> FullStateCountSummary

Combined count summary including indirect peers

Source

pub fn indirect_peer_count(&self) -> usize

Number of indirect peers

Source

pub fn set_indirect_callsign(&mut self, node_id: NodeId, callsign: String)

Set callsign for an indirect peer (learned from document)

Trait Implementations§

Source§

impl Clone for ConnectionStateGraph

Source§

fn clone(&self) -> ConnectionStateGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConnectionStateGraph

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ConnectionStateGraph

Source§

fn default() -> ConnectionStateGraph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.