diff --git a/whisper/whisperv5/filter.go b/whisper/whisperv5/filter.go index 091a31cc9e..889201e33e 100644 --- a/whisper/whisperv5/filter.go +++ b/whisper/whisperv5/filter.go @@ -21,6 +21,7 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/logger/glog" ) type Filter struct { @@ -82,8 +83,9 @@ func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) { fs.mutex.RLock() var msg *ReceivedMessage - for _, watcher := range fs.watchers { + for j, watcher := range fs.watchers { if messageCode == p2pCode && !watcher.AcceptP2P { + glog.V(9).Infof("msg [%x], filter [%d]: p2p messages are not allowed \n", env.Hash(), j) continue } @@ -94,6 +96,11 @@ func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) { match = watcher.MatchEnvelope(env) if match { msg = env.Open(watcher) + if msg == nil { + glog.V(9).Infof("msg [%x], filter [%d]: failed to open \n", env.Hash(), j) + } + } else { + glog.V(9).Infof("msg [%x], filter [%d]: does not match \n", env.Hash(), j) } } @@ -141,12 +148,12 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool { if f.PoW > 0 && msg.PoW < f.PoW { return false } - if f.Src != nil && !isPubKeyEqual(msg.Src, f.Src) { + if f.Src != nil && !IsPubKeyEqual(msg.Src, f.Src) { return false } if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() { - return isPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst) && f.MatchTopic(msg.Topic) + return IsPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst) && f.MatchTopic(msg.Topic) } else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() { return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic) } @@ -180,7 +187,7 @@ func (f *Filter) MatchTopic(topic TopicType) bool { return false } -func isPubKeyEqual(a, b *ecdsa.PublicKey) bool { +func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool { if !ValidatePublicKey(a) { return false } else if !ValidatePublicKey(b) { diff --git a/whisper/whisperv5/filter_test.go b/whisper/whisperv5/filter_test.go index 561bb8f7d6..bfa45782a0 100644 --- a/whisper/whisperv5/filter_test.go +++ b/whisper/whisperv5/filter_test.go @@ -139,7 +139,7 @@ func TestComparePubKey(t *testing.T) { if err != nil { t.Fatalf("failed to generate second key with seed %d: %s.", seed, err) } - if isPubKeyEqual(&key1.PublicKey, &key2.PublicKey) { + if IsPubKeyEqual(&key1.PublicKey, &key2.PublicKey) { t.Fatalf("public keys are equal, seed %d.", seed) } @@ -149,7 +149,7 @@ func TestComparePubKey(t *testing.T) { if err != nil { t.Fatalf("failed to generate third key with seed %d: %s.", seed, err) } - if isPubKeyEqual(&key1.PublicKey, &key3.PublicKey) { + if IsPubKeyEqual(&key1.PublicKey, &key3.PublicKey) { t.Fatalf("key1 == key3, seed %d.", seed) } } diff --git a/whisper/whisperv5/message_test.go b/whisper/whisperv5/message_test.go index 394291a837..5cbc9182f2 100644 --- a/whisper/whisperv5/message_test.go +++ b/whisper/whisperv5/message_test.go @@ -116,7 +116,7 @@ func singleMessageTest(t *testing.T, symmetric bool) { if len(decrypted.Signature) != signatureLength { t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature)) } - if !isPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) { + if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) { t.Fatalf("failed with seed %d: signature mismatch.", seed) } } @@ -268,7 +268,7 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) { if len(decrypted.Signature) != signatureLength { t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature)) } - if !isPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) { + if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) { t.Fatalf("failed with seed %d: signature mismatch.", seed) } if decrypted.isAsymmetricEncryption() == symmetric { @@ -281,7 +281,7 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) { if decrypted.Dst == nil { t.Fatalf("failed with seed %d: dst is nil.", seed) } - if !isPubKeyEqual(decrypted.Dst, &key.PublicKey) { + if !IsPubKeyEqual(decrypted.Dst, &key.PublicKey) { t.Fatalf("failed with seed %d: Dst.", seed) } }