Commit ac5a65b5 authored by nanamicat's avatar nanamicat

clean

parent 59c52ce0
...@@ -88,6 +88,13 @@ impl Router { ...@@ -88,6 +88,13 @@ 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) {
...@@ -110,8 +117,7 @@ impl Router { ...@@ -110,8 +117,7 @@ impl Router {
for (to, via) in self.via.iter_mut() { for (to, via) in self.via.iter_mut() {
*via = *to; *via = *to;
} }
self.via.append(&mut uplink.via); self.apply(&mut uplink.via, &mut uplink.plan);
self.plan.append(&mut uplink.plan);
self.online(addr, now); self.online(addr, now);
} }
None None
...@@ -121,8 +127,7 @@ impl Router { ...@@ -121,8 +127,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.via.append(&mut updating.message.via); self.apply(&mut updating.message.via, &mut updating.message.plan);
self.plan.append(&mut updating.message.plan);
self.last_update = now; self.last_update = now;
} }
None None
......
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