mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00:00
clean up some debug API output
This commit is contained in:
parent
d17ac39789
commit
82c54f87ea
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user