aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/network/kademlia.go
diff options
context:
space:
mode:
authorViktor TrĂ³n <viktor.tron@gmail.com>2019-01-10 10:36:19 +0800
committerGitHub <noreply@github.com>2019-01-10 10:36:19 +0800
commit6df3e4eeb0dda986aef3f71335151fa63c06f6d3 (patch)
treebefe88b3e0d044281037cd4fcaaab09d32338d6a /swarm/network/kademlia.go
parentd70c4faf20d5533e30eec5cbb9b5180eb837b78c (diff)
downloadgo-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar.gz
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar.bz2
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar.lz
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar.xz
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.tar.zst
go-tangerine-6df3e4eeb0dda986aef3f71335151fa63c06f6d3.zip
swarm/network: remove isproxbin bool from kad.Each* iterfunc (#18239)
* swarm/network, swarm/pss: remove isproxbin bool from kad.Each* iterfunc * swarm/network: restore comment and unskip snapshot sync tests
Diffstat (limited to 'swarm/network/kademlia.go')
-rw-r--r--swarm/network/kademlia.go31
1 files changed, 11 insertions, 20 deletions
diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go
index c5c2d79e3..3214e151d 100644
--- a/swarm/network/kademlia.go
+++ b/swarm/network/kademlia.go
@@ -390,46 +390,42 @@ func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(con
// EachConn is an iterator with args (base, po, f) applies f to each live peer
// that has proximity order po or less as measured from the base
// if base is nil, kademlia base address is used
-// It returns peers in order deepest to shallowest
-func (k *Kademlia) EachConn(base []byte, o int, f func(*Peer, int, bool) bool) {
+func (k *Kademlia) EachConn(base []byte, o int, f func(*Peer, int) bool) {
k.lock.RLock()
defer k.lock.RUnlock()
k.eachConn(base, o, f)
}
-func (k *Kademlia) eachConn(base []byte, o int, f func(*Peer, int, bool) bool) {
+func (k *Kademlia) eachConn(base []byte, o int, f func(*Peer, int) bool) {
if len(base) == 0 {
base = k.base
}
- depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
k.conns.EachNeighbour(base, Pof, func(val pot.Val, po int) bool {
if po > o {
return true
}
- return f(val.(*Peer), po, po >= depth)
+ return f(val.(*Peer), po)
})
}
// EachAddr called with (base, po, f) is an iterator applying f to each known peer
// that has proximity order o or less as measured from the base
// if base is nil, kademlia base address is used
-// It returns peers in order deepest to shallowest
-func (k *Kademlia) EachAddr(base []byte, o int, f func(*BzzAddr, int, bool) bool) {
+func (k *Kademlia) EachAddr(base []byte, o int, f func(*BzzAddr, int) bool) {
k.lock.RLock()
defer k.lock.RUnlock()
k.eachAddr(base, o, f)
}
-func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int, bool) bool) {
+func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int) bool) {
if len(base) == 0 {
base = k.base
}
- depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
k.addrs.EachNeighbour(base, Pof, func(val pot.Val, po int) bool {
if po > o {
return true
}
- return f(val.(*entry).BzzAddr, po, po >= depth)
+ return f(val.(*entry).BzzAddr, po)
})
}
@@ -687,12 +683,11 @@ func (k *Kademlia) saturation() int {
// TODO move to separate testing tools file
func (k *Kademlia) knowNeighbours(addrs [][]byte) (got bool, n int, missing [][]byte) {
pm := make(map[string]bool)
-
+ depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
// create a map with all peers at depth and deeper known in the kademlia
- // in order deepest to shallowest compared to the kademlia base address
- // all bins (except self) are included (0 <= bin <= 255)
- depth := depthForPot(k.addrs, k.MinProxBinSize, k.base)
- k.eachAddr(nil, 255, func(p *BzzAddr, po int, nn bool) bool {
+ k.eachAddr(nil, 255, func(p *BzzAddr, po int) bool {
+ // in order deepest to shallowest compared to the kademlia base address
+ // all bins (except self) are included (0 <= bin <= 255)
if po < depth {
return false
}
@@ -724,12 +719,8 @@ func (k *Kademlia) knowNeighbours(addrs [][]byte) (got bool, n int, missing [][]
// It is used in Healthy function for testing only
func (k *Kademlia) connectedNeighbours(peers [][]byte) (got bool, n int, missing [][]byte) {
pm := make(map[string]bool)
-
- // create a map with all peers at depth and deeper that are connected in the kademlia
- // in order deepest to shallowest compared to the kademlia base address
- // all bins (except self) are included (0 <= bin <= 255)
depth := depthForPot(k.conns, k.MinProxBinSize, k.base)
- k.eachConn(nil, 255, func(p *Peer, po int, nn bool) bool {
+ k.eachConn(nil, 255, func(p *Peer, po int) bool {
if po < depth {
return false
}