Skip to main content

Client

Struct Client 

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

Client simulates “connection” to STUN server.

Implementations§

Source§

impl Client

Source

pub fn local_addr(&self) -> SocketAddr

The address this client sends from.

Source

pub fn peer_addr(&self) -> SocketAddr

The STUN server this client talks to.

Source

pub fn rto(&self) -> Duration

The RTO the next transaction starts with: the initial RTO, or what the server’s round-trip times have made of it.

Source

pub fn outstanding_transactions(&self) -> usize

How many transactions are waiting for their response.

Source

pub fn max_message_size(&self) -> usize

The largest STUN message this client sends: unbounded over a reliable transport, and over UDP what fits the path MTU, known or assumed (RFC 8489 section 6.1).

Trait Implementations§

Source§

impl Protocol<TransportMessage<BytesMut>, TaggedMessage, ()> for Client

Source§

fn handle_read(&mut self, msg: TaggedBytesMut) -> Result<()>

Takes a datagram (or one framed message of a stream) from the network.

What is not the response to an outstanding request is dropped without an event (RFC 8489 section 6.3): a message from another address than the server’s, a request or an indication, a response with an unknown transaction id or of another method, and a message whose FINGERPRINT does not match.

§Errors

Fails when the server’s datagram is not a STUN message.

Source§

fn handle_write(&mut self, msg: TaggedMessage) -> Result<()>

Sends a message to the server.

A request starts a transaction, which ends with one event: the response, a timeout or a failure. An indication is sent and forgotten: it has no response and no timeout (RFC 8489 section 6.3.2).

§Errors

Fails when the client is closed, when the message is larger than the path MTU allows over UDP (ErrPacketTooBig; RFC 8489 section 6.1, with_path_mtu), when a request reuses the transaction id of an outstanding one, and when the limit of outstanding transactions is reached (RFC 8489 section 6.2; with_max_outstanding_transactions).

Source§

fn poll_write(&mut self) -> Option<Self::Wout>

Returns packets to transmit

It should be polled for transmit after:

  • the application performed some I/O
  • a call was made to handle_read
  • a call was made to handle_write
  • a call was made to handle_timeout
Source§

fn poll_timeout(&mut self) -> Option<Self::Time>

When handle_timeout is next due: the earliest retransmission or transaction end.

Source§

fn handle_timeout(&mut self, now: Instant) -> Result<()>

Advances time: every request whose interval has passed (deadline <= now) is sent again, or, after its last transmission, its transaction ends with StunEvent::TransactionTimeOut.

Source§

type Rout = ()

Output read message type Read more
Source§

type Wout = TransportMessage<BytesMut>

Output write message type Read more
Source§

type Eout = StunEvent

Output event type Read more
Source§

type Error = Error

Error type for protocol operations
Source§

type Time = Instant

Time/Instant type for timeout handling Read more
Source§

fn poll_read(&mut self) -> Option<Self::Rout>

Poll for a processed read message. Read more
Source§

fn poll_event(&mut self) -> Option<Self::Eout>

Poll for a generated event. Read more
Source§

fn close(&mut self) -> Result<()>

Close the protocol. Read more
Source§

fn handle_event(&mut self, _evt: Ein) -> Result<(), Self::Error>

Handle a custom event. 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.