fix admin dht function, more cleanup, and slowly throttle back dht traffic when idle

This commit is contained in:
Arceliar 2018-10-20 17:58:54 -05:00
parent 5a85d3515d
commit f3ec8c5b37
3 changed files with 24 additions and 24 deletions

View file

@ -555,27 +555,23 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo {
func (a *admin) getData_getDHT() []admin_nodeInfo {
var infos []admin_nodeInfo
getDHT := func() {
/* TODO fix this
now := time.Now()
for i := 0; i < a.core.dht.nBuckets(); i++ {
b := a.core.dht.getBucket(i)
getInfo := func(vs []*dhtInfo, isPeer bool) {
for _, v := range vs {
addr := *address_addrForNodeID(v.getNodeID())
info := admin_nodeInfo{
{"ip", net.IP(addr[:]).String()},
{"coords", fmt.Sprint(v.coords)},
{"bucket", i},
{"peer_only", isPeer},
{"last_seen", int(now.Sub(v.recv).Seconds())},
}
infos = append(infos, info)
}
}
getInfo(b.other, false)
getInfo(b.peers, true)
}
*/
now := time.Now()
var dhtInfos []*dhtInfo
for _, v := range a.core.dht.table {
dhtInfos = append(dhtInfos, v)
}
sort.SliceStable(dhtInfos, func(i, j int) bool {
return dht_ordered(&a.core.dht.nodeID, dhtInfos[i].getNodeID(), dhtInfos[j].getNodeID())
})
for _, v := range dhtInfos {
addr := *address_addrForNodeID(v.getNodeID())
info := admin_nodeInfo{
{"ip", net.IP(addr[:]).String()},
{"coords", fmt.Sprint(v.coords)},
{"last_seen", int(now.Sub(v.recv).Seconds())},
}
infos = append(infos, info)
}
}
a.core.router.doAdmin(getDHT)
return infos