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 {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue