Skip to main content

Relay

Struct Relay 

Source
pub struct Relay<'a> { /* private fields */ }
Expand description

A borrowed handle to one live allocation on the TURN server.

Obtained from Client::relay. Sending to a peer requires a permission for it first — see Self::create_permission.

Implementations§

Source§

impl Relay<'_>

Source

pub fn create_permission( &mut self, now: Instant, peer_addr: SocketAddr, ) -> Result<Option<TransactionId>>

Asks the server to permit traffic to and from peer_addr.

The relay silently drops data for peers with no permission, and permissions expire after five minutes unless refreshed. A permission is for the peer’s IP address, whatever the port (RFC 8656 §9), so one covers every port on that address. Returns the transaction id to match against the resulting Event, or None if a permission is already in place.

§Errors

Fails if the allocation no longer exists or was released, if peer_addr is not of the family of a relayed address of the allocation (RFC 8656 §10.1), or if the request cannot be encoded.

Source

pub fn send_to( &mut self, now: Instant, p: &[u8], peer_addr: SocketAddr, ) -> Result<()>

Sends p to peer_addr through the relay.

Uses ChannelData framing once a channel is bound for that peer, and a Send indication until then. A channel is bound for every peer address sent to, as long as channel numbers are free; without one the data keeps going as Send indications.

§Errors

Fails if the allocation is gone or was released, if no permission is in place for peer_addr (none was created, the server refused it, or its 300 s ran out without a refresh), or if p is longer than the message that would carry it can say (65 535 bytes of ChannelData).

Source

pub fn channel_ready(&mut self, now: Instant, peer_addr: SocketAddr) -> bool

Whether a channel to peer_addr is bound and live on the server, so that Self::send_to sends ChannelData.

Source

pub fn bind_channel( &mut self, now: Instant, peer_addr: SocketAddr, ) -> Result<()>

Asks the server for a channel to peer_addr (RFC 8656 §12) without sending data: a ChannelBind when none is bound, under way or refused for the moment. A permission for the peer must be in place, as for Self::send_to.

§Errors

As Self::send_to’s, but for the length.

Source

pub fn send_indication_to( &mut self, now: Instant, p: &[u8], peer_addr: SocketAddr, ) -> Result<()>

Sends p to peer_addr in a Send indication (RFC 8656 §11.1), never as ChannelData, and binds no channel for the peer. For a caller that defers channels, as RFC 8445 §7.2.1 recommends an ICE agent do “until ICE completes”: its connectivity checks go this way, and Self::send_to (which binds a channel to the peer) once a pair through the allocation is selected. A channel already bound to the peer is left as it is.

§Errors

As Self::send_to.

Source

pub fn send_to_dont_fragment( &mut self, now: Instant, p: &[u8], peer_addr: SocketAddr, ) -> Result<()>

Sends p to peer_addr in a Send indication carrying DONT-FRAGMENT, which asks the server to set the DF bit on the datagram it sends the peer (RFC 8656 §11.1). The data never goes as ChannelData, which cannot say so.

§Errors

As Self::send_to; and if the allocation was not made with AllocateOptions::dont_fragment, or the server answered that request with 420: the server is not known to support the attribute (RFC 8656 §7.1).

Source

pub fn relayed_addrs(&self) -> Vec<RelayedAddr>

The relayed addresses of the allocation: one, or an IPv4 and an IPv6 address when it was made with AllocateOptions::additional_ipv6 and the server gave both. Peers of either family can then be reached through it.

Source

pub fn mapped_addr(&self) -> Option<SocketAddr>

The client’s address as the server saw the Allocate request arrive from: its server-reflexive address (RFC 8656 §7.3), from the response’s XOR-MAPPED-ADDRESS.

Source

pub fn lifetime(&self) -> Option<Duration>

The lifetime the server last granted the allocation.

Source

pub fn reservation_token(&self) -> Option<ReservationToken>

The RESERVATION-TOKEN of the Allocate success response: the port the server holds for a later allocation, after an EVEN-PORT that asked for it (RFC 8656 §7.1).

Source

pub fn dont_fragment(&self) -> bool

Whether the server supports DONT-FRAGMENT: the allocation was made with it and the server took it.

Source

pub fn address_error(&self) -> Option<AddressErrorCode>

The ADDRESS-ERROR-CODE of the Allocate success response: which of the two address families asked for the server did not allocate, and why (RFC 8656 §7.3).

Source

pub fn transport(&self) -> RelayTransport

What the allocation relays: UDP datagrams, or TCP connections (RFC 6062).

Source

pub fn connect( &mut self, now: Instant, peer_addr: SocketAddr, ) -> Result<TransactionId>

