@@ -43,9 +43,10 @@ type Filter struct {
43
43
44
44
// Filters represents a collection of filters
45
45
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
49
50
50
51
whisper * Whisper
51
52
mutex sync.RWMutex
@@ -106,7 +107,9 @@ func (fs *Filters) Uninstall(id string) bool {
106
107
return false
107
108
}
108
109
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.
110
113
func (fs * Filters ) addTopicMatcher (watcher * Filter ) {
111
114
if len (watcher .Topics ) == 0 {
112
115
fs .allTopicsMatcher [watcher ] = struct {}{}
@@ -133,10 +136,10 @@ func (fs *Filters) removeFromTopicMatchers(watcher *Filter) {
133
136
// match a specific topic
134
137
func (fs * Filters ) getWatchersByTopic (topic TopicType ) []* Filter {
135
138
res := make ([]* Filter , 0 , len (fs .allTopicsMatcher ))
136
- for watcher , _ := range fs .allTopicsMatcher {
139
+ for watcher := range fs .allTopicsMatcher {
137
140
res = append (res , watcher )
138
141
}
139
- for watcher , _ := range fs .topicMatcher [topic ] {
142
+ for watcher := range fs .topicMatcher [topic ] {
140
143
res = append (res , watcher )
141
144
}
142
145
return res
0 commit comments