Documentation ¶
Overview ¶
Package stun represents the common data structures used in creating and parsing STUN messages.
Index ¶
Constants ¶
const ( // MagicCookie is a STUN defined constant for wire representation of messages. MagicCookie uint32 = 0x2112A442 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Address ¶
Address represents an Internet host and port
func NewAddress ¶
NewAddress creates a new address representing a given host and port.
func NewAddressFromString ¶
NewAddressFromString creates a new address from a string representation.
func (*Address) Family ¶
Family provides the STUN family of an address. A value of 1 if IPv4 and 2 if IPv6
type Attribute ¶
type Attribute interface { // Type provides the type of an attribute for encoding it into a STUN message. Type() AttributeType // Encode returns the byte array of the contents of the attribute when it // should be appended to a given STUN message. The message is provided because // some attributes must calculate a checksum based upon the previous contents // of the message. Encode(*Message) ([]byte, error) // Decode instantiates an Attribute from a []byte, when being parsed out of // a byte stream represented by a Parser. The attribute is assumed to have // been parsed correctly when a nil error is returned. Decode([]byte, uint16, *Parser) error // Length returns the length of the encoded attribute body when it would be // encoded as part of a STUN message. Length(*Message) uint16 }
Attribute represents a single serializable STUN attribute.
func DecodeAttribute ¶
func DecodeAttribute(data []byte, attrs AttributeSet, parser *Parser) (*Attribute, error)
DecodeAttribute returns a parsed Attribute representation of data based upon the known AttributeType's mapped by attrs.
func NewUnknownAttribute ¶
func NewUnknownAttribute() Attribute
NewUnknownAttribute Instantiates a new instance of an UnknownAttribute cast to the Attribute Interface.
type AttributeSet ¶
type AttributeSet map[AttributeType]func() Attribute
AttributeSet represents the mapping of known attribute types that a parser will use when parsing a STUN message.
type AttributeType ¶
type AttributeType uint16
AttributeType is the numeric representation of a STUN attribute.
type Credentials ¶
type Credentials struct { // Each conversation has a server-provided Nonce, learned in the first server // response. Nonce []byte // Conversations with a long-term identity will have a Username provided // out-of-band. Username string // Conversations with a long-term identity will have a Realm provided by the // server. Realm string // Conversations validated with a message integrity attribute must have a // password provided out-of-band. Password string }
Credentials represent knowledge about a STUN conversation that is more general than a single message.
func (*Credentials) ForNewConnection ¶
func (c *Credentials) ForNewConnection() *Credentials
ForNewConnection derives a new set of credentials with same authorization, as an existing set, but expecting a new Nonce to be provided.
func (Credentials) String ¶
func (c Credentials) String() string
String represents credentials as a string for debugging.
type Header ¶
type Header struct { // The Purpose of a STUN message is denoted by its Type. Type HeaderType // Length represents the total length of the Message Attributes. Length uint16 // Each STUN message has a unique Id. Id [12]byte }
Header represents the header of a STUN message.
type HeaderType ¶
type HeaderType uint16
HeaderType is a numeric representation of the type of STUN message and whether it is a request, response, indication, or error.
type Message ¶
type Message struct { // A message has a header, with the message ID and type. Header // A message has associated credentials, representing the implicit // conversation the message is part of. Credentials // A message has a set of Attributes, representing the body of the message. Attributes []Attribute }
Message represents a single STUN Message.
func Parse ¶
func Parse(data []byte, credentials *Credentials, attrs AttributeSet) (*Message, error)
Parse creates a Message representation of a data byte stream given provided credentials and a known mapping of Attributes.
func (*Message) GetAttribute ¶
func (m *Message) GetAttribute(typ AttributeType) *Attribute
GetAttribute extracts a single Attribute from the body of a Message
type Parser ¶
type Parser struct { // The message representation generated by the parser. *Message // The credentials used to verify a parsed message. *Credentials // The known STUN attribute types. AttributeSet // The binary data to parse. Data []byte // Which subset of the Data is represented by Message. Offset uint16 }
Parser creates a Message representation of a serialized []byte stream.
type UnknownStunAttribute ¶
type UnknownStunAttribute struct { // ClaimedType holds the AttributeType value of the unknown attribute. ClaimedType AttributeType // Data contains the unparsed body of the Attribute. Data []byte }
UnknownStunAttribute represents a STUN attribute found in a message for which there is no parsed attribute type available.
func (*UnknownStunAttribute) Decode ¶
func (h *UnknownStunAttribute) Decode(data []byte, length uint16, _ *Parser) error
func (*UnknownStunAttribute) Encode ¶
func (h *UnknownStunAttribute) Encode(msg *Message) ([]byte, error)
func (*UnknownStunAttribute) Length ¶
func (h *UnknownStunAttribute) Length(_ *Message) uint16
func (*UnknownStunAttribute) Type ¶
func (h *UnknownStunAttribute) Type() AttributeType