View Source ExSTUN.Message (ex_stun v0.2.0)
STUN Message
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0| STUN Message Type | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Magic Cookie |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Transaction ID (96 bits) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 2: Format of STUN Message Header
Summary
Functions
Adds attribute to a message.
Authenticates a message.
Decodes a binary into a STUN message.
Encodes a STUN message into a binary.
Gets all attributes of given type from the message.
Gets first attribute of given type from a message.
Create longe-term authentication key.
Creates a new STUN message with a random transaction id.
Creates a new STUN message.
Types
@type decode_error_t() ::
:not_enough_data
| :malformed_header
| :malformed_type
| :data_after_fingerprint
| :malformed_attr_padding
Possible decode/1
error reasons.
:not_enough_data
- provided binary is less than 20 bytes:malformed_header
- improper message header e.g. invalid cookie:unknown_method
- unknown message type method:data_after_finderprint
- fingerprint attribute is followed by other forbidden attributes:malformed_attr_padding
- one or more attributes are not followed by long enough padding or padding is not 0.
@type t() :: %ExSTUN.Message{ attributes: [ExSTUN.Message.RawAttribute.t()], fingerprint: boolean(), integrity: {boolean(), binary()}, len_to_int: integer(), raw: binary(), transaction_id: integer(), type: ExSTUN.Message.Type.t() }
Functions
@spec add_attribute(t(), ExSTUN.Message.RawAttribute.t()) :: t()
Adds attribute to a message.
Authenticates a message.
key
depends on the authentication method.
When authenticating using short-term mechanism, it is simply a password.
When authenticating using long-term mechanism, use lt_key/3
to obtain the key.
Presence of username, realm and nonce attributes is not checked. Depending on the authentication method and its context (client/server side), user has to perform those checks on their own.
@spec decode(binary()) :: {:ok, t()} | {:error, decode_error_t()}
Decodes a binary into a STUN message.
Encodes a STUN message into a binary.
Gets all attributes of given type from the message.
attr_mod
is a module implementing ExSTUN.Message.Attribute
behaviour.
Returns nil
if there is no attribute of given type.
Gets first attribute of given type from a message.
attr_mod
is a module implementing ExSTUN.Message.Attribute
behaviour.
Returns nil
if there is no attribute of given type.
Create longe-term authentication key.
@spec new(ExSTUN.Message.Type.t(), [struct()]) :: t()
Creates a new STUN message with a random transaction id.
@spec new(integer(), ExSTUN.Message.Type.t(), [struct()]) :: t()
Creates a new STUN message.