pub struct PairingService { /* private fields */ }connect-server only.Expand description
Runs the pairing half of an endpoint.
One PairingServer per node, because the rate limit is per node: “Pairing attempts
targeting different nodes may be processed in parallel… a server representing
multiple nodes is not globally limited to one pairing attempt per second.”
Serialisation is a per-node lock rather than a check-and-set, so two requests that arrive in the same millisecond cannot both see an idle slot.
Implementations§
Source§impl PairingService
impl PairingService
Sourcepub fn lan(
store: Arc<dyn Store>,
endpoint: EndpointDescription,
leaf: Fingerprint,
) -> Self
pub fn lan( store: Arc<dyn Store>, endpoint: EndpointDescription, leaf: Fingerprint, ) -> Self
A service for a LAN endpoint, bound to the leaf certificate it serves.
The endpoint description’s deployment is set to LAN when it says nothing: which
side becomes the communication server is decided from it, and a peer reading an
absent deployment cannot know.
Sourcepub fn wan(
store: Arc<dyn Store>,
endpoint: EndpointDescription,
domain: impl Into<String>,
) -> Self
pub fn wan( store: Arc<dyn Store>, endpoint: EndpointDescription, domain: impl Into<String>, ) -> Self
A service for a WAN endpoint, bound to its domain name.
The endpoint description’s deployment is set to WAN when it says nothing.
Sourcepub fn as_communication_server(self, communication: CommunicationServer) -> Self
pub fn as_communication_server(self, communication: CommunicationServer) -> Self
Be the communication server for clients that pair with this endpoint (7A).
Without this, a client that should be the communication client is refused with
IncompatibleCommunicationProtocols.
Sourcepub fn endpoint(&self) -> &EndpointDescription
pub fn endpoint(&self) -> &EndpointDescription
The endpoint’s own description.
Sourcepub fn request_pairing(
&self,
request: &PairingRequest,
server_nonce: &[u8],
attempt_id: PairingAttemptId,
now: Timestamp,
) -> Result<(NodeId, Timestamp, PairingAccepted), ConnectError>
pub fn request_pairing( &self, request: &PairingRequest, server_nonce: &[u8], attempt_id: PairingAttemptId, now: Timestamp, ) -> Result<(NodeId, Timestamp, PairingAccepted), ConnectError>
POST /v1/requestPairing.
Returns the body to send and the instant before which it must not be sent — the caller sleeps until then, because the delay is the specification’s brute-force mitigation and a server that computes it and answers anyway has implemented a comment.
“One attempt per second per node” is enforced by the state machine rather than by
holding a lock across the wait: PairingServer remembers the attempt in flight
and when the last one finished, so a second request is
ConnectError::RateLimited whether or not the first has finished sleeping. The
try_lock here is only about two requests reaching the same machine in the same
instant.
Sourcepub async fn request_connection_details(
&self,
node: NodeId,
bearer: &str,
response: &str,
now: Timestamp,
) -> Result<ConnectionDetails, ConnectError>
pub async fn request_connection_details( &self, node: NodeId, bearer: &str, response: &str, now: Timestamp, ) -> Result<ConnectionDetails, ConnectError>
POST /v1/requestConnectionDetails (6A) — this endpoint is the communication
server.
Sourcepub async fn post_connection_details(
&self,
node: NodeId,
bearer: &str,
response: &str,
details: ConnectionDetails,
now: Timestamp,
) -> Result<(), ConnectError>
pub async fn post_connection_details( &self, node: NodeId, bearer: &str, response: &str, details: ConnectionDetails, now: Timestamp, ) -> Result<(), ConnectError>
POST /v1/postConnectionDetails (6B) — the client is the communication server.