Represents a Stun attribute that can be added to a Stun message. More...
Inherited by NobleConnect.Stun.AttributeChangeRequest, NobleConnect.Stun.AttributeData, NobleConnect.Stun.AttributeErrorCode, NobleConnect.Stun.AttributeInt, NobleConnect.Stun.AttributeLong, NobleConnect.Stun.AttributeMappedAddress, NobleConnect.Stun.AttributeRaw, NobleConnect.Stun.AttributeString, NobleConnect.Turn.AttributeAddressFamily, NobleConnect.Turn.AttributeChannelNumber, and NobleConnect.Turn.AttributeProtocol.
Public Member Functions | |
Attribute (AttributeType type) | |
Construct an Attribute of the provided AttributeType More... | |
Attribute (AttributeType type, ref int offset) | |
virtual void | SerializeValues (BufferView buffer, ReadOnlyByteArray transactionID) |
Serialize Attribute values and add them to the buffer. More... | |
void | Serialize (BufferView buffer, ReadOnlyByteArray transactionID) |
Convert this attribute to a bunch of bytes and add them to the provided buffer More... | |
virtual ushort | GetValueSize () |
Get the serialized size of the attribute values More... | |
ushort | GetSize () |
Static Public Member Functions | |
static ushort | DeserializeLength (byte[] buffer, ref int offset) |
Read the Attribute length from a byte array. More... | |
static ushort | GetNumPaddingBytes (int length) |
Calculate padding based on length More... | |
Public Attributes | |
readonly AttributeType | attributeType |
The AttributeType of this Attribute More... | |
Static Public Attributes | |
const int | HEADER_SIZE = 4 |
Represents a Stun attribute that can be added to a Stun message.
All Stun messages are essentially a header followed by zero or more attributes.
Stun attribute format is described in RFC 5389 Section 15
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Value(variable) .... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Attribute Types are defined in RFC 5389 Section 18.2 and RFC 5780 Section 9.1
The format of the Value field is defined for each attribute in RFC 5389 Section 15 and RFC 5780 Section 7
Each STUN attribute ends on a 32-bit (4 byte) boundary. The value in the length field contains the length of the Value part of the attribute, prior to padding, measured in bytes. Attributes whose content is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes.
Attributes are immutable after creation. This is so that they can be safely shared between threads.
In order to maintain immutability Attributes: Do not expose any reference types unless the type is itself immutable. Do not expose arrays, instead they use ReadOnlyCollection. Can have public ValueType properties as long as they are readonly
NobleConnect.Stun.Attribute.Attribute | ( | AttributeType | type | ) |
Construct an Attribute of the provided AttributeType
This is called when constructing a new Attribute to send to a Stun server and also when deserializing an attribute from a Stun server.
type |
NobleConnect.Stun.Attribute.Attribute | ( | AttributeType | type, |
ref int | offset | ||
) |
|
static |
|
static |
Calculate padding based on length
length |
ushort NobleConnect.Stun.Attribute.GetSize | ( | ) |
|
virtual |
Get the serialized size of the attribute values
Child classes override this method to return the size of their custom payload.
Reimplemented in NobleConnect.Stun.AttributeMappedAddress, NobleConnect.Stun.AttributeErrorCode, NobleConnect.Stun.AttributeData, NobleConnect.Turn.AttributeProtocol, NobleConnect.Turn.AttributeChannelNumber, NobleConnect.Turn.AttributeAddressFamily, NobleConnect.Stun.AttributeRaw, NobleConnect.Stun.AttributeString, NobleConnect.Stun.AttributeChangeRequest, NobleConnect.Stun.AttributeInt, and NobleConnect.Stun.AttributeLong.
void NobleConnect.Stun.Attribute.Serialize | ( | BufferView | buffer, |
ReadOnlyByteArray | transactionID | ||
) |
Convert this attribute to a bunch of bytes and add them to the provided buffer
Note that unlike Deserialize, the attributeType is handled here. If the Length is not divisibly by 4 then extra padding is added to account for 32bit alignment as per RFC 5389 Section 15.
buffer |
|
virtual |
Serialize Attribute values and add them to the buffer.
Child classes override this method to do whatever they need to do to turn their custom values into bytes to add to the buffer.
Reimplemented in NobleConnect.Stun.AttributeMappedAddress, NobleConnect.Stun.AttributeErrorCode, NobleConnect.Stun.AttributeData, NobleConnect.Turn.AttributeProtocol, NobleConnect.Turn.AttributeChannelNumber, NobleConnect.Stun.AttributeRaw, NobleConnect.Turn.AttributeAddressFamily, NobleConnect.Stun.AttributeString, NobleConnect.Stun.AttributeInt, NobleConnect.Stun.AttributeLong, and NobleConnect.Stun.AttributeChangeRequest.
readonly AttributeType NobleConnect.Stun.Attribute.attributeType |
The AttributeType of this Attribute
|
static |