pub struct LanClient { /* private fields */ }connect-client only.Expand description
Asks a LAN endpoint what it is, before anyone has decided to pair with it.
Implementations§
Source§impl LanClient
impl LanClient
Sourcepub fn new(base_url: &str) -> Result<Self, Error>
pub fn new(base_url: &str) -> Result<Self, Error>
Point at an endpoint’s base URL — unversioned, as DNS-SD advertises it; the version is read from its index on the first request.
The certificate is self-signed and unverified, exactly as during pairing — and
nothing this client returns is authenticated. It is material for a user interface,
not a basis for a decision. See proto::lan.
Sourcepub async fn endpoint(&self) -> Result<EndpointDescription, Error>
pub async fn endpoint(&self) -> Result<EndpointDescription, Error>
GET /v1/endpoint — the endpoint’s own description.
Sourcepub async fn nodes(&self) -> Result<Vec<NodeDescription>, Error>
pub async fn nodes(&self) -> Result<Vec<NodeDescription>, Error>
GET /v1/nodes — every node this endpoint hosts.
Note that the schema returns bare NodeDescriptions, with no
NodeIdAlias — so a user interface can show
a list but cannot tell which entry a pairing code’s alias names
(erratum E21).
Sourcepub async fn prepare_pairing(&self, body: &PreparePairing) -> Result<(), Error>
pub async fn prepare_pairing(&self, body: &PreparePairing) -> Result<(), Error>
POST /v1/preparePairing — “the end user has started the process on the client”.
A hint that lets the server show the pairing code at the moment the user is looking for it. Best effort by design: “When a preparePairing is called, it is not guaranteed that a call to pairingRequest or cancelPreparePairing will follow.”
Sourcepub async fn cancel_prepare_pairing(
&self,
body: &CancelPreparePairing,
) -> Result<(), Error>
pub async fn cancel_prepare_pairing( &self, body: &CancelPreparePairing, ) -> Result<(), Error>
POST /v1/cancelPreparePairing — the user changed their mind.
Sourcepub async fn wait_for_pairing(
&self,
nodes: &[WaitForPairing],
) -> Result<Vec<WaitInstruction>, Error>
pub async fn wait_for_pairing( &self, nodes: &[WaitForPairing], ) -> Result<Vec<WaitInstruction>, Error>
POST /v1/waitForPairing — hold a request open until the endpoint has something
to say.
This is how a Resource Manager that is “purely an HTTPS client” — no listening
socket, nothing for a CEM to dial — takes part in a pairing at all: it asks the
other endpoint what to do, and the answer arrives whenever a person presses a
button there. The server holds the request for up to
LONG_POLL_HOLD and then answers 204,
read here as an empty list; that is not an error, it is “nothing yet, ask again”.
S2C §Long-polling: “the client can represent multiple nodes so the request body
and the response contains a list”, and the server “may only provide at most one
item for each clientNodeId”. Call it in a loop:
loop {
for instruction in client.wait_for_pairing(&mine).await? {
match instruction.action {
WaitAction::RequestPairing => { /* start `Pairing::run` now */ }
WaitAction::SendNodeDescription => { /* answer with descriptions */ }
_ => {}
}
}
}