Commit 10241602 authored by nanamicat's avatar nanamicat

clean

parent d6099740
use crate::api::create_app;
use crate::data::{DATABASE, GatewayGroupID, RegionID, RouterID};
use crate::data::{DATABASE, GatewayGroupID, RouterID};
use crate::protocol::{Downlink, Uplink};
use crate::router::Router;
use crate::settings::{Settings, TIMEOUT};
......
......@@ -179,15 +179,14 @@ impl Router {
}
// Plan updates (Gateways)
for (r, _) in DATABASE.regions.iter().enumerate() {
let region_id = RegionID(r as u8);
for (region_id, plan) in &self.plan {
for (&gid, gateways) in gateway_groups {
let current_gw = self.plan[&region_id][&gid];
let current_gw = plan[&gid];
let current_metric = metrics[&DATABASE.gateways.iter().find(|f| f.id == current_gw).unwrap().router];
let (best_gw, best_metric) = gateways
.iter()
.map(|g| (g, metrics[&g.router].saturating_add(g.cost_outbound).saturating_add(g.metrics[r])))
.map(|g| (g, metrics[&g.router].saturating_add(g.cost_outbound).saturating_add(g.metrics[region_id.0 as usize])))
.min_by_key(|(_, m)| *m)
.unwrap();
......@@ -195,7 +194,7 @@ impl Router {
if best_metric.saturating_add(penalty) < current_metric {
overcome = true;
}
changed_plan.entry(region_id).or_insert_with(BTreeMap::new).insert(gid, best_gw.id);
changed_plan.entry(*region_id).or_insert_with(BTreeMap::new).insert(gid, best_gw.id);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment