Start with discover routes, basic functionality

This commit is contained in:
Fran Bull
2024-04-08 11:53:38 -07:00
committed by Kevin Liang
parent c76d54a5c1
commit 75ba1c4d45
3 changed files with 86 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ func (ri *RouteInfo) Routes(local, control, discovered bool) []netip.Prefix {
if discovered {
for _, dr := range ri.Discovered {
ret = append(ret, dr.routesSlice()...)
ret = append(ret, dr.RoutesSlice()...)
}
}
return ret
@@ -53,10 +53,33 @@ type DatedRoutes struct {
LastCleanup time.Time
}
func (dr *DatedRoutes) routesSlice() []netip.Prefix {
func (dr *DatedRoutes) RoutesSlice() []netip.Prefix {
var routes []netip.Prefix
for k := range dr.Routes {
routes = append(routes, k)
}
return routes
}
func (r *RouteInfo) AddRoutesInDiscoveredForDomain(domain string, addrs []netip.Prefix) {
dr, hasKey := r.Discovered[domain]
if !hasKey || dr == nil || dr.Routes == nil {
newDatedRoutes := &DatedRoutes{make(map[netip.Prefix]time.Time), time.Now()}
newDatedRoutes.addAddrsToDatedRoute(addrs)
r.Discovered[domain] = newDatedRoutes
return
}
// kevin comment: we won't see any existing routes here because know addrs are filtered.
currentRoutes := r.Discovered[domain]
currentRoutes.addAddrsToDatedRoute(addrs)
r.Discovered[domain] = currentRoutes
return
}
func (d *DatedRoutes) addAddrsToDatedRoute(addrs []netip.Prefix) {
time := time.Now()
for _, addr := range addrs {
d.Routes[addr] = time
}
}