From cf32e10236078d5e56964e7b8dc1dba3d51fd214 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 31 Aug 2021 16:51:22 -0400 Subject: [PATCH] expose function to retrieve list of peers and supported protocols --- waku/v2/node/wakunode2.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 9a9f8b6c..332a7d5f 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -164,16 +164,7 @@ func (w *WakuNode) processHostEvent(e interface{}) { log.Debug("###ConnStatus isOnline: ", isOnline, "/", newIsOnline, " hasHistory: ", hasHistory, "/", newHasHistory) if w.connStatusChan != nil { - - // Creating a copy of the current peers map - w.peersMutex.Lock() - p := make(PeerStats) - for k, v := range w.peers { - p[k] = v - } - w.peersMutex.Unlock() - - connStatus := ConnStatus{IsOnline: newIsOnline, HasHistory: newHasHistory, Peers: p} + connStatus := ConnStatus{IsOnline: newIsOnline, HasHistory: newHasHistory, Peers: w.Peers()} log.Debug("New ConnStatus: ", connStatus) w.connStatusChan <- connStatus } @@ -733,6 +724,17 @@ func (w *WakuNode) PeerCount() int { return len(w.peers) } +func (w *WakuNode) Peers() PeerStats { + w.peersMutex.Lock() + defer w.peersMutex.Unlock() + p := make(PeerStats) + for k, v := range w.peers { + p[k] = v + } + + return p +} + func (w *WakuNode) startKeepAlive(t time.Duration) { log.Info("Setting up ping protocol with duration of ", t)