mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 07:30:27 +00:00
fix admin dht function, more cleanup, and slowly throttle back dht traffic when idle
This commit is contained in:
parent
5a85d3515d
commit
f3ec8c5b37
@ -555,28 +555,24 @@ 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 {
|
||||
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)},
|
||||
{"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)
|
||||
}
|
||||
*/
|
||||
}
|
||||
a.core.router.doAdmin(getDHT)
|
||||
return infos
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ type dhtInfo struct {
|
||||
coords []byte
|
||||
send time.Time // When we last sent a message
|
||||
recv time.Time // When we last received a message
|
||||
throttle time.Duration
|
||||
}
|
||||
|
||||
// Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times.
|
||||
@ -101,9 +102,14 @@ func (t *dht) insert(info *dhtInfo) {
|
||||
info.recv = time.Now()
|
||||
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
||||
info.send = oldInfo.send
|
||||
info.throttle = oldInfo.throttle
|
||||
} else {
|
||||
info.send = info.recv
|
||||
}
|
||||
info.throttle += time.Second
|
||||
if info.throttle > 30*time.Second {
|
||||
info.throttle = 30 * time.Second
|
||||
}
|
||||
t.table[*info.getNodeID()] = info
|
||||
}
|
||||
|
||||
@ -293,6 +299,7 @@ func (t *dht) doMaintenance() {
|
||||
}
|
||||
}
|
||||
if successor != nil &&
|
||||
now.Sub(successor.recv) > successor.throttle &&
|
||||
now.Sub(successor.send) > 6*time.Second {
|
||||
t.ping(successor, nil)
|
||||
}
|
||||
|
@ -126,10 +126,7 @@ func (s *searches) doSearchStep(sinfo *searchInfo) {
|
||||
// Send to the next search target
|
||||
var next *dhtInfo
|
||||
next, sinfo.toVisit = sinfo.toVisit[0], sinfo.toVisit[1:]
|
||||
//var oldPings int
|
||||
//oldPings, next.pings = next.pings, 0
|
||||
s.core.dht.ping(next, &sinfo.dest)
|
||||
//next.pings = oldPings // Don't evict a node for searching with it too much
|
||||
sinfo.visited[*next.getNodeID()] = true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user