Skip to content

Commit

Permalink
whisper: fixed broken partial topic filtering
Browse files Browse the repository at this point in the history
Changes in #15811 broke partial topic filtering. Re-enable it.
  • Loading branch information
evgen-povt authored and gballet committed Aug 13, 2018
1 parent d8328a9 commit e07e507
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 58 deletions.
2 changes: 1 addition & 1 deletion whisper/whisperv5/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func matchSingleTopic(topic TopicType, bt []byte) bool {
bt = bt[:TopicLength]
}

if len(bt) < TopicLength {
if len(bt) == 0 {
return false
}

Expand Down
8 changes: 4 additions & 4 deletions whisper/whisperv5/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,16 @@ func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) {
}
}

func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
func TestMatchSingleTopic_PartialTopic_ReturnTrue(t *testing.T) {
bt := []byte("tes")
topic := BytesToTopic(bt)
topic := BytesToTopic([]byte("test"))

if matchSingleTopic(topic, bt) {
if !matchSingleTopic(topic, bt) {
t.FailNow()
}
}

func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) {
func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
bt := []byte("test")
topic := BytesToTopic([]byte("not_equal"))

Expand Down
17 changes: 0 additions & 17 deletions whisper/whisperv6/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,6 @@ func (f *Filter) MatchEnvelope(envelope *Envelope) bool {
return f.PoW <= 0 || envelope.pow >= f.PoW
}

func matchSingleTopic(topic TopicType, bt []byte) bool {
if len(bt) > TopicLength {
bt = bt[:TopicLength]
}

if len(bt) < TopicLength {
return false
}

for j, b := range bt {
if topic[j] != b {
return false
}
}
return true
}

// IsPubKeyEqual checks that two public keys are equal
func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool {
if !ValidatePublicKey(a) {
Expand Down
36 changes: 0 additions & 36 deletions whisper/whisperv6/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,39 +829,3 @@ func TestVariableTopics(t *testing.T) {
}
}
}

func TestMatchSingleTopic_ReturnTrue(t *testing.T) {
bt := []byte("test")
topic := BytesToTopic(bt)

if !matchSingleTopic(topic, bt) {
t.FailNow()
}
}

func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) {
bt := []byte("test with tail")
topic := BytesToTopic([]byte("test"))

if !matchSingleTopic(topic, bt) {
t.FailNow()
}
}

func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
bt := []byte("tes")
topic := BytesToTopic(bt)

if matchSingleTopic(topic, bt) {
t.FailNow()
}
}

func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) {
bt := []byte("test")
topic := BytesToTopic([]byte("not_equal"))

if matchSingleTopic(topic, bt) {
t.FailNow()
}
}

0 comments on commit e07e507

Please sign in to comment.