Skip to content

Commit d24d10a

Browse files
committed
whisper: style fixes
1 parent c733792 commit d24d10a

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

whisper/whisperv6/filter.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ type Filter struct {
4343

4444
// Filters represents a collection of filters
4545
type Filters struct {
46-
watchers map[string]*Filter
47-
topicMatcher map[TopicType]map[*Filter]struct{}
48-
allTopicsMatcher map[*Filter]struct{}
46+
watchers map[string]*Filter
47+
48+
topicMatcher map[TopicType]map[*Filter]struct{} // map a topic to the filters that are interested in being notified when a message matches that topic
49+
allTopicsMatcher map[*Filter]struct{} // list all the filters that will be notified of a new message, no matter what its topic is
4950

5051
whisper *Whisper
5152
mutex sync.RWMutex
@@ -106,7 +107,9 @@ func (fs *Filters) Uninstall(id string) bool {
106107
return false
107108
}
108109

109-
// addTopicMatcher adds a filter to the topic matchers
110+
// addTopicMatcher adds a filter to the topic matchers.
111+
// If the filter's Topics array is empty, it will be tried on every topic.
112+
// Otherwise, it will be tried on the topics specified.
110113
func (fs *Filters) addTopicMatcher(watcher *Filter) {
111114
if len(watcher.Topics) == 0 {
112115
fs.allTopicsMatcher[watcher] = struct{}{}
@@ -133,10 +136,10 @@ func (fs *Filters) removeFromTopicMatchers(watcher *Filter) {
133136
// match a specific topic
134137
func (fs *Filters) getWatchersByTopic(topic TopicType) []*Filter {
135138
res := make([]*Filter, 0, len(fs.allTopicsMatcher))
136-
for watcher, _ := range fs.allTopicsMatcher {
139+
for watcher := range fs.allTopicsMatcher {
137140
res = append(res, watcher)
138141
}
139-
for watcher, _ := range fs.topicMatcher[topic] {
142+
for watcher := range fs.topicMatcher[topic] {
140143
res = append(res, watcher)
141144
}
142145
return res

whisper/whisperv6/filter_test.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,6 @@ func TestMatchEnvelope(t *testing.T) {
313313
if err != nil {
314314
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
315315
}
316-
match := fsym.MatchEnvelope(env)
317-
if !match {
318-
// topic mismatch should have no affect, as topics are handled by topic matchers
319-
t.Fatalf("failed MatchEnvelope symmetric with seed %d.", seed)
320-
}
321-
match = fasym.MatchEnvelope(env)
322-
if !match {
323-
// topic mismatch should have no affect, as topics are handled by topic matchers
324-
t.Fatalf("failed MatchEnvelope asymmetric with seed %d.", seed)
325-
}
326316

327317
// encrypt symmetrically
328318
i := mrand.Int() % 4
@@ -338,7 +328,7 @@ func TestMatchEnvelope(t *testing.T) {
338328
}
339329

340330
// symmetric + matching topic: match
341-
match = fsym.MatchEnvelope(env)
331+
match := fsym.MatchEnvelope(env)
342332
if !match {
343333
t.Fatalf("failed MatchEnvelope() symmetric with seed %d.", seed)
344334
}

0 commit comments

Comments
 (0)