From 1c8e5a998ac851b29cd43cf7f5ab568911ccffae Mon Sep 17 00:00:00 2001 From: Barnaby Gray Date: Thu, 31 Mar 2016 10:34:06 +0100 Subject: [PATCH] Remove found devices check in discovery - better done by caller. --- discovery/service.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/discovery/service.go b/discovery/service.go index 64a8908..dca86b4 100644 --- a/discovery/service.go +++ b/discovery/service.go @@ -18,15 +18,13 @@ type Service struct { found chan *cast.Client entriesCh chan *mdns.ServiceEntry - foundDevices map[string]bool stopPeriodic chan struct{} } func NewService(ctx context.Context) *Service { s := &Service{ - found: make(chan *cast.Client), - entriesCh: make(chan *mdns.ServiceEntry, 10), - foundDevices: make(map[string]bool), + found: make(chan *cast.Client), + entriesCh: make(chan *mdns.ServiceEntry, 10), } go s.listener(ctx) @@ -52,7 +50,6 @@ func (d *Service) Run(ctx context.Context, interval time.Duration) error { Entries: d.entriesCh, }) case <-ctx.Done(): - d.foundDevices = make(map[string]bool) return ctx.Err() } } @@ -80,21 +77,12 @@ func (d *Service) listener(ctx context.Context) { } log.Printf("New entry: %#v\n", entry) - key := entry.AddrV4.String() + ":" + strconv.Itoa(entry.Port) - - // Skip already found devices - if _, ok := d.foundDevices[key]; ok { - continue - } - client := cast.NewClient(entry.AddrV4, entry.Port) client.SetName(decodeDnsEntry(name[0])) info := decodeTxtRecord(entry.Info) client.SetUuid(info["id"]) - d.foundDevices[key] = true - select { case d.found <- client: case <-time.After(time.Second):