Skip to content

Commit

Permalink
Collect ANNOUNCE mesage events before adding default gateway.
Browse files Browse the repository at this point in the history
  • Loading branch information
milosgajdos committed Jul 9, 2019
1 parent 2652710 commit 449aa0a
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions network/router/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,23 @@ func (r *router) Advertise() (<-chan *Advert, error) {
return nil, fmt.Errorf("failed adding routes: %s", err)
}
log.Logf("Routing table:\n%s", r.opts.Table)

// list routing table routes to announce
routes, err := r.opts.Table.List()
if err != nil {
return nil, fmt.Errorf("failed listing routes: %s", err)
}
// collect all the added routes before we attempt to add default gateway
events := make([]*table.Event, len(routes))
for i, route := range routes {
event := &table.Event{
Type: table.Insert,
Timestamp: time.Now(),
Route: route,
}
events[i] = event
}

// add default gateway into routing table
if r.opts.Gateway != "" {
// note, the only non-default value is the gateway
Expand Down Expand Up @@ -491,17 +503,6 @@ func (r *router) Advertise() (<-chan *Advert, error) {
r.wg.Add(1)
go r.watchErrors(errChan)

// announce yourself with all the existing routes
events := make([]*table.Event, len(routes))
for i, route := range routes {
event := &table.Event{
Type: table.Insert,
Timestamp: time.Now(),
Route: route,
}
events[i] = event
}

// advertise your presence
r.advertWg.Add(1)
go r.advertEvents(Announce, events)
Expand Down

0 comments on commit 449aa0a

Please sign in to comment.