Only emit Update event if a route was updated/added

This commit is contained in:
Milos Gajdos 2019-09-26 12:45:10 +01:00
parent b2577e6022
commit a4c04d8f50
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -87,7 +87,7 @@ func (t *table) Delete(r Route) error {
} }
delete(t.routes[service], sum) delete(t.routes[service], sum)
log.Debugf("Router emitting %s for route: %s", Update, r.Address) log.Debugf("Router emitting %s for route: %s", Delete, r.Address)
go t.sendEvent(&Event{Type: Delete, Timestamp: time.Now(), Route: r}) go t.sendEvent(&Event{Type: Delete, Timestamp: time.Now(), Route: r})
return nil return nil
@ -106,9 +106,15 @@ func (t *table) Update(r Route) error {
t.routes[service] = make(map[uint64]Route) t.routes[service] = make(map[uint64]Route)
} }
if _, ok := t.routes[service][sum]; !ok {
t.routes[service][sum] = r
log.Debugf("Router emitting %s for route: %s", Update, r.Address)
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r})
return nil
}
// just update the route, but dont emit Update event
t.routes[service][sum] = r t.routes[service][sum] = r
log.Debugf("Router emitting %s for route: %s", Update, r.Address)
go t.sendEvent(&Event{Type: Update, Timestamp: time.Now(), Route: r})
return nil return nil
} }