f
This commit is contained in:
@@ -505,7 +505,7 @@ def discover_services_on_network(
|
||||
raise ValueError("network_id required")
|
||||
|
||||
ports = list(ports or [999])
|
||||
paths = list(paths or ["/health", "/api_version", "/api_version/", "/session_key"])
|
||||
paths = list(paths or ["/health", "/api_version"])
|
||||
|
||||
addresses = get_assigned_addresses(net)
|
||||
|
||||
@@ -515,8 +515,9 @@ def discover_services_on_network(
|
||||
# Look for online members with IP assignments
|
||||
if m.get("online") and m.get("config", {}).get("ipAssignments"):
|
||||
for ip in m["config"]["ipAssignments"]:
|
||||
if ip not in addresses:
|
||||
addresses.append(ip)
|
||||
addr = str(ip).split("/")[0]
|
||||
if addr not in addresses:
|
||||
addresses.append(addr)
|
||||
|
||||
probes: List[ZeroTierServiceProbe] = []
|
||||
|
||||
@@ -524,38 +525,41 @@ def discover_services_on_network(
|
||||
host = str(addr or "").strip()
|
||||
if not host:
|
||||
continue
|
||||
# Try both http and https schemes
|
||||
for port in ports:
|
||||
for path in paths:
|
||||
for scheme in ("http", "https"):
|
||||
url = f"{scheme}://{host}:{port}{path}"
|
||||
ok, code, payload = _probe_url(url, timeout=timeout, accept_json=accept_json)
|
||||
if ok:
|
||||
hint = None
|
||||
# Heuristics: hydrus exposes /api_version with a JSON payload
|
||||
try:
|
||||
if isinstance(payload, dict) and payload.get("api_version"):
|
||||
hint = "hydrus"
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if isinstance(payload, dict) and payload.get("status"):
|
||||
hint = hint or "remote_storage"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Performance optimization: if we have many addresses, skip those clearly not on our ZT subnet
|
||||
# (Though fetch_central_members already filters for this network)
|
||||
|
||||
probes.append(ZeroTierServiceProbe(
|
||||
address=host,
|
||||
port=int(port),
|
||||
path=path,
|
||||
url=url,
|
||||
ok=True,
|
||||
status_code=code,
|
||||
payload=payload,
|
||||
service_hint=hint,
|
||||
))
|
||||
# stop probing other schemes for this host/port/path
|
||||
break
|
||||
for port in ports:
|
||||
# Try HTTP first as it's the common case for local storage
|
||||
for scheme in ("http", "https"):
|
||||
# Fast probe of just the first path
|
||||
path = paths[0]
|
||||
url = f"{scheme}://{host}:{port}{path}"
|
||||
ok, code, payload = _probe_url(url, timeout=timeout, accept_json=accept_json)
|
||||
if ok:
|
||||
hint = None
|
||||
try:
|
||||
# remote_storage_server returns {"status": "ok", ...}
|
||||
if isinstance(payload, dict) and payload.get("status"):
|
||||
hint = "remote_storage"
|
||||
# hydrus returns {"api_version": ...}
|
||||
if isinstance(payload, dict) and payload.get("api_version"):
|
||||
hint = "hydrus"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
probes.append(ZeroTierServiceProbe(
|
||||
address=host,
|
||||
port=int(port),
|
||||
path=path,
|
||||
url=url,
|
||||
ok=True,
|
||||
status_code=code,
|
||||
payload=payload,
|
||||
service_hint=hint,
|
||||
))
|
||||
# Stop probing other schemes/paths for this host/port
|
||||
break
|
||||
return probes
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user