mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 07:20:39 +03:00
reintroduce (better) dht throttling
This commit is contained in:
parent
8825494d59
commit
95201669fe
@ -15,6 +15,7 @@ type dhtInfo struct {
|
|||||||
coords []byte
|
coords []byte
|
||||||
recv time.Time // When we last received a message
|
recv time.Time // When we last received a message
|
||||||
pings int // Time out if at least 3 consecutive maintenance pings drop
|
pings int // Time out if at least 3 consecutive maintenance pings drop
|
||||||
|
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.
|
// Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times.
|
||||||
@ -123,6 +124,22 @@ func (t *dht) insert(info *dhtInfo) {
|
|||||||
panic("FIXME")
|
panic("FIXME")
|
||||||
}
|
}
|
||||||
info.recv = time.Now()
|
info.recv = time.Now()
|
||||||
|
if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
|
||||||
|
sameCoords := true
|
||||||
|
if len(info.coords) != len(oldInfo.coords) {
|
||||||
|
sameCoords = false
|
||||||
|
} else {
|
||||||
|
for idx := 0; idx < len(info.coords); idx++ {
|
||||||
|
if info.coords[idx] != oldInfo.coords[idx] {
|
||||||
|
sameCoords = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sameCoords {
|
||||||
|
info.throttle = oldInfo.throttle
|
||||||
|
}
|
||||||
|
}
|
||||||
t.table[*info.getNodeID()] = info
|
t.table[*info.getNodeID()] = info
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,8 +326,13 @@ func (t *dht) doMaintenance() {
|
|||||||
successor = info
|
successor = info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if successor != nil {
|
if successor != nil &&
|
||||||
|
now.Sub(successor.recv) > successor.throttle {
|
||||||
t.ping(successor, nil)
|
t.ping(successor, nil)
|
||||||
successor.pings++
|
successor.pings++
|
||||||
|
successor.throttle += time.Second
|
||||||
|
if successor.throttle > 30*time.Second {
|
||||||
|
successor.throttle = 30 * time.Second
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user