STUN module (rfc5389)
stun
STUN messages, attributes, and transaction helpers defined by RFC 5389.
stun
STUN messages, attributes, and transaction helpers defined by RFC 5389.
Classes
| Name | Description |
|---|---|
AddressAttribute | Implements a STUN/TURN attribute that contains a socket address. Handles XOR encoding/decoding for address and port as required by RFC 5389 section 15.2. |
Attribute | The virtual base class for all STUN/TURN attributes. |
ErrorCode | Implements the STUN ERROR-CODE attribute (RFC 5389 section 15.6). Encodes a 3-digit error code as a class (hundreds digit) and number (tens + units digits), plus an optional UTF-8 reason phrase. |
FlagAttribute | Implements a zero-length STUN/TURN flag attribute (presence implies the flag is set). |
Message | STUN/TURN protocol message with method, class, transaction ID, and attributes. |
MessageIntegrity | Implements the STUN MESSAGE-INTEGRITY attribute (RFC 5389 section 15.4). On write, computes an HMAC-SHA1 over the message bytes preceding this attribute when a key is set. On read, captures the raw HMAC bytes and the input bytes needed to verify them later via verifyHmac(). |
StringAttribute | Implements a STUN/TURN attribute that holds an arbitrary byte string. Used for Username, Password, Realm, Nonce, Software, Data, and similar attributes. |
Transaction | STUN request/response transaction with timeout and retry logic. Extends the generic net::Transaction with STUN-specific transaction ID matching and response class inference (Success, Error, or Indication). |
UInt16ListAttribute | Implements a STUN/TURN attribute that holds a list of attribute type codes. Used by the UNKNOWN-ATTRIBUTES attribute (RFC 5389 section 15.9). |
UInt32Attribute | Implements a STUN/TURN attribute that holds a 32-bit integer. |
UInt64Attribute | Implements a STUN/TURN attribute that holds a 64-bit integer. |
UInt8Attribute | Implements a STUN/TURN attribute that holds an 8-bit integer. |
Enumerations
| Name | Description |
|---|---|
AddressFamily | STUN address types as defined in RFC 5389. NB: Undefined is not part of the STUN spec. |
AddressFamily
enum AddressFamilySTUN address types as defined in RFC 5389. NB: Undefined is not part of the STUN spec.
| Value | Description |
|---|---|
Undefined | Not a valid STUN address family; used as a sentinel. |
IPv4 | IPv4 transport address. |
IPv6 | IPv6 transport address. |
Typedefs
| Return | Name | Description |
|---|---|---|
std::string | TransactionID | Fixed-width 12-byte STUN transaction identifier stored as raw bytes. |
TransactionID
std::string TransactionID()Fixed-width 12-byte STUN transaction identifier stored as raw bytes.
Functions
| Return | Name | Description |
|---|---|---|
constexpr bool | isValidMethod | Returns true if methodType corresponds to a recognised STUN/TURN method. Used during parsing to reject malformed packets. |
isValidMethod
constexpr bool isValidMethod(uint16_t methodType)Returns true if methodType corresponds to a recognised STUN/TURN method. Used during parsing to reject malformed packets.
Parameters
methodTypeRaw method bits extracted from the message type field.
Returns
true if the method is one of the defined MethodType values.
Variables
| Return | Name | Description |
|---|---|---|
constexpr int | kAttributeHeaderSize | Bytes in a STUN attribute header. |
constexpr int | kMessageHeaderSize | Bytes in the fixed STUN message header. |
constexpr int | kTransactionIdOffset | Byte offset of the transaction ID inside the message header. |
constexpr int | kTransactionIdLength | Length in bytes of a STUN transaction ID. |
constexpr uint32_t | kMagicCookie | RFC 5389 magic cookie used by modern STUN/TURN messages. |
constexpr int | kMagicCookieLength | Length in bytes of the magic cookie field. |
kAttributeHeaderSize
constexpr int kAttributeHeaderSize = 4Bytes in a STUN attribute header.
kMessageHeaderSize
constexpr int kMessageHeaderSize = 20Bytes in the fixed STUN message header.
kTransactionIdOffset
constexpr int kTransactionIdOffset = 8Byte offset of the transaction ID inside the message header.
kTransactionIdLength
constexpr int kTransactionIdLength = 12Length in bytes of a STUN transaction ID.
kMagicCookie
constexpr uint32_t kMagicCookie = 0x2112A442RFC 5389 magic cookie used by modern STUN/TURN messages.
kMagicCookieLength
constexpr int kMagicCookieLength = sizeof()Length in bytes of the magic cookie field.
