mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
swarm/network: kademlia and tests fixes
This commit is contained in:
parent
5d6e4bba63
commit
0038106389
2 changed files with 12 additions and 18 deletions
|
|
@ -258,13 +258,11 @@ func (k *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
|||
// try to select a candidate peer
|
||||
// find the first callable peer
|
||||
nxt := bpo[0]
|
||||
var i int
|
||||
k.addrs.EachBin(k.base, pof, nxt, func(po, _ int, f func(func(pot.Val, int) bool) bool) bool {
|
||||
// for each bin (up until depth) we find callable candidate peers
|
||||
if po >= depth || po != nxt {
|
||||
if po >= depth {
|
||||
return false
|
||||
}
|
||||
i++
|
||||
ok := f(func(val pot.Val, _ int) bool {
|
||||
a = k.callable(val)
|
||||
return a == nil
|
||||
|
|
@ -272,10 +270,6 @@ func (k *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
|||
if !ok {
|
||||
return false
|
||||
}
|
||||
if i >= len(bpo) {
|
||||
return false
|
||||
}
|
||||
nxt = bpo[i]
|
||||
return true
|
||||
})
|
||||
// found a candidate
|
||||
|
|
@ -689,10 +683,10 @@ func (k *Kademlia) full(emptyBins []int) (full bool) {
|
|||
ok := true
|
||||
depth := k.neighbourhoodDepth()
|
||||
k.conns.EachBin(k.base, pof, 0, func(po, _ int, _ func(func(val pot.Val, i int) bool) bool) bool {
|
||||
if prev == depth+1 {
|
||||
return true
|
||||
}
|
||||
for i := prev; i < po; i++ {
|
||||
if prev == depth+1 {
|
||||
return true
|
||||
}
|
||||
e--
|
||||
if e < 0 {
|
||||
ok = false
|
||||
|
|
@ -703,6 +697,7 @@ func (k *Kademlia) full(emptyBins []int) (full bool) {
|
|||
if emptyBins[e] < i {
|
||||
panic("incorrect peerpot")
|
||||
}
|
||||
ok = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,19 +228,18 @@ func TestSuggestPeerFindPeers(t *testing.T) {
|
|||
}
|
||||
|
||||
k.Register("01000001")
|
||||
err = testSuggestPeer(t, k, "<nil>", 0, false)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
k.On("10000001")
|
||||
log.Trace("Kad:\n%v", k.String())
|
||||
err = testSuggestPeer(t, k, "01000001", 0, false)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
k.On("10000001")
|
||||
log.Trace(fmt.Sprintf("Kad:\n%v", k.String()))
|
||||
err = testSuggestPeer(t, k, "<nil>", 1, true)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
k.On("01000001")
|
||||
err = testSuggestPeer(t, k, "<nil>", 0, false)
|
||||
if err != nil {
|
||||
|
|
@ -283,7 +282,7 @@ func TestSuggestPeerFindPeers(t *testing.T) {
|
|||
func TestSuggestPeerRetries(t *testing.T) {
|
||||
// 2 row gap, unsaturated proxbin, no callables -> want PO 0
|
||||
k := newTestKademlia("00000000")
|
||||
k.RetryInterval = int64(time.Second) // cycle
|
||||
k.RetryInterval = int64(100 * time.Millisecond) // cycle
|
||||
k.MaxRetries = 50
|
||||
k.RetryExponent = 2
|
||||
sleep := func(n int) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue