From 7c0c318dca3054be6c7bacf5a4b3f5a4e47cc949 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 6 Nov 2026 19:53:27 +0100 Subject: topology neighbours and optional graph --- src/swarm/topology/graph.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/swarm/topology/graph.rs') diff --git a/src/swarm/topology/graph.rs b/src/swarm/topology/graph.rs index 92240e9..d8b2921 100644 --- a/src/swarm/topology/graph.rs +++ b/src/swarm/topology/graph.rs @@ -34,8 +34,8 @@ pub(crate) fn schemes(addresses: &[String]) -> BTreeSet { /// The neighbours of `local` among `members` (by the transports each is on), on each of /// `local_transports`: on each, its neighbours among the members on it /// (`neighbours`), all together. -pub(crate) fn neighbours_across( - topology: &dyn Topology, +pub(crate) fn neighbours_across( + topology: &T, members: &BTreeMap>, local: &str, local_transports: &BTreeSet, @@ -56,9 +56,10 @@ pub(crate) fn neighbours_across( } /// The neighbours of `local` among `members` (which may or may not contain `local`), -/// skipping members for which `unreachable` holds. -pub(crate) fn neighbours( - topology: &dyn Topology, +/// skipping members for which `unreachable` holds; none by a topology without a shared +/// graph. +pub(crate) fn neighbours( + topology: &T, members: &[String], local: &str, k: usize, @@ -69,7 +70,7 @@ pub(crate) fn neighbours( all.push(local.to_owned()); topology .graph(&all, k, &|m: &str| m != local && unreachable(m), stable) - .remove(local) + .and_then(|mut graph| graph.remove(local)) .unwrap_or_default() } @@ -88,8 +89,8 @@ impl Topology for RingAndPairs { k: usize, unreachable: &dyn Fn(&str) -> bool, stable: &dyn Fn(&str) -> bool, - ) -> BTreeMap> { - graph(members, k, unreachable, stable) + ) -> Option>> { + Some(graph(members, k, unreachable, stable)) } } -- cgit v1.3.1