From ca2bf7ff25a2e069cafe4fa66bd804f0c24f08f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 8 Mar 2022 16:46:03 +0100 Subject: [PATCH] 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. --- internal/upnp_ssdp/client.go | 18 ++++++------------ internal/upnp_ssdp/server.go | 8 ++------ internal/upnp_ssdp/upnp_ssdp.go | 2 -- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/internal/upnp_ssdp/client.go b/internal/upnp_ssdp/client.go index 8ee53623..9647655a 100644 --- a/internal/upnp_ssdp/client.go +++ b/internal/upnp_ssdp/client.go @@ -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") } diff --git a/internal/upnp_ssdp/server.go b/internal/upnp_ssdp/server.go index 8d6202f0..7d2fc5d5 100644 --- a/internal/upnp_ssdp/server.go +++ b/internal/upnp_ssdp/server.go @@ -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. diff --git a/internal/upnp_ssdp/upnp_ssdp.go b/internal/upnp_ssdp/upnp_ssdp.go index 5fee0047..210afcd6 100644 --- a/internal/upnp_ssdp/upnp_ssdp.go +++ b/internal/upnp_ssdp/upnp_ssdp.go @@ -24,6 +24,4 @@ package upnp_ssdp const ( FlamencoUUID = "aa80bc5f-d0af-46b8-8630-23bd7e80ec4d" FlamencoServiceType = "urn:flamenco:manager:0" - - LocationSeparator = ";" )