mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-24 18:01:30 +00:00
35 lines
687 B
Go
35 lines
687 B
Go
![]() |
package admin
|
||
|
|
||
|
import (
|
||
|
"encoding/hex"
|
||
|
"net"
|
||
|
|
||
|
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||
|
)
|
||
|
|
||
|
type GetDHTRequest struct{}
|
||
|
|
||
|
type GetDHTResponse struct {
|
||
|
DHT map[string]DHTEntry `json:"dht"`
|
||
|
}
|
||
|
|
||
|
type DHTEntry struct {
|
||
|
PublicKey string `json:"key"`
|
||
|
Port uint64 `json:"port"`
|
||
|
Next uint64 `json:"next"`
|
||
|
}
|
||
|
|
||
|
func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error {
|
||
|
res.DHT = map[string]DHTEntry{}
|
||
|
for _, d := range a.core.GetDHT() {
|
||
|
addr := address.AddrForKey(d.Key)
|
||
|
so := net.IP(addr[:]).String()
|
||
|
res.DHT[so] = DHTEntry{
|
||
|
PublicKey: hex.EncodeToString(d.Key[:]),
|
||
|
Port: d.Port,
|
||
|
Next: d.Next,
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|