The Stun MessageHeader. The format of the header is specified in RFC 5389 Section 6. More...
Public Member Functions | |
MessageHeader (MessageType messageType, ushort valueLength=0, ReadOnlyByteArray transactionID=null) | |
Construct a MessageHeader with the provided MessageType and optional valueLength and transactionID More... | |
MessageHeader (MessageType type, byte[] buffer, ref int bufferIndex, int bufferLength) | |
Construct a MessageHeader from some bytes More... | |
void | Serialize (BufferView buffer, ushort valueLength) |
Serialize this MessageHeader to the provided Buffer More... | |
Static Public Member Functions | |
static byte[] | GenerateTransationID () |
Generates the TransactionID More... | |
Public Attributes | |
readonly MessageType | messageType |
Stores the MessageType that represents the MessageMethod and MessageClass of a Message More... | |
readonly ushort | valueLength |
The length in bytes of the Attributes in the Message More... | |
readonly ReadOnlyByteArray | transactionID |
The transactionID as bytes More... | |
Static Public Attributes | |
const ushort | SIZE = 20 |
Serialiazed size in bytes More... | |
const ushort | TRANSACTION_ID_SIZE = 12 |
static RNGCryptoServiceProvider | random = new RNGCryptoServiceProvider() |
Our cryptographic randomness provider More... | |
The Stun MessageHeader. The format of the header is specified in RFC 5389 Section 6.
The layout is described by the diagram below: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0 0| STUN Message Type | Message Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Magic Cookie | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Transaction ID(96 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The message length contains the size, in bytes, of the message not including the 20-byte STUN header
The magic cookie field contains the COOKIE from Stun.Controller in network byte order
This class provides methods to generate the transaction ID as well as serialize and deserialize a MessageHeader for sending / receiving over the network.
NobleConnect.Stun.MessageHeader.MessageHeader | ( | MessageType | messageType, |
ushort | valueLength = 0 , |
||
ReadOnlyByteArray | transactionID = null |
||
) |
Construct a MessageHeader with the provided MessageType and optional valueLength and transactionID
This is called by the Message constructor when constructing a new outgoing Message for sending to a Stun server.
messageType | |
valueLength | |
transactionID |
NobleConnect.Stun.MessageHeader.MessageHeader | ( | MessageType | type, |
byte[] | buffer, | ||
ref int | bufferIndex, | ||
int | bufferLength | ||
) |
Construct a MessageHeader from some bytes
This is called by child classes when deserializing.
buffer | |
bufferIndex | |
bufferLength |
|
static |
Generates the TransactionID
void NobleConnect.Stun.MessageHeader.Serialize | ( | BufferView | buffer, |
ushort | valueLength | ||
) |
Serialize this MessageHeader to the provided Buffer
buffer | |
valueLength |
readonly MessageType NobleConnect.Stun.MessageHeader.messageType |
Stores the MessageType that represents the MessageMethod and MessageClass of a Message
|
static |
Our cryptographic randomness provider
|
static |
Serialiazed size in bytes
|
static |
readonly ReadOnlyByteArray NobleConnect.Stun.MessageHeader.transactionID |
The transactionID as bytes
The transaction ID is a 96-bit identifier, used to uniquely identify STUN transactions. For request/response transactions, the transaction ID is chosen by the STUN client for the request and echoed by the server in the response. For indications, it is chosen by the agent sending the indication. It primarily serves to correlate requests with responses, though it also plays a small role in helping to prevent certain types of attacks. The transaction ID is uniformly and randomly chosen from the interval 0 .. 2**96-1, and is cryptographically random.
readonly ushort NobleConnect.Stun.MessageHeader.valueLength |
The length in bytes of the Attributes in the Message