stun

package
v0.0.0-...-a61b7bd Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BindingRequest         uint16 = 0x0001
	BindingSuccessResponse uint16 = 0x0101
	BindingErrorResponse   uint16 = 0x0111
)
View Source
const (
	MessageHeaderLength = 20
	TransactionIDLength = 12
)
View Source
const (
	AttributeXorMappedAddress uint16 = 0x0020
	AttributeErrorCode        uint16 = 0x0009
)
View Source
const ClazzBadRequest uint8 = 0x04
View Source
const ErrNumBadRequest uint8 = 0x00
View Source
const ErrorCodePadding uint16 = 0x0000
View Source
const FamilyV4 uint8 = 0x01
View Source
const FamilyV6 uint8 = 0x02
View Source
const MagicCookie uint32 = 0x2112A442
View Source
const Offset uint8 = 0x00

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, serverAddr string, localAddr *string) Client

serverAddr is STUN server address. If localAddr is nil, a local address is automatically chosen.

func (*Client) Close

func (c *Client) Close()

func (*Client) Discover

func (c *Client) Discover() (net.UDPAddr, error)

Discover external ip address and port

func (*Client) Keepalive

func (c *Client) Keepalive() error

Keepalive stun server connection

type ErrorResponse

type ErrorResponse struct {
	Header MessageHeader
}

type IPV4Attribute

type IPV4Attribute struct {
	XorMappedAddressAttribute
	XAddress uint32
}

type IPV6Attribute

type IPV6Attribute struct {
	XorMappedAddressAttribute
	XAddress [16]uint8
}

type MessageHeader

type MessageHeader struct {
	Type          uint16
	Length        uint16
	MagicCookie   uint32
	TransactionID [TransactionIDLength]byte
}

func NewMessage

func NewMessage(buffer []byte) MessageHeader

func (*MessageHeader) CreateErrorResponse

func (m *MessageHeader) CreateErrorResponse() []byte

func (*MessageHeader) CreateSuccessResponse

func (m *MessageHeader) CreateSuccessResponse(port uint16, address net.IP) []byte

func (*MessageHeader) ValidateAsBindingRequest

func (m *MessageHeader) ValidateAsBindingRequest() error

type Result

type Result struct {
	Error error
	Addr  net.UDPAddr
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, serverAddr string) Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) Shutdown

func (s *Server) Shutdown()

type SuccessV4Response

type SuccessV4Response struct {
	Header    MessageHeader
	Attribute IPV4Attribute
}

type SuccessV6Response

type SuccessV6Response struct {
	Header    MessageHeader
	Attribute IPV6Attribute
}

type XorMappedAddressAttribute

type XorMappedAddressAttribute struct {
	Type   uint16
	Length uint16
	Offset uint8
	Family uint8
	XPort  uint16
}

Jump to

Keyboard shortcuts

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