chore: introduce `unhandledMessagesTracker`

This commit is contained in:
Patryk Osmaczko 2024-01-29 12:24:20 +01:00 committed by osmaczko
parent 9b97ecbd90
commit 67e18a8ff0
2 changed files with 37 additions and 0 deletions

View File

@ -178,6 +178,9 @@ type Messenger struct {
// used to track dispatched messages
dispatchMessageTestCallback func(common.RawMessage)
// used to track unhandled messages
unhandledMessagesTracker func(*v1protocol.StatusMessage, error)
peersyncing *peersyncing.PeerSyncing
peersyncingOffers map[string]uint64
peersyncingRequests map[string]uint64
@ -3836,6 +3839,9 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
if err != nil {
allMessagesProcessed = false
logger.Warn("failed to process protobuf", zap.Error(err))
if m.unhandledMessagesTracker != nil {
m.unhandledMessagesTracker(msg, err)
}
continue
}
logger.Debug("Handled parsed message")

View File

@ -12,7 +12,9 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/tt"
v1protocol "github.com/status-im/status-go/protocol/v1"
"github.com/status-im/status-go/t/helpers"
"github.com/status-im/status-go/walletdatabase"
)
@ -21,6 +23,8 @@ type testMessengerConfig struct {
name string
privateKey *ecdsa.PrivateKey
logger *zap.Logger
unhandledMessagesTracker *unhandledMessagesTracker
}
func (tmc *testMessengerConfig) complete() error {
@ -90,6 +94,10 @@ func newTestMessenger(waku types.Waku, config testMessengerConfig, extraOptions
return nil, err
}
if config.unhandledMessagesTracker != nil {
m.unhandledMessagesTracker = config.unhandledMessagesTracker.addMessage
}
err = m.Init()
if err != nil {
return nil, err
@ -97,3 +105,26 @@ func newTestMessenger(waku types.Waku, config testMessengerConfig, extraOptions
return m, nil
}
type unhandedMessage struct {
*v1protocol.StatusMessage
err error
}
type unhandledMessagesTracker struct {
messages map[protobuf.ApplicationMetadataMessage_Type][]*unhandedMessage
}
func (u *unhandledMessagesTracker) addMessage(msg *v1protocol.StatusMessage, err error) {
msgType := msg.ApplicationLayer.Type
if _, exists := u.messages[msgType]; !exists {
u.messages[msgType] = []*unhandedMessage{}
}
newMessage := &unhandedMessage{
StatusMessage: msg,
err: err,
}
u.messages[msgType] = append(u.messages[msgType], newMessage)
}