webrtc_stun_tx (webrtc v0.1.0)
View SourceSans-IO STUN client transaction table for UDP (RFC 8489 §6.2.1).
The table tracks outstanding requests by transaction ID, decides when a request must be retransmitted and when a transaction has failed. It never sends anything itself: every call returns the actions the owner must execute.
Retransmission follows RFC 8489 §6.2.1: the first retransmission is sent RTO after the request, the interval doubles after each retransmission, at most Rc requests are sent (default 7) and the transaction fails Rm times the initial RTO after the last request (default 16). With RTO = 500 ms requests leave at 0, 500, 1500, 3500, 7500, 15500 and 31500 ms and the transaction fails at 39500 ms.
The RTO of a transaction is, in order of preference: the rto option of send/6 (ICE computes a per-check RTO, RFC 8445 §14.3), the value cached for the transaction key (normally the server IP address, computed from RTT samples as in RFC 6298 with Karn's algorithm and discarded after 10 minutes without transactions), then the table default.
Actions:
{send, Dest, Bin}: transmitBintoDest(opaque term given tosend/6).{timeout, TxId, Dest, Meta}: the transaction failed.
A transaction can be cancelled (RFC 8445 §7.2.5.3 and §8.1.2): it is no longer retransmitted and its timeout is not reported, but a response arriving before the original deadline is still matched.
Summary
Functions
Stop retransmitting TxId. A response is still matched until the original transaction deadline; no timeout is reported.
Return the destination and metadata of an outstanding transaction without consuming it.
Create a table. Options: rto (initial RTO, ms, default 500), min_rto (floor for computed RTOs, default 500), max_rto (cap on the doubled interval, default infinity), rc (default 7), rm (default 16), cache_ttl (RTO cache lifetime, default 600000).
Forget a transaction immediately.
Complete a transaction on receipt of a (validated) response. rtt is only reported when the request was never retransmitted (Karn's algorithm); it then also updates the RTO cache for key.
RTO to use for a new transaction towards Key: the cached value when fresh, otherwise the table default.
Start a transaction and return the first transmission.
Types
-type send_opts() :: #{rto => pos_integer(), rc => pos_integer(), rm => pos_integer(), key => term(), meta => term()}.
-opaque table()
-type txid() :: <<_:96>>.
Functions
Stop retransmitting TxId. A response is still matched until the original transaction deadline; no timeout is reported.
Return the destination and metadata of an outstanding transaction without consuming it.
-spec new() -> table().
Create a table. Options: rto (initial RTO, ms, default 500), min_rto (floor for computed RTOs, default 500), max_rto (cap on the doubled interval, default infinity), rc (default 7), rm (default 16), cache_ttl (RTO cache lifetime, default 600000).
Forget a transaction immediately.
-spec response(txid(), integer(), table()) -> {ok, #{dest := term(), meta := term(), rtt := non_neg_integer() | undefined}, table()} | error.
Complete a transaction on receipt of a (validated) response. rtt is only reported when the request was never retransmitted (Karn's algorithm); it then also updates the RTO cache for key.
-spec rto(term(), integer(), table()) -> pos_integer().
RTO to use for a new transaction towards Key: the cached value when fresh, otherwise the table default.
Start a transaction and return the first transmission.
-spec size(table()) -> non_neg_integer().