Home
STUN module (rfc5389)

Message

STUN/TURN protocol message with method, class, transaction ID, and attributes.

Message

#include <icy/stun/message.h>
class Message

Defined in src/stun/include/icy/stun/message.h:31

Inherits: IPacket Subclassed by: Request

STUN/TURN protocol message with method, class, transaction ID, and attributes.

List of all members

NameKindOwner
MessagefunctionDeclared here
MessagefunctionDeclared here
MessagefunctionDeclared here
MessagefunctionDeclared here
operator=functionDeclared here
operator=functionDeclared here
~MessagefunctionDeclared here
clonefunctionDeclared here
setClassfunctionDeclared here
setMethodfunctionDeclared here
setTransactionIDfunctionDeclared here
classTypefunctionDeclared here
methodTypefunctionDeclared here
transactionIDfunctionDeclared here
sizefunctionDeclared here
methodStringfunctionDeclared here
classStringfunctionDeclared here
errorStringfunctionDeclared here
addfunctionDeclared here
addfunctionDeclared here
getfunctionDeclared here
getfunctionDeclared here
readfunctionDeclared here
writefunctionDeclared here
toStringfunctionDeclared here
printfunctionDeclared here
classNamefunctionDeclared here
_classvariableDeclared here
_methodvariableDeclared here
_sizevariableDeclared here
_transactionIDvariableDeclared here
_attrsvariableDeclared here
MethodTypeenumDeclared here
ClassTypeenumDeclared here
ErrorCodesenumDeclared here
computeBodySizefunctionDeclared here
operator<<friendInherited from IPacket
opaquevariableInherited from IPacket
infovariableInherited from IPacket
flagsvariableInherited from IPacket
IPacketfunctionInherited from IPacket
IPacketfunctionInherited from IPacket
operator=functionInherited from IPacket
clonefunctionInherited from IPacket
~IPacketfunctionInherited from IPacket
readfunctionInherited from IPacket
writefunctionInherited from IPacket
sizefunctionInherited from IPacket
hasDatafunctionInherited from IPacket
datafunctionInherited from IPacket
constDatafunctionInherited from IPacket
classNamefunctionInherited from IPacket
printfunctionInherited from IPacket

Inherited from IPacket

KindNameDescription
friendoperator<< inlineStream insertion operator; delegates to print().
variableopaqueOptional type-safe context data. Use std::any_cast to retrieve. Lifetime of the stored value is tied to the packet's lifetime.
variableinfoOptional extra information about the packet.
variableflagsProvides basic information about the packet.
functionIPacket inline
functionIPacket inlineCopy constructor; clones the info object if present.
functionoperator= inlineCopy assignment; clones the info object if present.
functionclone virtual constReturns a heap-allocated deep copy of this packet.
function~IPacket virtualDefaulted destructor.
functionread virtualRead/parse to the packet from the given input buffer. The number of bytes read is returned.
functionwrite virtual constCopy/generate to the packet given output buffer. The number of bytes written can be obtained from the buffer.
functionsize virtual const inlineThe size of the packet in bytes.
functionhasData virtual const inlineReturns true if the packet has a non-null data pointer.
functiondata virtual const inlineThe packet data pointer for buffered packets.
functionconstData virtual const inlineThe const packet data pointer for buffered packets.
functionclassName virtual constReturns the class name of this packet type for logging and diagnostics.
functionprint virtual const inlinePrints a human-readable representation to the given stream.

Public Methods

ReturnNameDescription
MessageConstructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.
MessageConstructs a message with explicit class and method.
MessageDeep-copy constructor; clones all attributes.
Message noexceptMove constructor.
Message &operator=Deep-copy assignment; clones all attributes from that.
Message &operator= noexceptMove assignment.
std::unique_ptr< IPacket >clone virtual const override
voidsetClassSets the message class field.
voidsetMethodSets the message method field.
voidsetTransactionIDSets the 12-byte transaction ID.
ClassTypeclassType const
MethodTypemethodType const
const TransactionID &transactionID const inline
size_tsize virtual const inline override
std::stringmethodString const
std::stringclassString const
std::stringerrorString constMaps a numeric error code to its canonical string description.
T &add inlineConstructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration.
voidaddAppends an attribute to the message, taking ownership via unique_ptr.
Attribute *get constReturns the Nth attribute of the given type, or nullptr if not found.
T *get const inlineType-safe attribute accessor using the concrete attribute's TypeID.
ssize_tread virtual overrideParses a STUN/TURN packet from the given buffer.
voidwrite virtual const overrideSerialises this message into a STUN/TURN wire-format packet.
std::stringtoString const
voidprint virtual const overrideWrites the same representation as toString() to the given stream.
const char *className virtual const inline overrideReturns the class name of this packet type for logging and diagnostics.

