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
impl ConnectionStateGraph
Sourcepub fn with_config(rssi_degraded_threshold: i8, lost_timeout_ms: u64) -> Self
pub fn with_config(rssi_degraded_threshold: i8, lost_timeout_ms: u64) -> Self
Create with custom thresholds
Sourcepub fn get_all(&self) -> Vec<&PeerConnectionState>
pub fn get_all(&self) -> Vec<&PeerConnectionState>
Get all tracked peers
Sourcepub fn get_all_owned(&self) -> Vec<PeerConnectionState>
pub fn get_all_owned(&self) -> Vec<PeerConnectionState>
Get all peers as owned values
Sourcepub fn get_peer(&self, node_id: NodeId) -> Option<&PeerConnectionState>
pub fn get_peer(&self, node_id: NodeId) -> Option<&PeerConnectionState>
Get a specific peer’s state
Sourcepub fn get_peer_mut(
&mut self,
node_id: NodeId,
) -> Option<&mut PeerConnectionState>
pub fn get_peer_mut( &mut self, node_id: NodeId, ) -> Option<&mut PeerConnectionState>
Get a mutable reference to a peer’s state
Sourcepub fn get_connected(&self) -> Vec<&PeerConnectionState>
pub fn get_connected(&self) -> Vec<&PeerConnectionState>
Get all currently connected peers (Connected or Degraded state)
Sourcepub fn get_degraded(&self) -> Vec<&PeerConnectionState>
pub fn get_degraded(&self) -> Vec<&PeerConnectionState>
Get all peers in Degraded state
Sourcepub fn get_recently_disconnected(
&self,
within_ms: u64,
now_ms: u64,
) -> Vec<&PeerConnectionState>
pub fn get_recently_disconnected( &self, within_ms: u64, now_ms: u64, ) -> Vec<&PeerConnectionState>
Get peers disconnected within the specified time window
Sourcepub fn get_lost(&self) -> Vec<&PeerConnectionState>
pub fn get_lost(&self) -> Vec<&PeerConnectionState>
Get all peers in Lost state
Sourcepub fn get_with_history(&self) -> Vec<&PeerConnectionState>
pub fn get_with_history(&self) -> Vec<&PeerConnectionState>
Get peers that were previously connected (have connection history)
Sourcepub fn state_counts(&self) -> StateCountSummary
pub fn state_counts(&self) -> StateCountSummary
Count of peers in each state
Sourcepub fn on_discovered(
&mut self,
node_id: NodeId,
identifier: String,
name: Option<String>,
mesh_id: Option<String>,
rssi: i8,
now_ms: u64,
) -> &PeerConnectionState
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
Sourcepub fn on_connecting(&mut self, node_id: NodeId, now_ms: u64)
pub fn on_connecting(&mut self, node_id: NodeId, now_ms: u64)
Handle connection start
Sourcepub fn on_connected(&mut self, node_id: NodeId, now_ms: u64)
pub fn on_connected(&mut self, node_id: NodeId, now_ms: u64)
Handle successful connection
Sourcepub fn on_disconnected(
&mut self,
node_id: NodeId,
reason: DisconnectReason,
now_ms: u64,
)
pub fn on_disconnected( &mut self, node_id: NodeId, reason: DisconnectReason, now_ms: u64, )
Handle disconnection
Sourcepub fn update_rssi(&mut self, node_id: NodeId, rssi: i8, now_ms: u64) -> bool
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
Sourcepub fn record_transfer(
&mut self,
node_id: NodeId,
bytes_received: u64,
bytes_sent: u64,
)
pub fn record_transfer( &mut self, node_id: NodeId, bytes_received: u64, bytes_sent: u64, )
Record data transfer for a peer
Sourcepub fn record_sync(&mut self, node_id: NodeId)
pub fn record_sync(&mut self, node_id: NodeId)
Record a document sync for a peer
Sourcepub fn tick(&mut self, now_ms: u64) -> Vec<NodeId>
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
Sourcepub fn cleanup_lost(&mut self, older_than_ms: u64, now_ms: u64) -> Vec<NodeId>
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
Sourcepub fn import_peer(&mut self, peer: &HivePeer, now_ms: u64)
pub fn import_peer(&mut self, peer: &HivePeer, now_ms: u64)
Import state from a HivePeer
Sourcepub fn on_relay_received(
&mut self,
source_peer: NodeId,
origin_node: NodeId,
hop_count: u8,
now_ms: u64,
) -> bool
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 fromorigin_node- The original sender (from relay envelope)hop_count- Current hop count from the relay envelopenow_ms- Current timestamp
§Returns
true if this is a newly discovered indirect peer
Sourcepub fn get_indirect_peers(&self) -> Vec<&IndirectPeer>
pub fn get_indirect_peers(&self) -> Vec<&IndirectPeer>
Get all indirect peers
Sourcepub fn get_indirect_peers_owned(&self) -> Vec<IndirectPeer>
pub fn get_indirect_peers_owned(&self) -> Vec<IndirectPeer>
Get all indirect peers as owned values
Sourcepub fn get_indirect_peer(&self, node_id: NodeId) -> Option<&IndirectPeer>
pub fn get_indirect_peer(&self, node_id: NodeId) -> Option<&IndirectPeer>
Get a specific indirect peer
Sourcepub fn get_peers_by_degree(&self, degree: PeerDegree) -> Vec<NodeId>
pub fn get_peers_by_degree(&self, degree: PeerDegree) -> Vec<NodeId>
Get peers by degree
Sourcepub fn peer_degree(&self, node_id: NodeId) -> Option<PeerDegree>
pub fn peer_degree(&self, node_id: NodeId) -> Option<PeerDegree>
Get the degree of a specific peer (direct or indirect)
Sourcepub fn get_paths_to(&self, node_id: NodeId) -> Vec<(NodeId, u8)>
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
Sourcepub fn is_known(&self, node_id: NodeId) -> bool
pub fn is_known(&self, node_id: NodeId) -> bool
Check if a node is known (either direct or indirect)
Sourcepub fn cleanup_indirect(&mut self, now_ms: u64) -> Vec<NodeId>
pub fn cleanup_indirect(&mut self, now_ms: u64) -> Vec<NodeId>
Cleanup stale indirect peers
Returns list of removed peer IDs
Sourcepub fn remove_via_peer(&mut self, via_peer: NodeId)
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.
Sourcepub fn full_state_counts(&self) -> FullStateCountSummary
pub fn full_state_counts(&self) -> FullStateCountSummary
Combined count summary including indirect peers
Sourcepub fn indirect_peer_count(&self) -> usize
pub fn indirect_peer_count(&self) -> usize
Number of indirect peers
Sourcepub fn set_indirect_callsign(&mut self, node_id: NodeId, callsign: String)
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
impl Clone for ConnectionStateGraph
Source§fn clone(&self) -> ConnectionStateGraph
fn clone(&self) -> ConnectionStateGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more