UPnP/SSDP Server: allow advertising slice of URLs
This makes it possible for the Manager to expose multiple URLs. This way the Worker can try them out and see which ones work.
This commit is contained in:
parent
13a74e61d4
commit
d6a60c73d0
@ -31,6 +31,7 @@ import (
|
||||
"git.blender.org/flamenco/internal/manager/swagger_ui"
|
||||
"git.blender.org/flamenco/internal/manager/task_logs"
|
||||
"git.blender.org/flamenco/internal/manager/task_state_machine"
|
||||
"git.blender.org/flamenco/internal/own_url"
|
||||
"git.blender.org/flamenco/internal/upnp_ssdp"
|
||||
"git.blender.org/flamenco/pkg/api"
|
||||
)
|
||||
@ -67,12 +68,7 @@ func main() {
|
||||
_, port, _ := net.SplitHostPort(listen)
|
||||
log.Info().Str("port", port).Msg("listening")
|
||||
|
||||
ssdp, err := upnp_ssdp.NewServer(log.Logger)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error creating UPnP/SSDP server")
|
||||
} else {
|
||||
ssdp.AddAdvertisement(listen) // TODO: convert this to an entire URL.
|
||||
}
|
||||
ssdp := makeAutoDiscoverable("http", listen)
|
||||
|
||||
// Construct the services.
|
||||
persist := openDB(*configService)
|
||||
@ -271,3 +267,20 @@ func installSignalHandler(cancelFunc context.CancelFunc) {
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func makeAutoDiscoverable(scheme, listen string) *upnp_ssdp.Server {
|
||||
urls, err := own_url.AvailableURLs("http", listen)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("unable to figure out my own URL")
|
||||
return nil
|
||||
}
|
||||
|
||||
ssdp, err := upnp_ssdp.NewServer(log.Logger)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("error creating UPnP/SSDP server")
|
||||
return nil
|
||||
}
|
||||
|
||||
ssdp.AddAdvertisementURLs(urls)
|
||||
return ssdp
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ package upnp_ssdp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/fromkeith/gossdp"
|
||||
"github.com/rs/zerolog"
|
||||
@ -54,6 +56,18 @@ func (s *Server) AddAdvertisement(serviceLocation string) {
|
||||
MaxAge: 3600, // Number of seconds this advertisement is valid for.
|
||||
}
|
||||
s.ssdp.AdvertiseServer(serverDef)
|
||||
s.log.Info().Str("location", serviceLocation).Msg("UPnP/SSDP location registered")
|
||||
}
|
||||
|
||||
// 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()
|
||||
}
|
||||
location := strings.Join(urlStrings, LocationSeparator)
|
||||
s.AddAdvertisement(location)
|
||||
}
|
||||
|
||||
// Run starts the advertisement, and blocks until the context is closed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user