mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
fix admin dht function, more cleanup, and slowly throttle back dht traffic when idle
This commit is contained in:
parent
5a85d3515d
commit
f3ec8c5b37
3 changed files with 24 additions and 24 deletions
|
@ -15,6 +15,7 @@ type dhtInfo struct {
|
|||
coords []byte
|
||||
send time.Time // When we last sent 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.
|
||||
|
@ -101,9 +102,14 @@ func (t *dht) insert(info *dhtInfo) {
|
|||
info.recv = time.Now()
|
||||
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
||||
info.send = oldInfo.send
|
||||
info.throttle = oldInfo.throttle
|
||||
} else {
|
||||
info.send = info.recv
|
||||
}
|
||||
info.throttle += time.Second
|
||||
if info.throttle > 30*time.Second {
|
||||
info.throttle = 30 * time.Second
|
||||
}
|
||||
t.table[*info.getNodeID()] = info
|
||||
}
|
||||
|
||||
|
@ -293,6 +299,7 @@ func (t *dht) doMaintenance() {
|
|||
}
|
||||
}
|
||||
if successor != nil &&
|
||||
now.Sub(successor.recv) > successor.throttle &&
|
||||
now.Sub(successor.send) > 6*time.Second {
|
||||
t.ping(successor, nil)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue