@@ -54,27 +54,27 @@ var Pof = pot.DefaultPof(256)
5454// KadParams holds the config params for Kademlia
5555type KadParams struct {
5656 // adjustable parameters
57- MaxProxDisplay int // number of rows the table shows
58- MinProxBinSize int // nearest neighbour core minimum cardinality
59- MinBinSize int // minimum number of peers in a row
60- MaxBinSize int // maximum number of peers in a row before pruning
61- RetryInterval int64 // initial interval before a peer is first redialed
62- RetryExponent int // exponent to multiply retry intervals with
63- MaxRetries int // maximum number of redial attempts
57+ MaxProxDisplay int // number of rows the table shows
58+ NeighbourhoodSize int // nearest neighbour core minimum cardinality
59+ MinBinSize int // minimum number of peers in a row
60+ MaxBinSize int // maximum number of peers in a row before pruning
61+ RetryInterval int64 // initial interval before a peer is first redialed
62+ RetryExponent int // exponent to multiply retry intervals with
63+ MaxRetries int // maximum number of redial attempts
6464 // function to sanction or prevent suggesting a peer
6565 Reachable func (* BzzAddr ) bool `json:"-"`
6666}
6767
6868// NewKadParams returns a params struct with default values
6969func NewKadParams () * KadParams {
7070 return & KadParams {
71- MaxProxDisplay : 16 ,
72- MinProxBinSize : 2 ,
73- MinBinSize : 2 ,
74- MaxBinSize : 4 ,
75- RetryInterval : 4200000000 , // 4.2 sec
76- MaxRetries : 42 ,
77- RetryExponent : 2 ,
71+ MaxProxDisplay : 16 ,
72+ NeighbourhoodSize : 2 ,
73+ MinBinSize : 2 ,
74+ MaxBinSize : 4 ,
75+ RetryInterval : 4200000000 , // 4.2 sec
76+ MaxRetries : 42 ,
77+ RetryExponent : 2 ,
7878 }
7979}
8080
@@ -175,7 +175,7 @@ func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool) {
175175 k .lock .Lock ()
176176 defer k .lock .Unlock ()
177177 minsize := k .MinBinSize
178- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
178+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
179179 // if there is a callable neighbour within the current proxBin, connect
180180 // this makes sure nearest neighbour set is fully connected
181181 var ppo int
@@ -306,7 +306,7 @@ func (k *Kademlia) sendNeighbourhoodDepthChange() {
306306 // It provides signaling of neighbourhood depth change.
307307 // This part of the code is sending new neighbourhood depth to nDepthC if that condition is met.
308308 if k .nDepthC != nil {
309- nDepth := depthForPot (k .conns , k .MinProxBinSize , k .base )
309+ nDepth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
310310 if nDepth != k .nDepth {
311311 k .nDepth = nDepth
312312 k .nDepthC <- nDepth
@@ -366,7 +366,7 @@ func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(con
366366
367367 var startPo int
368368 var endPo int
369- kadDepth := depthForPot (k .conns , k .MinProxBinSize , k .base )
369+ kadDepth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
370370
371371 k .conns .EachBin (base , Pof , o , func (po , size int , f func (func (val pot.Val , i int ) bool ) bool ) bool {
372372 if startPo > 0 && endPo != k .MaxProxDisplay {
@@ -432,23 +432,23 @@ func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int) bool) {
432432func (k * Kademlia ) NeighbourhoodDepth () (depth int ) {
433433 k .lock .RLock ()
434434 defer k .lock .RUnlock ()
435- return depthForPot (k .conns , k .MinProxBinSize , k .base )
435+ return depthForPot (k .conns , k .NeighbourhoodSize , k .base )
436436}
437437
438438// depthForPot returns the proximity order that defines the distance of
439- // the nearest neighbour set with cardinality >= MinProxBinSize
440- // if there is altogether less than MinProxBinSize peers it returns 0
439+ // the nearest neighbour set with cardinality >= NeighbourhoodSize
440+ // if there is altogether less than NeighbourhoodSize peers it returns 0
441441// caller must hold the lock
442- func depthForPot (p * pot.Pot , minProxBinSize int , pivotAddr []byte ) (depth int ) {
443- if p .Size () <= minProxBinSize {
442+ func depthForPot (p * pot.Pot , neighbourhoodSize int , pivotAddr []byte ) (depth int ) {
443+ if p .Size () <= neighbourhoodSize {
444444 return 0
445445 }
446446
447447 // total number of peers in iteration
448448 var size int
449449
450450 // determining the depth is a two-step process
451- // first we find the proximity bin of the shallowest of the MinProxBinSize peers
451+ // first we find the proximity bin of the shallowest of the NeighbourhoodSize peers
452452 // the numeric value of depth cannot be higher than this
453453 var maxDepth int
454454
@@ -461,7 +461,7 @@ func depthForPot(p *pot.Pot, minProxBinSize int, pivotAddr []byte) (depth int) {
461461
462462 // this means we have all nn-peers.
463463 // depth is by default set to the bin of the farthest nn-peer
464- if size == minProxBinSize {
464+ if size == neighbourhoodSize {
465465 maxDepth = i
466466 return false
467467 }
@@ -538,12 +538,12 @@ func (k *Kademlia) string() string {
538538
539539 rows = append (rows , "=========================================================================" )
540540 rows = append (rows , fmt .Sprintf ("%v KΛÐΞMLIΛ hive: queen's address: %x" , time .Now ().UTC ().Format (time .UnixDate ), k .BaseAddr ()[:3 ]))
541- rows = append (rows , fmt .Sprintf ("population: %d (%d), MinProxBinSize : %d, MinBinSize: %d, MaxBinSize: %d" , k .conns .Size (), k .addrs .Size (), k .MinProxBinSize , k .MinBinSize , k .MaxBinSize ))
541+ rows = append (rows , fmt .Sprintf ("population: %d (%d), NeighbourhoodSize : %d, MinBinSize: %d, MaxBinSize: %d" , k .conns .Size (), k .addrs .Size (), k .NeighbourhoodSize , k .MinBinSize , k .MaxBinSize ))
542542
543543 liverows := make ([]string , k .MaxProxDisplay )
544544 peersrows := make ([]string , k .MaxProxDisplay )
545545
546- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
546+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
547547 rest := k .conns .Size ()
548548 k .conns .EachBin (k .base , Pof , 0 , func (po , size int , f func (func (val pot.Val , i int ) bool ) bool ) bool {
549549 var rowlen int
@@ -611,10 +611,10 @@ type PeerPot struct {
611611
612612// NewPeerPotMap creates a map of pot record of *BzzAddr with keys
613613// as hexadecimal representations of the address.
614- // the MinProxBinSize of the passed kademlia is used
614+ // the NeighbourhoodSize of the passed kademlia is used
615615// used for testing only
616616// TODO move to separate testing tools file
617- func NewPeerPotMap (minProxBinSize int , addrs [][]byte ) map [string ]* PeerPot {
617+ func NewPeerPotMap (neighbourhoodSize int , addrs [][]byte ) map [string ]* PeerPot {
618618
619619 // create a table of all nodes for health check
620620 np := pot .NewPot (nil , 0 )
@@ -628,7 +628,7 @@ func NewPeerPotMap(minProxBinSize int, addrs [][]byte) map[string]*PeerPot {
628628 for i , a := range addrs {
629629
630630 // actual kademlia depth
631- depth := depthForPot (np , minProxBinSize , a )
631+ depth := depthForPot (np , neighbourhoodSize , a )
632632
633633 // all nn-peers
634634 var nns [][]byte
@@ -670,7 +670,7 @@ func (k *Kademlia) saturation() int {
670670 return prev == po && size >= k .MinBinSize
671671 })
672672 // TODO evaluate whether this check cannot just as well be done within the eachbin
673- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
673+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
674674 if depth < prev {
675675 return depth
676676 }
@@ -683,7 +683,7 @@ func (k *Kademlia) saturation() int {
683683// TODO move to separate testing tools file
684684func (k * Kademlia ) knowNeighbours (addrs [][]byte ) (got bool , n int , missing [][]byte ) {
685685 pm := make (map [string ]bool )
686- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
686+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
687687 // create a map with all peers at depth and deeper known in the kademlia
688688 k .eachAddr (nil , 255 , func (p * BzzAddr , po int ) bool {
689689 // in order deepest to shallowest compared to the kademlia base address
@@ -719,7 +719,11 @@ func (k *Kademlia) knowNeighbours(addrs [][]byte) (got bool, n int, missing [][]
719719// It is used in Healthy function for testing only
720720func (k * Kademlia ) connectedNeighbours (peers [][]byte ) (got bool , n int , missing [][]byte ) {
721721 pm := make (map [string ]bool )
722- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
722+
723+ // create a map with all peers at depth and deeper that are connected in the kademlia
724+ // in order deepest to shallowest compared to the kademlia base address
725+ // all bins (except self) are included (0 <= bin <= 255)
726+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
723727 k .eachConn (nil , 255 , func (p * Peer , po int ) bool {
724728 if po < depth {
725729 return false
@@ -772,7 +776,7 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
772776 defer k .lock .RUnlock ()
773777 gotnn , countgotnn , culpritsgotnn := k .connectedNeighbours (pp .NNSet )
774778 knownn , countknownn , culpritsknownn := k .knowNeighbours (pp .NNSet )
775- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
779+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
776780 saturated := k .saturation () < depth
777781 log .Trace (fmt .Sprintf ("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n " , k .base , knownn , gotnn , saturated ))
778782 return & Health {
0 commit comments