1.8 KiB
tractor/discovery/_api.py
git diff befedc49~1..befedc49 -- tractor/discovery/_api.py
Add _is_local_addr() and prefer_addr() transport preference helpers.
_is_local_addr(addr: Address) -> bool
Determines whether an Address is reachable on the local host:
UDSAddress: always returnsTrue(filesystem-bound, inherently local)TCPAddress: checks if._hostis a loopback IP viaipaddress.ip_address().is_loopback, then falls back to comparing against the machine’s own interface IPs viasocket.getaddrinfo(socket.gethostname(), None)
prefer_addr(addrs: list[UnwrappedAddress]) -> UnwrappedAddress
Selects the “best” transport address from a multihomed actor’s address list. Wraps each candidate via wrap_address() to get typed Address objects, then classifies into three tiers:
- UDS (same-host guaranteed, lowest overhead)
- TCP loopback / same-host IP (local network)
- TCP remote (only option for distributed)
Within each tier, the last-registered (latest) entry is preferred. Falls back to addrs[-1] if no heuristic matches.
tractor/discovery/_registry.py
git diff befedc49~1..befedc49 -- tractor/discovery/_registry.py
Registrar.find_actor() return type broadened from single addr to list[UnwrappedAddress]|None — full addr list lets callers apply transport preference.
Integration
query_actor() and wait_for_actor() now call prefer_addr(addrs) instead of addrs[-1].
Verification
All discovery tests pass (13/13 non-daemon). test_local.py and test_multi_program.py also pass (daemon fixture teardown failures are pre-existing and unrelated).