fix: advertise LAN IP instead of mDNS hostname when --host 0.0.0.0
socket.getfqdn() returns *.localdomain names that other machines on the same LAN (especially cross-OS) cannot resolve via DNS. When the node is bound to 0.0.0.0 and --advertise-host is not given, probe the outbound IP by connecting a UDP socket toward the tracker — this picks the correct interface IP without sending any data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -128,6 +128,19 @@ def run_startup(
|
||||
tracker_url = tracker_url.rstrip("/")
|
||||
|
||||
# 1. Hardware detection
|
||||
if advertise_host is None and host == "0.0.0.0":
|
||||
# socket.getfqdn() returns an mDNS name (.local / .localdomain) that remote
|
||||
# machines on a different OS or subnet often can't resolve. Instead, probe the
|
||||
# outbound IP by opening a UDP socket toward the tracker — no data is sent.
|
||||
try:
|
||||
_tracker_host = urllib.parse.urlparse(tracker_url).hostname or "8.8.8.8"
|
||||
_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
_s.connect((_tracker_host, 80))
|
||||
advertise_host = _s.getsockname()[0]
|
||||
_s.close()
|
||||
except Exception:
|
||||
advertise_host = socket.getfqdn()
|
||||
|
||||
print("Detecting hardware...", flush=True)
|
||||
hw = detect_hardware()
|
||||
device: str = hw["device"]
|
||||
|
||||
Reference in New Issue
Block a user