Changed names of some variables.

This commit is contained in:
Milos Gajdos 2019-10-09 19:08:24 +01:00
parent d5ce96da24
commit 7a4bff4e9f
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
3 changed files with 19 additions and 16 deletions

View File

@ -682,7 +682,7 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) {
return nil, fmt.Errorf("failed listing routes: %s", err)
}
if r.options.Advertise == All {
if r.options.Advertise == AdvertiseAll {
// build a list of events to advertise
events := make([]*Event, len(routes))
for i, route := range routes {
@ -697,33 +697,36 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) {
}
// routeMap stores optimal routes per service
optimalRoutes := make(map[string]Route)
bestRoutes := make(map[string]Route)
// go through all routes found in the routing table and collapse them to optimal routes
for _, route := range routes {
optimal, ok := optimalRoutes[route.Service]
routeKey := route.Service + "@" + route.Network
optimal, ok := bestRoutes[routeKey]
if !ok {
optimalRoutes[route.Service] = route
bestRoutes[routeKey] = route
continue
}
// if the current optimal route metric is higher than routing table route, replace it
if optimal.Metric > route.Metric {
optimalRoutes[route.Service] = route
bestRoutes[routeKey] = route
continue
}
// if the metrics are the same, prefer advertising your own route
if optimal.Metric == route.Metric {
if route.Router == r.options.Id {
optimalRoutes[route.Service] = route
bestRoutes[routeKey] = route
continue
}
}
}
log.Debugf("Router advertising %d best routes out of %d", len(bestRoutes), len(routes))
// build a list of events to advertise
events := make([]*Event, len(optimalRoutes))
events := make([]*Event, len(bestRoutes))
i := 0
for _, route := range optimalRoutes {
for _, route := range bestRoutes {
event := &Event{
Type: evType,
Timestamp: time.Now(),

View File

@ -80,6 +80,6 @@ func DefaultOptions() Options {
Address: DefaultAddress,
Network: DefaultNetwork,
Registry: registry.DefaultRegistry,
Advertise: Optimal,
Advertise: AdvertiseBest,
}
}

View File

@ -143,19 +143,19 @@ type Advert struct {
type Strategy int
const (
// All advertises all routes to the network
All Strategy = iota
// Optimal advertises optimal routes to the network
Optimal
// AdvertiseAll advertises all routes to the network
AdvertiseAll Strategy = iota
// AdvertiseBest advertises optimal routes to the network
AdvertiseBest
)
// String returns human readable Strategy
func (s Strategy) String() string {
switch s {
case All:
case AdvertiseAll:
return "all"
case Optimal:
return "optimal"
case AdvertiseBest:
return "best"
default:
return "unknown"
}