5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 15:20:30 +00:00

clean up old requests during dht maintenance

This commit is contained in:
Arceliar 2018-11-24 20:04:14 -06:00
parent 5a7c2b250c
commit 8d6beebac4

View File

@ -273,6 +273,19 @@ func (t *dht) ping(info *dhtInfo, target *NodeID) {
// Periodic maintenance work to keep important DHT nodes alive.
func (t *dht) doMaintenance() {
now := time.Now()
for key, dests := range t.reqs {
for nodeID, start := range dests {
if now.Sub(start) > 6*time.Second {
if info, isIn := t.table[*getNodeID(&key)]; isIn {
info.pings++
}
delete(dests, nodeID)
}
if len(dests) == 0 {
delete(t.reqs, key)
}
}
}
for infoID, info := range t.table {
if now.Sub(info.recv) > time.Minute || info.pings > 3 {
delete(t.table, infoID)