whisper: logging updated

This commit is contained in:
Vlad 2016-12-09 19:56:48 +01:00
parent 3cf9b8dc83
commit 1ea86735a8
3 changed files with 16 additions and 9 deletions

View file

@ -21,6 +21,7 @@ import (
"sync" "sync"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger/glog"
) )
type Filter struct { type Filter struct {
@ -82,8 +83,9 @@ func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) {
fs.mutex.RLock() fs.mutex.RLock()
var msg *ReceivedMessage var msg *ReceivedMessage
for _, watcher := range fs.watchers { for j, watcher := range fs.watchers {
if messageCode == p2pCode && !watcher.AcceptP2P { if messageCode == p2pCode && !watcher.AcceptP2P {
glog.V(9).Infof("msg [%x], filter [%d]: p2p messages are not allowed \n", env.Hash(), j)
continue continue
} }
@ -94,6 +96,11 @@ func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) {
match = watcher.MatchEnvelope(env) match = watcher.MatchEnvelope(env)
if match { if match {
msg = env.Open(watcher) 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 { if f.PoW > 0 && msg.PoW < f.PoW {
return false return false
} }
if f.Src != nil && !isPubKeyEqual(msg.Src, f.Src) { if f.Src != nil && !IsPubKeyEqual(msg.Src, f.Src) {
return false return false
} }
if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() { 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() { } else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() {
return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic) return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic)
} }
@ -180,7 +187,7 @@ func (f *Filter) MatchTopic(topic TopicType) bool {
return false return false
} }
func isPubKeyEqual(a, b *ecdsa.PublicKey) bool { func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool {
if !ValidatePublicKey(a) { if !ValidatePublicKey(a) {
return false return false
} else if !ValidatePublicKey(b) { } else if !ValidatePublicKey(b) {

View file

@ -139,7 +139,7 @@ func TestComparePubKey(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to generate second key with seed %d: %s.", seed, err) 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) t.Fatalf("public keys are equal, seed %d.", seed)
} }
@ -149,7 +149,7 @@ func TestComparePubKey(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to generate third key with seed %d: %s.", seed, err) 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) t.Fatalf("key1 == key3, seed %d.", seed)
} }
} }

View file

@ -116,7 +116,7 @@ func singleMessageTest(t *testing.T, symmetric bool) {
if len(decrypted.Signature) != signatureLength { if len(decrypted.Signature) != signatureLength {
t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature)) t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
} }
if !isPubKeyEqual(decrypted.Src, &params.Src.PublicKey) { if !IsPubKeyEqual(decrypted.Src, &params.Src.PublicKey) {
t.Fatalf("failed with seed %d: signature mismatch.", seed) 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 { if len(decrypted.Signature) != signatureLength {
t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature)) t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
} }
if !isPubKeyEqual(decrypted.Src, &params.Src.PublicKey) { if !IsPubKeyEqual(decrypted.Src, &params.Src.PublicKey) {
t.Fatalf("failed with seed %d: signature mismatch.", seed) t.Fatalf("failed with seed %d: signature mismatch.", seed)
} }
if decrypted.isAsymmetricEncryption() == symmetric { if decrypted.isAsymmetricEncryption() == symmetric {
@ -281,7 +281,7 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) {
if decrypted.Dst == nil { if decrypted.Dst == nil {
t.Fatalf("failed with seed %d: dst is nil.", seed) 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) t.Fatalf("failed with seed %d: Dst.", seed)
} }
} }