Message

Message()

Defined in src/stun/include/icy/stun/message.h:92

Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.


Message

Message(ClassType clss, MethodType meth)

Defined in src/stun/include/icy/stun/message.h:97

Constructs a message with explicit class and method.

Parameters

  • clss Message class (Request, Indication, SuccessResponse, or ErrorResponse).

  • meth Message method (Binding, Allocate, Refresh, etc.).


Message

Message(const Message & that)

Defined in src/stun/include/icy/stun/message.h:100

Deep-copy constructor; clones all attributes.


Message

noexcept

Message(Message && that) noexcept

Defined in src/stun/include/icy/stun/message.h:103

Move constructor.


operator=

Message & operator=(const Message & that)

Defined in src/stun/include/icy/stun/message.h:106

Deep-copy assignment; clones all attributes from that.


operator=

noexcept

Message & operator=(Message && that) noexcept

Defined in src/stun/include/icy/stun/message.h:109

Move assignment.


clone

virtual const override

virtual std::unique_ptr< IPacket > clone() const override

Defined in src/stun/include/icy/stun/message.h:114

Returns

A heap-allocated deep copy of this message.

Reimplements

setClass

void setClass(ClassType type)

Defined in src/stun/include/icy/stun/message.h:118

Sets the message class field.

Parameters

  • type One of Request, Indication, SuccessResponse, ErrorResponse.

setMethod

void setMethod(MethodType type)

Defined in src/stun/include/icy/stun/message.h:122

Sets the message method field.

Parameters

  • type One of the MethodType enumerators.

setTransactionID

void setTransactionID(const std::string & id)

Defined in src/stun/include/icy/stun/message.h:126

Sets the 12-byte transaction ID.

Parameters

  • id Must be exactly kTransactionIdLength (12) bytes.

classType

const

ClassType classType() const

Defined in src/stun/include/icy/stun/message.h:129

Returns

The message class.


methodType

const

MethodType methodType() const

Defined in src/stun/include/icy/stun/message.h:132

Returns

The message method.


transactionID

const inline

inline const TransactionID & transactionID() const

Defined in src/stun/include/icy/stun/message.h:135

Returns

Reference to the 12-byte transaction ID string.


size

virtual const inline override

virtual inline size_t size() const override

Defined in src/stun/include/icy/stun/message.h:138

Returns

Total body size in bytes (sum of padded attribute headers and bodies).

Reimplements

methodString

const

std::string methodString() const

Defined in src/stun/include/icy/stun/message.h:141

Returns

Human-readable method name (e.g. "BINDING", "ALLOCATE").


classString

const

std::string classString() const

Defined in src/stun/include/icy/stun/message.h:144

Returns

Human-readable class name (e.g. "Request", "SuccessResponse").


errorString

const

std::string errorString(uint16_t errorCode) const

Defined in src/stun/include/icy/stun/message.h:149

Maps a numeric error code to its canonical string description.

Parameters

  • errorCode One of the ErrorCodes enumerators.

Returns

Human-readable error string, or "UnknownError" if not recognised.


add

inline

template<typename T> inline T & add()

Defined in src/stun/include/icy/stun/message.h:156

Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration.

Parameters

  • T Concrete attribute type (e.g. stun::Lifetime, stun::XorMappedAddress).

Returns

Reference to the newly added attribute.


add

void add(std::unique_ptr< Attribute > attr)

Defined in src/stun/include/icy/stun/message.h:166

Appends an attribute to the message, taking ownership via unique_ptr.

Parameters


get

