Files
pipelines/cmd/pipelines-server/mdns.go
T
alan 929e4cc017 Advertise tailnet and public routes in server discovery
The mDNS record now carries ts= (tailnet IPv4 addresses) and public= (the
installer's HTTPS origin from PIPELINES_WEB_PUBLIC_URL) in TXT, and browse,
the discover_servers RPC and /discovery return every route to a machine as
addresses with kinds lan, tailscale and public. Endpoint stays the LAN route
for older clients. Unsafe ts/public values are dropped.
2026-11-08 23:59:19 +00:00

54 lines
1.7 KiB
Go

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()
// The installer exports the TLS front's origin (tailscale serve) for the
// same proxy; it is advertised so clients can choose that route by name.
advert, err := discovery.Plan(discovery.Config{ListenAddr: addr, ProxyPort: proxyPort,
Version: buildinfo.Current().Version, Hostname: hostname, IPs: discovery.LANAddresses(),
TailscaleIPs: discovery.TailscaleAddresses(), PublicURL: os.Getenv("PIPELINES_WEB_PUBLIC_URL")})
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
}