pub struct NetworkTopologyMapper { /* private fields */ }Expand description
Live network topology mapper.
Tracks peer nodes and directed edges, computes graph algorithms, and maintains a bounded ring-buffer of snapshots.
Implementations§
Source§impl NetworkTopologyMapper
impl NetworkTopologyMapper
Sourcepub fn new(config: NtmMapperConfig) -> Self
pub fn new(config: NtmMapperConfig) -> Self
Create a new mapper with the given config.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a mapper with default configuration.
Sourcepub fn add_node(
&mut self,
id: NtmNodeId,
addr: impl Into<String>,
region: Option<String>,
rtt_ms: f64,
last_seen: u64,
) -> Result<(), NtmMapperError>
pub fn add_node( &mut self, id: NtmNodeId, addr: impl Into<String>, region: Option<String>, rtt_ms: f64, last_seen: u64, ) -> Result<(), NtmMapperError>
Insert or update a node.
If the node already exists its addr, region, rtt_ms, and
last_seen fields are refreshed. Returns Err(CapacityExceeded)
when the node is new and the graph is full.
Sourcepub fn remove_node(&mut self, id: &NtmNodeId) -> Result<(), NtmMapperError>
pub fn remove_node(&mut self, id: &NtmNodeId) -> Result<(), NtmMapperError>
Remove a node and all edges incident to it.
Sourcepub fn update_node_rtt(
&mut self,
id: &NtmNodeId,
rtt_ms: f64,
) -> Result<(), NtmMapperError>
pub fn update_node_rtt( &mut self, id: &NtmNodeId, rtt_ms: f64, ) -> Result<(), NtmMapperError>
Update the RTT measurement for an existing node.
Sourcepub fn set_bootstrap(
&mut self,
id: &NtmNodeId,
flag: bool,
) -> Result<(), NtmMapperError>
pub fn set_bootstrap( &mut self, id: &NtmNodeId, flag: bool, ) -> Result<(), NtmMapperError>
Mark a node as a bootstrap / well-known anchor.
Sourcepub fn get_node(&self, id: &NtmNodeId) -> Option<&NtmNode>
pub fn get_node(&self, id: &NtmNodeId) -> Option<&NtmNode>
Return an immutable reference to a node.
Sourcepub fn add_edge(
&mut self,
src: NtmNodeId,
dst: NtmNodeId,
latency_ms: f64,
bandwidth_kbps: f64,
observed_at: u64,
) -> Result<NtmEdgeId, NtmMapperError>
pub fn add_edge( &mut self, src: NtmNodeId, dst: NtmNodeId, latency_ms: f64, bandwidth_kbps: f64, observed_at: u64, ) -> Result<NtmEdgeId, NtmMapperError>
Insert a directed edge src → dst.
If an edge with the same (src, dst) pair already exists, its
latency_ms, bandwidth_kbps, and observed_at fields are updated.
Returns the edge identifier.
Sourcepub fn remove_edge(&mut self, id: NtmEdgeId) -> Result<(), NtmMapperError>
pub fn remove_edge(&mut self, id: NtmEdgeId) -> Result<(), NtmMapperError>
Remove a directed edge by its identifier.
Sourcepub fn update_edge_latency(
&mut self,
id: NtmEdgeId,
latency_ms: f64,
) -> Result<(), NtmMapperError>
pub fn update_edge_latency( &mut self, id: NtmEdgeId, latency_ms: f64, ) -> Result<(), NtmMapperError>
Update the latency measurement for an existing edge.
Sourcepub fn get_edge(&self, id: NtmEdgeId) -> Option<&NtmEdge>
pub fn get_edge(&self, id: NtmEdgeId) -> Option<&NtmEdge>
Return an immutable reference to an edge.
Sourcepub fn find_edge(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<NtmEdgeId>
pub fn find_edge(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<NtmEdgeId>
Return the edge identifier for the directed pair (src, dst), if any.
Sourcepub fn neighbors(&self, node_id: &NtmNodeId) -> Vec<NtmNodeId> ⓘ
pub fn neighbors(&self, node_id: &NtmNodeId) -> Vec<NtmNodeId> ⓘ
Return the neighbour node ids reachable via outgoing edges from node_id.
Sourcepub fn shortest_path(
&self,
src: &NtmNodeId,
dst: &NtmNodeId,
) -> Option<Vec<NtmNodeId>>
pub fn shortest_path( &self, src: &NtmNodeId, dst: &NtmNodeId, ) -> Option<Vec<NtmNodeId>>
Dijkstra shortest path from src to dst weighted by latency_ms.
Returns None if either node is unknown or no path exists.
Sourcepub fn bfs_distance(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<u32>
pub fn bfs_distance(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<u32>
BFS-based shortest path counting hops (ignores weights).
Returns None if no path exists.
Sourcepub fn diameter(&self) -> u32
pub fn diameter(&self) -> u32
Graph diameter: maximum of all pairwise BFS distances.
Returns 0 when the graph has fewer than two nodes.
Sourcepub fn clustering_coefficient(&self, node_id: &NtmNodeId) -> f64
pub fn clustering_coefficient(&self, node_id: &NtmNodeId) -> f64
Local clustering coefficient for node_id.
C(u) = triangles / (k * (k-1)) where k = degree(u).
Returns 0.0 for nodes with degree < 2.
Sourcepub fn compute_betweenness_centrality(&self) -> HashMap<NtmNodeId, f64>
pub fn compute_betweenness_centrality(&self) -> HashMap<NtmNodeId, f64>
Brandes algorithm for betweenness centrality on the directed graph.
Complexity O(V * E) — suitable for moderate-sized graphs (≤ 4096 nodes).
Sourcepub fn take_snapshot(&mut self, ts: u64) -> NtmSnapshot
pub fn take_snapshot(&mut self, ts: u64) -> NtmSnapshot
Capture the current state into a snapshot and store it.
If the snapshot buffer is full (20 entries) the oldest entry is dropped before the new one is inserted.
Sourcepub fn snapshots(&self) -> &VecDeque<NtmSnapshot>
pub fn snapshots(&self) -> &VecDeque<NtmSnapshot>
Access the snapshot history (oldest first).
Sourcepub fn prune_stale(&mut self, now_ts: u64)
pub fn prune_stale(&mut self, now_ts: u64)
Remove all nodes (and their edges) whose last_seen is older than
now_ts - config.prune_disconnected_after_secs.
Sourcepub fn topology_stats(&self) -> NtmTopologyMetrics
pub fn topology_stats(&self) -> NtmTopologyMetrics
Compute the full suite of topology metrics.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Return the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Return the number of edges.
Sourcepub fn config(&self) -> &NtmMapperConfig
pub fn config(&self) -> &NtmMapperConfig
Return the current configuration.
Auto Trait Implementations§
impl Freeze for NetworkTopologyMapper
impl RefUnwindSafe for NetworkTopologyMapper
impl Send for NetworkTopologyMapper
impl Sync for NetworkTopologyMapper
impl Unpin for NetworkTopologyMapper
impl UnsafeUnpin for NetworkTopologyMapper
impl UnwindSafe for NetworkTopologyMapper
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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