Commit bd81c826 authored by nanamicat's avatar nanamicat

fix

parent 0da5fc8b
Pipeline #42521 passed with stages
in 12 minutes and 8 seconds
use crate::quality::Quality; use crate::quality::Quality;
use crate::settings::{HALF_LIFE, PENALTY, PENALTY_MIN}; use crate::settings::{HALF_LIFE, PENALTY, PENALTY_MIN};
use crate::shared::{ use crate::shared::{
data::{DATABASE, GatewayGroupID, GatewayID, RegionID, RouterID}, data::{self, DATABASE, GatewayGroupID, GatewayID, RegionID, RouterID},
protocol::{Downlink, MessageType, PeerQuality, Uplink}, protocol::{Downlink, MessageType, PeerQuality, Uplink},
}; };
use crate::{UpdatingState, shared}; use crate::{UpdatingState, shared};
...@@ -73,13 +73,6 @@ impl Router { ...@@ -73,13 +73,6 @@ impl Router {
self.addr.is_some() self.addr.is_some()
} }
pub fn apply(&mut self, via: &mut BTreeMap<RouterID, RouterID>, plan: &mut BTreeMap<RegionID, BTreeMap<GatewayGroupID, GatewayID>>) {
self.via.append(via);
for (region, mut plan) in std::mem::take(plan) {
self.plan.entry(region).or_default().append(&mut plan);
}
}
pub fn on_message(&mut self, uplink: &mut Uplink, addr: SocketAddr, updating: &mut UpdatingState, now: Instant) -> Option<Downlink> { pub fn on_message(&mut self, uplink: &mut Uplink, addr: SocketAddr, updating: &mut UpdatingState, now: Instant) -> Option<Downlink> {
if uplink.peers.len() == self.peers.len() { if uplink.peers.len() == self.peers.len() {
for (current, new) in self.peers.values_mut().zip(&mut uplink.peers) { for (current, new) in self.peers.values_mut().zip(&mut uplink.peers) {
...@@ -102,7 +95,7 @@ impl Router { ...@@ -102,7 +95,7 @@ impl Router {
for (to, via) in self.via.iter_mut() { for (to, via) in self.via.iter_mut() {
*via = *to; *via = *to;
} }
self.apply(&mut uplink.via, &mut uplink.plan); data::GatewayGroup::apply(&mut self.via, &mut uplink.via, &mut self.plan, &mut uplink.plan);
self.online(addr, now); self.online(addr, now);
} }
None None
...@@ -112,7 +105,7 @@ impl Router { ...@@ -112,7 +105,7 @@ impl Router {
self.online(addr, now); self.online(addr, now);
if updating.router_id == self.id { if updating.router_id == self.id {
updating.router_id = Default::default(); updating.router_id = Default::default();
self.apply(&mut updating.message.via, &mut updating.message.plan); data::GatewayGroup::apply(&mut self.via, &mut updating.message.via, &mut self.plan, &mut updating.message.plan);
self.last_update = now; self.last_update = now;
} }
None None
......
...@@ -47,6 +47,20 @@ impl GatewayGroup { ...@@ -47,6 +47,20 @@ impl GatewayGroup {
.collect() .collect()
} }
pub fn apply(
self_via: &mut BTreeMap<RouterID, RouterID>,
new_via: &mut BTreeMap<RouterID, RouterID>,
self_plan: &mut BTreeMap<RegionID, BTreeMap<GatewayGroupID, GatewayID>>,
new_plan: &mut BTreeMap<RegionID, BTreeMap<GatewayGroupID, GatewayID>>,
) {
self_via.append(new_via);
for (region, inner) in new_plan {
if let Some(p) = self_plan.get_mut(region) {
p.append(inner);
}
}
}
fn guess(id: RouterID, gw: &data::Gateway, region: usize) -> i32 { fn guess(id: RouterID, gw: &data::Gateway, region: usize) -> i32 {
gw.metrics[region].saturating_add(gw.cost_outbound).saturating_add(if gw.router == id { 0 } else { 100 }) gw.metrics[region].saturating_add(gw.cost_outbound).saturating_add(if gw.router == id { 0 } else { 100 })
} }
......
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