UPnP/SSDP: respond with multiple service descriptors

Instead of violating the standard and putting multiple locations in one
SSDP response, just send a single response for each possible location.
This commit is contained in:
Sybren A. Stüvel 2022-03-08 16:46:03 +01:00
parent a19aa86c4e
commit ca2bf7ff25
3 changed files with 8 additions and 20 deletions

View File

@ -23,7 +23,6 @@ package upnp_ssdp
import (
"context"
"fmt"
"strings"
"sync"
"time"
@ -104,26 +103,21 @@ func (c *Client) Response(message gossdp.ResponseMessage) {
}
logger.Debug().Msg("UPnP/SSDP message received")
c.appendURLs(message.Location)
c.appendURL(message.Location)
}
func (c *Client) appendURLs(location string) {
urls := strings.Split(location, LocationSeparator)
func (c *Client) appendURL(url string) {
c.mutex.Lock()
defer c.mutex.Unlock()
// Only append URLs that we haven't seen yet.
for _, url := range urls {
if c.seenURLs[url] {
continue
}
c.urls = append(c.urls, url)
c.seenURLs[url] = true
if c.seenURLs[url] {
return
}
c.urls = append(c.urls, url)
c.seenURLs[url] = true
c.log.Debug().
Int("new", len(urls)).
Int("total", len(c.urls)).
Msg("new URLs received")
}

View File

@ -23,7 +23,6 @@ package upnp_ssdp
import (
"context"
"net/url"
"strings"
"github.com/fromkeith/gossdp"
"github.com/rs/zerolog"
@ -62,12 +61,9 @@ func (s *Server) AddAdvertisement(serviceLocation string) {
// AddAdvertisementURLs constructs a service location from the given URLs, and
// adds the advertisement for it.
func (s *Server) AddAdvertisementURLs(urls []url.URL) {
urlStrings := make([]string, len(urls))
for idx := range urls {
urlStrings[idx] = urls[idx].String()
for _, url := range urls {
s.AddAdvertisement(url.String())
}
location := strings.Join(urlStrings, LocationSeparator)
s.AddAdvertisement(location)
}
// Run starts the advertisement, and blocks until the context is closed.

View File

@ -24,6 +24,4 @@ package upnp_ssdp
const (
FlamencoUUID = "aa80bc5f-d0af-46b8-8630-23bd7e80ec4d"
FlamencoServiceType = "urn:flamenco:manager:0"
LocationSeparator = ";"
)