diff --git a/protocol/common/feature_flags.go b/protocol/common/feature_flags.go index 7272e8cca..9e42e323c 100644 --- a/protocol/common/feature_flags.go +++ b/protocol/common/feature_flags.go @@ -11,4 +11,10 @@ type FeatureFlags struct { // MailserverCycle indicates whether we should enable or not the mailserver cycle MailserverCycle bool + + // DisableCheckingForBackup disables backup loop + DisableCheckingForBackup bool + + // DisableAutoMessageLoop disables auto message loop + DisableAutoMessageLoop bool } diff --git a/protocol/messenger.go b/protocol/messenger.go index 064022e7d..2735ae2f9 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -796,10 +796,14 @@ func (m *Messenger) Start() (*MessengerResponse, error) { m.watchPendingCommunityRequestToJoin() m.broadcastLatestUserStatus() m.timeoutAutomaticStatusUpdates() - m.startBackupLoop() - err = m.startAutoMessageLoop() - if err != nil { - return nil, err + if !m.config.featureFlags.DisableCheckingForBackup { + m.startBackupLoop() + } + if !m.config.featureFlags.DisableAutoMessageLoop { + err = m.startAutoMessageLoop() + if err != nil { + return nil, err + } } m.startSyncSettingsLoop() m.startSettingsChangesLoop() @@ -930,7 +934,7 @@ func (m *Messenger) handleConnectionChange(online bool) { m.ensVerifier.SetOnline(online) } -func (m *Messenger) online() bool { +func (m *Messenger) Online() bool { switch m.transport.WakuVersion() { case 2: return m.transport.PeerCount() > 0 @@ -1443,13 +1447,13 @@ func (m *Messenger) handleENSVerificationSubscription(c chan []*ens.Verification // watchConnectionChange checks the connection status and call handleConnectionChange when this changes func (m *Messenger) watchConnectionChange() { m.logger.Debug("watching connection changes") - state := m.online() + state := m.Online() m.handleConnectionChange(state) go func() { for { select { case <-time.After(200 * time.Millisecond): - newState := m.online() + newState := m.Online() if state != newState { state = newState m.logger.Debug("connection changed", zap.Bool("online", state)) @@ -1526,7 +1530,7 @@ func (m *Messenger) watchExpiredMessages() { for { select { case <-time.After(time.Second): - if m.online() { + if m.Online() { err := m.resendExpiredMessages() if err != nil { m.logger.Debug("Error when resending expired emoji reactions", zap.Error(err)) @@ -1609,7 +1613,7 @@ func (m *Messenger) PublishIdentityImage() error { } // If not online, we schedule it - if !m.online() { + if !m.Online() { m.shouldPublishContactCode = true return nil } diff --git a/protocol/messenger_backup.go b/protocol/messenger_backup.go index 936214cb5..81cf6b8a9 100644 --- a/protocol/messenger_backup.go +++ b/protocol/messenger_backup.go @@ -38,7 +38,7 @@ func (m *Messenger) startBackupLoop() { for { select { case <-ticker.C: - if !m.online() { + if !m.Online() { continue } diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index e47271de8..fa8490889 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -427,7 +427,7 @@ func (m *Messenger) handleCommunitiesSubscription(c chan *communities.Subscripti case <-ticker.C: // If we are not online, we don't even try - if !m.online() { + if !m.Online() { continue } diff --git a/protocol/messenger_config.go b/protocol/messenger_config.go index 40f824376..e1e17eca9 100644 --- a/protocol/messenger_config.go +++ b/protocol/messenger_config.go @@ -275,6 +275,20 @@ func WithPushNotifications() func(c *config) error { } } +func WithCheckingForBackupDisabled() func(c *config) error { + return func(c *config) error { + c.featureFlags.DisableCheckingForBackup = true + return nil + } +} + +func WithAutoMessageDisabled() func(c *config) error { + return func(c *config) error { + c.featureFlags.DisableAutoMessageLoop = true + return nil + } +} + func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option { return func(c *config) error { c.envelopesMonitorConfig = emc diff --git a/protocol/messenger_mailserver.go b/protocol/messenger_mailserver.go index 89e3d3870..c34e2cc9d 100644 --- a/protocol/messenger_mailserver.go +++ b/protocol/messenger_mailserver.go @@ -41,7 +41,7 @@ var maxTopicsPerRequest int = 10 var ErrNoFiltersForChat = errors.New("no filter registered for given chat") func (m *Messenger) shouldSync() (bool, error) { - if m.mailserverCycle.activeMailserver == nil || !m.online() { + if m.mailserverCycle.activeMailserver == nil || !m.Online() { return false, nil }