From 67364dadc80fc1ef7625d014b9603bdbdaad196a Mon Sep 17 00:00:00 2001 From: Vitaly Vlasov Date: Tue, 25 Jun 2024 12:22:42 +0300 Subject: [PATCH] chore_: small mailserver async fetching refactor --- protocol/messenger.go | 10 +++------- protocol/messenger_mailserver_cycle.go | 16 ++-------------- protocol/messenger_test.go | 2 +- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/protocol/messenger.go b/protocol/messenger.go index 25646ddc946..1140290afa5 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1568,13 +1568,9 @@ func (m *Messenger) watchConnectionChange() { return } - subscription, err := waku.SubscribeToConnStatusChanges() - if err != nil { - // Log error and fallback to polling - m.logger.Error("failed to subscribe to connection status changes", zap.Error(err)) - go pollConnectionStatus() - return - } + // Wakuv2 is not going to return an error + // from SubscribeToConnStatusChanges + subscription, _ := waku.SubscribeToConnStatusChanges() go subscribedConnectionStatus(subscription) } diff --git a/protocol/messenger_mailserver_cycle.go b/protocol/messenger_mailserver_cycle.go index bbbd6a605be..53861757a68 100644 --- a/protocol/messenger_mailserver_cycle.go +++ b/protocol/messenger_mailserver_cycle.go @@ -434,14 +434,7 @@ func (m *Messenger) connectToMailserver(ms mailservers.Mailserver) error { // Query mailserver if m.config.codeControlFlags.AutoRequestHistoricMessages { - go func() { - _, err := m.performMailserverRequest(&ms, func(_ mailservers.Mailserver) (*MessengerResponse, error) { - return m.RequestAllHistoricMessages(false, false) - }) - if err != nil { - m.logger.Error("could not perform mailserver request", zap.Error(err)) - } - }() + m.asyncRequestAllHistoricMessages() } } } @@ -587,12 +580,7 @@ func (m *Messenger) handleMailserverCycleEvent(connectedPeers []ConnectedPeer) e } // Query mailserver if m.config.codeControlFlags.AutoRequestHistoricMessages { - go func() { - _, err := m.RequestAllHistoricMessages(false, true) - if err != nil { - m.logger.Error("failed to request historic messages", zap.Error(err)) - } - }() + m.asyncRequestAllHistoricMessages() } } else { m.mailPeersMutex.Unlock() diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index aa9da1117d0..2258ca715b9 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -70,7 +70,7 @@ func (n *testNode) GetWaku(_ interface{}) (types.Waku, error) { } func (n *testNode) GetWakuV2(_ interface{}) (types.Waku, error) { - return n.shh, nil + return nil, errors.New("No waku v2 support") } func (n *testNode) GetWhisper(_ interface{}) (types.Whisper, error) {