transport
transport
¶
Getting a signed command to the device it names — LAN first.
Ordering follows spec §12: the closest usable path wins, because latency and privacy improve together. Today that means loopback and the local network; the relay transport slots in later behind the same interface without any caller changing.
This module also owns the one privacy exemption the mesh is allowed
(documented in core/local_mode): a TRUSTED, paired device at a PRIVATE
address is the user's own other computer, not "elsewhere". Anything failing
either half of that — unknown device, revoked device, public address — is
refused exactly as before.
Classes¶
TransportError
¶
Bases: RuntimeError
Delivery failed. The command is not lost — the queue still holds it.
RemoteRefusal
¶
Bases: TransportError
The device ANSWERED, and it said no. This is not a network fault.
26 August 2026. Both cases lived under one name, so the caller — which
could not tell them apart — said "could not be reached" for both. A
desktop.open refused by the Windows PC therefore sent its owner to
check a Wi-Fi that was working perfectly, while the PC's own sentence,
the ONLY one that explained the refusal, was captured into str(exc)
and then dropped without even reaching the log.
retryable separates "it refused" from "it cannot right now": a 4xx is
a verdict, a 429 or a 5xx is a hiccup. Confusing them costs in both
directions — retrying a verdict forever, or giving up on a server that
was merely restarting.
Source code in src/diapason/mesh/transport.py
Functions:¶
address_is_private
¶
True for loopback and RFC1918 — the network the user is standing on.
A hostname we cannot resolve to a private literal is treated as public: a destination we cannot vouch for is not one we quietly trust.
Source code in src/diapason/mesh/transport.py
assert_may_reach_device
¶
The mesh's narrow exemption to local-only. Both halves are required.
Refusing here rather than at the socket keeps the reason legible: the user learns whether the problem is trust or reachability, not a bare connection error.
Source code in src/diapason/mesh/transport.py
deliver
¶
deliver(
command: RemoteCommand,
device: Mapping[str, Any],
*,
timeout_s: float = DELIVER_TIMEOUT_S,
post=None,
) -> dict[str, Any]
Push a signed command to device and return its result envelope.
post is injectable so the whole path can be tested without a socket;
production passes nothing and gets httpx.