aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
Diffstat (limited to 'whisper')
-rw-r--r--whisper/shhapi/api.go6
-rw-r--r--whisper/shhapi/api_test.go2
-rw-r--r--whisper/whisperv2/envelope_test.go12
-rw-r--r--whisper/whisperv2/filter.go7
-rw-r--r--whisper/whisperv2/filter_test.go8
-rw-r--r--whisper/whisperv2/message_test.go4
-rw-r--r--whisper/whisperv2/peer.go2
-rw-r--r--whisper/whisperv2/peer_test.go2
-rw-r--r--whisper/whisperv2/topic_test.go60
-rw-r--r--whisper/whisperv5/message_test.go8
-rw-r--r--whisper/whisperv5/peer.go2
-rw-r--r--whisper/whisperv5/peer_test.go2
-rw-r--r--whisper/whisperv5/whisper.go2
-rw-r--r--whisper/whisperv5/whisper_test.go6
14 files changed, 58 insertions, 65 deletions
diff --git a/whisper/shhapi/api.go b/whisper/shhapi/api.go
index 24d54b653..379bb90d3 100644
--- a/whisper/shhapi/api.go
+++ b/whisper/shhapi/api.go
@@ -178,14 +178,10 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
Messages: make(map[common.Hash]*whisperv5.ReceivedMessage),
AcceptP2P: args.AcceptP2P,
}
-
if len(filter.KeySym) > 0 {
filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym)
}
-
- for _, t := range args.Topics {
- filter.Topics = append(filter.Topics, t)
- }
+ filter.Topics = append(filter.Topics, args.Topics...)
if len(args.Topics) == 0 {
info := "NewFilter: at least one topic must be specified"
diff --git a/whisper/shhapi/api_test.go b/whisper/shhapi/api_test.go
index d2890a9a3..60b6fbd04 100644
--- a/whisper/shhapi/api_test.go
+++ b/whisper/shhapi/api_test.go
@@ -253,7 +253,7 @@ func TestUnmarshalPostArgs(t *testing.T) {
if a.FilterID != 64 {
t.Fatalf("wrong FilterID: %d.", a.FilterID)
}
- if bytes.Compare(a.PeerID[:], a.Topic[:]) != 0 {
+ if !bytes.Equal(a.PeerID[:], a.Topic[:]) {
t.Fatalf("wrong PeerID: %x.", a.PeerID)
}
}
diff --git a/whisper/whisperv2/envelope_test.go b/whisper/whisperv2/envelope_test.go
index 75e2fbe8a..c1b128c61 100644
--- a/whisper/whisperv2/envelope_test.go
+++ b/whisper/whisperv2/envelope_test.go
@@ -40,10 +40,10 @@ func TestEnvelopeOpen(t *testing.T) {
if opened.Flags != message.Flags {
t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags)
}
- if bytes.Compare(opened.Signature, message.Signature) != 0 {
+ if !bytes.Equal(opened.Signature, message.Signature) {
t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature)
}
- if bytes.Compare(opened.Payload, message.Payload) != 0 {
+ if !bytes.Equal(opened.Payload, message.Payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload)
}
if opened.Sent.Unix() != message.Sent.Unix() {
@@ -71,7 +71,7 @@ func TestEnvelopeAnonymousOpenUntargeted(t *testing.T) {
if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
}
- if bytes.Compare(opened.Payload, payload) != 0 {
+ if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
}
}
@@ -96,7 +96,7 @@ func TestEnvelopeAnonymousOpenTargeted(t *testing.T) {
if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
}
- if bytes.Compare(opened.Payload, payload) == 0 {
+ if bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload match, should have been encrypted: 0x%x", opened.Payload)
}
}
@@ -127,7 +127,7 @@ func TestEnvelopeIdentifiedOpenUntargeted(t *testing.T) {
if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
}
- if bytes.Compare(opened.Payload, payload) != 0 {
+ if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
}
}
@@ -152,7 +152,7 @@ func TestEnvelopeIdentifiedOpenTargeted(t *testing.T) {
if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
}
- if bytes.Compare(opened.Payload, payload) != 0 {
+ if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
}
}
diff --git a/whisper/whisperv2/filter.go b/whisper/whisperv2/filter.go
index 8ce4a54fb..7404859b7 100644
--- a/whisper/whisperv2/filter.go
+++ b/whisper/whisperv2/filter.go
@@ -116,14 +116,11 @@ func (self filterer) Compare(f filter.Filter) bool {
topics := make([]Topic, len(filter.matcher.conditions))
for i, group := range filter.matcher.conditions {
// Message should contain a single topic entry, extract
- for topics[i], _ = range group {
+ for topics[i] = range group {
break
}
}
- if !self.matcher.Matches(topics) {
- return false
- }
- return true
+ return self.matcher.Matches(topics)
}
// Trigger is called when a filter successfully matches an inbound message.
diff --git a/whisper/whisperv2/filter_test.go b/whisper/whisperv2/filter_test.go
index 5a14a84bb..ffdfd7b34 100644
--- a/whisper/whisperv2/filter_test.go
+++ b/whisper/whisperv2/filter_test.go
@@ -91,7 +91,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue
}
for k := 0; k < len(condition); k++ {
- if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 {
+ if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
}
}
@@ -115,7 +115,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue
}
for k := 0; k < len(condition); k++ {
- if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 {
+ if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
}
}
@@ -135,7 +135,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue
}
for k := 0; k < len(condition); k++ {
- if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 {
+ if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
}
}
@@ -156,7 +156,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue
}
for k := 0; k < len(condition); k++ {
- if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 {
+ if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
}
}
diff --git a/whisper/whisperv2/message_test.go b/whisper/whisperv2/message_test.go
index efa64e431..d3b307d2a 100644
--- a/whisper/whisperv2/message_test.go
+++ b/whisper/whisperv2/message_test.go
@@ -40,7 +40,7 @@ func TestMessageSimpleWrap(t *testing.T) {
if len(msg.Signature) != 0 {
t.Fatalf("signature found for simple wrapping: 0x%x", msg.Signature)
}
- if bytes.Compare(msg.Payload, payload) != 0 {
+ if !bytes.Equal(msg.Payload, payload) {
t.Fatalf("payload mismatch after wrapping: have 0x%x, want 0x%x", msg.Payload, payload)
}
if msg.TTL/time.Second != DefaultTTL/time.Second {
@@ -65,7 +65,7 @@ func TestMessageCleartextSignRecover(t *testing.T) {
if msg.Flags&signatureFlag != signatureFlag {
t.Fatalf("signature flag mismatch: have %d, want %d", msg.Flags&signatureFlag, signatureFlag)
}
- if bytes.Compare(msg.Payload, payload) != 0 {
+ if !bytes.Equal(msg.Payload, payload) {
t.Fatalf("payload mismatch after signing: have 0x%x, want 0x%x", msg.Payload, payload)
}
diff --git a/whisper/whisperv2/peer.go b/whisper/whisperv2/peer.go
index 404ebd513..f09ce3523 100644
--- a/whisper/whisperv2/peer.go
+++ b/whisper/whisperv2/peer.go
@@ -149,7 +149,7 @@ func (self *peer) expire() {
return true
})
// Dump all known but unavailable
- for hash, _ := range unmark {
+ for hash := range unmark {
self.known.Remove(hash)
}
}
diff --git a/whisper/whisperv2/peer_test.go b/whisper/whisperv2/peer_test.go
index 9755e134c..87ca5063d 100644
--- a/whisper/whisperv2/peer_test.go
+++ b/whisper/whisperv2/peer_test.go
@@ -221,7 +221,7 @@ func TestPeerMessageExpiration(t *testing.T) {
t.Fatalf("peer pool size mismatch: have %v, want %v", peers, 1)
}
var peer *peer
- for peer, _ = range tester.client.peers {
+ for peer = range tester.client.peers {
break
}
tester.client.peerMu.RUnlock()
diff --git a/whisper/whisperv2/topic_test.go b/whisper/whisperv2/topic_test.go
index efd4a2c61..bb6568996 100644
--- a/whisper/whisperv2/topic_test.go
+++ b/whisper/whisperv2/topic_test.go
@@ -33,13 +33,13 @@ func TestTopicCreation(t *testing.T) {
// Create the topics individually
for i, tt := range topicCreationTests {
topic := NewTopic(tt.data)
- if bytes.Compare(topic[:], tt.hash[:]) != 0 {
+ if !bytes.Equal(topic[:], tt.hash[:]) {
t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash)
}
}
for i, tt := range topicCreationTests {
topic := NewTopicFromString(string(tt.data))
- if bytes.Compare(topic[:], tt.hash[:]) != 0 {
+ if !bytes.Equal(topic[:], tt.hash[:]) {
t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash)
}
}
@@ -55,13 +55,13 @@ func TestTopicCreation(t *testing.T) {
topics := NewTopics(binaryData...)
for i, tt := range topicCreationTests {
- if bytes.Compare(topics[i][:], tt.hash[:]) != 0 {
+ if !bytes.Equal(topics[i][:], tt.hash[:]) {
t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash)
}
}
topics = NewTopicsFromStrings(textualData...)
for i, tt := range topicCreationTests {
- if bytes.Compare(topics[i][:], tt.hash[:]) != 0 {
+ if !bytes.Equal(topics[i][:], tt.hash[:]) {
t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash)
}
}
@@ -73,30 +73,30 @@ var topicMatcherCreationTest = struct {
matcher []map[[4]byte]struct{}
}{
binary: [][][]byte{
- [][]byte{},
- [][]byte{
+ {},
+ {
[]byte("Topic A"),
},
- [][]byte{
+ {
[]byte("Topic B1"),
[]byte("Topic B2"),
[]byte("Topic B3"),
},
},
textual: [][]string{
- []string{},
- []string{"Topic A"},
- []string{"Topic B1", "Topic B2", "Topic B3"},
+ {},
+ {"Topic A"},
+ {"Topic B1", "Topic B2", "Topic B3"},
},
matcher: []map[[4]byte]struct{}{
- map[[4]byte]struct{}{},
- map[[4]byte]struct{}{
- [4]byte{0x25, 0xfc, 0x95, 0x66}: struct{}{},
+ {},
+ {
+ {0x25, 0xfc, 0x95, 0x66}: {},
},
- map[[4]byte]struct{}{
- [4]byte{0x93, 0x6d, 0xec, 0x09}: struct{}{},
- [4]byte{0x25, 0x23, 0x34, 0xd3}: struct{}{},
- [4]byte{0x6b, 0xc2, 0x73, 0xd1}: struct{}{},
+ {
+ {0x93, 0x6d, 0xec, 0x09}: {},
+ {0x25, 0x23, 0x34, 0xd3}: {},
+ {0x6b, 0xc2, 0x73, 0xd1}: {},
},
},
}
@@ -106,14 +106,14 @@ func TestTopicMatcherCreation(t *testing.T) {
matcher := newTopicMatcherFromBinary(test.binary...)
for i, cond := range matcher.conditions {
- for topic, _ := range cond {
+ for topic := range cond {
if _, ok := test.matcher[i][topic]; !ok {
t.Errorf("condition %d; extra topic found: 0x%x", i, topic[:])
}
}
}
for i, cond := range test.matcher {
- for topic, _ := range cond {
+ for topic := range cond {
if _, ok := matcher.conditions[i][topic]; !ok {
t.Errorf("condition %d; topic not found: 0x%x", i, topic[:])
}
@@ -122,14 +122,14 @@ func TestTopicMatcherCreation(t *testing.T) {
matcher = newTopicMatcherFromStrings(test.textual...)
for i, cond := range matcher.conditions {
- for topic, _ := range cond {
+ for topic := range cond {
if _, ok := test.matcher[i][topic]; !ok {
t.Errorf("condition %d; extra topic found: 0x%x", i, topic[:])
}
}
}
for i, cond := range test.matcher {
- for topic, _ := range cond {
+ for topic := range cond {
if _, ok := matcher.conditions[i][topic]; !ok {
t.Errorf("condition %d; topic not found: 0x%x", i, topic[:])
}
@@ -155,49 +155,49 @@ var topicMatcherTests = []struct {
},
// Fixed topic matcher should match strictly, but only prefix
{
- filter: [][]string{[]string{"a"}, []string{"b"}},
+ filter: [][]string{{"a"}, {"b"}},
topics: []string{"a"},
match: false,
},
{
- filter: [][]string{[]string{"a"}, []string{"b"}},
+ filter: [][]string{{"a"}, {"b"}},
topics: []string{"a", "b"},
match: true,
},
{
- filter: [][]string{[]string{"a"}, []string{"b"}},
+ filter: [][]string{{"a"}, {"b"}},
topics: []string{"a", "b", "c"},
match: true,
},
// Multi-matcher should match any from a sub-group
{
- filter: [][]string{[]string{"a1", "a2"}},
+ filter: [][]string{{"a1", "a2"}},
topics: []string{"a"},
match: false,
},
{
- filter: [][]string{[]string{"a1", "a2"}},
+ filter: [][]string{{"a1", "a2"}},
topics: []string{"a1"},
match: true,
},
{
- filter: [][]string{[]string{"a1", "a2"}},
+ filter: [][]string{{"a1", "a2"}},
topics: []string{"a2"},
match: true,
},
// Wild-card condition should match anything
{
- filter: [][]string{[]string{}, []string{"b"}},
+ filter: [][]string{{}, {"b"}},
topics: []string{"a"},
match: false,
},
{
- filter: [][]string{[]string{}, []string{"b"}},
+ filter: [][]string{{}, {"b"}},
topics: []string{"a", "b"},
match: true,
},
{
- filter: [][]string{[]string{}, []string{"b"}},
+ filter: [][]string{{}, {"b"}},
topics: []string{"b", "b"},
match: true,
},
diff --git a/whisper/whisperv5/message_test.go b/whisper/whisperv5/message_test.go
index 5cbc9182f..3eb71653d 100644
--- a/whisper/whisperv5/message_test.go
+++ b/whisper/whisperv5/message_test.go
@@ -104,10 +104,10 @@ func singleMessageTest(t *testing.T, symmetric bool) {
}
padsz := len(decrypted.Padding)
- if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 {
+ if !bytes.Equal(steg[:padsz], decrypted.Padding) {
t.Fatalf("failed with seed %d: compare padding.", seed)
}
- if bytes.Compare(text, decrypted.Payload) != 0 {
+ if !bytes.Equal(text, decrypted.Payload) {
t.Fatalf("failed with seed %d: compare payload.", seed)
}
if !isMessageSigned(decrypted.Raw[0]) {
@@ -256,10 +256,10 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) {
}
padsz := len(decrypted.Padding)
- if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 {
+ if !bytes.Equal(steg[:padsz], decrypted.Padding) {
t.Fatalf("failed with seed %d: compare padding.", seed)
}
- if bytes.Compare(text, decrypted.Payload) != 0 {
+ if !bytes.Equal(text, decrypted.Payload) {
t.Fatalf("failed with seed %d: compare payload.", seed)
}
if !isMessageSigned(decrypted.Raw[0]) {
diff --git a/whisper/whisperv5/peer.go b/whisper/whisperv5/peer.go
index 4273cfce1..634045504 100644
--- a/whisper/whisperv5/peer.go
+++ b/whisper/whisperv5/peer.go
@@ -148,7 +148,7 @@ func (peer *Peer) expire() {
return true
})
// Dump all known but unavailable
- for hash, _ := range unmark {
+ for hash := range unmark {
peer.known.Remove(hash)
}
}
diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go
index 88da59bff..34e2ec255 100644
--- a/whisper/whisperv5/peer_test.go
+++ b/whisper/whisperv5/peer_test.go
@@ -207,7 +207,7 @@ func checkPropagation(t *testing.T) {
func validateMail(t *testing.T, index int, mail []*ReceivedMessage) bool {
var cnt int
for _, m := range mail {
- if bytes.Compare(m.Payload, expectedMessage) == 0 {
+ if bytes.Equal(m.Payload, expectedMessage) {
cnt++
}
}
diff --git a/whisper/whisperv5/whisper.go b/whisper/whisperv5/whisper.go
index 789adbdb3..b514c022e 100644
--- a/whisper/whisperv5/whisper.go
+++ b/whisper/whisperv5/whisper.go
@@ -105,7 +105,7 @@ func (w *Whisper) Version() uint {
func (w *Whisper) getPeer(peerID []byte) (*Peer, error) {
w.peerMu.Lock()
defer w.peerMu.Unlock()
- for p, _ := range w.peers {
+ for p := range w.peers {
id := p.peer.ID()
if bytes.Equal(peerID, id[:]) {
return p, nil
diff --git a/whisper/whisperv5/whisper_test.go b/whisper/whisperv5/whisper_test.go
index 9af95f445..dbe0627fa 100644
--- a/whisper/whisperv5/whisper_test.go
+++ b/whisper/whisperv5/whisper_test.go
@@ -239,7 +239,7 @@ func TestWhisperSymKeyManagement(t *testing.T) {
if k1 == nil {
t.Fatalf("first key does not exist.")
}
- if bytes.Compare(k1, randomKey) == 0 {
+ if bytes.Equal(k1, randomKey) {
t.Fatalf("k1 == randomKey.")
}
if k2 != nil {
@@ -264,10 +264,10 @@ func TestWhisperSymKeyManagement(t *testing.T) {
if k2 == nil {
t.Fatalf("k2 does not exist.")
}
- if bytes.Compare(k1, k2) == 0 {
+ if bytes.Equal(k1, k2) {
t.Fatalf("k1 == k2.")
}
- if bytes.Compare(k1, randomKey) == 0 {
+ if bytes.Equal(k1, randomKey) {
t.Fatalf("k1 == randomKey.")
}
if len(k1) != aesKeyLength {