Simplified table logic. Lookup tests. mucp/cient update
This commit is contained in:
@@ -67,27 +67,14 @@ func (t *table) Add(r Route) error {
|
||||
if _, ok := t.m[destAddr]; !ok {
|
||||
t.m[destAddr] = make(map[uint64]Route)
|
||||
t.m[destAddr][sum] = r
|
||||
go t.sendEvent(&Event{Type: Create, Route: r})
|
||||
go t.sendEvent(&Event{Type: Insert, Route: r})
|
||||
return nil
|
||||
}
|
||||
|
||||
// add new route to the table for the route destination
|
||||
if _, ok := t.m[destAddr][sum]; !ok {
|
||||
t.m[destAddr][sum] = r
|
||||
go t.sendEvent(&Event{Type: Create, Route: r})
|
||||
return nil
|
||||
}
|
||||
|
||||
// only add the route if the route override is explicitly requested
|
||||
if _, ok := t.m[destAddr][sum]; ok && r.Policy == Override {
|
||||
t.m[destAddr][sum] = r
|
||||
go t.sendEvent(&Event{Type: Update, Route: r})
|
||||
return nil
|
||||
}
|
||||
|
||||
// if we reached this point the route must already exist
|
||||
// we return nil only if explicitly requested by the client
|
||||
if r.Policy == Skip {
|
||||
go t.sendEvent(&Event{Type: Insert, Route: r})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -122,23 +109,9 @@ func (t *table) Update(r Route) error {
|
||||
|
||||
// check if the route destination has any routes in the table
|
||||
if _, ok := t.m[destAddr]; !ok {
|
||||
if r.Policy == Insert {
|
||||
t.m[destAddr] = make(map[uint64]Route)
|
||||
t.m[destAddr][sum] = r
|
||||
go t.sendEvent(&Event{Type: Create, Route: r})
|
||||
return nil
|
||||
}
|
||||
return ErrRouteNotFound
|
||||
}
|
||||
|
||||
// check if the route for the route destination already exists
|
||||
// NOTE: We only insert the route if explicitly requested by the client
|
||||
if _, ok := t.m[destAddr][sum]; !ok && r.Policy == Insert {
|
||||
t.m[destAddr][sum] = r
|
||||
go t.sendEvent(&Event{Type: Create, Route: r})
|
||||
return nil
|
||||
}
|
||||
|
||||
// if the route has been found update it
|
||||
if _, ok := t.m[destAddr][sum]; ok {
|
||||
t.m[destAddr][sum] = r
|
||||
|
||||
Reference in New Issue
Block a user