Skip to content

Commit

Permalink
chore_: small mailserver async fetching refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vitvly committed Jul 16, 2024
1 parent 621b31a commit 67364da
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
10 changes: 3 additions & 7 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 2 additions & 14 deletions protocol/messenger_mailserver_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 67364da

Please sign in to comment.