fix_: add ticker to check peers and update connection status

This commit is contained in:
Prem Chaitanya Prathi 2024-08-10 16:54:09 +05:30 committed by Andrea Maria Piana
parent f0b6e3d06b
commit a2ec9c2d8b

View File

@ -1352,7 +1352,8 @@ func (w *Waku) Start() error {
go func() {
defer w.wg.Done()
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-w.ctx.Done():
@ -1360,8 +1361,54 @@ func (w *Waku) Start() error {
case <-w.topicHealthStatusChan:
// TODO: https://github.com/status-im/status-go/issues/4628
case <-w.connectionNotifChan:
w.checkForConnectionChanges()
case <-ticker.C:
w.checkForConnectionChanges()
}
}
}()
go w.telemetryBandwidthStats(w.cfg.TelemetryServerURL)
//TODO: commenting for now so that only fleet nodes are used.
//Need to uncomment once filter peer scoring etc is implemented.
go w.runPeerExchangeLoop()
if w.cfg.EnableMissingMessageVerification {
w.wg.Add(1)
go w.checkForMissingMessages()
}
if w.cfg.LightClient {
// Create FilterManager that will main peer connectivity
// for installed filters
w.filterManager = newFilterManager(w.ctx, w.logger, w.cfg,
func(env *protocol.Envelope) error { return w.OnNewEnvelopes(env, common.RelayedMessageType, false) },
w.node.FilterLightnode())
}
err = w.setupRelaySubscriptions()
if err != nil {
return err
}
numCPU := runtime.NumCPU()
for i := 0; i < numCPU; i++ {
go w.processQueueLoop()
}
go w.broadcast()
go w.checkIfMessagesStored()
// we should wait `seedBootnodesForDiscV5` shutdown smoothly before set w.ctx to nil within `w.Stop()`
w.wg.Add(1)
go w.seedBootnodesForDiscV5()
return nil
}
func (w *Waku) checkForConnectionChanges() {
isOnline := len(w.node.Host().Network().Peers()) > 0
@ -1416,47 +1463,6 @@ func (w *Waku) Start() error {
Offline: !latestConnStatus.IsOnline,
})
}
}
}()
go w.telemetryBandwidthStats(w.cfg.TelemetryServerURL)
//TODO: commenting for now so that only fleet nodes are used.
//Need to uncomment once filter peer scoring etc is implemented.
go w.runPeerExchangeLoop()
if w.cfg.EnableMissingMessageVerification {
w.wg.Add(1)
go w.checkForMissingMessages()
}
if w.cfg.LightClient {
// Create FilterManager that will main peer connectivity
// for installed filters
w.filterManager = newFilterManager(w.ctx, w.logger, w.cfg,
func(env *protocol.Envelope) error { return w.OnNewEnvelopes(env, common.RelayedMessageType, false) },
w.node.FilterLightnode())
}
err = w.setupRelaySubscriptions()
if err != nil {
return err
}
numCPU := runtime.NumCPU()
for i := 0; i < numCPU; i++ {
go w.processQueueLoop()
}
go w.broadcast()
go w.checkIfMessagesStored()
// we should wait `seedBootnodesForDiscV5` shutdown smoothly before set w.ctx to nil within `w.Stop()`
w.wg.Add(1)
go w.seedBootnodesForDiscV5()
return nil
}
func (w *Waku) setupRelaySubscriptions() error {
if w.cfg.LightClient {