mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-02-14 19:01:52 +00:00
clean up old requests during dht maintenance
This commit is contained in:
parent
5a7c2b250c
commit
8d6beebac4
1 changed files with 13 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue