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:
@@ -38,6 +38,18 @@ def server_address(config):
|
||||
return f"{config.get('bind_address') or '127.0.0.1'}:{config['server_port']}"
|
||||
|
||||
|
||||
def mdns_args(config):
|
||||
"""The LAN port the server advertises over mDNS.
|
||||
|
||||
LAN clients dial the authenticated web proxy, not the loopback server, so
|
||||
the proxy's port is advertised when the proxy listens beyond loopback.
|
||||
"""
|
||||
web = config.get("web") or {}
|
||||
if web.get("port") and web.get("host") not in (None, "", "127.0.0.1", "localhost", "::1"):
|
||||
return ["-mdns-port", str(web["port"])]
|
||||
return []
|
||||
|
||||
|
||||
def load(prefix):
|
||||
prefix = Path(prefix).expanduser().resolve()
|
||||
path = prefix / MARKER
|
||||
@@ -408,6 +420,7 @@ def supervise(config):
|
||||
server_address(config), "-db", str(root / "data/pipelines.db")]
|
||||
if config.get("allow_authoring") is True:
|
||||
server_command.append("-allow-authoring")
|
||||
server_command += mdns_args(config)
|
||||
with (root / "logs/server.log").open("a") as log:
|
||||
child = subprocess.Popen(server_command, cwd=config["workspace"], env=env, stdout=log, stderr=log)
|
||||
if config.get("web"):
|
||||
|
||||
@@ -144,6 +144,15 @@ class ManageNativeTests(unittest.TestCase):
|
||||
"-db", str(root / "data/pipelines.db")])
|
||||
self.assertEqual("-allow-authoring" in command, role is True)
|
||||
|
||||
def test_mdns_advertises_the_lan_web_proxy_port(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
config = self.config(Path(directory))
|
||||
self.assertEqual(manage.mdns_args(config), [])
|
||||
config["web"]["host"] = "0.0.0.0"
|
||||
self.assertEqual(manage.mdns_args(config), ["-mdns-port", "8082"])
|
||||
config.pop("web")
|
||||
self.assertEqual(manage.mdns_args(config), [])
|
||||
|
||||
def config(self, root, mode="native"):
|
||||
(root / "lib/app-web").mkdir(parents=True, exist_ok=True)
|
||||
(root / "lib/app-web/index.html").write_text("app")
|
||||
|
||||
Reference in New Issue
Block a user