diff options
author | Vlad <gluk256@gmail.com> | 2018-02-28 06:38:20 +0800 |
---|---|---|
committer | Vlad <gluk256@gmail.com> | 2018-02-28 06:38:20 +0800 |
commit | c733792be4b49ec47c5307b1a3b8fa116ea16933 (patch) | |
tree | 33e804424ca1e220c2a6ae9cd7177f8623893883 /whisper/whisperv6/filter.go | |
parent | 014d8d98370abf770b89f7987a92999133e3d4ea (diff) | |
download | go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar.gz go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar.bz2 go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar.lz go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar.xz go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.tar.zst go-tangerine-c733792be4b49ec47c5307b1a3b8fa116ea16933.zip |
whsiper: refactoring
Diffstat (limited to 'whisper/whisperv6/filter.go')
-rw-r--r-- | whisper/whisperv6/filter.go | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/whisper/whisperv6/filter.go b/whisper/whisperv6/filter.go index 75c31209c..d7b71795d 100644 --- a/whisper/whisperv6/filter.go +++ b/whisper/whisperv6/filter.go @@ -238,16 +238,17 @@ func (f *Filter) Retrieve() (all []*ReceivedMessage) { // MatchMessage checks if the filter matches an already decrypted // message (i.e. a Message that has already been handled by -// MatchEnvelope when checked by a previous filter) +// MatchEnvelope when checked by a previous filter). +// Topics are not checked here, since this is done by topic matchers. func (f *Filter) MatchMessage(msg *ReceivedMessage) bool { if f.PoW > 0 && msg.PoW < f.PoW { 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) } else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() { - return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic) + return f.SymKeyHash == msg.SymKeyHash } return false } @@ -255,27 +256,9 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool { // MatchEnvelope checks if it's worth decrypting the message. If // it returns `true`, client code is expected to attempt decrypting // the message and subsequently call MatchMessage. +// Topics are not checked here, since this is done by topic matchers. func (f *Filter) MatchEnvelope(envelope *Envelope) bool { - if f.PoW > 0 && envelope.pow < f.PoW { - return false - } - - return f.MatchTopic(envelope.Topic) -} - -// MatchTopic checks that the filter captures a given topic. -func (f *Filter) MatchTopic(topic TopicType) bool { - if len(f.Topics) == 0 { - // any topic matches - return true - } - - for _, bt := range f.Topics { - if matchSingleTopic(topic, bt) { - return true - } - } - return false + return f.PoW <= 0 || envelope.pow >= f.PoW } func matchSingleTopic(topic TopicType, bt []byte) bool { |