mirror of https://github.com/status-im/go-waku.git
expose function to retrieve list of peers and supported protocols
This commit is contained in:
parent
4450e6bba0
commit
cf32e10236
|
@ -164,16 +164,7 @@ func (w *WakuNode) processHostEvent(e interface{}) {
|
||||||
log.Debug("###ConnStatus isOnline: ", isOnline, "/", newIsOnline, " hasHistory: ",
|
log.Debug("###ConnStatus isOnline: ", isOnline, "/", newIsOnline, " hasHistory: ",
|
||||||
hasHistory, "/", newHasHistory)
|
hasHistory, "/", newHasHistory)
|
||||||
if w.connStatusChan != nil {
|
if w.connStatusChan != nil {
|
||||||
|
connStatus := ConnStatus{IsOnline: newIsOnline, HasHistory: newHasHistory, Peers: w.Peers()}
|
||||||
// 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}
|
|
||||||
log.Debug("New ConnStatus: ", connStatus)
|
log.Debug("New ConnStatus: ", connStatus)
|
||||||
w.connStatusChan <- connStatus
|
w.connStatusChan <- connStatus
|
||||||
}
|
}
|
||||||
|
@ -733,6 +724,17 @@ func (w *WakuNode) PeerCount() int {
|
||||||
return len(w.peers)
|
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) {
|
func (w *WakuNode) startKeepAlive(t time.Duration) {
|
||||||
log.Info("Setting up ping protocol with duration of ", t)
|
log.Info("Setting up ping protocol with duration of ", t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue