smarter topology parsing

This commit is contained in:
Joe Ardent 2025-09-17 13:08:07 -07:00
parent 6e9dfe881a
commit 024005d59e

View file

@ -38,13 +38,12 @@ struct BCaster {
}
impl BCaster {
fn topology(&mut self, topology: HashMap<&str, Vec<String>>, id: &str) {
fn topology(&mut self, topology: HashMap<String, Vec<String>>, 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<String>> = 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);