mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +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
|
// try to select a candidate peer
|
||||||
// find the first callable peer
|
// find the first callable peer
|
||||||
nxt := bpo[0]
|
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 {
|
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
|
// for each bin (up until depth) we find callable candidate peers
|
||||||
if po >= depth || po != nxt {
|
if po >= depth {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
i++
|
|
||||||
ok := f(func(val pot.Val, _ int) bool {
|
ok := f(func(val pot.Val, _ int) bool {
|
||||||
a = k.callable(val)
|
a = k.callable(val)
|
||||||
return a == nil
|
return a == nil
|
||||||
|
|
@ -272,10 +270,6 @@ func (k *Kademlia) SuggestPeer() (a OverlayAddr, o int, want bool) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if i >= len(bpo) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
nxt = bpo[i]
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
// found a candidate
|
// found a candidate
|
||||||
|
|
@ -689,10 +683,10 @@ func (k *Kademlia) full(emptyBins []int) (full bool) {
|
||||||
ok := true
|
ok := true
|
||||||
depth := k.neighbourhoodDepth()
|
depth := k.neighbourhoodDepth()
|
||||||
k.conns.EachBin(k.base, pof, 0, func(po, _ int, _ func(func(val pot.Val, i int) bool) bool) bool {
|
k.conns.EachBin(k.base, pof, 0, func(po, _ int, _ func(func(val pot.Val, i int) bool) bool) bool {
|
||||||
for i := prev; i < po; i++ {
|
|
||||||
if prev == depth+1 {
|
if prev == depth+1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
for i := prev; i < po; i++ {
|
||||||
e--
|
e--
|
||||||
if e < 0 {
|
if e < 0 {
|
||||||
ok = false
|
ok = false
|
||||||
|
|
@ -703,6 +697,7 @@ func (k *Kademlia) full(emptyBins []int) (full bool) {
|
||||||
if emptyBins[e] < i {
|
if emptyBins[e] < i {
|
||||||
panic("incorrect peerpot")
|
panic("incorrect peerpot")
|
||||||
}
|
}
|
||||||
|
ok = false
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,19 +228,18 @@ func TestSuggestPeerFindPeers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
k.Register("01000001")
|
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)
|
err = testSuggestPeer(t, k, "01000001", 0, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
k.On("10000001")
|
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")
|
k.On("01000001")
|
||||||
err = testSuggestPeer(t, k, "<nil>", 0, false)
|
err = testSuggestPeer(t, k, "<nil>", 0, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -283,7 +282,7 @@ func TestSuggestPeerFindPeers(t *testing.T) {
|
||||||
func TestSuggestPeerRetries(t *testing.T) {
|
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")
|
||||||
k.RetryInterval = int64(time.Second) // cycle
|
k.RetryInterval = int64(100 * time.Millisecond) // 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