expose function to retrieve list of peers and supported protocols

This commit is contained in:
Richard Ramos 2021-08-31 16:51:22 -04:00 committed by Vitaliy Vlasov
parent 4450e6bba0
commit cf32e10236
1 changed files with 12 additions and 10 deletions

View File

@ -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)