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<'_>
impl Relay<'_>
Sourcepub fn create_permission(
&mut self,
now: Instant,
peer_addr: SocketAddr,
) -> Result<Option<TransactionId>>
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.
Sourcepub fn send_to(
&mut self,
now: Instant,
p: &[u8],
peer_addr: SocketAddr,
) -> Result<()>
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).
Sourcepub fn channel_ready(&mut self, now: Instant, peer_addr: SocketAddr) -> bool
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.
Sourcepub fn bind_channel(
&mut self,
now: Instant,
peer_addr: SocketAddr,
) -> Result<()>
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.
Sourcepub fn send_indication_to(
&mut self,
now: Instant,
p: &[u8],
peer_addr: SocketAddr,
) -> Result<()>
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.
Sourcepub fn send_to_dont_fragment(
&mut self,
now: Instant,
p: &[u8],
peer_addr: SocketAddr,
) -> Result<()>
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).
Sourcepub fn relayed_addrs(&self) -> Vec<RelayedAddr>
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.
Sourcepub fn mapped_addr(&self) -> Option<SocketAddr>
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.
Sourcepub fn lifetime(&self) -> Option<Duration>
pub fn lifetime(&self) -> Option<Duration>
The lifetime the server last granted the allocation.
Sourcepub fn reservation_token(&self) -> Option<ReservationToken>
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).
Sourcepub fn dont_fragment(&self) -> bool
pub fn dont_fragment(&self) -> bool
Whether the server supports DONT-FRAGMENT: the allocation was made with it and the server took it.
Sourcepub fn address_error(&self) -> Option<AddressErrorCode>
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).
Sourcepub fn transport(&self) -> RelayTransport
pub fn transport(&self) -> RelayTransport
What the allocation relays: UDP datagrams, or TCP connections (RFC 6062).
Sourcepub fn connect(
&mut self,
now: Instant,
peer_addr: SocketAddr,
) -> Result<TransactionId>
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.
Sourcepub fn data_connection(
&mut self,
now: Instant,
connection_id: ConnectionId,
local_addr: SocketAddr,
) -> Result<DataConnection>
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.
Sourcepub fn release_family(
&mut self,
now: Instant,
family: RequestedAddressFamily,
) -> Result<()>
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.
Sourcepub fn close(&mut self, now: Instant) -> Result<()>
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.