diff --git a/whisper/whisperv5/doc.go b/whisper/whisperv5/doc.go index ef3b93d12a..14a6c867b2 100644 --- a/whisper/whisperv5/doc.go +++ b/whisper/whisperv5/doc.go @@ -46,7 +46,9 @@ const ( messagesCode = 1 p2pCode = 2 mailRequestCode = 3 - NumberOfMessageCodes = 4 + bloomExchangeCode = 4 + reservedCode = 5 + NumberOfMessageCodes = 6 paddingMask = byte(3) signatureFlag = byte(4) diff --git a/whisper/whisperv5/filter.go b/whisper/whisperv5/filter.go index 5cc7be5874..350aadba24 100644 --- a/whisper/whisperv5/filter.go +++ b/whisper/whisperv5/filter.go @@ -143,18 +143,9 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool { } if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() { - // if Dst match, ignore the topic - return isPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst) + return isPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst) && f.MatchTopic(msg.Topic) } else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() { - // check if that both the key and the topic match - if f.SymKeyHash == msg.SymKeyHash { - for _, t := range f.Topics { - if t == msg.Topic { - return true - } - } - return false - } + return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic) } return false } @@ -175,14 +166,15 @@ func (f *Filter) MatchEnvelope(envelope *Envelope) bool { encryptionMethodMatch = true } - if encryptionMethodMatch { - for _, t := range f.Topics { - if t == envelope.Topic { - return true - } + return encryptionMethodMatch && f.MatchTopic(envelope.Topic) +} + +func (f *Filter) MatchTopic(topic TopicType) bool { + for _, t := range f.Topics { + if t == topic { + return true } } - return false } diff --git a/whisper/whisperv5/filter_test.go b/whisper/whisperv5/filter_test.go index 8c25b05190..171e68d047 100644 --- a/whisper/whisperv5/filter_test.go +++ b/whisper/whisperv5/filter_test.go @@ -487,10 +487,9 @@ func TestMatchMessageAsym(x *testing.T) { return } - // topic mismatch, but still match, because for asymmetric encryption - // only private key matters (in case the message is already decrypted) + // topic mismatch f.Topics[index][0]++ - if !f.MatchMessage(msg) { + if f.MatchMessage(msg) { x.Errorf("failed test case 8 with seed %d.", seed) return }