3. Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119]. Readers are expected to be familiar with [RFC5389] and the terms defined there. The following terms are used in this document: TURN: The protocol spoken between a TURN client and a TURN server. It is an extension to the STUN protocol [RFC5389]. The protocol allows a client to allocate and use a relayed transport address. TURN client: A STUN client that implements this specification. TURN server: A STUN server that implements this specification. It relays data between a TURN client and its peer(s). Peer: A host with which the TURN client wishes to communicate. The TURN server relays traffic between the TURN client and its peer(s). The peer does not interact with the TURN server using the protocol defined in this document; rather, the peer receives data sent by the TURN server and the peer sends data towards the TURN server. Transport Address: The combination of an IP address and a port. Host Transport Address: A transport address on a client or a peer. Server-Reflexive Transport Address: A transport address on the "public side" of a NAT. This address is allocated by the NAT to correspond to a specific host transport address. Relayed Transport Address: A transport address on the TURN server that is used for relaying packets between the client and a peer. A peer sends to this address on the TURN server, and the packet is then relayed to the client. TURN Server Transport Address: A transport address on the TURN server that is used for sending TURN messages to the server. This is the transport address that the client uses to communicate with the server. Peer Transport Address: The transport address of the peer as seen by the server. When the peer is behind a NAT, this is the peer's server-reflexive transport address.
Allocation: The relayed transport address granted to a client
through an Allocate request, along with related state, such as
permissions and expiration timers.
5-tuple: The combination (client IP address and port, server IP
address and port, and transport protocol (currently one of UDP,
TCP, or TLS)) used to communicate between the client and the
server. The 5-tuple uniquely identifies this communication
stream. The 5-tuple also uniquely identifies the Allocation on
the server.
Channel: A channel number and associated peer transport address.
Once a channel number is bound to a peer's transport address, the
client and server can use the more bandwidth-efficient ChannelData
message to exchange data.
Permission: The IP address and transport protocol (but not the port)
of a peer that is permitted to send traffic to the TURN server and
have that traffic relayed to the TURN client. The TURN server
will only forward traffic to its client from peers that match an
existing permission.
Realm: A string used to describe the server or a context within the
server. The realm tells the client which username and password
combination to use to authenticate requests.
Nonce: A string chosen at random by the server and included in the
message-digest. To prevent reply attacks, the server should
change the nonce regularly.
4. General Behavior
This section contains general TURN processing rules that apply to all
TURN messages.
TURN is an extension to STUN. All TURN messages, with the exception
of the ChannelData message, are STUN-formatted messages. All the
base processing rules described in [RFC5389] apply to STUN-formatted
messages. This means that all the message-forming and message-
processing descriptions in this document are implicitly prefixed with
the rules of [RFC5389].
[RFC5389] specifies an authentication mechanism called the long-term
credential mechanism. TURN servers and clients MUST implement this
mechanism. The server MUST demand that all requests from the client
be authenticated using this mechanism, or that a equally strong or
stronger mechanism for client authentication is used.
Note that the long-term credential mechanism applies only to requests and cannot be used to authenticate indications; thus, indications in TURN are never authenticated. If the server requires requests to be authenticated, then the server's administrator MUST choose a realm value that will uniquely identify the username and password combination that the client must use, even if the client uses multiple servers under different administrations. The server's administrator MAY choose to allocate a unique username to each client, or MAY choose to allocate the same username to more than one client (for example, to all clients from the same department or company). For each allocation, the server SHOULD generate a new random nonce when the allocation is first attempted following the randomness recommendations in [RFC4086] and SHOULD expire the nonce at least once every hour during the lifetime of the allocation. All requests after the initial Allocate must use the same username as that used to create the allocation, to prevent attackers from hijacking the client's allocation. Specifically, if the server requires the use of the long-term credential mechanism, and if a non- Allocate request passes authentication under this mechanism, and if the 5-tuple identifies an existing allocation, but the request does not use the same username as used to create the allocation, then the request MUST be rejected with a 441 (Wrong Credentials) error. When a TURN message arrives at the server from the client, the server uses the 5-tuple in the message to identify the associated allocation. For all TURN messages (including ChannelData) EXCEPT an Allocate request, if the 5-tuple does not identify an existing allocation, then the message MUST either be rejected with a 437 Allocation Mismatch error (if it is a request) or silently ignored (if it is an indication or a ChannelData message). A client receiving a 437 error response to a request other than Allocate MUST assume the allocation no longer exists. [RFC5389] defines a number of attributes, including the SOFTWARE and FINGERPRINT attributes. The client SHOULD include the SOFTWARE attribute in all Allocate and Refresh requests and MAY include it in any other requests or indications. The server SHOULD include the SOFTWARE attribute in all Allocate and Refresh responses (either success or failure) and MAY include it in other responses or indications. The client and the server MAY include the FINGERPRINT attribute in any STUN-formatted messages defined in this document. TURN does not use the backwards-compatibility mechanism described in [RFC5389].
TURN, as defined in this specification, only supports IPv4. The client's IP address, the server's IP address, and all IP addresses appearing in a relayed transport address MUST be IPv4 addresses. By default, TURN runs on the same ports as STUN: 3478 for TURN over UDP and TCP, and 5349 for TURN over TLS. However, TURN has its own set of Service Record (SRV) names: "turn" for UDP and TCP, and "turns" for TLS. Either the SRV procedures or the ALTERNATE-SERVER procedures, both described in Section 6, can be used to run TURN on a different port. To ensure interoperability, a TURN server MUST support the use of UDP transport between the client and the server, and SHOULD support the use of TCP and TLS transport. When UDP transport is used between the client and the server, the client will retransmit a request if it does not receive a response within a certain timeout period. Because of this, the server may receive two (or more) requests with the same 5-tuple and same transaction id. STUN requires that the server recognize this case and treat the request as idempotent (see [RFC5389]). Some implementations may choose to meet this requirement by remembering all received requests and the corresponding responses for 40 seconds. Other implementations may choose to reprocess the request and arrange that such reprocessing returns essentially the same response. To aid implementors who choose the latter approach (the so-called "stateless stack approach"), this specification includes some implementation notes on how this might be done. Implementations are free to choose either approach or choose some other approach that gives the same results. When TCP transport is used between the client and the server, it is possible that a bit error will cause a length field in a TURN packet to become corrupted, causing the receiver to lose synchronization with the incoming stream of TURN messages. A client or server that detects a long sequence of invalid TURN messages over TCP transport SHOULD close the corresponding TCP connection to help the other end detect this situation more rapidly. To mitigate either intentional or unintentional denial-of-service attacks against the server by clients with valid usernames and passwords, it is RECOMMENDED that the server impose limits on both the number of allocations active at one time for a given username and on the amount of bandwidth those allocations can use. The server should reject new allocations that would exceed the limit on the allowed number of allocations active at one time with a 486 (Allocation Quota Exceeded) (see Section 6.2), and should discard application data traffic that exceeds the bandwidth quota.
5. Allocations
All TURN operations revolve around allocations, and all TURN messages are associated with an allocation. An allocation conceptually consists of the following state data: o the relayed transport address; o the 5-tuple: (client's IP address, client's port, server IP address, server port, transport protocol); o the authentication information; o the time-to-expiry; o a list of permissions; o a list of channel to peer bindings. The relayed transport address is the transport address allocated by the server for communicating with peers, while the 5-tuple describes the communication path between the client and the server. On the client, the 5-tuple uses the client's host transport address; on the server, the 5-tuple uses the client's server-reflexive transport address. Both the relayed transport address and the 5-tuple MUST be unique across all allocations, so either one can be used to uniquely identify the allocation. The authentication information (e.g., username, password, realm, and nonce) is used to both verify subsequent requests and to compute the message integrity of responses. The username, realm, and nonce values are initially those used in the authenticated Allocate request that creates the allocation, though the server can change the nonce value during the lifetime of the allocation using a 438 (Stale Nonce) reply. Note that, rather than storing the password explicitly, for security reasons, it may be desirable for the server to store the key value, which is an MD5 hash over the username, realm, and password (see [RFC5389]). The time-to-expiry is the time in seconds left until the allocation expires. Each Allocate or Refresh transaction sets this timer, which then ticks down towards 0. By default, each Allocate or Refresh transaction resets this timer to the default lifetime value of 600 seconds (10 minutes), but the client can request a different value in the Allocate and Refresh request. Allocations can only be refreshed using the Refresh request; sending data to a peer does not refresh an
allocation. When an allocation expires, the state data associated with the allocation can be freed. The list of permissions is described in Section 8 and the list of channels is described in Section 11.6. Creating an Allocation
An allocation on the server is created using an Allocate transaction.6.1. Sending an Allocate Request
The client forms an Allocate request as follows. The client first picks a host transport address. It is RECOMMENDED that the client pick a currently unused transport address, typically by allowing the underlying OS to pick a currently unused port for a new socket. The client then picks a transport protocol to use between the client and the server. The transport protocol MUST be one of UDP, TCP, or TLS-over-TCP. Since this specification only allows UDP between the server and the peers, it is RECOMMENDED that the client pick UDP unless it has a reason to use a different transport. One reason to pick a different transport would be that the client believes, either through configuration or by experiment, that it is unable to contact any TURN server using UDP. See Section 2.1 for more discussion. The client also picks a server transport address, which SHOULD be done as follows. The client receives (perhaps through configuration) a domain name for a TURN server. The client then uses the DNS procedures described in [RFC5389], but using an SRV service name of "turn" (or "turns" for TURN over TLS) instead of "stun" (or "stuns"). For example, to find servers in the example.com domain, the client performs a lookup for '_turn._udp.example.com', '_turn._tcp.example.com', and '_turns._tcp.example.com' if the client wants to communicate with the server using UDP, TCP, or TLS-over-TCP, respectively. The client MUST include a REQUESTED-TRANSPORT attribute in the request. This attribute specifies the transport protocol between the server and the peers (note that this is NOT the transport protocol that appears in the 5-tuple). In this specification, the REQUESTED- TRANSPORT type is always UDP. This attribute is included to allow future extensions to specify other protocols. If the client wishes the server to initialize the time-to-expiry field of the allocation to some value other than the default
lifetime, then it MAY include a LIFETIME attribute specifying its desired value. This is just a request, and the server may elect to use a different value. Note that the server will ignore requests to initialize the field to less than the default value. If the client wishes to later use the DONT-FRAGMENT attribute in one or more Send indications on this allocation, then the client SHOULD include the DONT-FRAGMENT attribute in the Allocate request. This allows the client to test whether this attribute is supported by the server. If the client requires the port number of the relayed transport address be even, the client includes the EVEN-PORT attribute. If this attribute is not included, then the port can be even or odd. By setting the R bit in the EVEN-PORT attribute to 1, the client can request that the server reserve the next highest port number (on the same IP address) for a subsequent allocation. If the R bit is 0, no such request is made. The client MAY also include a RESERVATION-TOKEN attribute in the request to ask the server to use a previously reserved port for the allocation. If the RESERVATION-TOKEN attribute is included, then the client MUST omit the EVEN-PORT attribute. Once constructed, the client sends the Allocate request on the 5-tuple.6.2. Receiving an Allocate Request
When the server receives an Allocate request, it performs the following checks: 1. The server MUST require that the request be authenticated. This authentication MUST be done using the long-term credential mechanism of [RFC5389] unless the client and server agree to use another mechanism through some procedure outside the scope of this document. 2. The server checks if the 5-tuple is currently in use by an existing allocation. If yes, the server rejects the request with a 437 (Allocation Mismatch) error. 3. The server checks if the request contains a REQUESTED-TRANSPORT attribute. If the REQUESTED-TRANSPORT attribute is not included or is malformed, the server rejects the request with a 400 (Bad Request) error. Otherwise, if the attribute is included but specifies a protocol other that UDP, the server rejects the request with a 442 (Unsupported Transport Protocol) error.
4. The request may contain a DONT-FRAGMENT attribute. If it does,
but the server does not support sending UDP datagrams with the DF
bit set to 1 (see Section 12), then the server treats the DONT-
FRAGMENT attribute in the Allocate request as an unknown
comprehension-required attribute.
5. The server checks if the request contains a RESERVATION-TOKEN
attribute. If yes, and the request also contains an EVEN-PORT
attribute, then the server rejects the request with a 400 (Bad
Request) error. Otherwise, it checks to see if the token is
valid (i.e., the token is in range and has not expired and the
corresponding relayed transport address is still available). If
the token is not valid for some reason, the server rejects the
request with a 508 (Insufficient Capacity) error.
6. The server checks if the request contains an EVEN-PORT attribute.
If yes, then the server checks that it can satisfy the request
(i.e., can allocate a relayed transport address as described
below). If the server cannot satisfy the request, then the
server rejects the request with a 508 (Insufficient Capacity)
error.
7. At any point, the server MAY choose to reject the request with a
486 (Allocation Quota Reached) error if it feels the client is
trying to exceed some locally defined allocation quota. The
server is free to define this allocation quota any way it wishes,
but SHOULD define it based on the username used to authenticate
the request, and not on the client's transport address.
8. Also at any point, the server MAY choose to reject the request
with a 300 (Try Alternate) error if it wishes to redirect the
client to a different server. The use of this error code and
attribute follow the specification in [RFC5389].
If all the checks pass, the server creates the allocation. The
5-tuple is set to the 5-tuple from the Allocate request, while the
list of permissions and the list of channels are initially empty.
The server chooses a relayed transport address for the allocation as
follows:
o If the request contains a RESERVATION-TOKEN, the server uses the
previously reserved transport address corresponding to the
included token (if it is still available). Note that the
reservation is a server-wide reservation and is not specific to a
particular allocation, since the Allocate request containing the
RESERVATION-TOKEN uses a different 5-tuple than the Allocate
request that made the reservation. The 5-tuple for the Allocate
request containing the RESERVATION-TOKEN attribute can be any
allowed 5-tuple; it can use a different client IP address and
port, a different transport protocol, and even different server IP
address and port (provided, of course, that the server IP address
and port are ones on which the server is listening for TURN
requests).
o If the request contains an EVEN-PORT attribute with the R bit set
to 0, then the server allocates a relayed transport address with
an even port number.
o If the request contains an EVEN-PORT attribute with the R bit set
to 1, then the server looks for a pair of port numbers N and N+1
on the same IP address, where N is even. Port N is used in the
current allocation, while the relayed transport address with port
N+1 is assigned a token and reserved for a future allocation. The
server MUST hold this reservation for at least 30 seconds, and MAY
choose to hold longer (e.g., until the allocation with port N
expires). The server then includes the token in a RESERVATION-
TOKEN attribute in the success response.
o Otherwise, the server allocates any available relayed transport
address.
In all cases, the server SHOULD only allocate ports from the range
49152 - 65535 (the Dynamic and/or Private Port range [Port-Numbers]),
unless the TURN server application knows, through some means not
specified here, that other applications running on the same host as
the TURN server application will not be impacted by allocating ports
outside this range. This condition can often be satisfied by running
the TURN server application on a dedicated machine and/or by
arranging that any other applications on the machine allocate ports
before the TURN server application starts. In any case, the TURN
server SHOULD NOT allocate ports in the range 0 - 1023 (the Well-
Known Port range) to discourage clients from using TURN to run
standard services.
NOTE: The IETF is currently investigating the topic of randomized
port assignments to avoid certain types of attacks (see
[TSVWG-PORT]). It is strongly recommended that a TURN implementor
keep abreast of this topic and, if appropriate, implement a
randomized port assignment algorithm. This is especially
applicable to servers that choose to pre-allocate a number of
ports from the underlying OS and then later assign them to
allocations; for example, a server may choose this technique to
implement the EVEN-PORT attribute.
The server determines the initial value of the time-to-expiry field
as follows. If the request contains a LIFETIME attribute, then the
server computes the minimum of the client's proposed lifetime and the
server's maximum allowed lifetime. If this computed value is greater
than the default lifetime, then the server uses the computed lifetime
as the initial value of the time-to-expiry field. Otherwise, the
server uses the default lifetime. It is RECOMMENDED that the server
use a maximum allowed lifetime value of no more than 3600 seconds (1
hour). Servers that implement allocation quotas or charge users for
allocations in some way may wish to use a smaller maximum allowed
lifetime (perhaps as small as the default lifetime) to more quickly
remove orphaned allocations (that is, allocations where the
corresponding client has crashed or terminated or the client
connection has been lost for some reason). Also, note that the time-
to-expiry is recomputed with each successful Refresh request, and
thus the value computed here applies only until the first refresh.
Once the allocation is created, the server replies with a success
response. The success response contains:
o An XOR-RELAYED-ADDRESS attribute containing the relayed transport
address.
o A LIFETIME attribute containing the current value of the time-to-
expiry timer.
o A RESERVATION-TOKEN attribute (if a second relayed transport
address was reserved).
o An XOR-MAPPED-ADDRESS attribute containing the client's IP address
and port (from the 5-tuple).
NOTE: The XOR-MAPPED-ADDRESS attribute is included in the response
as a convenience to the client. TURN itself does not make use of
this value, but clients running ICE can often need this value and
can thus avoid having to do an extra Binding transaction with some
STUN server to learn it.
The response (either success or error) is sent back to the client on
the 5-tuple.
NOTE: When the Allocate request is sent over UDP, section 7.3.1 of
[RFC5389] requires that the server handle the possible
retransmissions of the request so that retransmissions do not
cause multiple allocations to be created. Implementations may
achieve this using the so-called "stateless stack approach" as
follows. To detect retransmissions when the original request was
successful in creating an allocation, the server can store the
transaction id that created the request with the allocation data
and compare it with incoming Allocate requests on the same
5-tuple. Once such a request is detected, the server can stop
parsing the request and immediately generate a success response.
When building this response, the value of the LIFETIME attribute
can be taken from the time-to-expiry field in the allocate state
data, even though this value may differ slightly from the LIFETIME
value originally returned. In addition, the server may need to
store an indication of any reservation token returned in the
original response, so that this may be returned in any
retransmitted responses.
For the case where the original request was unsuccessful in
creating an allocation, the server may choose to do nothing
special. Note, however, that there is a rare case where the
server rejects the original request but accepts the retransmitted
request (because conditions have changed in the brief intervening
time period). If the client receives the first failure response,
it will ignore the second (success) response and believe that an
allocation was not created. An allocation created in this matter
will eventually timeout, since the client will not refresh it.
Furthermore, if the client later retries with the same 5-tuple but
different transaction id, it will receive a 437 (Allocation
Mismatch), which will cause it to retry with a different 5-tuple.
The server may use a smaller maximum lifetime value to minimize
the lifetime of allocations "orphaned" in this manner.
6.3. Receiving an Allocate Success Response
If the client receives an Allocate success response, then it MUST
check that the mapped address and the relayed transport address are
in an address family that the client understands and is prepared to
handle. This specification only covers the case where these two
addresses are IPv4 addresses. If these two addresses are not in an
address family which the client is prepared to handle, then the
client MUST delete the allocation (Section 7) and MUST NOT attempt to
create another allocation on that server until it believes the
mismatch has been fixed.
The IETF is currently considering mechanisms for transitioning
between IPv4 and IPv6 that could result in a client originating an
Allocate request over IPv6, but the request would arrive at the
server over IPv4, or vice versa.
Otherwise, the client creates its own copy of the allocation data
structure to track what is happening on the server. In particular,
the client needs to remember the actual lifetime received back from
the server, rather than the value sent to the server in the request.
The client must also remember the 5-tuple used for the request and the username and password it used to authenticate the request to ensure that it reuses them for subsequent messages. The client also needs to track the channels and permissions it establishes on the server. The client will probably wish to send the relayed transport address to peers (using some method not specified here) so the peers can communicate with it. The client may also wish to use the server- reflexive address it receives in the XOR-MAPPED-ADDRESS attribute in its ICE processing.6.4. Receiving an Allocate Error Response
If the client receives an Allocate error response, then the processing depends on the actual error code returned: o (Request timed out): There is either a problem with the server, or a problem reaching the server with the chosen transport. The client considers the current transaction as having failed but MAY choose to retry the Allocate request using a different transport (e.g., TCP instead of UDP). o 300 (Try Alternate): The server would like the client to use the server specified in the ALTERNATE-SERVER attribute instead. The client considers the current transaction as having failed, but SHOULD try the Allocate request with the alternate server before trying any other servers (e.g., other servers discovered using the SRV procedures). When trying the Allocate request with the alternate server, the client follows the ALTERNATE-SERVER procedures specified in [RFC5389]. o 400 (Bad Request): The server believes the client's request is malformed for some reason. The client considers the current transaction as having failed. The client MAY notify the user or operator and SHOULD NOT retry the request with this server until it believes the problem has been fixed. o 401 (Unauthorized): If the client has followed the procedures of the long-term credential mechanism and still gets this error, then the server is not accepting the client's credentials. In this case, the client considers the current transaction as having failed and SHOULD notify the user or operator. The client SHOULD NOT send any further requests to this server until it believes the problem has been fixed.
o 403 (Forbidden): The request is valid, but the server is refusing
to perform it, likely due to administrative restrictions. The
client considers the current transaction as having failed. The
client MAY notify the user or operator and SHOULD NOT retry the
same request with this server until it believes the problem has
been fixed.
o 420 (Unknown Attribute): If the client included a DONT-FRAGMENT
attribute in the request and the server rejected the request with
a 420 error code and listed the DONT-FRAGMENT attribute in the
UNKNOWN-ATTRIBUTES attribute in the error response, then the
client now knows that the server does not support the DONT-
FRAGMENT attribute. The client considers the current transaction
as having failed but MAY choose to retry the Allocate request
without the DONT-FRAGMENT attribute.
o 437 (Allocation Mismatch): This indicates that the client has
picked a 5-tuple that the server sees as already in use. One way
this could happen is if an intervening NAT assigned a mapped
transport address that was used by another client that recently
crashed. The client considers the current transaction as having
failed. The client SHOULD pick another client transport address
and retry the Allocate request (using a different transaction id).
The client SHOULD try three different client transport addresses
before giving up on this server. Once the client gives up on the
server, it SHOULD NOT try to create another allocation on the
server for 2 minutes.
o 438 (Stale Nonce): See the procedures for the long-term credential
mechanism [RFC5389].
o 441 (Wrong Credentials): The client should not receive this error
in response to a Allocate request. The client MAY notify the user
or operator and SHOULD NOT retry the same request with this server
until it believes the problem has been fixed.
o 442 (Unsupported Transport Address): The client should not receive
this error in response to a request for a UDP allocation. The
client MAY notify the user or operator and SHOULD NOT reattempt
the request with this server until it believes the problem has
been fixed.
o 486 (Allocation Quota Reached): The server is currently unable to
create any more allocations with this username. The client
considers the current transaction as having failed. The client
SHOULD wait at least 1 minute before trying to create any more
allocations on the server.
o 508 (Insufficient Capacity): The server has no more relayed
transport addresses available, or has none with the requested
properties, or the one that was reserved is no longer available.
The client considers the current operation as having failed. If
the client is using either the EVEN-PORT or the RESERVATION-TOKEN
attribute, then the client MAY choose to remove or modify this
attribute and try again immediately. Otherwise, the client SHOULD
wait at least 1 minute before trying to create any more
allocations on this server.
An unknown error response MUST be handled as described in [RFC5389].
7. Refreshing an Allocation
A Refresh transaction can be used to either (a) refresh an existing
allocation and update its time-to-expiry or (b) delete an existing
allocation.
If a client wishes to continue using an allocation, then the client
MUST refresh it before it expires. It is suggested that the client
refresh the allocation roughly 1 minute before it expires. If a
client no longer wishes to use an allocation, then it SHOULD
explicitly delete the allocation. A client MAY refresh an allocation
at any time for other reasons.
7.1. Sending a Refresh Request
If the client wishes to immediately delete an existing allocation, it
includes a LIFETIME attribute with a value of 0. All other forms of
the request refresh the allocation.
The Refresh transaction updates the time-to-expiry timer of an
allocation. If the client wishes the server to set the time-to-
expiry timer to something other than the default lifetime, it
includes a LIFETIME attribute with the requested value. The server
then computes a new time-to-expiry value in the same way as it does
for an Allocate transaction, with the exception that a requested
lifetime of 0 causes the server to immediately delete the allocation.
7.2. Receiving a Refresh Request
When the server receives a Refresh request, it processes as per
Section 4 plus the specific rules mentioned here.
The server computes a value called the "desired lifetime" as follows:
if the request contains a LIFETIME attribute and the attribute value
is 0, then the "desired lifetime" is 0. Otherwise, if the request
contains a LIFETIME attribute, then the server computes the minimum
of the client's requested lifetime and the server's maximum allowed
lifetime. If this computed value is greater than the default
lifetime, then the "desired lifetime" is the computed value.
Otherwise, the "desired lifetime" is the default lifetime.
Subsequent processing depends on the "desired lifetime" value:
o If the "desired lifetime" is 0, then the request succeeds and the
allocation is deleted.
o If the "desired lifetime" is non-zero, then the request succeeds
and the allocation's time-to-expiry is set to the "desired
lifetime".
If the request succeeds, then the server sends a success response
containing:
o A LIFETIME attribute containing the current value of the time-to-
expiry timer.
NOTE: A server need not do anything special to implement
idempotency of Refresh requests over UDP using the "stateless
stack approach". Retransmitted Refresh requests with a non-zero
"desired lifetime" will simply refresh the allocation. A
retransmitted Refresh request with a zero "desired lifetime" will
cause a 437 (Allocation Mismatch) response if the allocation has
already been deleted, but the client will treat this as equivalent
to a success response (see below).
7.3. Receiving a Refresh Response
If the client receives a success response to its Refresh request with
a non-zero lifetime, it updates its copy of the allocation data
structure with the time-to-expiry value contained in the response.
If the client receives a 437 (Allocation Mismatch) error response to
a request to delete the allocation, then the allocation no longer
exists and it should consider its request as having effectively
succeeded.
8. Permissions
For each allocation, the server keeps a list of zero or more
permissions. Each permission consists of an IP address and an
associated time-to-expiry. While a permission exists, all peers
using the IP address in the permission are allowed to send data to
the client. The time-to-expiry is the number of seconds until the
permission expires. Within the context of an allocation, a
permission is uniquely identified by its associated IP address.
By sending either CreatePermission requests or ChannelBind requests,
the client can cause the server to install or refresh a permission
for a given IP address. This causes one of two things to happen:
o If no permission for that IP address exists, then a permission is
created with the given IP address and a time-to-expiry equal to
Permission Lifetime.
o If a permission for that IP address already exists, then the time-
to-expiry for that permission is reset to Permission Lifetime.
The Permission Lifetime MUST be 300 seconds (= 5 minutes).
Each permission's time-to-expiry decreases down once per second until
it reaches 0; at which point, the permission expires and is deleted.
CreatePermission and ChannelBind requests may be freely intermixed on
a permission. A given permission may be initially installed and/or
refreshed with a CreatePermission request, and then later refreshed
with a ChannelBind request, or vice versa.
When a UDP datagram arrives at the relayed transport address for the
allocation, the server extracts the source IP address from the IP
header. The server then compares this address with the IP address
associated with each permission in the list of permissions for the
allocation. If no match is found, relaying is not permitted, and the
server silently discards the UDP datagram. If an exact match is
found, then the permission check is considered to have succeeded and
the server continues to process the UDP datagram as specified
elsewhere (Section 10.3). Note that only addresses are compared and
port numbers are not considered.
The permissions for one allocation are totally unrelated to the
permissions for a different allocation. If an allocation expires,
all its permissions expire with it.
NOTE: Though TURN permissions expire after 5 minutes, many NATs
deployed at the time of publication expire their UDP bindings
considerably faster. Thus, an application using TURN will
probably wish to send some sort of keep-alive traffic at a much
faster rate. Applications using ICE should follow the keep-alive
guidelines of ICE [RFC5245], and applications not using ICE are
advised to do something similar.
9. CreatePermission
TURN supports two ways for the client to install or refresh permissions on the server. This section describes one way: the CreatePermission request. A CreatePermission request may be used in conjunction with either the Send mechanism in Section 10 or the Channel mechanism in Section 11.9.1. Forming a CreatePermission Request
The client who wishes to install or refresh one or more permissions can send a CreatePermission request to the server. When forming a CreatePermission request, the client MUST include at least one XOR-PEER-ADDRESS attribute, and MAY include more than one such attribute. The IP address portion of each XOR-PEER-ADDRESS attribute contains the IP address for which a permission should be installed or refreshed. The port portion of each XOR-PEER-ADDRESS attribute will be ignored and can be any arbitrary value. The various XOR-PEER-ADDRESS attributes can appear in any order.9.2. Receiving a CreatePermission Request
When the server receives the CreatePermission request, it processes as per Section 4 plus the specific rules mentioned here. The message is checked for validity. The CreatePermission request MUST contain at least one XOR-PEER-ADDRESS attribute and MAY contain multiple such attributes. If no such attribute exists, or if any of these attributes are invalid, then a 400 (Bad Request) error is returned. If the request is valid, but the server is unable to satisfy the request due to some capacity limit or similar, then a 508 (Insufficient Capacity) error is returned. The server MAY impose restrictions on the IP address allowed in the XOR-PEER-ADDRESS attribute -- if a value is not allowed, the server rejects the request with a 403 (Forbidden) error. If the message is valid and the server is capable of carrying out the request, then the server installs or refreshes a permission for the IP address contained in each XOR-PEER-ADDRESS attribute as described in Section 8. The port portion of each attribute is ignored and may be any arbitrary value. The server then responds with a CreatePermission success response. There are no mandatory attributes in the success response.
NOTE: A server need not do anything special to implement
idempotency of CreatePermission requests over UDP using the
"stateless stack approach". Retransmitted CreatePermission
requests will simply refresh the permissions.
9.3. Receiving a CreatePermission Response
If the client receives a valid CreatePermission success response,
then the client updates its data structures to indicate that the
permissions have been installed or refreshed.