stun

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package stun implements the small subset of STUN (RFC 5389) Transporter needs: binding requests and responses carrying XOR-MAPPED-ADDRESS, so a node can learn the public address its NAT maps its UDP socket to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(b []byte) bool

Is reports whether b looks like a STUN message. It is cheap enough to run on every packet arriving on a socket shared with other protocols.

func Request

func Request(tx TxID) []byte

Request builds a binding request.

func Requests

func Requests() uint64

Requests returns the number of binding requests answered by Serve.

func Response

func Response(tx TxID, addr netip.AddrPort) []byte

Response builds a binding success response reporting addr.

func Serve

func Serve(ctx context.Context, conn net.PacketConn, log *slog.Logger) error

Serve answers binding requests on conn until ctx is cancelled.

Types

type TxID

type TxID [12]byte

TxID is a STUN transaction ID.

func NewTxID

func NewTxID() TxID

NewTxID returns a random transaction ID.

func ParseRequest

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

ParseRequest returns the transaction ID of a binding request.

func ParseResponse

func ParseResponse(b []byte) (TxID, netip.AddrPort, error)

ParseResponse returns the transaction ID and mapped address of a binding success response.

Jump to

Keyboard shortcuts

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