Commit 473d1dae authored by nanamicat's avatar nanamicat

metric

parent 5d5295c4
Pipeline #42461 passed with stages
in 46 seconds
......@@ -18,13 +18,7 @@ impl Quality {
}
pub fn metric(&self) -> i32 {
assert!(0.0 <= self.reliability && self.reliability <= 1.0);
if self.reliability == 0.0 {
i32::MAX
} else {
self.delay + ((1.0 - self.reliability) * 3000.0).round() as i32 + self.cost as i32
}
self.delay + ((1.0 - self.reliability) * 3000.0).round() as i32 + self.cost as i32
}
}
......
......@@ -119,6 +119,7 @@ impl Router {
updating.router_id = 0;
self.via.append(&mut updating.message.via);
self.plan.append(&mut updating.message.plan);
self.last_update = now;
}
None
} else if !self.is_online() {
......@@ -147,6 +148,7 @@ impl Router {
let penalty = self.penalty(now);
let mut changed_via: BTreeMap<u8, u8> = BTreeMap::new();
// let mut metric: BTreeMap<u8, i32> = BTreeMap::new();
let mut overcome = false;
for to in routers.values().filter(|&r| r != self) {
let current_router = routers.get(self.via.get(&to.id).unwrap()).unwrap();
......@@ -161,16 +163,20 @@ impl Router {
match candidate.iter().min_by_key(|(_, m)| m) {
None if current_router != to => {
// 无论如何都不可达就标记为直连
overcome = true;
changed_via.insert(to.id, to.id);
}
Some((best_router, best_metric)) if current_router != *best_router && (*best_metric + penalty < current_metric) => {
Some((best_router, best_metric)) if current_router != *best_router && *best_metric < current_metric => {
if *best_metric + penalty < current_metric {
overcome = true
}
changed_via.insert(to.id, best_router.id);
}
_ => {}
}
}
if changed_via.len() > 0 {
if overcome {
Some(Downlink {
action: MessageType::Update,
version: self.version + 1,
......
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