LAN discovery: server advertises _pipelines._tcp over mDNS; app finds servers on the connect screen
Server: internal/discovery publishes a DNS-SD record (hashicorp/mdns) with the port LAN clients dial (the web proxy via -mdns-port, which the supervisor passes, or a non-loopback -addr) and TXT v, name, path, tls, auth. On by default; -mdns=false or PIPELINES_MDNS=off disables it. Failures are logged and never block startup; the advert is withdrawn on shutdown. App: the Connect to Pipelines screen gets 'Find servers on this network' behind a ServerDiscovery interface (Bonsoir: Android NSD with multicast lock, iOS Bonjour with NSLocalNetworkUsageDescription and NSBonjourServices). Tapping a server fills the address and connects; manual entry stays. Web has no scan.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/buildinfo"
|
||||
"git.a-wan.net/alan/pipelines/internal/discovery"
|
||||
)
|
||||
|
||||
// advertise publishes the server on the LAN. Any failure is logged and the
|
||||
// server carries on: discovery is a convenience, never a startup requirement.
|
||||
// The returned stop (nil when nothing was published) withdraws the advert.
|
||||
func advertise(addr string, proxyPort int) func() {
|
||||
hostname, _ := os.Hostname()
|
||||
advert, err := discovery.Plan(discovery.Config{ListenAddr: addr, ProxyPort: proxyPort,
|
||||
Version: buildinfo.Current().Version, Hostname: hostname, IPs: discovery.LANAddresses()})
|
||||
if err != nil {
|
||||
log.Printf("mDNS: not advertising: %v", err)
|
||||
return nil
|
||||
}
|
||||
stop, err := discovery.Start(advert, log.Default())
|
||||
if err != nil {
|
||||
log.Printf("mDNS: advertising failed: %v", err)
|
||||
return nil
|
||||
}
|
||||
log.Printf("mDNS: advertising %s.%s on port %d (%s)", advert.Instance, discovery.ServiceType, advert.Port, strings.Join(advert.TXT, " "))
|
||||
return stop
|
||||
}
|
||||
|
||||
// envEnabled reads PIPELINES_MDNS: unset or anything but an explicit off value
|
||||
// leaves advertising on.
|
||||
func envEnabled(value string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "0", "false", "off", "no", "disabled":
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// envPort reads PIPELINES_MDNS_PORT; anything unusable means "not set".
|
||||
func envPort(value string) int {
|
||||
port, err := strconv.Atoi(strings.TrimSpace(value))
|
||||
if err != nil || port < 0 || port > 65535 {
|
||||
return 0
|
||||
}
|
||||
return port
|
||||
}
|
||||
Reference in New Issue
Block a user