smarter topology parsing
This commit is contained in:
parent
6e9dfe881a
commit
024005d59e
1 changed files with 7 additions and 25 deletions
|
@ -38,13 +38,12 @@ struct BCaster {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 = topology[id].clone();
|
||||||
self.neighbors.sort_unstable();
|
self.neighbors.sort_unstable();
|
||||||
for &node in topology.keys() {
|
for node in topology.keys() {
|
||||||
let node = node.to_string();
|
if !(node == id || self.neighbors.binary_search(node).is_ok()) {
|
||||||
if !(node == id || self.neighbors.binary_search(&node).is_ok()) {
|
self.others.push(node.to_owned());
|
||||||
self.others.push(node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,26 +104,9 @@ impl Node for BCaster {
|
||||||
}
|
}
|
||||||
"topology" => {
|
"topology" => {
|
||||||
let nid = runner.node_id();
|
let nid = runner.node_id();
|
||||||
let topology = req
|
let topology =
|
||||||
.body
|
serde_json::from_value(req.body.payload.get("topology").cloned().unwrap())
|
||||||
.payload
|
|
||||||
.get("topology")
|
|
||||||
.unwrap()
|
|
||||||
.as_object()
|
|
||||||
.unwrap();
|
.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();
|
|
||||||
self.topology(topology, nid);
|
self.topology(topology, nid);
|
||||||
let body = Body::from_type("topology_ok");
|
let body = Body::from_type("topology_ok");
|
||||||
runner.reply(&req, body);
|
runner.reply(&req, body);
|
||||||
|
|
Loading…
Reference in a new issue