pub struct TurnClient { /* private fields */ }Expand description
A TURN client.
Implementations§
Source§impl TurnClient
impl TurnClient
Sourcepub fn allocate(
ttype: TransportType,
local_addr: SocketAddr,
remote_addr: SocketAddr,
credentials: TurnCredentials,
) -> Self
pub fn allocate( ttype: TransportType, local_addr: SocketAddr, remote_addr: SocketAddr, credentials: TurnCredentials, ) -> Self
Allocate an address on a TURN server to relay data to and from peers.
§Examples
let credentials = TurnCredentials::new("tuser", "tpass");
let transport = TransportType::Udp;
let local_addr = "192.168.0.1:4000".parse().unwrap();
let remote_addr = "10.0.0.1:3478".parse().unwrap();
let client = TurnClient::allocate(transport, local_addr, remote_addr, credentials);
assert_eq!(client.transport(), transport);
assert_eq!(client.local_addr(), local_addr);
assert_eq!(client.remote_addr(), remote_addr);Sourcepub fn transport(&self) -> TransportType
pub fn transport(&self) -> TransportType
The transport of the connection to the TURN server.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
The local address of this TURN client.
Sourcepub fn remote_addr(&self) -> SocketAddr
pub fn remote_addr(&self) -> SocketAddr
The remote TURN server’s address.
Sourcepub fn poll(&mut self, now: Instant) -> TurnPollRet
pub fn poll(&mut self, now: Instant) -> TurnPollRet
Poll the client for further progress.
Sourcepub fn relayed_addresses(
&self,
) -> impl Iterator<Item = (TransportType, SocketAddr)> + '_
pub fn relayed_addresses( &self, ) -> impl Iterator<Item = (TransportType, SocketAddr)> + '_
The list of allocated relayed addresses on the TURN server.
Sourcepub fn permissions(
&self,
transport: TransportType,
relayed: SocketAddr,
) -> impl Iterator<Item = IpAddr> + '_
pub fn permissions( &self, transport: TransportType, relayed: SocketAddr, ) -> impl Iterator<Item = IpAddr> + '_
The list of permissions available for the provided relayed address.
Sourcepub fn poll_transmit(&mut self, now: Instant) -> Option<Transmit<Data<'static>>>
pub fn poll_transmit(&mut self, now: Instant) -> Option<Transmit<Data<'static>>>
Poll for a packet to send.
Sourcepub fn poll_event(&mut self) -> Option<TurnEvent>
pub fn poll_event(&mut self) -> Option<TurnEvent>
Poll for an event that has occurred.
Sourcepub fn recv<T: AsRef<[u8]> + Debug>(
&mut self,
transmit: Transmit<T>,
now: Instant,
) -> TurnRecvRet<T>
pub fn recv<T: AsRef<[u8]> + Debug>( &mut self, transmit: Transmit<T>, now: Instant, ) -> TurnRecvRet<T>
Provide received data to the TURN client for handling.
The returned data outlines what to do with this data.
Sourcepub fn delete(&mut self, now: Instant) -> Option<Transmit<Data<'static>>>
pub fn delete(&mut self, now: Instant) -> Option<Transmit<Data<'static>>>
Remove the allocation/s on the server.
Sourcepub fn create_permission(
&mut self,
transport: TransportType,
peer_addr: IpAddr,
now: Instant,
) -> Result<Transmit<Data<'static>>, CreatePermissionError>
pub fn create_permission( &mut self, transport: TransportType, peer_addr: IpAddr, now: Instant, ) -> Result<Transmit<Data<'static>>, CreatePermissionError>
Create a permission address to allow sending/receiving data to/from.
Sourcepub fn bind_channel(
&mut self,
transport: TransportType,
peer_addr: SocketAddr,
now: Instant,
) -> Result<Transmit<Data<'static>>, BindChannelError>
pub fn bind_channel( &mut self, transport: TransportType, peer_addr: SocketAddr, now: Instant, ) -> Result<Transmit<Data<'static>>, BindChannelError>
Bind a channel for sending/receiving data to/from a particular peer.
Sourcepub fn send_to<T: AsRef<[u8]> + Debug>(
&mut self,
transport: TransportType,
to: SocketAddr,
data: T,
now: Instant,
) -> Result<TransmitBuild<DelayedMessageOrChannelSend<T>>, StunError>
pub fn send_to<T: AsRef<[u8]> + Debug>( &mut self, transport: TransportType, to: SocketAddr, data: T, now: Instant, ) -> Result<TransmitBuild<DelayedMessageOrChannelSend<T>>, StunError>
Send data to a peer through the TURN server.
The provided transport, address and data are the data to send to the peer.
The returned value will instruct the caller to send a message to the turn server.