@@ -54,27 +54,27 @@ var Pof = pot.DefaultPof(256)
54
54
// KadParams holds the config params for Kademlia
55
55
type KadParams struct {
56
56
// 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
64
64
// function to sanction or prevent suggesting a peer
65
65
Reachable func (* BzzAddr ) bool `json:"-"`
66
66
}
67
67
68
68
// NewKadParams returns a params struct with default values
69
69
func NewKadParams () * KadParams {
70
70
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 ,
78
78
}
79
79
}
80
80
@@ -175,7 +175,7 @@ func (k *Kademlia) SuggestPeer() (a *BzzAddr, o int, want bool) {
175
175
k .lock .Lock ()
176
176
defer k .lock .Unlock ()
177
177
minsize := k .MinBinSize
178
- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
178
+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
179
179
// if there is a callable neighbour within the current proxBin, connect
180
180
// this makes sure nearest neighbour set is fully connected
181
181
var ppo int
@@ -306,7 +306,7 @@ func (k *Kademlia) sendNeighbourhoodDepthChange() {
306
306
// It provides signaling of neighbourhood depth change.
307
307
// This part of the code is sending new neighbourhood depth to nDepthC if that condition is met.
308
308
if k .nDepthC != nil {
309
- nDepth := depthForPot (k .conns , k .MinProxBinSize , k .base )
309
+ nDepth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
310
310
if nDepth != k .nDepth {
311
311
k .nDepth = nDepth
312
312
k .nDepthC <- nDepth
@@ -366,7 +366,7 @@ func (k *Kademlia) EachBin(base []byte, pof pot.Pof, o int, eachBinFunc func(con
366
366
367
367
var startPo int
368
368
var endPo int
369
- kadDepth := depthForPot (k .conns , k .MinProxBinSize , k .base )
369
+ kadDepth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
370
370
371
371
k .conns .EachBin (base , Pof , o , func (po , size int , f func (func (val pot.Val , i int ) bool ) bool ) bool {
372
372
if startPo > 0 && endPo != k .MaxProxDisplay {
@@ -432,23 +432,23 @@ func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int) bool) {
432
432
func (k * Kademlia ) NeighbourhoodDepth () (depth int ) {
433
433
k .lock .RLock ()
434
434
defer k .lock .RUnlock ()
435
- return depthForPot (k .conns , k .MinProxBinSize , k .base )
435
+ return depthForPot (k .conns , k .NeighbourhoodSize , k .base )
436
436
}
437
437
438
438
// 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
441
441
// 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 {
444
444
return 0
445
445
}
446
446
447
447
// total number of peers in iteration
448
448
var size int
449
449
450
450
// 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
452
452
// the numeric value of depth cannot be higher than this
453
453
var maxDepth int
454
454
@@ -461,7 +461,7 @@ func depthForPot(p *pot.Pot, minProxBinSize int, pivotAddr []byte) (depth int) {
461
461
462
462
// this means we have all nn-peers.
463
463
// depth is by default set to the bin of the farthest nn-peer
464
- if size == minProxBinSize {
464
+ if size == neighbourhoodSize {
465
465
maxDepth = i
466
466
return false
467
467
}
@@ -538,12 +538,12 @@ func (k *Kademlia) string() string {
538
538
539
539
rows = append (rows , "=========================================================================" )
540
540
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 ))
542
542
543
543
liverows := make ([]string , k .MaxProxDisplay )
544
544
peersrows := make ([]string , k .MaxProxDisplay )
545
545
546
- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
546
+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
547
547
rest := k .conns .Size ()
548
548
k .conns .EachBin (k .base , Pof , 0 , func (po , size int , f func (func (val pot.Val , i int ) bool ) bool ) bool {
549
549
var rowlen int
@@ -611,10 +611,10 @@ type PeerPot struct {
611
611
612
612
// NewPeerPotMap creates a map of pot record of *BzzAddr with keys
613
613
// as hexadecimal representations of the address.
614
- // the MinProxBinSize of the passed kademlia is used
614
+ // the NeighbourhoodSize of the passed kademlia is used
615
615
// used for testing only
616
616
// 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 {
618
618
619
619
// create a table of all nodes for health check
620
620
np := pot .NewPot (nil , 0 )
@@ -628,7 +628,7 @@ func NewPeerPotMap(minProxBinSize int, addrs [][]byte) map[string]*PeerPot {
628
628
for i , a := range addrs {
629
629
630
630
// actual kademlia depth
631
- depth := depthForPot (np , minProxBinSize , a )
631
+ depth := depthForPot (np , neighbourhoodSize , a )
632
632
633
633
// all nn-peers
634
634
var nns [][]byte
@@ -670,7 +670,7 @@ func (k *Kademlia) saturation() int {
670
670
return prev == po && size >= k .MinBinSize
671
671
})
672
672
// 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 )
674
674
if depth < prev {
675
675
return depth
676
676
}
@@ -683,7 +683,7 @@ func (k *Kademlia) saturation() int {
683
683
// TODO move to separate testing tools file
684
684
func (k * Kademlia ) knowNeighbours (addrs [][]byte ) (got bool , n int , missing [][]byte ) {
685
685
pm := make (map [string ]bool )
686
- depth := depthForPot (k .conns , k .MinProxBinSize , k .base )
686
+ depth := depthForPot (k .conns , k .NeighbourhoodSize , k .base )
687
687
// create a map with all peers at depth and deeper known in the kademlia
688
688
k .eachAddr (nil , 255 , func (p * BzzAddr , po int ) bool {
689
689
// 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 [][]
719
719
// It is used in Healthy function for testing only
720
720
func (k * Kademlia ) connectedNeighbours (peers [][]byte ) (got bool , n int , missing [][]byte ) {
721
721
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 )
723
727
k .eachConn (nil , 255 , func (p * Peer , po int ) bool {
724
728
if po < depth {
725
729
return false
@@ -772,7 +776,7 @@ func (k *Kademlia) Healthy(pp *PeerPot) *Health {
772
776
defer k .lock .RUnlock ()
773
777
gotnn , countgotnn , culpritsgotnn := k .connectedNeighbours (pp .NNSet )
774
778
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 )
776
780
saturated := k .saturation () < depth
777
781
log .Trace (fmt .Sprintf ("%08x: healthy: knowNNs: %v, gotNNs: %v, saturated: %v\n " , k .base , knownn , gotnn , saturated ))
778
782
return & Health {
0 commit comments