@@ -43,9 +43,10 @@ type Filter struct {
4343
4444// Filters represents a collection of filters
4545type 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.
110113func (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
134137func (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
0 commit comments