stun

package
v0.0.0-...-31c0879 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package stun implements a subset of the Session Traversal Utilities for NAT (STUN) protocol, described in RFC 5389. Notably absent is support for long-term credentials.

Index

Constants

View Source
const (
	ClassRequest = iota
	ClassIndication
	ClassSuccess
	ClassError
	MethodBinding = 1
)

Possible classes and methods for a STUN packet.

Variables

This section is empty.

Functions

func BindRequest

func BindRequest(tid []byte, macKey []byte, compat bool, useCandidate bool) ([]byte, error)

BindRequest constructs and returns a Binding Request STUN packet.

tid must be 12 bytes long. If a macKey is provided, the returned packet is signed.

func BindResponse

func BindResponse(tid []byte, addr *net.UDPAddr, macKey []byte, compat bool) ([]byte, error)

BindResponse constructs and returns a Binding Success STUN packet.

tid must be 12 bytes long. If a macKey is provided, the returned packet is signed.

func RandomTid

func RandomTid() ([]byte, error)

Types

type BadMac

type BadMac struct{}

A BadMac error is returned by ParsePacket when a structurally sound STUN packet is received with a signature not matching the provided macKey.

func (BadMac) Error

func (b BadMac) Error() string

type Class

type Class uint8

type MalformedPacket

type MalformedPacket struct{}

A MalformedPacket error is returned by ParsePacket when it encounters structural malformations in the STUN packet.

On a network endpoing where STUN coexists with another protocol, this error can be used to differentiate STUN and non-STUN traffic.

func (MalformedPacket) Error

func (m MalformedPacket) Error() string

type Method

type Method uint16

type MissingMac

type MissingMac struct{}

A MissingMac error is returned by ParsePacket when it receives a valid but unsigned STUN packet where it expected a signed packet.

func (MissingMac) Error

func (m MissingMac) Error() string

type Packet

type Packet struct {
	Class        Class
	Method       Method
	Tid          [12]byte
	Addr         *net.UDPAddr
	HasMac       bool
	Software     string
	UseCandidate bool

	Error     *PacketError
	Alternate *net.UDPAddr
}

A Packet presents select information about a STUN packet.

func ParsePacket

func ParsePacket(raw []byte, macKey []byte) (*Packet, error)

ParsePacket parses a byte slice as a STUN packet.

If a macKey is provided, only packets correctly signed with that key will be accepted. If no macKey is provided, only unsigned packets will be accepted.

type PacketError

type PacketError struct {
	Code   uint16
	Reason string
}

A PacketError describes an error returned by a STUN server.

func (PacketError) Error

func (p PacketError) Error() string

type UnverifiableMac

type UnverifiableMac struct{}

An UnverifiableMac error is returned by ParsePacket when it encounters a valid and signed STUN packet, and no macKey was provided.

func (UnverifiableMac) Error

func (u UnverifiableMac) Error() string

Directories

Path Synopsis
stunclient is a simple STUN client implementation using the STUN library.
stunclient is a simple STUN client implementation using the STUN library.

Jump to

Keyboard shortcuts

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