Find the best routes in the routes we would advertise based on Strategy
This commit is contained in:
parent
793e6013e5
commit
60c05bd899
@ -1058,17 +1058,18 @@ func (n *network) processNetChan(listener tunnel.Listener) {
|
|||||||
// lookup best routes for the services in the just received route
|
// lookup best routes for the services in the just received route
|
||||||
q := []router.QueryOption{
|
q := []router.QueryOption{
|
||||||
router.QueryService(route.Service),
|
router.QueryService(route.Service),
|
||||||
router.QueryStrategy(router.AdvertiseBest),
|
router.QueryStrategy(n.router.Options().Advertise),
|
||||||
}
|
}
|
||||||
bestRoutes, err := n.options.Router.Table().Query(q...)
|
|
||||||
|
routes, err := n.options.Router.Table().Query(q...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err)
|
log.Debugf("Network node %s failed listing best routes for %s: %v", n.id, route.Service, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// we found no route for the given service
|
// we found no routes for the given service
|
||||||
// create new route we have just received
|
// create the new route we have just received
|
||||||
if len(bestRoutes) == 0 {
|
if len(routes) == 0 {
|
||||||
// add routes to the routing table
|
// add routes to the routing table
|
||||||
if err := n.router.Table().Create(route); err != nil && err != router.ErrDuplicateRoute {
|
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)
|
log.Debugf("Network node %s failed to add route: %v", n.id, err)
|
||||||
@ -1076,10 +1077,18 @@ func (n *network) processNetChan(listener tunnel.Listener) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find the best route for the given service
|
||||||
|
// from the routes that we would advertise
|
||||||
|
bestRoute := routes[0]
|
||||||
|
for _, r := range routes[0:] {
|
||||||
|
if bestRoute.Metric > r.Metric {
|
||||||
|
bestRoute = r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Take the best route to given service and:
|
// Take the best route to given service and:
|
||||||
// * prefer our own routes if metric is the same
|
// only add new routes if the metric is better
|
||||||
// * only add new routes if the metric is better than the metric of our best route
|
// than the metric of our best route
|
||||||
bestRoute := bestRoutes[0]
|
|
||||||
|
|
||||||
if bestRoute.Metric <= route.Metric {
|
if bestRoute.Metric <= route.Metric {
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user