aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/topology.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs
index 3731036..063fc41 100644
--- a/src/swarm/topology.rs
+++ b/src/swarm/topology.rs
@@ -119,6 +119,41 @@ pub(crate) fn is_neighbour(state: &AppState, peer: &str) -> bool {
}
}
+/// Every member's neighbours as the member list makes them, as this node sees it (whom
+/// it can reach, who is stable): the graph each node computes its own part of. Ours as
+/// they are (with members that only connect out, or aren't listed yet). For a map of
+/// the swarm (the dashboard); None until the view is known. A link exists if either end
+/// chose it: draw one if either lists the other. About `members²` work: compute it when
+/// the member list may have changed, not on every look.
+#[cfg_attr(not(feature = "dashboard"), allow(dead_code))]
+pub(crate) fn intended_graph(state: &AppState) -> Option<BTreeMap<String, BTreeSet<String>>> {
+ let view = state.neighbours.read_or_recover();
+ let view = view.as_ref()?;
+ let unreachable = |member: &str| view.unreachable.contains(member);
+ let stable = |member: &str| view.stable.contains(member);
+ let graph = view
+ .members
+ .iter()
+ .map(|member| {
+ let neighbours = if member == state.local_id() {
+ view.neighbours.clone()
+ } else {
+ let own = view.transports.get(member).cloned().unwrap_or_default();
+ neighbours_across(
+ &view.transports,
+ member,
+ &own,
+ view.k,
+ &unreachable,
+ &stable,
+ )
+ };
+ (member.clone(), neighbours)
+ })
+ .collect();
+ Some(graph)
+}
+
/// How the neighbours changed.
pub(crate) struct NeighbourChange {
pub(crate) added: Vec<String>,