mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
add dht time since last ping to admin socket, some DHT code cleanup, bugfix to insertIfNew
This commit is contained in:
parent
edf8f2e239
commit
8d9887294c
2 changed files with 39 additions and 46 deletions
|
@ -10,6 +10,7 @@ import "net/url"
|
|||
import "sort"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
import "time"
|
||||
|
||||
// TODO? Make all of this JSON
|
||||
// TODO: Add authentication
|
||||
|
@ -339,27 +340,24 @@ func (a *admin) getData_getSwitchPeers() []admin_nodeInfo {
|
|||
|
||||
func (a *admin) getData_getDHT() []admin_nodeInfo {
|
||||
var infos []admin_nodeInfo
|
||||
now := time.Now()
|
||||
getDHT := func() {
|
||||
for i := 0; i < a.core.dht.nBuckets(); i++ {
|
||||
b := a.core.dht.getBucket(i)
|
||||
for _, v := range b.other {
|
||||
addr := *address_addrForNodeID(v.getNodeID())
|
||||
info := admin_nodeInfo{
|
||||
{"IP", net.IP(addr[:]).String()},
|
||||
{"coords", fmt.Sprint(v.coords)},
|
||||
{"bucket", fmt.Sprint(i)},
|
||||
getInfo := func(vs []*dhtInfo) {
|
||||
for _, v := range vs {
|
||||
addr := *address_addrForNodeID(v.getNodeID())
|
||||
info := admin_nodeInfo{
|
||||
{"IP", net.IP(addr[:]).String()},
|
||||
{"coords", fmt.Sprint(v.coords)},
|
||||
{"bucket", fmt.Sprint(i)},
|
||||
{"lastSeen", fmt.Sprint(now.Sub(v.recv))},
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
for _, v := range b.peers {
|
||||
addr := *address_addrForNodeID(v.getNodeID())
|
||||
info := admin_nodeInfo{
|
||||
{"IP", net.IP(addr[:]).String()},
|
||||
{"coords", fmt.Sprint(v.coords)},
|
||||
{"bucket", fmt.Sprint(i)},
|
||||
}
|
||||
infos = append(infos, info)
|
||||
}
|
||||
getInfo(b.other)
|
||||
getInfo(b.peers)
|
||||
}
|
||||
}
|
||||
a.core.router.doAdmin(getDHT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue