From 024005d59e3dee6941eb7caba2f8dc14cea9c1ff Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 17 Sep 2025 13:08:07 -0700 Subject: [PATCH] smarter topology parsing --- gg-broadcast/src/main.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/gg-broadcast/src/main.rs b/gg-broadcast/src/main.rs index 0b877ec..3e25ab2 100644 --- a/gg-broadcast/src/main.rs +++ b/gg-broadcast/src/main.rs @@ -38,13 +38,12 @@ struct BCaster { } impl BCaster { - fn topology(&mut self, topology: HashMap<&str, Vec>, id: &str) { + fn topology(&mut self, topology: HashMap>, id: &str) { self.neighbors = topology[id].clone(); self.neighbors.sort_unstable(); - for &node in topology.keys() { - let node = node.to_string(); - if !(node == id || self.neighbors.binary_search(&node).is_ok()) { - self.others.push(node); + for node in topology.keys() { + if !(node == id || self.neighbors.binary_search(node).is_ok()) { + self.others.push(node.to_owned()); } } } @@ -105,26 +104,9 @@ impl Node for BCaster { } "topology" => { let nid = runner.node_id(); - let topology = req - .body - .payload - .get("topology") - .unwrap() - .as_object() - .unwrap(); - let topology: HashMap<&str, Vec> = topology - .iter() - .map(|(k, v)| { - ( - k.as_str(), - v.as_array() - .unwrap() - .iter() - .map(|v| v.as_str().unwrap().to_string()) - .collect(), - ) - }) - .collect(); + let topology = + serde_json::from_value(req.body.payload.get("topology").cloned().unwrap()) + .unwrap(); self.topology(topology, nid); let body = Body::from_type("topology_ok"); runner.reply(&req, body);