Skip to main content

Module message

Module message 

Source
Expand description

The STUN message itself: header, attributes, and encoding. The STUN message: header, attributes, and encoding.

A Message is a class and method (MessageType), a 96-bit TransactionId, and a list of attributes. Build one by applying Setters, read one back with Getters, and move it across the wire with marshal/unmarshal.

Two attributes are special, because their value covers the encoded message: FINGERPRINT and MESSAGE-INTEGRITY must be appended last and are validated through Checker. That is why Message::raw is kept alongside the parsed attributes — those checks are computed over it rather than over a re-encoding.

Structs§

Message
A STUN message: type, transaction id, and attributes, plus the encoded bytes.
MessageClass
A STUN message class: request, indication, success response or error response.
MessageType
A message’s class and method together, as encoded in the first two header bytes.
Method
A STUN method, such as Binding or one of TURN’s.
TransactionId
A 96-bit transaction id, which pairs a response with its request.

Constants§

ATTRIBUTE_HEADER_SIZE
Bytes of type and length preceding each attribute value.
BINDING_ERROR
Binding error response message type.
BINDING_REQUEST
Common STUN message types. Binding request message type.
BINDING_SUCCESS
Binding success response message type.
CLASS_ERROR_RESPONSE
0b11.
CLASS_INDICATION
0b01.
CLASS_REQUEST
Possible values for message class in STUN Message Type. 0b00.
CLASS_SUCCESS_RESPONSE
0b10.
MAGIC_COOKIE
Fixed value that aids in distinguishing STUN packets from packets of other protocols when STUN is multiplexed with those other protocols on the same Port.
MESSAGE_HEADER_SIZE
Bytes in the STUN message header.
METHOD_ALLOCATE
TURN Allocate: asks a relay for a public address.
METHOD_BINDING
Possible methods for STUN Message.
METHOD_CHANNEL_BIND
TURN ChannelBind: binds a channel number to a peer for compact framing.
METHOD_CONNECT
Methods from RFC 6062.
METHOD_CONNECTION_ATTEMPT
TURN-TCP ConnectionAttempt: notifies the client of an inbound TCP connection.
METHOD_CONNECTION_BIND
TURN-TCP ConnectionBind: associates a new TCP connection with an allocation.
METHOD_CREATE_PERMISSION
TURN CreatePermission: authorizes traffic to and from a peer address.
METHOD_DATA
TURN Data: an indication carrying data from a peer through the relay.
METHOD_REFRESH
TURN Refresh: extends or releases an allocation.
METHOD_SEND
TURN Send: an indication carrying data to a peer through the relay.
TRANSACTION_ID_SIZE
Length of transaction id array (in bytes). 96 bit.

Traits§

Checker
Checker checks *Message attribute.
Getter
Getter parses attribute from *Message.
Setter
Interfaces that are implemented by message attributes, shorthands for them, or helpers for message fields as type or transaction id.

Functions§

is_stun_message
Is_stun_message returns true if b looks like STUN message. Useful for multiplexing. is_stun_message does not guarantee that decoding will be successful.