STUN message structure. More...
#include <stun.h>
Public Member Functions | |
| StunMessage () | |
| StunMessage (StunMessageType t) | |
| void | generate_transaction_id () |
| Generate random transaction ID. | |
| StunMessageClass | get_class () const |
| Get message class from type. | |
| StunMethod | get_method () const |
| Get method from type. | |
| bool | is_request () const |
| Check if this is a request. | |
| bool | is_success_response () const |
| Check if this is a success response. | |
| bool | is_error_response () const |
| Check if this is an error response. | |
| const StunAttribute * | find_attribute (StunAttributeType attr_type) const |
| Find attribute by type. | |
| void | add_attribute (StunAttributeType attr_type, const std::vector< uint8_t > &value) |
| Add an attribute. | |
| void | add_xor_mapped_address (const StunMappedAddress &addr) |
| Add XOR-MAPPED-ADDRESS attribute. | |
| void | add_xor_relayed_address (const StunMappedAddress &addr) |
| Add XOR-RELAYED-ADDRESS attribute (TURN) | |
| void | add_error_code (StunErrorCode code, const std::string &reason="") |
| Add ERROR-CODE attribute. | |
| void | add_username (const std::string &username) |
| Add USERNAME attribute. | |
| void | add_realm (const std::string &realm) |
| Add REALM attribute. | |
| void | add_nonce (const std::string &nonce) |
| Add NONCE attribute. | |
| void | add_software (const std::string &software) |
| Add SOFTWARE attribute. | |
| void | add_lifetime (uint32_t seconds) |
| Add LIFETIME attribute (TURN) | |
| void | add_requested_transport (uint8_t protocol) |
| Add REQUESTED-TRANSPORT attribute (TURN) | |
| void | add_xor_peer_address (const StunMappedAddress &addr) |
| Add XOR-PEER-ADDRESS attribute (TURN) | |
| void | add_data (const std::vector< uint8_t > &data) |
| Add DATA attribute (TURN) | |
| void | add_channel_number (uint16_t channel) |
| Add CHANNEL-NUMBER attribute (TURN) | |
| std::optional< StunMappedAddress > | get_xor_mapped_address () const |
| Parse XOR-MAPPED-ADDRESS from attributes. | |
| std::optional< StunMappedAddress > | get_mapped_address () const |
| Parse MAPPED-ADDRESS from attributes (legacy) | |
| std::optional< StunMappedAddress > | get_xor_relayed_address () const |
| Parse XOR-RELAYED-ADDRESS from attributes (TURN) | |
| std::optional< StunMappedAddress > | get_xor_peer_address () const |
| Parse XOR-PEER-ADDRESS from attributes (TURN) | |
| std::optional< StunError > | get_error () const |
| Parse ERROR-CODE from attributes. | |
| std::optional< uint32_t > | get_lifetime () const |
| Parse LIFETIME from attributes (TURN) | |
| std::optional< std::vector< uint8_t > > | get_data () const |
| Parse DATA from attributes (TURN) | |
| std::optional< std::string > | get_realm () const |
| Parse REALM from attributes. | |
| std::optional< std::string > | get_nonce () const |
| Parse NONCE from attributes. | |
| std::vector< uint8_t > | serialize () const |
| Serialize message to bytes. | |
| std::vector< uint8_t > | serialize_with_integrity (const std::string &key) const |
| Serialize message with MESSAGE-INTEGRITY and FINGERPRINT. | |
Static Public Member Functions | |
| static std::optional< StunMessage > | deserialize (const std::vector< uint8_t > &data) |
| Deserialize message from bytes. | |
| static bool | is_stun_message (const std::vector< uint8_t > &data) |
| Check if data looks like a STUN message. | |
Public Attributes | |
| StunMessageType | type |
| std::array< uint8_t, STUN_TRANSACTION_ID_SIZE > | transaction_id |
| std::vector< StunAttribute > | attributes |
|
inline |
Definition at line 235 of file stun.h.
References transaction_id.
|
inlineexplicit |
Definition at line 239 of file stun.h.
References generate_transaction_id().
| void librats::StunMessage::add_attribute | ( | StunAttributeType | attr_type, |
| const std::vector< uint8_t > & | value | ||
| ) |
Add an attribute.
| void librats::StunMessage::add_channel_number | ( | uint16_t | channel | ) |
Add CHANNEL-NUMBER attribute (TURN)
| void librats::StunMessage::add_data | ( | const std::vector< uint8_t > & | data | ) |
Add DATA attribute (TURN)
| void librats::StunMessage::add_error_code | ( | StunErrorCode | code, |
| const std::string & | reason = "" |
||
| ) |
Add ERROR-CODE attribute.
| void librats::StunMessage::add_lifetime | ( | uint32_t | seconds | ) |
Add LIFETIME attribute (TURN)
| void librats::StunMessage::add_nonce | ( | const std::string & | nonce | ) |
Add NONCE attribute.
| void librats::StunMessage::add_realm | ( | const std::string & | realm | ) |
Add REALM attribute.
| void librats::StunMessage::add_requested_transport | ( | uint8_t | protocol | ) |
Add REQUESTED-TRANSPORT attribute (TURN)
| void librats::StunMessage::add_software | ( | const std::string & | software | ) |
Add SOFTWARE attribute.
| void librats::StunMessage::add_username | ( | const std::string & | username | ) |
Add USERNAME attribute.
| void librats::StunMessage::add_xor_mapped_address | ( | const StunMappedAddress & | addr | ) |
Add XOR-MAPPED-ADDRESS attribute.
| void librats::StunMessage::add_xor_peer_address | ( | const StunMappedAddress & | addr | ) |
Add XOR-PEER-ADDRESS attribute (TURN)
| void librats::StunMessage::add_xor_relayed_address | ( | const StunMappedAddress & | addr | ) |
Add XOR-RELAYED-ADDRESS attribute (TURN)
|
static |
Deserialize message from bytes.
| const StunAttribute * librats::StunMessage::find_attribute | ( | StunAttributeType | attr_type | ) | const |
Find attribute by type.
| void librats::StunMessage::generate_transaction_id | ( | ) |
Generate random transaction ID.
Referenced by StunMessage().
| StunMessageClass librats::StunMessage::get_class | ( | ) | const |
Get message class from type.
Referenced by is_error_response(), is_request(), and is_success_response().
| std::optional< std::vector< uint8_t > > librats::StunMessage::get_data | ( | ) | const |
Parse DATA from attributes (TURN)
| std::optional< StunError > librats::StunMessage::get_error | ( | ) | const |
Parse ERROR-CODE from attributes.
| std::optional< uint32_t > librats::StunMessage::get_lifetime | ( | ) | const |
Parse LIFETIME from attributes (TURN)
| std::optional< StunMappedAddress > librats::StunMessage::get_mapped_address | ( | ) | const |
Parse MAPPED-ADDRESS from attributes (legacy)
| StunMethod librats::StunMessage::get_method | ( | ) | const |
Get method from type.
| std::optional< std::string > librats::StunMessage::get_nonce | ( | ) | const |
Parse NONCE from attributes.
| std::optional< std::string > librats::StunMessage::get_realm | ( | ) | const |
Parse REALM from attributes.
| std::optional< StunMappedAddress > librats::StunMessage::get_xor_mapped_address | ( | ) | const |
Parse XOR-MAPPED-ADDRESS from attributes.
| std::optional< StunMappedAddress > librats::StunMessage::get_xor_peer_address | ( | ) | const |
Parse XOR-PEER-ADDRESS from attributes (TURN)
| std::optional< StunMappedAddress > librats::StunMessage::get_xor_relayed_address | ( | ) | const |
Parse XOR-RELAYED-ADDRESS from attributes (TURN)
|
inline |
Check if this is an error response.
Definition at line 259 of file stun.h.
References librats::ErrorResponse, and get_class().
|
inline |
Check if this is a request.
Definition at line 253 of file stun.h.
References get_class(), and librats::Request.
|
static |
Check if data looks like a STUN message.
|
inline |
Check if this is a success response.
Definition at line 256 of file stun.h.
References get_class(), and librats::SuccessResponse.
| std::vector< uint8_t > librats::StunMessage::serialize | ( | ) | const |
Serialize message to bytes.
| std::vector< uint8_t > librats::StunMessage::serialize_with_integrity | ( | const std::string & | key | ) | const |
Serialize message with MESSAGE-INTEGRITY and FINGERPRINT.
| std::vector<StunAttribute> librats::StunMessage::attributes |
| std::array<uint8_t, STUN_TRANSACTION_ID_SIZE> librats::StunMessage::transaction_id |
Definition at line 232 of file stun.h.
Referenced by StunMessage().
| StunMessageType librats::StunMessage::type |