From 82c54f87eae55c7f0acbb1dfb91a91482b393ce3 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 28 Oct 2023 06:36:01 -0500 Subject: [PATCH] clean up some debug API output --- src/admin/options.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/admin/options.go b/src/admin/options.go index b2e273b..03cf74a 100644 --- a/src/admin/options.go +++ b/src/admin/options.go @@ -1,12 +1,16 @@ package admin import ( + "crypto/ed25519" "encoding/hex" "encoding/json" + "net" "sync" "time" "github.com/Arceliar/ironwood/network" + + "github.com/yggdrasil-network/yggdrasil-go/src/address" ) func (c *AdminSocket) _applyOption(opt SetupOption) { @@ -32,9 +36,10 @@ func (l LogLookups) isSetupOption() {} func (a *AdminSocket) logLookups() { type resi struct { - Key string `json:"key"` - Path []uint64 `json:"path"` - Time int64 `json:"time"` + Address string `json:"addr"` + Key string `json:"key"` + Path []uint64 `json:"path"` + Time int64 `json:"time"` } type res struct { Infos []resi `json:"infos"` @@ -43,12 +48,14 @@ func (a *AdminSocket) logLookups() { path []uint64 time time.Time } - infos := make(map[string]info) + type edk [ed25519.PublicKeySize]byte + infos := make(map[edk]info) var m sync.Mutex a.core.PacketConn.PacketConn.Debug.SetDebugLookupLogger(func(l network.DebugLookupInfo) { - key := hex.EncodeToString(l.Key[:]) + var k edk + copy(k[:], l.Key[:]) m.Lock() - infos[key] = info{path: l.Path, time: time.Now()} + infos[k] = info{path: l.Path, time: time.Now()} m.Unlock() }) _ = a.AddHandler( @@ -61,7 +68,9 @@ func (a *AdminSocket) logLookups() { // TODO? automatic cleanup, so we don't need to call lookups periodically to prevent leaks delete(infos, k) } - rs = append(rs, resi{Key: k, Path: v.path, Time: v.time.Unix()}) + a := address.AddrForKey(ed25519.PublicKey(k[:])) + addr := net.IP(a[:]).String() + rs = append(rs, resi{Address: addr, Key: hex.EncodeToString(k[:]), Path: v.path, Time: v.time.Unix()}) } m.Unlock() return &res{Infos: rs}, nil