fix: convert TopicType to stack variable and use recvMessage.Topic instead of extracting content topic from WakuMessage

This commit is contained in:
Richard Ramos 2023-01-10 10:50:49 -04:00 committed by RichΛrd
parent e98e6b61af
commit 490570c0ec
3 changed files with 9 additions and 16 deletions

View File

@ -165,18 +165,11 @@ func (fs *Filters) NotifyWatchers(recvMessage *ReceivedMessage) bool {
fs.mutex.RLock()
defer fs.mutex.RUnlock()
topic, err := ExtractTopicFromContentTopic(recvMessage.Envelope.Message().ContentTopic)
if err != nil {
log.Trace(err.Error(), "topic", recvMessage.Envelope.Message().ContentTopic)
return false
}
var matched bool
candidates := fs.GetWatchersByTopic(*topic)
candidates := fs.GetWatchersByTopic(recvMessage.Topic)
if len(candidates) == 0 {
log.Debug("no filters available for this topic", "message", recvMessage.Hash().Hex(), "topic", (*topic).String())
log.Debug("no filters available for this topic", "message", recvMessage.Hash().Hex(), "topic", recvMessage.Topic.String())
}
for _, watcher := range candidates {

View File

@ -154,14 +154,14 @@ type MemoryMessageStore struct {
func NewReceivedMessage(env *protocol.Envelope, msgType MessageType) *ReceivedMessage {
ct, err := ExtractTopicFromContentTopic(env.Message().ContentTopic)
if err != nil {
ct = new(TopicType)
log.Error("failed to extract content topic from message", "topic", env.Message().ContentTopic, "err", err)
}
return &ReceivedMessage{
Envelope: env,
MsgType: msgType,
Sent: uint32(env.Message().Timestamp / int64(time.Second)),
Topic: *ct,
Topic: ct,
}
}
@ -241,7 +241,7 @@ func (msg *ReceivedMessage) Open(watcher *Filter) (result *ReceivedMessage) {
return nil
}
result.Topic = *ct
result.Topic = ct
return result
}

View File

@ -69,18 +69,18 @@ func (t TopicType) ContentTopic() string {
return "/waku/1/" + enc + "/rfc26"
}
func ExtractTopicFromContentTopic(s string) (*TopicType, error) {
func ExtractTopicFromContentTopic(s string) (TopicType, error) {
p := strings.Split(s, "/")
if len(p) != 5 || p[1] != "waku" || p[2] != "1" || p[4] != "rfc26" {
return nil, errors.New("invalid content topic format")
return TopicType{}, errors.New("invalid content topic format")
}
str, err := hexutil.Decode(p[3])
if err != nil {
return nil, err
return TopicType{}, err
}
result := BytesToTopic(str)
return &result, nil
return result, nil
}