mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-19 08:17:01 +02:00
Ignore no unique route updates (#2266)
This commit is contained in:
parent
88d1c5a0fd
commit
12ff93ba72
@ -3,6 +3,7 @@ package routemanager
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
@ -309,22 +310,33 @@ func (c *clientNetwork) sendUpdateToClientNetworkWatcher(update routesUpdate) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientNetwork) handleUpdate(update routesUpdate) {
|
func (c *clientNetwork) handleUpdate(update routesUpdate) bool {
|
||||||
|
isUpdateMapDifferent := false
|
||||||
updateMap := make(map[route.ID]*route.Route)
|
updateMap := make(map[route.ID]*route.Route)
|
||||||
|
|
||||||
for _, r := range update.routes {
|
for _, r := range update.routes {
|
||||||
updateMap[r.ID] = r
|
updateMap[r.ID] = r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.routes) != len(updateMap) {
|
||||||
|
isUpdateMapDifferent = true
|
||||||
|
}
|
||||||
|
|
||||||
for id, r := range c.routes {
|
for id, r := range c.routes {
|
||||||
_, found := updateMap[id]
|
_, found := updateMap[id]
|
||||||
if !found {
|
if !found {
|
||||||
close(c.routePeersNotifiers[r.Peer])
|
close(c.routePeersNotifiers[r.Peer])
|
||||||
delete(c.routePeersNotifiers, r.Peer)
|
delete(c.routePeersNotifiers, r.Peer)
|
||||||
|
isUpdateMapDifferent = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(c.routes[id], updateMap[id]) {
|
||||||
|
isUpdateMapDifferent = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.routes = updateMap
|
c.routes = updateMap
|
||||||
|
return isUpdateMapDifferent
|
||||||
}
|
}
|
||||||
|
|
||||||
// peersStateAndUpdateWatcher is the main point of reacting on client network routing events.
|
// peersStateAndUpdateWatcher is the main point of reacting on client network routing events.
|
||||||
@ -351,14 +363,20 @@ func (c *clientNetwork) peersStateAndUpdateWatcher() {
|
|||||||
|
|
||||||
log.Debugf("Received a new client network route update for [%v]", c.handler)
|
log.Debugf("Received a new client network route update for [%v]", c.handler)
|
||||||
|
|
||||||
c.handleUpdate(update)
|
// hash update somehow
|
||||||
|
isTrueRouteUpdate := c.handleUpdate(update)
|
||||||
|
|
||||||
c.updateSerial = update.updateSerial
|
c.updateSerial = update.updateSerial
|
||||||
|
|
||||||
|
if isTrueRouteUpdate {
|
||||||
|
log.Debug("Client network update contains different routes, recalculating routes")
|
||||||
err := c.recalculateRouteAndUpdatePeerAndSystem()
|
err := c.recalculateRouteAndUpdatePeerAndSystem()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to recalculate routes for network [%v]: %v", c.handler, err)
|
log.Errorf("Failed to recalculate routes for network [%v]: %v", c.handler, err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Debug("Route update is not different, skipping route recalculation")
|
||||||
|
}
|
||||||
|
|
||||||
c.startPeersStatusChangeWatcher()
|
c.startPeersStatusChangeWatcher()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user