Advertise routes with configured strategy. Simplify Sync apply logic
This commit is contained in:
parent
eda8b00f84
commit
793e6013e5
@ -851,7 +851,9 @@ func (n *network) processNetChan(listener tunnel.Listener) {
|
||||
}
|
||||
|
||||
// get a list of the best routes for each service in our routing table
|
||||
q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)}
|
||||
q := []router.QueryOption{
|
||||
router.QueryStrategy(n.router.Options().Advertise),
|
||||
}
|
||||
routes, err := n.options.Router.Table().Query(q...)
|
||||
switch err {
|
||||
case nil:
|
||||
@ -1048,19 +1050,24 @@ func (n *network) processNetChan(listener tunnel.Listener) {
|
||||
for _, pbRoute := range pbNetSync.Routes {
|
||||
// unmarshal the routes received from remote peer
|
||||
route := pbUtil.ProtoToRoute(pbRoute)
|
||||
// lookup the best route for the given service in our routing table
|
||||
// continue if we are the originator of the route
|
||||
if route.Router == n.options.Router.Options().Id {
|
||||
log.Debugf("Network node %s skipping route addition: route already present", n.id)
|
||||
continue
|
||||
}
|
||||
// lookup best routes for the services in the just received route
|
||||
q := []router.QueryOption{
|
||||
router.QueryService(route.Service),
|
||||
router.QueryStrategy(router.AdvertiseBest),
|
||||
}
|
||||
// NOTE: bestRoutes is either an empty slice or one element slice
|
||||
bestRoutes, err := n.options.Router.Table().Query(q...)
|
||||
if err != nil {
|
||||
log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err)
|
||||
continue
|
||||
}
|
||||
// we found no route for given service
|
||||
// create the route we have just received
|
||||
|
||||
// we found no route for the given service
|
||||
// create new route we have just received
|
||||
if len(bestRoutes) == 0 {
|
||||
// add routes to the routing table
|
||||
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
|
||||
@ -1073,24 +1080,14 @@ func (n *network) processNetChan(listener tunnel.Listener) {
|
||||
// * prefer our own routes if metric is the same
|
||||
// * only add new routes if the metric is better than the metric of our best route
|
||||
bestRoute := bestRoutes[0]
|
||||
if bestRoute.Metric == route.Metric {
|
||||
if route.Router == n.options.Router.Options().Id {
|
||||
log.Debugf("Network node %s skipping route addition: already has local route", n.id)
|
||||
continue
|
||||
}
|
||||
// NOTE: we might want to skip here, too as we already have equally good route
|
||||
// add routes to the routing table
|
||||
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
|
||||
log.Debugf("Network node %s failed to add route: %v", n.id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if bestRoute.Metric <= route.Metric {
|
||||
continue
|
||||
}
|
||||
if bestRoute.Metric > route.Metric {
|
||||
// TODO: should we delete our best route here?
|
||||
// add route to the routing table
|
||||
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
|
||||
log.Debugf("Network node %s failed to add route: %v", n.id, err)
|
||||
}
|
||||
|
||||
// add route to the routing table
|
||||
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
|
||||
log.Debugf("Network node %s failed to add route: %v", n.id, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1372,7 +1369,9 @@ func (n *network) manage() {
|
||||
}
|
||||
|
||||
// get a list of the best routes for each service in our routing table
|
||||
q := []router.QueryOption{router.QueryStrategy(router.AdvertiseBest)}
|
||||
q := []router.QueryOption{
|
||||
router.QueryStrategy(n.router.Options().Advertise),
|
||||
}
|
||||
routes, err := n.options.Router.Table().Query(q...)
|
||||
switch err {
|
||||
case nil:
|
||||
|
Loading…
Reference in New Issue
Block a user