diff options
author | Aria <me@aria.rip> | 2023-11-04 20:06:12 +0000 |
---|---|---|
committer | Aria <me@aria.rip> | 2023-11-04 20:06:12 +0000 |
commit | f9c7ae8fddbeac4dfce760b260c705ff3ac9d118 (patch) | |
tree | 197cb19750e1ec15dd977dd2d245baec7273c313 /broadcast/src/topology.rs | |
parent | 4b6e257263f7bb6eaebb9be672f88bda85c77586 (diff) |
This reverts commit 4b6e257263f7bb6eaebb9be672f88bda85c77586.
Diffstat (limited to 'broadcast/src/topology.rs')
-rw-r--r-- | broadcast/src/topology.rs | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/broadcast/src/topology.rs b/broadcast/src/topology.rs index bb10466..5e16666 100644 --- a/broadcast/src/topology.rs +++ b/broadcast/src/topology.rs @@ -14,40 +14,16 @@ impl Topology { for node_id in node_ids.iter() { top.insert(node_id.clone(), node_ids.iter().cloned().collect()); } - Self::filter_desc(&mut top); Topology(RwLock::new(top)) } /// Replace the current topology with a new one. - pub async fn replace(&self, mut new: TopologyDesc) { - Self::filter_desc(&mut new); + pub async fn replace(&self, new: TopologyDesc) { *self.0.write().await = new; } - fn filter_desc(desc: &mut TopologyDesc) { - for (node_id, neighbours) in desc.iter_mut() { - neighbours.remove(node_id); - } - } - - /// Get the next targets from the given topology, for a message - /// which has travelled across the given path and is now at node_id. - pub async fn targets(&self, node_id: &String, last_node_id: &String) -> HashSet<String> { - // Ensure we don't keep holding the read lock - let topology = self.0.read().await; - - // Get all nodes the last node sent it to - let visited = topology.get(last_node_id); - - let neighbours = topology.get(node_id).unwrap(); - match visited { - Some(visited) => neighbours - .difference(&visited) - .cloned() - .filter(|n| n != node_id) - .collect(), - None => neighbours.clone(), - } + pub async fn all_targets(&self, node_id: &NodeId) -> HashSet<String> { + self.0.read().await.get(node_id).unwrap().clone() } } |