#include <icy/turn/iallocation.h>Subclassed by:
Client,ServerAllocation
Base class for TURN relay allocations shared by client and server flows.
All TURN operations revolve around allocations, and all TURN messages are associated with an allocation. An allocation conceptually consists of:
the relayed transport address;
the 5-tuple: client's IP address, client's port, server IP address, server port, and transport protocol;
the authentication information;
the time-to-expiry;
a list of permissions;
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, such as username, password, realm, and nonce, is used to verify subsequent requests and 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 during the allocation lifetime using a 438 (Stale Nonce) reply. Rather than storing the password explicitly, a server may prefer to store the key value, which is an MD5 hash over the username, realm, and password as described by RFC 5389.
The time-to-expiry is the time left until the allocation expires. Each Allocate or Refresh transaction resets this timer, which then ticks down toward zero. By default, each Allocate or Refresh resets the lifetime to 600 seconds (10 minutes), but the client can request a different value in the Allocate and Refresh requests. Allocations can only be refreshed using Refresh; sending data to a peer does not refresh an allocation. When an allocation expires, the state data associated with it can be freed.
| Return | Name | Description |
|---|---|---|
IAllocation | #### Parameters | |
IAllocation | Deleted constructor. | |
IAllocation | Deleted constructor. | |
void | updateUsage virtual | Updates the last-activity timestamp and accumulates bandwidth usage. Call this whenever data is relayed through the allocation. |
void | setLifetime virtual | Sets the allocation lifetime in seconds and resets the activity timestamp, effectively extending the expiry from the current moment. |
void | setBandwidthLimit virtual | Sets the maximum number of bytes this allocation may relay in its lifetime. Pass 0 to disable bandwidth limiting. |
bool | expired virtual const | #### Returns |
bool | deleted virtual const | Returns true if the allocation's deleted flag is set and or if the allocation has expired. |
std::int64_t | bandwidthLimit virtual const | #### Returns |
std::int64_t | bandwidthUsed virtual const | #### Returns |
std::int64_t | bandwidthRemaining virtual const | #### Returns |
std::int64_t | timeRemaining virtual const | #### Returns |
FiveTuple & | tuple virtual | #### Returns |
std::string | username virtual const | #### Returns |
std::int64_t | lifetime virtual const | #### Returns |
PermissionList | permissions virtual const | #### Returns |
net::Address | relayedAddress const | #### Returns |
void | addPermission virtual | Adds a permission for ip, or refreshes the existing one. |
void | addPermission virtual | Adds a permission for address, or refreshes the existing one. The port is ignored; TURN permissions are IP-only. |
void | addPermissions virtual | Adds (or refreshes) permissions for multiple IPs. |
void | removePermission virtual | Removes the permission for ip if present. |
void | removePermission virtual | Removes the permission for address if present. The port is ignored; TURN permissions are IP-only. |
void | removeAllPermissions virtual | Removes all permissions from the list. |
void | removeExpiredPermissions virtual | Removes any permissions whose 5-minute lifetime has elapsed. |
bool | hasPermission virtual | Checks whether a permission exists for peerIP. Local addresses (192.168.x.x and 127.x.x.x) are always permitted. |
bool | hasPermission virtual | Checks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only. |
void | print virtual const inline |
IAllocation(const FiveTuple & tuple, const std::string & username, std::int64_t lifetime)tuple The 5-tuple identifying this allocation.
username Authenticated username associated with this allocation.
lifetime Initial lifetime in seconds.
IAllocation(const IAllocation &) = deleteDeleted constructor.
IAllocation(IAllocation &&) = deleteDeleted constructor.
virtual
virtual void updateUsage(std::int64_t numBytes)Updates the last-activity timestamp and accumulates bandwidth usage. Call this whenever data is relayed through the allocation.
numBytes Number of bytes relayed (0 just refreshes the timestamp).virtual
virtual void setLifetime(std::int64_t lifetime)Sets the allocation lifetime in seconds and resets the activity timestamp, effectively extending the expiry from the current moment.
lifetime New lifetime in seconds.virtual
virtual void setBandwidthLimit(std::int64_t numBytes)Sets the maximum number of bytes this allocation may relay in its lifetime. Pass 0 to disable bandwidth limiting.
numBytes Bandwidth cap in bytes (0 = unlimited).virtual const
virtual bool expired() consttrue if the allocation's lifetime has elapsed or the bandwidth quota has been exhausted.
virtual const
virtual bool deleted() constReturns true if the allocation's deleted flag is set and or if the allocation has expired.
This signifies that the allocation is ready to be destroyed via async garbage collection. See Server::onTimer() and Client::onTimer()
virtual const
virtual std::int64_t bandwidthLimit() constThe configured bandwidth limit in bytes (0 means unlimited).
virtual const
virtual std::int64_t bandwidthUsed() constTotal bytes transferred through this allocation since creation.
virtual const
virtual std::int64_t bandwidthRemaining() constBytes remaining before the bandwidth quota is exhausted. Returns a large sentinel value when no limit is configured.
virtual const
virtual std::int64_t timeRemaining() constSeconds until the allocation expires (0 if already expired).
virtual
virtual FiveTuple & tuple()Reference to the 5-tuple identifying this allocation.
virtual const
virtual std::string username() constThe username associated with this allocation.
virtual const
virtual std::int64_t lifetime() constThe configured lifetime in seconds.
virtual const
virtual PermissionList permissions() constA copy of the current permission list.
const
net::Address relayedAddress() constThe relay transport address assigned to this allocation.
virtual
virtual void addPermission(const std::string & ip)Adds a permission for ip, or refreshes the existing one.
ip IPv4 address string to permit.virtual
virtual void addPermission(const net::Address & address)Adds a permission for address, or refreshes the existing one. The port is ignored; TURN permissions are IP-only.
virtual
virtual void addPermissions(const IPList & ips)Adds (or refreshes) permissions for multiple IPs.
ips List of IPv4 address strings.virtual
virtual void removePermission(const std::string & ip)Removes the permission for ip if present.
ip IPv4 address string to remove.virtual
virtual void removePermission(const net::Address & address)Removes the permission for address if present. The port is ignored; TURN permissions are IP-only.
virtual
virtual void removeAllPermissions()Removes all permissions from the list.
virtual
virtual void removeExpiredPermissions()Removes any permissions whose 5-minute lifetime has elapsed.
virtual
virtual bool hasPermission(const std::string & peerIP)Checks whether a permission exists for peerIP. Local addresses (192.168.x.x and 127.x.x.x) are always permitted.
peerIP IPv4 address string to check.true if a valid (non-expired) permission exists.
virtual
virtual bool hasPermission(const net::Address & peerAddress)Checks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only.
virtual const inline
virtual inline void print(std::ostream & os) const| Return | Name | Description |
|---|---|---|
FiveTuple | _tuple | |
std::string | _username | |
PermissionList | _permissions | |
std::int64_t | _lifetime | |
std::int64_t | _bandwidthLimit | |
std::int64_t | _bandwidthUsed | |
time_t | _createdAt | |
time_t | _updatedAt | |
bool | _deleted |
FiveTuple _tuplestd::string _usernamePermissionList _permissionsstd::int64_t _lifetimestd::int64_t _bandwidthLimitstd::int64_t _bandwidthUsedtime_t _createdAttime_t _updatedAtbool _deleted