mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network: re-added saturation func in Kademlia as it is used elsewhere
This commit is contained in:
parent
6f81df32bb
commit
99df803e89
1 changed files with 18 additions and 0 deletions
|
|
@ -683,6 +683,24 @@ func NewPeerPotMap(neighbourhoodSize int, addrs [][]byte) map[string]*PeerPot {
|
||||||
return ppmap
|
return ppmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// saturation returns the smallest po value in which the node has less than MinBinSize peers
|
||||||
|
// if the iterator reaches neighbourhood radius, then the last bin + 1 is returned
|
||||||
|
func (k *Kademlia) saturation() int {
|
||||||
|
prev := -1
|
||||||
|
radius := neighbourhoodRadiusForPot(k.conns, k.NeighbourhoodSize, k.base)
|
||||||
|
k.conns.EachBin(k.base, Pof, 0, func(po, size int, f func(func(val pot.Val) bool) bool) bool {
|
||||||
|
prev++
|
||||||
|
if po >= radius {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return prev == po && size >= k.MinBinSize
|
||||||
|
})
|
||||||
|
if prev < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
|
||||||
// getUnsaturatedBins returns an array of ints; each item in that array corresponds
|
// getUnsaturatedBins returns an array of ints; each item in that array corresponds
|
||||||
// to the bin which is unsaturated (number of connections < k.MinBinSize).
|
// to the bin which is unsaturated (number of connections < k.MinBinSize).
|
||||||
// The bin is considered unsaturated only if there are actual peers in that PeerPot's bin (peersPerBin)
|
// The bin is considered unsaturated only if there are actual peers in that PeerPot's bin (peersPerBin)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue