1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Merge pull request #1123 from milosgajdos83/sync-metric

Update route metric before sending the Sync message
This commit is contained in:
Asim Aslam 2020-01-17 15:44:49 +00:00 committed by GitHub
commit f78e30770e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1293,6 +1293,20 @@ func (n *network) getProtoRoutes() ([]*pbRtr.Route, error) {
// encode the routes to protobuf
pbRoutes := make([]*pbRtr.Route, 0, len(routes))
for _, route := range routes {
// calculate route metric and add to the advertised metric
// we need to make sure we do not overflow math.MaxInt64
metric := n.getRouteMetric(route.Router, route.Gateway, route.Link)
log.Tracef("Network metric for router %s and gateway %s: %v", route.Router, route.Gateway, metric)
// check we don't overflow max int 64
if d := route.Metric + metric; d <= 0 {
// set to max int64 if we overflow
route.Metric = math.MaxInt64
} else {
// set the combined value of metrics otherwise
route.Metric = d
}
// generate new route proto
pbRoute := pbUtil.RouteToProto(route)
// mask the route before outbounding