whisper: allowed filtering for variable topic size

This commit is contained in:
Vlad 2017-03-20 17:34:58 +01:00
parent 13caba9c95
commit 258ca75759
2 changed files with 18 additions and 5 deletions

View file

@ -17,6 +17,7 @@
package whisperv5 package whisperv5
import ( import (
"bytes"
"encoding/json" "encoding/json"
"testing" "testing"
"time" "time"

View file

@ -89,12 +89,12 @@ func (fs *Filters) Get(id string) *Filter {
} }
func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) { func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
var j int
var msg *ReceivedMessage var msg *ReceivedMessage
fs.mutex.RLock() fs.mutex.RLock()
defer fs.mutex.RUnlock() defer fs.mutex.RUnlock()
j := -1
for _, watcher := range fs.watchers { for _, watcher := range fs.watchers {
j++ j++
if p2pMessage && !watcher.AllowP2P { if p2pMessage && !watcher.AllowP2P {
@ -118,6 +118,7 @@ func (fs *Filters) NotifyWatchers(env *Envelope, p2pMessage bool) {
} }
if match && msg != nil { if match && msg != nil {
log.Trace(fmt.Sprintf("message decrypted [%x]", env.Hash()))
watcher.Trigger(msg) watcher.Trigger(msg)
} }
} }
@ -202,10 +203,21 @@ func (f *Filter) MatchTopic(topic TopicType) bool {
} }
for _, bt := range f.Topics { for _, bt := range f.Topics {
for j, b := range bt { if MatchSingleTopic(topic, bt) {
if topic[j] != b { return true
return false }
} }
return false
}
func MatchSingleTopic(topic TopicType, bt []byte) bool {
if len(bt) > 4 {
bt = bt[0:4]
}
for j, b := range bt {
if topic[j] != b {
return false
} }
} }
return true return true