Skip to content

Commit

Permalink
clean up some debug API output
Browse files Browse the repository at this point in the history
  • Loading branch information
Arceliar committed Oct 28, 2023
1 parent d17ac39 commit 82c54f8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/admin/options.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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"`
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 82c54f8

Please sign in to comment.