Back to Site
Loading...
Searching...
No Matches
librats::StunMessage Struct Reference

STUN message structure. More...

#include <stun.h>

Collaboration diagram for librats::StunMessage:
[legend]

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 StunAttributefind_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< StunMappedAddressget_xor_mapped_address () const
 Parse XOR-MAPPED-ADDRESS from attributes.
 
std::optional< StunMappedAddressget_mapped_address () const
 Parse MAPPED-ADDRESS from attributes (legacy)
 
std::optional< StunMappedAddressget_xor_relayed_address () const
 Parse XOR-RELAYED-ADDRESS from attributes (TURN)
 
std::optional< StunMappedAddressget_xor_peer_address () const
 Parse XOR-PEER-ADDRESS from attributes (TURN)
 
std::optional< StunErrorget_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< StunMessagedeserialize (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_SIZEtransaction_id
 
std::vector< StunAttributeattributes
 

Detailed Description

STUN message structure.

Definition at line 230 of file stun.h.

Constructor & Destructor Documentation

◆ StunMessage() [1/2]

librats::StunMessage::StunMessage ( )
inline

Definition at line 235 of file stun.h.

References transaction_id.

◆ StunMessage() [2/2]

librats::StunMessage::StunMessage ( StunMessageType  t)
inlineexplicit

Definition at line 239 of file stun.h.

References generate_transaction_id().

Member Function Documentation

◆ add_attribute()

void librats::StunMessage::add_attribute ( StunAttributeType  attr_type,
const std::vector< uint8_t > &  value 
)

Add an attribute.

◆ add_channel_number()

void librats::StunMessage::add_channel_number ( uint16_t  channel)

Add CHANNEL-NUMBER attribute (TURN)

◆ add_data()

void librats::StunMessage::add_data ( const std::vector< uint8_t > &  data)

Add DATA attribute (TURN)

◆ add_error_code()

void librats::StunMessage::add_error_code ( StunErrorCode  code,
const std::string &  reason = "" 
)

Add ERROR-CODE attribute.

◆ add_lifetime()

void librats::StunMessage::add_lifetime ( uint32_t  seconds)

Add LIFETIME attribute (TURN)

◆ add_nonce()

void librats::StunMessage::add_nonce ( const std::string &  nonce)

Add NONCE attribute.

◆ add_realm()

void librats::StunMessage::add_realm ( const std::string &  realm)

Add REALM attribute.

◆ add_requested_transport()

void librats::StunMessage::add_requested_transport ( uint8_t  protocol)

Add REQUESTED-TRANSPORT attribute (TURN)

◆ add_software()

void librats::StunMessage::add_software ( const std::string &  software)

Add SOFTWARE attribute.

◆ add_username()

void librats::StunMessage::add_username ( const std::string &  username)

Add USERNAME attribute.

◆ add_xor_mapped_address()

void librats::StunMessage::add_xor_mapped_address ( const StunMappedAddress addr)

Add XOR-MAPPED-ADDRESS attribute.

◆ add_xor_peer_address()

void librats::StunMessage::add_xor_peer_address ( const StunMappedAddress addr)

Add XOR-PEER-ADDRESS attribute (TURN)

◆ add_xor_relayed_address()

void librats::StunMessage::add_xor_relayed_address ( const StunMappedAddress addr)

Add XOR-RELAYED-ADDRESS attribute (TURN)

◆ deserialize()

static std::optional< StunMessage > librats::StunMessage::deserialize ( const std::vector< uint8_t > &  data)
static

Deserialize message from bytes.

◆ find_attribute()

const StunAttribute * librats::StunMessage::find_attribute ( StunAttributeType  attr_type) const

Find attribute by type.

◆ generate_transaction_id()

void librats::StunMessage::generate_transaction_id ( )

Generate random transaction ID.

Referenced by StunMessage().

◆ get_class()

StunMessageClass librats::StunMessage::get_class ( ) const

Get message class from type.

Referenced by is_error_response(), is_request(), and is_success_response().

◆ get_data()

std::optional< std::vector< uint8_t > > librats::StunMessage::get_data ( ) const

Parse DATA from attributes (TURN)

◆ get_error()

std::optional< StunError > librats::StunMessage::get_error ( ) const

Parse ERROR-CODE from attributes.

◆ get_lifetime()

std::optional< uint32_t > librats::StunMessage::get_lifetime ( ) const

Parse LIFETIME from attributes (TURN)

◆ get_mapped_address()

std::optional< StunMappedAddress > librats::StunMessage::get_mapped_address ( ) const

Parse MAPPED-ADDRESS from attributes (legacy)

◆ get_method()

StunMethod librats::StunMessage::get_method ( ) const

Get method from type.

◆ get_nonce()

std::optional< std::string > librats::StunMessage::get_nonce ( ) const

Parse NONCE from attributes.

◆ get_realm()

std::optional< std::string > librats::StunMessage::get_realm ( ) const

Parse REALM from attributes.

◆ get_xor_mapped_address()

std::optional< StunMappedAddress > librats::StunMessage::get_xor_mapped_address ( ) const

Parse XOR-MAPPED-ADDRESS from attributes.

◆ get_xor_peer_address()

std::optional< StunMappedAddress > librats::StunMessage::get_xor_peer_address ( ) const

Parse XOR-PEER-ADDRESS from attributes (TURN)

◆ get_xor_relayed_address()

std::optional< StunMappedAddress > librats::StunMessage::get_xor_relayed_address ( ) const

Parse XOR-RELAYED-ADDRESS from attributes (TURN)

◆ is_error_response()

bool librats::StunMessage::is_error_response ( ) const
inline

Check if this is an error response.

Definition at line 259 of file stun.h.

References librats::ErrorResponse, and get_class().

◆ is_request()

bool librats::StunMessage::is_request ( ) const
inline

Check if this is a request.

Definition at line 253 of file stun.h.

References get_class(), and librats::Request.

◆ is_stun_message()

static bool librats::StunMessage::is_stun_message ( const std::vector< uint8_t > &  data)
static

Check if data looks like a STUN message.

◆ is_success_response()

bool librats::StunMessage::is_success_response ( ) const
inline

Check if this is a success response.

Definition at line 256 of file stun.h.

References get_class(), and librats::SuccessResponse.

◆ serialize()

std::vector< uint8_t > librats::StunMessage::serialize ( ) const

Serialize message to bytes.

◆ serialize_with_integrity()

std::vector< uint8_t > librats::StunMessage::serialize_with_integrity ( const std::string &  key) const

Serialize message with MESSAGE-INTEGRITY and FINGERPRINT.

Member Data Documentation

◆ attributes

std::vector<StunAttribute> librats::StunMessage::attributes

Definition at line 233 of file stun.h.

◆ transaction_id

std::array<uint8_t, STUN_TRANSACTION_ID_SIZE> librats::StunMessage::transaction_id

Definition at line 232 of file stun.h.

Referenced by StunMessage().

◆ type

StunMessageType librats::StunMessage::type

Definition at line 231 of file stun.h.


The documentation for this struct was generated from the following file: