mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
swarm/network: Fix kademlia param overflow on 32bit
This commit is contained in:
parent
d9652fdf7b
commit
3a4875fc87
2 changed files with 11 additions and 11 deletions
|
|
@ -58,8 +58,8 @@ type KadParams struct {
|
||||||
MinProxBinSize int // nearest neighbour core minimum cardinality
|
MinProxBinSize int // nearest neighbour core minimum cardinality
|
||||||
MinBinSize int // minimum number of peers in a row
|
MinBinSize int // minimum number of peers in a row
|
||||||
MaxBinSize int // maximum number of peers in a row before pruning
|
MaxBinSize int // maximum number of peers in a row before pruning
|
||||||
RetryInterval int // initial interval before a peer is first redialed
|
RetryInterval uint // initial interval before a peer is first redialed
|
||||||
RetryExponent int // exponent to multiply retry intervals with
|
RetryExponent uint // exponent to multiply retry intervals with
|
||||||
MaxRetries int // maximum number of redial attempts
|
MaxRetries int // maximum number of redial attempts
|
||||||
PruneInterval int // interval between peer pruning cycles
|
PruneInterval int // interval between peer pruning cycles
|
||||||
// function to sanction or prevent suggesting a peer
|
// function to sanction or prevent suggesting a peer
|
||||||
|
|
@ -400,10 +400,10 @@ func (k *Kademlia) callable(val pot.Val) OverlayAddr {
|
||||||
}
|
}
|
||||||
// calculate the allowed number of retries based on time lapsed since last seen
|
// calculate the allowed number of retries based on time lapsed since last seen
|
||||||
timeAgo := int(time.Since(e.seenAt))
|
timeAgo := int(time.Since(e.seenAt))
|
||||||
div := k.RetryExponent
|
div := int(k.RetryExponent)
|
||||||
div += (150000 - rand.Intn(300000)) * div / 1000000
|
div += (150000 - rand.Intn(300000)) * div / 1000000
|
||||||
var retries int
|
var retries int
|
||||||
for delta := timeAgo; delta > k.RetryInterval; delta /= div {
|
for delta := timeAgo; uint(delta) > k.RetryInterval; delta /= div {
|
||||||
retries++
|
retries++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ func TestSuggestPeerRetries(t *testing.T) {
|
||||||
// 2 row gap, unsaturated proxbin, no callables -> want PO 0
|
// 2 row gap, unsaturated proxbin, no callables -> want PO 0
|
||||||
k := newTestKademlia("00000000")
|
k := newTestKademlia("00000000")
|
||||||
cycle := time.Second
|
cycle := time.Second
|
||||||
k.RetryInterval = int(cycle)
|
k.RetryInterval = uint(cycle)
|
||||||
k.MaxRetries = 50
|
k.MaxRetries = 50
|
||||||
k.RetryExponent = 2
|
k.RetryExponent = 2
|
||||||
sleep := func(n int) {
|
sleep := func(n int) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue