mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
whisper: Filter refactoring
This commit is contained in:
parent
36956da4d2
commit
2010c20a15
3 changed files with 14 additions and 21 deletions
|
|
@ -46,7 +46,9 @@ const (
|
||||||
messagesCode = 1
|
messagesCode = 1
|
||||||
p2pCode = 2
|
p2pCode = 2
|
||||||
mailRequestCode = 3
|
mailRequestCode = 3
|
||||||
NumberOfMessageCodes = 4
|
bloomExchangeCode = 4
|
||||||
|
reservedCode = 5
|
||||||
|
NumberOfMessageCodes = 6
|
||||||
|
|
||||||
paddingMask = byte(3)
|
paddingMask = byte(3)
|
||||||
signatureFlag = byte(4)
|
signatureFlag = byte(4)
|
||||||
|
|
|
||||||
|
|
@ -143,18 +143,9 @@ func (f *Filter) MatchMessage(msg *ReceivedMessage) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() {
|
if f.expectsAsymmetricEncryption() && msg.isAsymmetricEncryption() {
|
||||||
// if Dst match, ignore the topic
|
return isPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst) && f.MatchTopic(msg.Topic)
|
||||||
return isPubKeyEqual(&f.KeyAsym.PublicKey, msg.Dst)
|
|
||||||
} else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() {
|
} else if f.expectsSymmetricEncryption() && msg.isSymmetricEncryption() {
|
||||||
// check if that both the key and the topic match
|
return f.SymKeyHash == msg.SymKeyHash && f.MatchTopic(msg.Topic)
|
||||||
if f.SymKeyHash == msg.SymKeyHash {
|
|
||||||
for _, t := range f.Topics {
|
|
||||||
if t == msg.Topic {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -175,14 +166,15 @@ func (f *Filter) MatchEnvelope(envelope *Envelope) bool {
|
||||||
encryptionMethodMatch = true
|
encryptionMethodMatch = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if encryptionMethodMatch {
|
return encryptionMethodMatch && f.MatchTopic(envelope.Topic)
|
||||||
for _, t := range f.Topics {
|
}
|
||||||
if t == envelope.Topic {
|
|
||||||
return true
|
func (f *Filter) MatchTopic(topic TopicType) bool {
|
||||||
}
|
for _, t := range f.Topics {
|
||||||
|
if t == topic {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -487,10 +487,9 @@ func TestMatchMessageAsym(x *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// topic mismatch, but still match, because for asymmetric encryption
|
// topic mismatch
|
||||||
// only private key matters (in case the message is already decrypted)
|
|
||||||
f.Topics[index][0]++
|
f.Topics[index][0]++
|
||||||
if !f.MatchMessage(msg) {
|
if f.MatchMessage(msg) {
|
||||||
x.Errorf("failed test case 8 with seed %d.", seed)
|
x.Errorf("failed test case 8 with seed %d.", seed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue