Skip to main content

PairingService

Struct PairingService 

Source
pub struct PairingService { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

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.

Source

pub fn store(&self) -> &Arc<dyn Store> ⓘ

The store, for a route that needs it.

Source

pub fn endpoint(&self) -> &EndpointDescription

The endpoint’s own description.

Source

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.

Source

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.

Source

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.

Source

pub async fn finalize( &self, node: NodeId, bearer: &str, success: bool, now: Timestamp, ) -> Result<Finalized, ConnectError>

POST /v1/finalizePairing.

Trait Implementations§

Source§

impl Debug for PairingService

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more