Skip to content

Commit 3b3f6b7

Browse files
authored
Merge pull request #23 from arduino/scerza/filter-entries
Discovered entries not supporting Arduino OTA are now filtered
2 parents c809249 + 3559dc6 commit 3b3f6b7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disco
117117
go func() {
118118
for entry := range d.entriesChan {
119119
port := toDiscoveryPort(entry)
120+
if port == nil {
121+
continue
122+
}
120123
if updated := d.portsCache.storeOrUpdate(port); !updated {
121124
// Port is not cached so let the user know a new one has been found
122125
eventCB("add", port)
@@ -189,6 +192,12 @@ func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disco
189192
}
190193

191194
func toDiscoveryPort(entry *mdns.ServiceEntry) *discovery.Port {
195+
// Only entries that match the Arduino OTA service name must
196+
// be returned
197+
if !strings.HasSuffix(entry.Name, mdnsServiceName+".local.") {
198+
return nil
199+
}
200+
192201
ip := ""
193202
if len(entry.AddrV4) > 0 {
194203
ip = entry.AddrV4.String()

0 commit comments

Comments
 (0)