Class TurnClient
A TURN client over UDP: allocates a relayed address on a TURN server, permits peers, and relays datagrams to and from them, refreshing all until closed.
Implements
Inherited Members
Namespace: Uniform.Stun
Assembly: Uniform.Stun.dll
Syntax
public sealed class TurnClient : IAsyncDisposable
Remarks
The socket is shared, e.g. with ICE: the owner reads it, gives STUN responses to Receive(ReadOnlySpan<byte>), and asks TryUnwrap(ReadOnlySpan<byte>, IPEndPoint, out IPEndPoint, out byte[]) for the data of datagrams from the server. Channels carry data with four bytes of overhead instead of a STUN indication's thirty-six; SendAsync(ReadOnlyMemory<byte>, IPEndPoint, CancellationToken) uses one once BindChannelAsync(IPEndPoint, CancellationToken) has bound it.
Constructors
| Edit this page View SourceTurnClient(StunClient, DatagramSender, IPEndPoint, string, string)
Create a client of the TURN server at server.
Declaration
public TurnClient(StunClient stun, DatagramSender send, IPEndPoint server, string username, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| StunClient | stun | STUN transactions over the shared socket. |
| DatagramSender | send | Sends a datagram over the shared socket, for channel data. |
| IPEndPoint | server | The TURN server's UDP address. |
| string | username | Username, e.g. of the time-limited credentials of a Matrix homeserver's |
| string | password | Password of |
Properties
| Edit this page View SourceMappedAddress
This client's public address as the server saw it, once allocated; a server-reflexive candidate.
Declaration
public IPEndPoint? MappedAddress { get; }
Property Value
| Type | Description |
|---|---|
| IPEndPoint |
RelayedAddress
The relayed address peers send to, once allocated.
Declaration
public IPEndPoint? RelayedAddress { get; }
Property Value
| Type | Description |
|---|---|
| IPEndPoint |
Server
The TURN server's address.
Declaration
public IPEndPoint Server { get; }
Property Value
| Type | Description |
|---|---|
| IPEndPoint |
Methods
| Edit this page View SourceAllocateAsync(CancellationToken)
Allocate a relayed address; return whether the server gave one.
Declaration
public Task<bool> AllocateAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<bool> |
BindChannelAsync(IPEndPoint, CancellationToken)
Bind a channel to a peer, which also permits it; return whether the server agreed.
Declaration
public Task<bool> BindChannelAsync(IPEndPoint peer, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IPEndPoint | peer | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<bool> |
DisposeAsync()
Release the allocation, and stop refreshing.
Declaration
public ValueTask DisposeAsync()
Returns
| Type | Description |
|---|---|
| ValueTask |
PermitAsync(IPAddress, CancellationToken)
Permit a peer's address to send to the relayed address, and this client to send to it; return whether the server agreed.
Declaration
public Task<bool> PermitAsync(IPAddress peer, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| IPAddress | peer | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task<bool> |
SendAsync(ReadOnlyMemory<byte>, IPEndPoint, CancellationToken)
Relay data to peer, on its channel when bound, else in a Send indication; the peer must be permitted.
Declaration
public ValueTask SendAsync(ReadOnlyMemory<byte> data, IPEndPoint peer, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyMemory<byte> | data | |
| IPEndPoint | peer | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| ValueTask |
TryUnwrap(ReadOnlySpan<byte>, IPEndPoint, out IPEndPoint, out byte[])
Return whether datagram, received from from, is data the server relays from a peer: a Data indication or channel data.
Declaration
public bool TryUnwrap(ReadOnlySpan<byte> datagram, IPEndPoint from, out IPEndPoint peer, out byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | datagram | Datagram as received. |
| IPEndPoint | from | Address it came from; only the server's are unwrapped. |
| IPEndPoint | peer | The peer that sent the data. |
| byte[] | data | The data the peer sent. |
Returns
| Type | Description |
|---|---|
| bool |