stun

package module
v0.0.0-...-7f491e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: GPL-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Request byte = iota
	Indication
	Success
	Error
)
View Source
const (
	Binding uint16
	SharedSecret
)
View Source
const (
	MappedAddressCode uint16
	ResponseAddressCode
	ChangeAddressCode
	SourceAddressCode
	ChangedAddressCode
	UsernameCode
	PasswordCode
	MessageIntegrityCode
	ErrorCode
	UnknownAttributesCode
	ReflectedFromCode
)

Variables

This section is empty.

Functions

func ToType

func ToType(method uint16, class byte) []byte

Encode the method and class as a type in network order

Types

type AttributeValue

type AttributeValue interface {
	Bytes() []byte
}

type MappedAddressAttr

type MappedAddressAttr struct {
	Family  byte
	Port    int
	Address net.IP
}

func (MappedAddressAttr) Bytes

func (m MappedAddressAttr) Bytes() []byte

type RawAttr

type RawAttr struct {
	Data []byte
}

func (RawAttr) Bytes

func (r RawAttr) Bytes() []byte

type StunAttribute

type StunAttribute struct {
	// 16 bit Type
	Type uint16

	// 16 bit length
	Length int

	// Variable Length Attribute
	Attr AttributeValue
}

func MappedAddress

func MappedAddress(address string, port int) StunAttribute

func ParseAttr

func ParseAttr(bytes []byte) (StunAttribute, int)

func (StunAttribute) Bytes

func (a StunAttribute) Bytes() []byte

type StunMessage

type StunMessage struct {
	// 14 bit message type: 12 bit Method + 2 bit Class encoding
	//	+--+--+-+-+-+-+-+-+-+-+-+-+-+-+
	//	|M |M |M|M|M|C|M|M|M|C|M|M|M|M|
	//	|11|10|9|8|7|1|6|5|4|0|3|2|1|0|
	//	+--+--+-+-+-+-+-+-+-+-+-+-+-+-+
	Method uint16
	Class  byte

	// Message Length: 16 bits
	Length int

	// Magic Cookie: always 0x2112A442 in network order
	Cookie []byte

	// Transaction ID: Random 96 bits
	TransID []byte

	Attrs []StunAttribute
}

func NewMessage

func NewMessage() StunMessage

Generates new StunHeader with random TransactionID

func ParseMessage

func ParseMessage(bytes []byte) StunMessage

func SendMessage

func SendMessage(m StunMessage, local, remote string) StunMessage

func (*StunMessage) AddAttribute

func (m *StunMessage) AddAttribute(attr StunAttribute)

func (StunMessage) Bytes

func (h StunMessage) Bytes() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL