aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/topology/graph.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/topology/graph.rs')
-rw-r--r--src/swarm/topology/graph.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/swarm/topology/graph.rs b/src/swarm/topology/graph.rs
index 5401506..92240e9 100644
--- a/src/swarm/topology/graph.rs
+++ b/src/swarm/topology/graph.rs
@@ -35,6 +35,7 @@ pub(crate) fn schemes(addresses: &[String]) -> BTreeSet<String> {
/// `local_transports`: on each, its neighbours among the members on it
/// (`neighbours`), all together.
pub(crate) fn neighbours_across(
+ topology: &dyn Topology,
members: &BTreeMap<String, BTreeSet<String>>,
local: &str,
local_transports: &BTreeSet<String>,
@@ -49,7 +50,7 @@ pub(crate) fn neighbours_across(
.filter(|(member, transports)| *member != local && transports.contains(transport))
.map(|(member, _)| member.clone())
.collect();
- all.extend(neighbours(&on_it, local, k, unreachable, stable));
+ all.extend(neighbours(topology, &on_it, local, k, unreachable, stable));
}
all
}
@@ -57,6 +58,7 @@ 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,
members: &[String],
local: &str,
k: usize,
@@ -65,11 +67,32 @@ pub(crate) fn neighbours(
) -> BTreeSet<String> {
let mut all: Vec<String> = members.to_vec();
all.push(local.to_owned());
- graph(&all, k, &|m: &str| m != local && unreachable(m), stable)
+ topology
+ .graph(&all, k, &|m: &str| m != local && unreachable(m), stable)
.remove(local)
.unwrap_or_default()
}
+/// The graph described above (`graph`): a ring by key hash, plus each member's
+/// lowest-scoring pairs, stable members preferred.
+pub(crate) struct RingAndPairs;
+
+impl Topology for RingAndPairs {
+ fn name(&self) -> &'static str {
+ "ring-and-pairs"
+ }
+
+ fn graph(
+ &self,
+ members: &[String],
+ k: usize,
+ unreachable: &dyn Fn(&str) -> bool,
+ stable: &dyn Fn(&str) -> bool,
+ ) -> BTreeMap<String, BTreeSet<String>> {
+ graph(members, k, unreachable, stable)
+ }
+}
+
/// Every reachable member's neighbours. Hashes each member once and scores pairs by
/// mixing the two hashes (`pair_score`), so the N² scores are a few nanoseconds each:
/// tens of milliseconds for thousands of members. `stable` members (`swarm::stability`)