mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network: kademlia suggestPeer algo correction
This commit is contained in:
parent
bd9014da69
commit
df0928bfaf
1 changed files with 18 additions and 6 deletions
|
|
@ -214,12 +214,24 @@ func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool) {
|
||||||
return nil, 0, false
|
return nil, 0, false
|
||||||
}
|
}
|
||||||
// find the first callable peer
|
// find the first callable peer
|
||||||
nxt := bpo[0]
|
// for each bin (up until neighbourhood radius) we find callable candidate peers
|
||||||
k.addrs.EachBin(k.base, Pof, nxt, func(po, _ int, f func(func(pot.Val) bool) bool) bool {
|
// nxt := bpo[0]
|
||||||
// for each bin (up until depth) we find callable candidate peers
|
ci := 0
|
||||||
|
saturationDepth := bpo[0]
|
||||||
|
cpo := saturationDepth
|
||||||
|
k.addrs.EachBin(k.base, Pof, cpo, func(po, _ int, f func(func(pot.Val) bool) bool) bool {
|
||||||
if po >= radius {
|
if po >= radius {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if po < cpo {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for ; ci < len(bpo) && cpo < po; ci++ {
|
||||||
|
cpo = bpo[ci]
|
||||||
|
}
|
||||||
|
if ci == len(bpo) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return f(func(val pot.Val) bool {
|
return f(func(val pot.Val) bool {
|
||||||
e := val.(*entry)
|
e := val.(*entry)
|
||||||
c := k.callable(e)
|
c := k.callable(e)
|
||||||
|
|
@ -235,11 +247,11 @@ func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool) {
|
||||||
}
|
}
|
||||||
// no candidate peer found, request for the short bin
|
// no candidate peer found, request for the short bin
|
||||||
var changed bool
|
var changed bool
|
||||||
if uint8(nxt) < k.depth {
|
if uint8(saturationDepth) < k.depth {
|
||||||
k.depth = uint8(nxt)
|
k.depth = uint8(saturationDepth)
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
return a, nxt, changed
|
return a, saturationDepth, changed
|
||||||
}
|
}
|
||||||
|
|
||||||
// On inserts the peer as a kademlia peer into the live peers
|
// On inserts the peer as a kademlia peer into the live peers
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue