lib/upnp: Correct the result deduplication mechanism (fixes #3578)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3618
This commit is contained in:
Jakob Borg 2016-09-24 07:33:56 +00:00 committed by Audrius Butkevicius
parent 6d3160b0ab
commit 3cabecda04

View File

@ -108,19 +108,21 @@ func Discover(renewal, timeout time.Duration) []nat.Device {
close(resultChan)
}()
seenResults := make(map[string]bool)
nextResult:
for result := range resultChan {
for _, existingResult := range results {
if existingResult.ID() == result.ID() {
if seenResults[result.ID()] {
l.Debugf("Skipping duplicate result %s with services:", result.uuid)
for _, service := range result.services {
l.Debugf("* [%s] %s", service.ID, service.URL)
}
continue nextResult
}
}
result := result // Reallocate as we need to keep a pointer
results = append(results, &result)
seenResults[result.ID()] = true
l.Debugf("UPnP discovery result %s with services:", result.uuid)
for _, service := range result.services {
l.Debugf("* [%s] %s", service.ID, service.URL)