@@ -81,14 +81,15 @@ func NewKadParams() *KadParams {
81
81
// Kademlia is a table of live peers and a db of known peers (node records)
82
82
type Kademlia struct {
83
83
lock sync.RWMutex
84
- * KadParams // Kademlia configuration parameters
85
- base []byte // immutable baseaddress of the table
86
- addrs * pot.Pot // pots container for known peer addresses
87
- conns * pot.Pot // pots container for live peer connections
88
- depth uint8 // stores the last current depth of saturation
89
- nDepth int // stores the last neighbourhood depth
90
- nDepthC chan int // returned by DepthC function to signal neighbourhood depth change
91
- addrCountC chan int // returned by AddrCountC function to signal peer count change
84
+ * KadParams // Kademlia configuration parameters
85
+ base []byte // immutable baseaddress of the table
86
+ addrs * pot.Pot // pots container for known peer addresses
87
+ conns * pot.Pot // pots container for live peer connections
88
+ depth uint8 // stores the last current depth of saturation
89
+ nDepth int // stores the last neighbourhood depth
90
+ nDepthC chan int // returned by DepthC function to signal neighbourhood depth change
91
+ addrCountC chan int // returned by AddrCountC function to signal peer count change
92
+ Pof func (pot.Val , pot.Val , int ) (int , bool ) // function for calculating kademlia routing distance between two addresses
92
93
}
93
94
94
95
// NewKademlia creates a Kademlia table for base address addr
@@ -103,6 +104,7 @@ func NewKademlia(addr []byte, params *KadParams) *Kademlia {
103
104
KadParams : params ,
104
105
addrs : pot .NewPot (nil , 0 ),
105
106
conns : pot .NewPot (nil , 0 ),
107
+ Pof : pof ,
106
108
}
107
109
}
108
110
@@ -289,6 +291,7 @@ func (k *Kademlia) On(p *Peer) (uint8, bool) {
289
291
// neighbourhood depth on each change.
290
292
// Not receiving from the returned channel will block On function
291
293
// when the neighbourhood depth is changed.
294
+ // TODO: Why is this exported, and if it should be; why can't we have more subscribers than one?
292
295
func (k * Kademlia ) NeighbourhoodDepthC () <- chan int {
293
296
k .lock .Lock ()
294
297
defer k .lock .Unlock ()
@@ -429,7 +432,12 @@ func (k *Kademlia) eachAddr(base []byte, o int, f func(*BzzAddr, int, bool) bool
429
432
// neighbourhoodDepth returns the proximity order that defines the distance of
430
433
// the nearest neighbour set with cardinality >= MinProxBinSize
431
434
// if there is altogether less than MinProxBinSize peers it returns 0
432
- // caller must hold the lock
435
+ func (k * Kademlia ) NeighbourhoodDepth () (depth int ) {
436
+ k .lock .RLock ()
437
+ defer k .lock .RUnlock ()
438
+ return k .neighbourhoodDepth ()
439
+ }
440
+
433
441
func (k * Kademlia ) neighbourhoodDepth () (depth int ) {
434
442
if k .conns .Size () < k .MinProxBinSize {
435
443
return 0
0 commit comments