mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 23:55:40 +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 {
|
func (a *admin) getData_getDHT() []admin_nodeInfo {
|
||||||
var infos []admin_nodeInfo
|
var infos []admin_nodeInfo
|
||||||
getDHT := func() {
|
getDHT := func() {
|
||||||
/* TODO fix this
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for i := 0; i < a.core.dht.nBuckets(); i++ {
|
var dhtInfos []*dhtInfo
|
||||||
b := a.core.dht.getBucket(i)
|
for _, v := range a.core.dht.table {
|
||||||
getInfo := func(vs []*dhtInfo, isPeer bool) {
|
dhtInfos = append(dhtInfos, v)
|
||||||
for _, v := range vs {
|
}
|
||||||
|
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())
|
addr := *address_addrForNodeID(v.getNodeID())
|
||||||
info := admin_nodeInfo{
|
info := admin_nodeInfo{
|
||||||
{"ip", net.IP(addr[:]).String()},
|
{"ip", net.IP(addr[:]).String()},
|
||||||
{"coords", fmt.Sprint(v.coords)},
|
{"coords", fmt.Sprint(v.coords)},
|
||||||
{"bucket", i},
|
|
||||||
{"peer_only", isPeer},
|
|
||||||
{"last_seen", int(now.Sub(v.recv).Seconds())},
|
{"last_seen", int(now.Sub(v.recv).Seconds())},
|
||||||
}
|
}
|
||||||
infos = append(infos, info)
|
infos = append(infos, info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getInfo(b.other, false)
|
|
||||||
getInfo(b.peers, true)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
a.core.router.doAdmin(getDHT)
|
a.core.router.doAdmin(getDHT)
|
||||||
return infos
|
return infos
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ type dhtInfo struct {
|
|||||||
coords []byte
|
coords []byte
|
||||||
send time.Time // When we last sent a message
|
send time.Time // When we last sent a message
|
||||||
recv time.Time // When we last received 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.
|
// 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()
|
info.recv = time.Now()
|
||||||
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
||||||
info.send = oldInfo.send
|
info.send = oldInfo.send
|
||||||
|
info.throttle = oldInfo.throttle
|
||||||
} else {
|
} else {
|
||||||
info.send = info.recv
|
info.send = info.recv
|
||||||
}
|
}
|
||||||
|
info.throttle += time.Second
|
||||||
|
if info.throttle > 30*time.Second {
|
||||||
|
info.throttle = 30 * time.Second
|
||||||
|
}
|
||||||
t.table[*info.getNodeID()] = info
|
t.table[*info.getNodeID()] = info
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +299,7 @@ func (t *dht) doMaintenance() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if successor != nil &&
|
if successor != nil &&
|
||||||
|
now.Sub(successor.recv) > successor.throttle &&
|
||||||
now.Sub(successor.send) > 6*time.Second {
|
now.Sub(successor.send) > 6*time.Second {
|
||||||
t.ping(successor, nil)
|
t.ping(successor, nil)
|
||||||
}
|
}
|
||||||
|
@ -126,10 +126,7 @@ func (s *searches) doSearchStep(sinfo *searchInfo) {
|
|||||||
// Send to the next search target
|
// Send to the next search target
|
||||||
var next *dhtInfo
|
var next *dhtInfo
|
||||||
next, sinfo.toVisit = sinfo.toVisit[0], sinfo.toVisit[1:]
|
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)
|
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
|
sinfo.visited[*next.getNodeID()] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user