From 8d6beebac48674b4677a1acc6f389c0756d276a4 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 24 Nov 2018 20:04:14 -0600 Subject: [PATCH] clean up old requests during dht maintenance --- src/yggdrasil/dht.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index 31acd8a2..84d8e409 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -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)