Fix #41 - collisions with same USN as multiple locations.
This commit is contained in:
parent
16e24d5762
commit
33cdcbb30d
@ -51,7 +51,8 @@ func (err ContextError) Error() string {
|
||||
|
||||
// MaybeRootDevice contains either a RootDevice or an error.
|
||||
type MaybeRootDevice struct {
|
||||
// Identifier of the device.
|
||||
// Identifier of the device. Note that this in combination with Location
|
||||
// uniquely identifies a result from DiscoverDevices.
|
||||
USN string
|
||||
|
||||
// Set iff Err == nil.
|
||||
|
19
ssdp/ssdp.go
19
ssdp/ssdp.go
@ -72,7 +72,7 @@ func SSDPRawSearch(
|
||||
|
||||
isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice
|
||||
|
||||
seenUSNs := make(map[string]bool)
|
||||
seenIDs := make(map[string]bool)
|
||||
var responses []*http.Response
|
||||
for _, response := range allResponses {
|
||||
if response.StatusCode != 200 {
|
||||
@ -83,17 +83,14 @@ func SSDPRawSearch(
|
||||
continue
|
||||
}
|
||||
usn := response.Header.Get("USN")
|
||||
if usn == "" {
|
||||
// Empty/missing USN in search response - using location instead.
|
||||
location, err := response.Location()
|
||||
if err != nil {
|
||||
// No usable location in search response - discard.
|
||||
continue
|
||||
}
|
||||
usn = location.String()
|
||||
loc, err := response.Location()
|
||||
if err != nil {
|
||||
// No usable location in search response - discard.
|
||||
continue
|
||||
}
|
||||
if _, alreadySeen := seenUSNs[usn]; !alreadySeen {
|
||||
seenUSNs[usn] = true
|
||||
id := loc.String() + "\x00" + usn
|
||||
if _, alreadySeen := seenIDs[id]; !alreadySeen {
|
||||
seenIDs[id] = true
|
||||
responses = append(responses, response)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user