stun

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package stun generates STUN request packets and parses response packets.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSTUN            = errors.New("response is not a STUN packet")
	ErrNotSuccessResponse = errors.New("STUN packet is not a response")
	ErrMalformedAttrs     = errors.New("STUN response has malformed attributes")
	ErrNotBindingRequest  = errors.New("STUN request not a binding request")
	ErrWrongSoftware      = errors.New("STUN request came from non-PairMesh software")
	ErrNoFingerprint      = errors.New("STUN request didn't end in fingerprint")
	ErrWrongFingerprint   = errors.New("STUN request had bogus fingerprint")
)

Functions

func Is

func Is(b []byte) bool

Is reports whether b is a STUN message.

func Request

func Request(tID TxID) []byte

Request generates a binding request STUN packet. The transaction ID, tID, should be a random sequence of bytes.

func Response

func Response(txID TxID, ip net.IP, port uint16) []byte

Response generates a binding response.

Types

type TxID

type TxID [12]byte

TxID is a transaction ID.

func NewTxID

func NewTxID() TxID

NewTxID returns a new random TxID.

func ParseBindingRequest

func ParseBindingRequest(b []byte) (TxID, error)

ParseBindingRequest parses a STUN binding request.

It returns an error unless it advertises that it came from PairMesh.

func ParseResponse

func ParseResponse(b []byte) (txID TxID, addr []byte, port uint16, err error)

ParseResponse parses a successful binding response STUN packet. The IP address is extracted from the XOR-MAPPED-ADDRESS attribute. The returned addr slice is owned by the caller and does not alias b.

Jump to

Keyboard shortcuts

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