Inherits NobleConnect.IMessage.
Public Member Functions | |
Message (MessageHeader header, List< Attribute > attributes=null, int retryCount=0) | |
Construct a Message with the provided MessageHeader and optional Attributes More... | |
Message (MessageClass messageClass, MessageMethod messageMethod, List< Attribute > attributes=null) | |
Construct a Message with the provided MessageClass and MessageMethod with optional Attributes More... | |
T | GetAttribute< T > (AttributeType type) |
Get the first Attribute of the provided AttributeType from this Message. More... | |
AttributeRaw | GetMessageIntegrity () |
Get the first Attribute of type MessageIntegrity from this Message. More... | |
AttributeXORMappedAddress | GetXORMappedAddress () |
Get the first Attribute of type XORMappedAddress from this Message. More... | |
AttributeMappedAddress | GetMappedAddress () |
Get the first Attribute of type MappedAddress from this Message. More... | |
AttributeString | GetUsername () |
Get the first Attribute of type Username from this Message. More... | |
AttributeString | GetRealm () |
Get the first Attribute of type Realm from this Message. More... | |
AttributeString | GetNonce () |
Get the first Attribute of type Nonce from this Message. More... | |
AttributeErrorCode | GetErrorCode () |
Get the first Attribute of type ErrorCode from this Message. More... | |
void | Serialize (BufferView buffer) |
Serialize the Message to the provided Buffer for sending to a Stun server More... | |
Static Public Member Functions | |
static void | Serialize (BufferView buffer, MessageHeader header, IEnumerable< Attribute > attributes, ushort overrideValueLength=0) |
Serialize a MessageHeader and Attribute list to the provided buffer. More... | |
static void | AddCredentials (Credentials credentials, MessageHeader header, List< Attribute > attributeList) |
Add long-term authentication credentials to list of attributes. More... | |
static ushort | CalculateValueLength (IEnumerable< Attribute > attributeList) |
Calculate the total byte length of the provided attribute list. More... | |
static bool | IsStunMessage (byte[] bytes, int offset, int bytesRead) |
Inspect some bytes and determine if they represent a Stun message More... | |
Public Attributes | |
readonly MessageHeader | header |
This Message's MessageHeader. More... | |
readonly ReadOnlyCollection< Attribute > | attributes |
The message attributes. More... | |
int | retryCount = 0 |
Properties | |
MessageType | MessageType [get] |
The MessageType of this Message More... | |
MessageClass | MessageClass [get] |
The MessageClass of this Message More... | |
MessageMethod | MessageMethod [get] |
The MessageMethod of this Message More... | |
override ReadOnlyByteArray | TransactionID [get] |
The transactionID of this Message More... | |
Messages are comprised of a MessageHeader followed by zero or more Attributes This class also provides a convenient method for adding Credentials to a message. Messages are immutable so that they can be safely passed to another thread.
NobleConnect.Stun.Message.Message | ( | MessageHeader | header, |
List< Attribute > | attributes = null , |
||
int | retryCount = 0 |
||
) |
Construct a Message with the provided MessageHeader and optional Attributes
header | |
attributes |
NobleConnect.Stun.Message.Message | ( | MessageClass | messageClass, |
MessageMethod | messageMethod, | ||
List< Attribute > | attributes = null |
||
) |
Construct a Message with the provided MessageClass and MessageMethod with optional Attributes
A MessageHeader is constructed from the provided MessageClass and MessageMethod.
messageClass | |
messageMethod | |
attributes |
|
static |
Add long-term authentication credentials to list of attributes.
To use this first construct a MessageHeader and the full list of Attributes to send. Then pass your Credentials, MessageHeader, and Attribute list into this method. Several attributes will be added to the attribute list (username, realm, nonce, and message integrity). The header and attribute list can then be used to construct a new message that can be properly authenticated by the Stun server. This MUST be called after all other Attributes have already been added to the list. If you add an Attribute to the list after calling this method then the message integrity check will fail on the Stun server and the message will be rejected. See RFC 5389 Section 10.2 for details about the long-term authentication process.
credentials |
|
static |
Calculate the total byte length of the provided attribute list.
This accounts for any padding required to keep bytes on 32bit alignment.
T NobleConnect.Stun.Message.GetAttribute< T > | ( | AttributeType | type | ) |
Get the first Attribute of the provided AttributeType from this Message.
T | The class to cast the Attribute as. |
type | The AttributeType to search for |
T | : | Attribute |
AttributeErrorCode NobleConnect.Stun.Message.GetErrorCode | ( | ) |
AttributeMappedAddress NobleConnect.Stun.Message.GetMappedAddress | ( | ) |
AttributeRaw NobleConnect.Stun.Message.GetMessageIntegrity | ( | ) |
AttributeString NobleConnect.Stun.Message.GetNonce | ( | ) |
AttributeString NobleConnect.Stun.Message.GetRealm | ( | ) |
AttributeString NobleConnect.Stun.Message.GetUsername | ( | ) |
AttributeXORMappedAddress NobleConnect.Stun.Message.GetXORMappedAddress | ( | ) |
|
static |
Inspect some bytes and determine if they represent a Stun message
This is accomplished by checking that: The first two bits are 0. The COOKIE is present and correct. TODO: Check that the fingerprint is present and correct (when enabled)
bytes | |
bytesRead |
void NobleConnect.Stun.Message.Serialize | ( | BufferView | buffer | ) |
|
static |
Serialize a MessageHeader and Attribute list to the provided buffer.
Calling the Serialize() method on a message instance will call this static method and pass in the Message's MessageHeader and attributes in order to serialize them to the provided buffer.
This method is also called directly while crafting the AttributeMessageIntegrity to partially serialize a Message as part of generating the integrity hash. The value length can be overridden because AttributeMessageIntegrity requires the length in the header to include the length of the AttributeMessageIntegrity itself even though it is not included in the attribute list for partial serialization.
buffer | |
header | |
attributes | |
overrideValueLength |
readonly ReadOnlyCollection<Attribute> NobleConnect.Stun.Message.attributes |
The message attributes.
readonly MessageHeader NobleConnect.Stun.Message.header |
This Message's MessageHeader.
int NobleConnect.Stun.Message.retryCount = 0 |
|
get |
The MessageClass of this Message
|
get |
The MessageMethod of this Message
|
get |
The MessageType of this Message
|
get |
The transactionID of this Message