Asks the server to open a TCP connection from the relayed address to peer_addr (RFC 6062 §4.3), with a Connect request on the control connection. Returns the id that Event::ConnectResponse, Event::ConnectError or Event::TransactionTimeout will name. The server answers when the peer accepted, or after it gave up (about 30 seconds).

Connect requests to different peers can be outstanding together.

§Errors

Fails, with nothing sent, if the allocation is gone, was released, or relays UDP; if peer_addr is not of the family of its relayed address; if a Connect to peer_addr is still outstanding (RFC 6062 §4.3: never two for one peer address); or if the server answered 447 for peer_addr less than ten seconds ago.

Source

pub fn data_connection( &mut self, now: Instant, connection_id: ConnectionId, local_addr: SocketAddr, ) -> Result<DataConnection>

The protocol side of a new TCP connection to the server that is to carry the peer connection connection_id: from Event::ConnectResponse for a connection this client asked for, from Event::ConnectionAttempt for one a peer made (RFC 6062 §4.3, §4.4).

The application opens the connection itself, to the server address the control connection goes to (DataConnection::server_addr) and from local_addr, which must not be the control connection’s local address. The returned DataConnection has the ConnectionBind request queued, with the CONNECTION-ID and the credential of the control connection; the server waits 30 seconds for it.

§Errors

Fails if the allocation is gone, was released, or relays UDP, or if local_addr is the control connection’s.

Source

pub fn release_family( &mut self, now: Instant, family: RequestedAddressFamily, ) -> Result<()>

Deletes the relayed address of one family from an allocation that has two, with a Refresh of LIFETIME 0 naming the family (RFC 8656 §8.1). The other address, with its permissions and channel bindings, stays. Event::AllocationReleased names the address when the server confirms. For an allocation with one address this is Self::close.

§Errors

Fails if the allocation is gone or was released, or has no relayed address of family: REQUESTED-ADDRESS-FAMILY may only name a family the allocation holds.

Source

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

Releases the allocation by refreshing it with a zero lifetime (RFC 8656 §8).

From here on the allocation is not refreshed and nothing can be sent through it, whatever becomes of the request. Event::AllocationReleased follows when the server confirms, answers 437 (it no longer had the allocation), or never answers; in that last case the server drops the allocation when its lifetime runs out.

§Re-allocating on the same socket after a release

An allocation is its 5-tuple’s (RFC 8656 §2.2): an allocate from the same local address to the same server before Event::AllocationReleased can be refused with 437 (Allocation Mismatch, §7.2). On a 437 the client “SHOULD pick another client transport address and retry”, tries three, and then “SHOULD NOT try to create another allocation on the server for 2 minutes” (§7.4): never retry on the refused 5-tuple. RFC 8656 §8.2 has the server delete the allocation when it answers; coturn keeps it for one second more and answers 437 meanwhile, so wait about two seconds after Event::AllocationReleased (or use another socket) before allocating there again.

§Errors

Fails if the refresh request cannot be sent.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Relay<'a>

§

impl<'a> !UnwindSafe for Relay<'a>

§

impl<'a> Forget for Relay<'a>

§

impl<'a> Freeze for Relay<'a>
where &'a mut Client: Freeze,

§

impl<'a> Move for Relay<'a>

§

impl<'a> Send for Relay<'a>
where Arc<dyn RTCCryptoProvider>: Send, Arc<Login>: Send, RawVecInner: Send, RawTable<(TransactionId, Transaction)>: Send, RawTable<(SocketAddr, usize)>: Send, RawTable<(SocketAddr, RtoEstimator)>: Send, BytesMut: Send, RawTable<(SocketAddr, RelayState)>: Send, &'static str: Send, BoxRaw<Error>: Send, Repr: Send, BoxRaw<dyn Error + Sync + Send>: Send, BoxRaw<AllocateState>: Send, Arc<Credential>: Send,

§

impl<'a> Sync for Relay<'a>
where Arc<dyn RTCCryptoProvider>: Sync, Arc<Login>: Sync, RawVecInner: Sync, RawTable<(TransactionId, Transaction)>: Sync, RawTable<(SocketAddr, usize)>: Sync, RawTable<(SocketAddr, RtoEstimator)>: Sync, BytesMut: Sync, RawTable<(SocketAddr, RelayState)>: Sync, BoxRaw<Error>: Sync, Repr: Sync, BoxRaw<dyn Error + Sync + Send>: Sync, BoxRaw<AllocateState>: Sync, Arc<Credential>: Sync,

§

impl<'a> Unpin for Relay<'a>
where &'a mut Client: Unpin,

§

impl<'a> UnsafeUnpin for Relay<'a>
where &'a mut Client: UnsafeUnpin,

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.