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
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