5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 15:21:37 +00:00

add max pings before timing out a successor

This commit is contained in:
Arceliar 2018-10-20 18:31:11 -05:00
parent 63d6ab4251
commit d851d9afe7

View File

@ -16,6 +16,7 @@ type dhtInfo struct {
send time.Time // When we last sent a message send time.Time // When we last sent a message
recv time.Time // When we last received a message recv time.Time // When we last received a message
throttle time.Duration throttle time.Duration
pings int // Time out if at least 3 consecutive maintenance pings drop
} }
// Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times. // Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times.
@ -314,7 +315,7 @@ func (t *dht) doMaintenance() {
var successor *dhtInfo var successor *dhtInfo
now := time.Now() now := time.Now()
for infoID, info := range t.table { for infoID, info := range t.table {
if now.Sub(info.recv) > time.Minute { if now.Sub(info.recv) > time.Minute || info.pings > 3 {
delete(t.table, infoID) delete(t.table, infoID)
} else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) { } else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
successor = info successor = info
@ -324,5 +325,6 @@ func (t *dht) doMaintenance() {
now.Sub(successor.recv) > successor.throttle && now.Sub(successor.recv) > successor.throttle &&
now.Sub(successor.send) > 6*time.Second { now.Sub(successor.send) > 6*time.Second {
t.ping(successor, nil) t.ping(successor, nil)
successor.pings++
} }
} }