Skip to content

Commit

Permalink
Remove found devices check in discovery - better done by caller.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnybug committed Mar 31, 2016
1 parent 7adb11d commit 1c8e5a9
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions discovery/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1c8e5a9

Please # to comment.