mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 21:10:29 +00:00
clean up old requests during dht maintenance
This commit is contained in:
parent
5a7c2b250c
commit
8d6beebac4
@ -273,6 +273,19 @@ func (t *dht) ping(info *dhtInfo, target *NodeID) {
|
|||||||
// Periodic maintenance work to keep important DHT nodes alive.
|
// Periodic maintenance work to keep important DHT nodes alive.
|
||||||
func (t *dht) doMaintenance() {
|
func (t *dht) doMaintenance() {
|
||||||
now := time.Now()
|
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 {
|
for infoID, info := range t.table {
|
||||||
if now.Sub(info.recv) > time.Minute || info.pings > 3 {
|
if now.Sub(info.recv) > time.Minute || info.pings > 3 {
|
||||||
delete(t.table, infoID)
|
delete(t.table, infoID)
|
||||||
|
Loading…
Reference in New Issue
Block a user