expose how many initial nodes are found

This commit is contained in:
Alex Grintsvayg 2018-04-24 21:12:32 -04:00
parent 9979a70c61
commit 3d4253b934
3 changed files with 16 additions and 3 deletions

View file

@ -270,7 +270,7 @@ func (dht *DHT) Start() error {
go dht.runHandler()
dht.join()
log.Debugf("[%s] DHT ready on %s", dht.node.id.HexShort(), dht.node.Addr().String())
log.Debugf("[%s] DHT ready on %s (%d nodes found during join)", dht.node.id.HexShort(), dht.node.Addr().String(), dht.rt.Count())
return nil
}

View file

@ -48,10 +48,10 @@ func TestNodeFinder_FindNodes(t *testing.T) {
}
if !foundOne {
t.Errorf("did not find node %s", dhts[0].node.id.Hex())
t.Errorf("did not find first node %s", dhts[0].node.id.Hex())
}
if !foundTwo {
t.Errorf("did not find node %s", dhts[1].node.id.Hex())
t.Errorf("did not find second node %s", dhts[1].node.id.Hex())
}
}

View file

@ -243,6 +243,19 @@ func (rt *routingTable) GetClosest(target Bitmap, limit int) []Node {
return nodes
}
// Count returns the number of nodes in the routing table
func (rt *routingTable) Count() int {
rt.lock.RLock()
defer rt.lock.RUnlock()
count := 0
for _, bucket := range rt.buckets {
for curr := bucket.Front(); curr != nil; curr = curr.Next() {
count++
}
}
return count
}
func findInList(bucket *list.List, value Bitmap) *list.Element {
for curr := bucket.Front(); curr != nil; curr = curr.Next() {
if curr.Value.(Node).id.Equals(value) {