aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv5/filter.go
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2016-12-20 07:58:01 +0800
committerFelix Lange <fjl@users.noreply.github.com>2016-12-20 07:58:01 +0800
commitba996f5e27572e853bcc5c815ae72082a15c9183 (patch)
tree16d6fd41d3d77208597683c71bdc9af603d43a77 /whisper/whisperv5/filter.go
parent64bf5bafe9ced66bfb11f34fed9181aa89399473 (diff)
downloaddexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar.gz
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar.bz2
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar.lz
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar.xz
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.tar.zst
dexon-ba996f5e27572e853bcc5c815ae72082a15c9183.zip
whisper: refactoring (#3411)
* whisper: refactored message processing * whisper: final polishing * whisper: logging updated * whisper: moved the check, changed the default PoW * whisper: refactoring of message queuing * whisper: refactored parameters
Diffstat (limited to 'whisper/whisperv5/filter.go')
-rw-r--r--whisper/whisperv5/filter.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/whisper/whisperv5/filter.go b/whisper/whisperv5/filter.go
index fd5f5083f..3845d0c20 100644
--- a/whisper/whisperv5/filter.go
+++ b/whisper/whisperv5/filter.go
@@ -21,6 +21,8 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
)
type Filter struct {
@@ -75,11 +77,12 @@ func (fs *Filters) Get(i uint32) *Filter {
return fs.watchers[i]
}
-func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) {
+func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
fs.mutex.RLock()
var msg *ReceivedMessage
- for _, watcher := range fs.watchers {
- if messageCode == p2pCode && !watcher.AcceptP2P {
+ for j, watcher := range fs.watchers {
+ if p2pMessage && !watcher.AcceptP2P {
+ glog.V(logger.Detail).Infof("msg [%x], filter [%d]: p2p messages are not allowed \n", env.Hash(), j)
continue
}
@@ -90,6 +93,11 @@ func (fs *Filters) NotifyWatchers(env *Envelope, messageCode uint64) {
match = watcher.MatchEnvelope(env)
if match {
msg = env.Open(watcher)
+ if msg == nil {
+ glog.V(logger.Detail).Infof("msg [%x], filter [%d]: failed to open \n", env.Hash(), j)
+ }
+ } else {
+ glog.V(logger.Detail).Infof("msg [%x], filter [%d]: does not match \n", env.Hash(), j)
}
}
@@ -137,12 +145,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)
}
@@ -176,7 +184,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) {