fix_: peer counter (#5348)

This commit is contained in:
richΛrd 2024-06-14 12:35:05 -04:00 committed by GitHub
parent eb0f907137
commit b18baea5cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 0 deletions

View File

@ -1349,6 +1349,11 @@ func (w *Waku) Start() error {
defer w.wg.Done() defer w.wg.Done()
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop() defer ticker.Stop()
peerCountTimer := time.NewTimer(0) // fire immediately
defer peerCountTimer.Stop()
peerCount := 0
for { for {
select { select {
case <-w.ctx.Done(): case <-w.ctx.Done():
@ -1361,6 +1366,20 @@ func (w *Waku) Start() error {
if w.cfg.LightClient { if w.cfg.LightClient {
w.lightClientConnectionStatus() w.lightClientConnectionStatus()
} }
case <-peerCountTimer.C:
peerCountTimer.Reset(3 * time.Second)
newPeerCount := len(w.node.Host().Network().Peers())
if newPeerCount != peerCount && w.onPeerStats != nil {
peerCount = newPeerCount
// TODO: `IsOnline` is not implemented correctly here, however
// this is not a problem because Desktop ignores that value.
// This should be fixed to as part of issue
// https://github.com/status-im/status-go/issues/4628
w.onPeerStats(types.ConnStatus{
IsOnline: true,
Peers: FormatPeerStats(w.node),
})
}
case c := <-w.topicHealthStatusChan: case c := <-w.topicHealthStatusChan:
w.connStatusMu.Lock() w.connStatusMu.Lock()