mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-13 00:40:24 +03:00
commit
977a0e7215
@ -268,11 +268,11 @@ func (a *admin) init(c *Core, listenaddr string) {
|
|||||||
return admin_info{"source_subnets": subnets}, nil
|
return admin_info{"source_subnets": subnets}, nil
|
||||||
})
|
})
|
||||||
a.addHandler("getRoutes", []string{}, func(in admin_info) (admin_info, error) {
|
a.addHandler("getRoutes", []string{}, func(in admin_info) (admin_info, error) {
|
||||||
var routes []string
|
routes := make(admin_info)
|
||||||
a.core.router.doAdmin(func() {
|
a.core.router.doAdmin(func() {
|
||||||
getRoutes := func(ckrs []cryptokey_route) {
|
getRoutes := func(ckrs []cryptokey_route) {
|
||||||
for _, ckr := range ckrs {
|
for _, ckr := range ckrs {
|
||||||
routes = append(routes, fmt.Sprintf("%s via %s", ckr.subnet.String(), hex.EncodeToString(ckr.destination[:])))
|
routes[ckr.subnet.String()] = hex.EncodeToString(ckr.destination[:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getRoutes(a.core.router.cryptokey.ipv4routes)
|
getRoutes(a.core.router.cryptokey.ipv4routes)
|
||||||
|
@ -241,6 +241,16 @@ func (c *cryptokey) getPublicKeyForAddress(addr address, addrlen int) (boxPubKey
|
|||||||
for _, route := range *routingtable {
|
for _, route := range *routingtable {
|
||||||
// Does this subnet match the given IP?
|
// Does this subnet match the given IP?
|
||||||
if route.subnet.Contains(ip) {
|
if route.subnet.Contains(ip) {
|
||||||
|
// Check if the routing cache is above a certain size, if it is evict
|
||||||
|
// a random entry so we can make room for this one. We take advantage
|
||||||
|
// of the fact that the iteration order is random here
|
||||||
|
for k := range *routingcache {
|
||||||
|
if len(*routingcache) < 1024 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
delete(*routingcache, k)
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the entry for future packets to get a faster lookup
|
// Cache the entry for future packets to get a faster lookup
|
||||||
(*routingcache)[addr] = route
|
(*routingcache)[addr] = route
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user