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.
|
// MaybeRootDevice contains either a RootDevice or an error.
|
||||||
type MaybeRootDevice struct {
|
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
|
USN string
|
||||||
|
|
||||||
// Set iff Err == nil.
|
// Set iff Err == nil.
|
||||||
|
19
ssdp/ssdp.go
19
ssdp/ssdp.go
@ -72,7 +72,7 @@ func SSDPRawSearch(
|
|||||||
|
|
||||||
isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice
|
isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice
|
||||||
|
|
||||||
seenUSNs := make(map[string]bool)
|
seenIDs := make(map[string]bool)
|
||||||
var responses []*http.Response
|
var responses []*http.Response
|
||||||
for _, response := range allResponses {
|
for _, response := range allResponses {
|
||||||
if response.StatusCode != 200 {
|
if response.StatusCode != 200 {
|
||||||
@ -83,17 +83,14 @@ func SSDPRawSearch(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
usn := response.Header.Get("USN")
|
usn := response.Header.Get("USN")
|
||||||
if usn == "" {
|
loc, err := response.Location()
|
||||||
// Empty/missing USN in search response - using location instead.
|
if err != nil {
|
||||||
location, err := response.Location()
|
// No usable location in search response - discard.
|
||||||
if err != nil {
|
continue
|
||||||
// No usable location in search response - discard.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
usn = location.String()
|
|
||||||
}
|
}
|
||||||
if _, alreadySeen := seenUSNs[usn]; !alreadySeen {
|
id := loc.String() + "\x00" + usn
|
||||||
seenUSNs[usn] = true
|
if _, alreadySeen := seenIDs[id]; !alreadySeen {
|
||||||
|
seenIDs[id] = true
|
||||||
responses = append(responses, response)
|
responses = append(responses, response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user