Collect ANNOUNCE mesage events before adding default gateway.

This commit is contained in:
Milos Gajdos 2019-07-09 15:01:52 +01:00
parent 265271008e
commit 449aa0a339
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -418,11 +418,23 @@ func (r *router) Advertise() (<-chan *Advert, error) {
return nil, fmt.Errorf("failed adding routes: %s", err) return nil, fmt.Errorf("failed adding routes: %s", err)
} }
log.Logf("Routing table:\n%s", r.opts.Table) log.Logf("Routing table:\n%s", r.opts.Table)
// list routing table routes to announce // list routing table routes to announce
routes, err := r.opts.Table.List() routes, err := r.opts.Table.List()
if err != nil { if err != nil {
return nil, fmt.Errorf("failed listing routes: %s", err) 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 // add default gateway into routing table
if r.opts.Gateway != "" { if r.opts.Gateway != "" {
// note, the only non-default value is the gateway // note, the only non-default value is the gateway
@ -491,17 +503,6 @@ func (r *router) Advertise() (<-chan *Advert, error) {
r.wg.Add(1) r.wg.Add(1)
go r.watchErrors(errChan) 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 // advertise your presence
r.advertWg.Add(1) r.advertWg.Add(1)
go r.advertEvents(Announce, events) go r.advertEvents(Announce, events)