Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Builds a Client with a chosen transaction timeout, retransmission schedule and handler.

Implementations§

Source§

impl ClientBuilder

Source

pub fn with_rto(self, rto: Duration) -> Self

Sets the initial RTO (RFC 8489 section 6.2.1; 500 ms by default, and the RFC asks for no less unless something else bounds the rate, as ICE’s pacing does).

It is the RTO of the first transaction and the floor of every later one: the RTO then follows the server’s round-trip time upwards (see with_rto_estimation).

Source

pub fn with_rc(self, rc: u32) -> Self

Sets Rc, how many times a request is sent before the transaction fails (RFC 8489 section 6.2.1; 7 by default). Values below 1 are 1.

Source

pub fn with_rm(self, rm: u32) -> Self

Sets Rm: the transaction fails Rm x RTO after the last request (RFC 8489 section 6.2.1; 16 by default).

Source

pub fn with_ti(self, ti: Duration) -> Self

Sets Ti, how long a request waits for its response over a reliable transport, where it is never retransmitted (RFC 8489 section 6.2.2; 39.5 s by default).

Source

pub fn with_rto_estimation(self, on: bool) -> Self

Turns the RFC 6298 computation of the RTO on or off (on by default).

On: a request answered without a retransmission gives a round-trip sample, and the RTO of the next transaction is SRTT + 4 x RTTVAR, to 1 ms, never below the initial RTO. It is kept for the server and dropped after ten minutes without a transaction. Off: every transaction starts at the initial RTO.

Source

pub fn with_max_outstanding_transactions(self, max: usize) -> Self

Sets how many transactions may be outstanding at once (RFC 8489 section 6.2; 10 by default). A request past the limit is refused by handle_write. 0 lifts the limit, for a caller that limits its rate some other way.

Source

pub fn with_path_mtu(self, mtu: usize) -> Self

Sets the path MTU to the server, when the caller knows it: a message over UDP then has to fit an IP packet of that size (RFC 8489 section 6.1).

Without it the RFC’s sizes for an unknown path MTU apply: an IP packet of 576 bytes for IPv4 and 1280 bytes for IPv6, which is a STUN message of 548 or 1232 bytes. handle_write refuses a larger one, so that it is never fragmented on the way. A message that probes the path MTU is the one case where the RFC lets the rule go: set usize::MAX for the client that sends it.

Source

pub fn with_known_attributes(self, known: &[AttrType]) -> Self

Sets the comprehension-required attributes the usage understands in a response: STUN_ATTRIBUTES plus its own. A response that carries any other fails its transaction with TransactionFailure::UnknownAttributes (RFC 8489 sections 6.3.3 and 6.3.4).

The default is STUN_ATTRIBUTES and RFC 3489’s SOURCE-ADDRESS, CHANGED-ADDRESS and REFLECTED-FROM, which old servers still send in a Binding response.

Source

pub fn with_response_integrity( self, key: impl Into<Vec<u8>>, provider: Arc<dyn RTCCryptoProvider>, ) -> Self

Requires every response to be authenticated with key (the short-term credential mechanism, RFC 8489 section 9.1.4).

A response whose integrity attribute is absent or wrong is discarded as if it had never arrived, so retransmissions continue; if the transaction then ends without an authentic response, it ends with TransactionFailure::IntegrityViolation rather than a timeout. Over a reliable transport such a response ends the transaction at once. The message of StunEvent::Message then holds the authenticated attributes only.

The long-term mechanism has responses that are valid unsigned (401, 438): its caller leaves this off and uses LongTermCredentials::check_response.

Source

pub fn with_timeout_rate(self, d: Duration) -> Self

👎Deprecated:

has no effect: a sans-I/O client has no timer of its own, the caller’s handle_timeout calls set the resolution

with_timeout_rate sets RTO timer minimum resolution.

Source

pub fn with_buffer_size(self, buffer_size: usize) -> Self

👎Deprecated:

has no effect: the client buffers nothing of a fixed size

with_buffer_size sets buffer size.

Source

pub fn with_no_retransmit(self) -> Self

Disables retransmissions: each request is sent once (Rc = 1) and its transaction fails Rm x RTO later.

A client built for TransportProtocol::TCP never retransmits and waits Ti, with or without this (RFC 8489 section 6.2.2).

Source

pub fn new() -> Self

A builder with the RFC’s default timings.

Source

pub fn build( self, now: Instant, local: SocketAddr, remote: SocketAddr, protocol: TransportProtocol, ) -> Result<Client>

Builds the client for the given local and remote addresses.

§Errors

Fails if the configured timings are inconsistent.

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.