for range ticker.C {
nodes := make([]*dht.Node, nodesToDiscv)
n := m.sw.GetDiscv().ReadRandomNodes(nodes)
- m.collectDiscoveredNodes(nodes[:n])
+ for i := 0; i < n; i++ {
+ m.discvCh <- nodes[i]
+ }
}
}
-func (m *monitor) collectDiscoveredNodes(nodes []*dht.Node) {
- for _, node := range nodes {
+func (m *monitor) collectDiscoveredNodes() {
+ for node := range m.discvCh {
if n, ok := m.nodeMap[node.ID.String()]; ok && n.String() == node.String() {
continue
}
privKey chainkd.XPrv
chain *mock.Chain
txPool *mock.Mempool
+ discvCh chan *dht.Node
// nodeMap maps a node's public key to the node itself
nodeMap map[string]*dht.Node
dialCh chan struct{}
privKey: privKey.(chainkd.XPrv),
chain: chain,
txPool: txPool,
+ discvCh: make(chan *dht.Node),
nodeMap: make(map[string]*dht.Node),
dialCh: make(chan struct{}, 1),
checkStatusCh: make(chan struct{}, 1),