const

Attribute * get(Attribute::Type type, int index = 0) const

Defined in src/stun/include/icy/stun/message.h:172

Returns the Nth attribute of the given type, or nullptr if not found.

Parameters

  • type Attribute type code to search for.

  • index Zero-based occurrence index (0 = first match).

Returns

Raw pointer to the attribute (owned by this message), or nullptr.


get

const inline

template<typename T> inline T * get(int index = 0) const

Defined in src/stun/include/icy/stun/message.h:179

Type-safe attribute accessor using the concrete attribute's TypeID.

Parameters

  • T Concrete attribute type (must define TypeID).

Parameters

  • index Zero-based occurrence index.

Returns

Pointer to T, or nullptr if the attribute is absent.


read

virtual override

virtual ssize_t read(const ConstBuffer & buf) override

Defined in src/stun/include/icy/stun/message.h:188

Parses a STUN/TURN packet from the given buffer.

Parameters

  • buf Buffer containing at least one complete STUN message.

Returns

Number of bytes consumed, or 0 on parse failure.

Reimplements

write

virtual const override

virtual void write(Buffer & buf) const override

Defined in src/stun/include/icy/stun/message.h:192

Serialises this message into a STUN/TURN wire-format packet.

Parameters

  • buf Destination buffer; data is appended.
Reimplements

toString

const

std::string toString() const

Defined in src/stun/include/icy/stun/message.h:195

Returns

A concise string representation for logging (method, transaction ID, attribute types).


print

virtual const override

virtual void print(std::ostream & os) const override

Defined in src/stun/include/icy/stun/message.h:199

Writes the same representation as toString() to the given stream.

Parameters

  • os Output stream.
Reimplements

className

virtual const inline override

virtual inline const char * className() const override

Defined in src/stun/include/icy/stun/message.h:201

Returns the class name of this packet type for logging and diagnostics.

Reimplements

Protected Attributes

ReturnNameDescription
uint16_t_class
uint16_t_method
uint16_t_sizeSet by read(); write() uses computeBodySize() instead.
TransactionID_transactionID
std::vector< std::unique_ptr< Attribute > >_attrs

_class

uint16_t _class

Defined in src/stun/include/icy/stun/message.h:204


_method

uint16_t _method

Defined in src/stun/include/icy/stun/message.h:205


_size

uint16_t _size

Defined in src/stun/include/icy/stun/message.h:206

Set by read(); write() uses computeBodySize() instead.


_transactionID

TransactionID _transactionID

Defined in src/stun/include/icy/stun/message.h:207


_attrs

std::vector< std::unique_ptr< Attribute > > _attrs

Defined in src/stun/include/icy/stun/message.h:208

Public Types


MethodType

enum MethodType

Defined in src/stun/include/icy/stun/message.h:34

ValueDescription
Undefineddefault error type
BindingSTUN.
AllocateTURN.
Refresh
SendIndication(only indication semantics defined)
DataIndication(only indication semantics defined)
CreatePermission(only request/response semantics defined)
ChannelBind(only request/response semantics defined)
ConnectTURN TCP RFC 6062.
ConnectionBind
ConnectionAttempt

ClassType

enum ClassType

Defined in src/stun/include/icy/stun/message.h:55

ValueDescription
Request
Indication
SuccessResponse
ErrorResponse

ErrorCodes

enum ErrorCodes

Defined in src/stun/include/icy/stun/message.h:63

ValueDescription
TryAlternate
BadRequest
NotAuthorized
Forbidden
UnknownAttribute
StaleCredentials
IntegrityCheckFailure
MissingUsername
UseTLS
AllocationMismatch
StaleNonce
WrongCredentials
UnsupportedTransport
AllocationQuotaReached
RoleConflict
ServerError
InsufficientCapacity
GlobalFailure
ConnectionAlreadyExistsTURN TCP.
ConnectionTimeoutOrFailure

Private Methods

ReturnNameDescription
uint16_tcomputeBodySize constComputes the wire body size from the current attribute list.

computeBodySize

const

uint16_t computeBodySize() const

Defined in src/stun/include/icy/stun/message.h:212

Computes the wire body size from the current attribute list.