package stun
Import Path
github.com/pion/stun/v3 (on go.dev)
Dependency Relation
imports 24 packages, and imported by 8 packages
Involved Source Files
addr.go
agent.go
attributes.go
checks.go
client.go
errorcode.go
errors.go
fingerprint.go
helpers.go
integrity.go
message.go
Package stun implements Session Traversal Utilities for NAT (STUN) RFC 5389.
The stun package is intended to use by package that implements extension
to STUN (e.g. TURN) or client/server applications.
Most methods are designed to be zero allocations. If it is not enough,
low-level methods are available. On other hand, there are helpers that
reduce code repeat.
See examples for Message for basic usage, or https://github.com/pion/turn
package for example of stun extension implementation.
textattrs.go
uattrs.go
uri.go
xoraddr.go
Package-Level Type Names (total 42)
Agent is low-level abstraction over transaction list that
handles concurrency (all calls are goroutine-safe) and
time outs (via Collect call).
Close terminates all transactions with ErrAgentClosed and renders Agent to
closed state.
Collect terminates all transactions that have deadline before provided
time, blocking until all handlers will process ErrTransactionTimeOut.
Will return ErrAgentClosed if agent is already closed.
It is safe to call Collect concurrently but makes no sense.
Process incoming message, synchronously passing it to handler.
SetHandler sets agent handler to h.
Start registers transaction with provided id and deadline.
Could return ErrAgentClosed, ErrTransactionExists.
Agent handler is guaranteed to be eventually called.
Stop stops transaction by id with ErrTransactionStopped, blocking
until handler returns.
StopWithError removes transaction from list and calls handler with
provided error. Can return ErrTransactionNotExists and ErrAgentClosed.
*Agent : ClientAgent
*Agent : github.com/prometheus/common/expfmt.Closer
*Agent : io.Closer
func NewAgent(h Handler) *Agent
AlternateServer represents ALTERNATE-SERVER attribute.
RFC 5389 Section 15.11
IP net.IP
Port int
AddTo adds ALTERNATE-SERVER attribute to message.
GetFrom decodes ALTERNATE-SERVER from message.
*AlternateServer : Getter
*AlternateServer : Setter
Attributes is list of message attributes.
Get returns first attribute from list by the type.
If attribute is present the RawAttribute is returned and the
boolean is true. Otherwise the returned RawAttribute will be
empty and boolean will be false.
AttrType is attribute type.
Optional returns true if type is from comprehension-optional range (0x8000-0xFFFF).
Required returns true if type is from comprehension-required range (0x0000-0x7FFF).
( AttrType) String() string
Value returns uint16 representation of attribute type.
AttrType : expvar.Var
AttrType : fmt.Stringer
func CheckOverflow(_ AttrType, got, max int) error
func CheckSize(_ AttrType, got, expected int) error
func Attributes.Get(t AttrType) (RawAttribute, bool)
func (*MappedAddress).AddToAs(m *Message, t AttrType) error
func (*MappedAddress).GetFromAs(m *Message, t AttrType) error
func (*Message).Add(t AttrType, v []byte)
func (*Message).Contains(t AttrType) bool
func (*Message).ForEach(t AttrType, f func(m *Message) error) error
func (*Message).Get(t AttrType) ([]byte, error)
func TextAttribute.AddToAs(m *Message, t AttrType, maxLen int) error
func (*TextAttribute).GetFromAs(m *Message, t AttrType) error
func XORMappedAddress.AddToAs(m *Message, t AttrType) error
func (*XORMappedAddress).GetFromAs(m *Message, t AttrType) error
const AttrAlternateDomain
const AttrAlternateServer
const AttrCacheTimeout
const AttrChangedAddress
const AttrChangeRequest
const AttrChannelNumber
const AttrConnectionID
const AttrData
const AttrDontFragment
const AttrErrorCode
const AttrEvenPort
const AttrFingerprint
const AttrICEControlled
const AttrICEControlling
const AttrLifetime
const AttrMappedAddress
const AttrMessageIntegrity
const AttrMessageIntegritySHA256
const AttrNonce
const AttrOrigin
const AttrOtherAddress
const AttrPadding
const AttrPasswordAlgorithm
const AttrPasswordAlgorithms
const AttrPriority
const AttrRealm
const AttrRequestedAddressFamily
const AttrRequestedTransport
const AttrReservationToken
const AttrResponseOrigin
const AttrResponsePort
const AttrSoftware
const AttrSourceAddress
const AttrUnknownAttributes
const AttrUseCandidate
const AttrUserhash
const AttrUsername
const AttrXORMappedAddress
const AttrXORPeerAddress
const AttrXORRelayedAddress
Checker checks *Message attribute.
( Checker) Check(m *Message) error
FingerprintAttr
MessageIntegrity
func (*Message).Check(checkers ...Checker) error
Client simulates "connection" to STUN server.
Close stops internal connection and agent, returning CloseErr on error.
Do is Start wrapper that waits until callback is called. If no callback
provided, Indicate is called instead.
Do has cpu overhead due to blocking, see BenchmarkClient_Do.
Use Start method for less overhead.
Indicate sends indication m to server. Shorthand to Start call
with zero deadline and callback.
SetRTO sets current RTO value.
Start starts transaction (if h set) and writes message to server, handler
is called asynchronously.
*Client : github.com/prometheus/common/expfmt.Closer
*Client : io.Closer
func Dial(network, address string) (*Client, error)
func DialURI(uri *URI, cfg *DialConfig) (*Client, error)
func NewClient(conn Connection, options ...ClientOption) (*Client, error)
func WithNoRetransmit(c *Client)
ClientAgent is Agent implementation that is used by Client to
process transactions.
( ClientAgent) Close() error
( ClientAgent) Collect(time.Time) error
( ClientAgent) Process(*Message) error
( ClientAgent) SetHandler(h Handler) error
( ClientAgent) Start(id [12]byte, deadline time.Time) error
( ClientAgent) Stop(id [12]byte) error
*Agent
ClientAgent : github.com/prometheus/common/expfmt.Closer
ClientAgent : io.Closer
func WithAgent(a ClientAgent) ClientOption
ClientOption sets some client option.
func WithAgent(a ClientAgent) ClientOption
func WithClock(clock Clock) ClientOption
func WithCollector(coll Collector) ClientOption
func WithHandler(h Handler) ClientOption
func WithNoConnClose() ClientOption
func WithRTO(rto time.Duration) ClientOption
func WithTimeoutRate(d time.Duration) ClientOption
func NewClient(conn Connection, options ...ClientOption) (*Client, error)
Clock abstracts the source of current time.
( Clock) Now() time.Time
github.com/pion/stun.Clock (interface)
github.com/benbjohnson/clock.Clock (interface)
*github.com/benbjohnson/clock.Mock
github.com/hibiken/asynq/internal/timeutil.Clock (interface)
*github.com/hibiken/asynq/internal/timeutil.SimulatedClock
github.com/libp2p/go-libp2p/p2p/host/autorelay.ClockWithInstantTimer (interface)
github.com/libp2p/go-libp2p/p2p/host/autorelay.RealClock
github.com/libp2p/go-libp2p/p2p/net/swarm.Clock (interface)
github.com/libp2p/go-libp2p/p2p/net/swarm.RealClock
github.com/quic-go/quic-go/internal/congestion.Clock (interface)
github.com/quic-go/quic-go/internal/congestion.DefaultClock
go.uber.org/dig/internal/digclock.Clock (interface)
*go.uber.org/dig/internal/digclock.Mock
go.uber.org/fx/internal/fxclock.Clock (interface)
*go.uber.org/fx/internal/fxclock.Mock
go.uber.org/zap/zapcore.Clock (interface)
Clock : github.com/pion/stun.Clock
Clock : github.com/hibiken/asynq/internal/timeutil.Clock
Clock : github.com/quic-go/quic-go/internal/congestion.Clock
func WithClock(clock Clock) ClientOption
CloseErr indicates client close failure.
AgentErr error
ConnectionErr error
( CloseErr) Error() string
CloseErr : error
Collector calls function f with constant rate.
The simple Collector is ticker which calls function on each tick.
( Collector) Close() error
( Collector) Start(rate time.Duration, f func(now time.Time)) error
github.com/pion/stun.Collector (interface)
Collector : github.com/pion/stun.Collector
Collector : github.com/prometheus/common/expfmt.Closer
Collector : io.Closer
func WithCollector(coll Collector) ClientOption
Connection wraps Reader, Writer and Closer interfaces.
( Connection) Close() error
( Connection) Read(p []byte) (n int, err error)
( Connection) Write([]byte) (int, error)
github.com/pion/stun.Connection (interface)
*github.com/pion/datachannel.DataChannel
github.com/pion/datachannel.ReadWriteCloser (interface)
github.com/pion/datachannel.ReadWriteCloserDeadliner (interface)
*github.com/pion/dtls/v2.Conn
*github.com/pion/dtls/v3.Conn
*github.com/pion/ice/v4.Conn
github.com/pion/ice/v4/internal/fakenet.PacketConn
*github.com/pion/sctp.Stream
github.com/pion/transport/v2.TCPConn (interface)
github.com/pion/transport/v2.UDPConn (interface)
*github.com/pion/transport/v2/packetio.Buffer
*github.com/pion/transport/v2/udp.Conn
github.com/pion/transport/v3.TCPConn (interface)
github.com/pion/transport/v3.UDPConn (interface)
*github.com/pion/transport/v3/packetio.Buffer
*github.com/pion/transport/v3/vnet.UDPConn
github.com/pion/turn/v4/internal/client.TCPConn
*github.com/pion/webrtc/v4/internal/mux.Endpoint
github.com/apache/thrift/lib/go/thrift.RichTransport
*github.com/apache/thrift/lib/go/thrift.StreamTransport
*github.com/apache/thrift/lib/go/thrift.TBufferedTransport
*github.com/apache/thrift/lib/go/thrift.TFramedTransport
*github.com/apache/thrift/lib/go/thrift.THeaderTransport
*github.com/apache/thrift/lib/go/thrift.THttpClient
*github.com/apache/thrift/lib/go/thrift.TMemoryBuffer
*github.com/apache/thrift/lib/go/thrift.TSocket
*github.com/apache/thrift/lib/go/thrift.TSSLSocket
github.com/apache/thrift/lib/go/thrift.TTransport (interface)
*github.com/apache/thrift/lib/go/thrift.TZlibTransport
github.com/coreos/etcd/pkg/fileutil.LockedFile
github.com/gdamore/tcell/v2.Tty (interface)
github.com/gliderlabs/ssh.Session (interface)
github.com/libp2p/go-libp2p/core/network.MuxedStream (interface)
github.com/libp2p/go-libp2p/core/network.Stream (interface)
github.com/libp2p/go-libp2p/core/sec.SecureConn (interface)
github.com/libp2p/go-libp2p/core/sec/insecure.Conn
*github.com/libp2p/go-libp2p/p2p/net/swarm.Stream
*github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client.Conn
github.com/libp2p/go-libp2p/p2p/transport/tcpreuse/internal/sampledconn.ManetTCPConnInterface (interface)
*github.com/libp2p/go-libp2p/p2p/transport/websocket.Conn
github.com/libp2p/go-msgio.ReadWriteCloser (interface)
*github.com/libp2p/go-yamux/v5.Stream
github.com/marten-seemann/tcp.Conn
*github.com/miekg/dns.Conn
github.com/miekg/dns.Transfer
github.com/multiformats/go-multiaddr/net.Conn (interface)
github.com/multiformats/go-multistream.LazyConn (interface)
*github.com/ncruces/go-sqlite3.Blob
*github.com/polarsignals/wal/fs.File
github.com/quic-go/quic-go.Stream (interface)
github.com/quic-go/quic-go/http3.RequestStream (interface)
github.com/quic-go/quic-go/http3.Stream (interface)
github.com/quic-go/webtransport-go.Stream (interface)
*github.com/soheilhy/cmux.MuxConn
*crypto/tls.Conn
golang.org/x/crypto/ssh.Channel (interface)
golang.org/x/net/internal/socks.Conn
*golang.org/x/net/ipv4.RawConn
*internal/poll.FD
io.ReadWriteCloser (interface)
net.Conn (interface)
*net.IPConn
*net.TCPConn
*net.UDPConn
*net.UnixConn
*os.File
Connection : github.com/pion/stun.Connection
Connection : github.com/miekg/dns.Writer
Connection : github.com/prometheus/common/expfmt.Closer
Connection : internal/bisect.Writer
Connection : io.Closer
Connection : io.ReadCloser
Connection : io.Reader
Connection : io.ReadWriteCloser
Connection : io.ReadWriter
Connection : io.WriteCloser
Connection : io.Writer
func NewClient(conn Connection, options ...ClientOption) (*Client, error)
DecodeErr records an error and place when it is occurred.
Message string
Place DecodeErrPlace
( DecodeErr) Error() string
IsInvalidCookie returns true if error means that magic cookie
value is invalid.
IsPlace reports if error place is p.
IsPlaceChildren reports if error place children is c.
IsPlaceParent reports if error place parent is p.
DecodeErr : error
DecodeErrPlace records a place where error is occurred.
Children string
Parent string
( DecodeErrPlace) String() string
DecodeErrPlace : expvar.Var
DecodeErrPlace : fmt.Stringer
func DecodeErr.IsPlace(p DecodeErrPlace) bool
DialConfig is used to pass configuration to DialURI()
DTLSConfig dtls.Config
Net transport.Net
TLSConfig tls.Config
func DialURI(uri *URI, cfg *DialConfig) (*Client, error)
ErrorCode is code for ERROR-CODE attribute.
AddTo adds ERROR-CODE with default reason to m. If there
is no default reason, returns ErrNoDefaultReason.
ErrorCode : Setter
const CodeAddrFamilyNotSupported
const CodeAllocMismatch
const CodeAllocQuotaReached
const CodeBadRequest
const CodeConnAlreadyExists
const CodeConnTimeoutOrFailure
const CodeForbidden
const CodeInsufficientCapacity
const CodePeerAddrFamilyMismatch
const CodeRoleConflict
const CodeServerError
const CodeStaleNonce
const CodeTryAlternate
const CodeUnauthorised
const CodeUnauthorized
const CodeUnknownAttribute
const CodeUnsupportedTransProto
const CodeWrongCredentials
ErrorCodeAttribute represents ERROR-CODE attribute.
RFC 5389 Section 15.6
Code ErrorCode
Reason []byte
AddTo adds ERROR-CODE to m.
GetFrom decodes ERROR-CODE from m. Reason is valid until m.Raw is valid.
( ErrorCodeAttribute) String() string
*ErrorCodeAttribute : Getter
ErrorCodeAttribute : Setter
ErrorCodeAttribute : expvar.Var
ErrorCodeAttribute : fmt.Stringer
Event is passed to Handler describing the transaction event.
Do not reuse outside Handler.
Error error
Message *Message
TransactionID [12]byte
FingerprintAttr represents FINGERPRINT attribute.
RFC 5389 Section 15.5
AddTo adds fingerprint to message.
Check reads fingerprint value from m and checks it, returning error if any.
Can return *AttrLengthErr, ErrAttributeNotFound, and *CRCMismatch.
FingerprintAttr : Checker
FingerprintAttr : Setter
var Fingerprint
Getter parses attribute from *Message.
( Getter) GetFrom(m *Message) error
*AlternateServer
*ErrorCodeAttribute
*MappedAddress
*Nonce
*OtherAddress
*Realm
*ResponseOrigin
*Software
*UnknownAttributes
*Username
*XORMappedAddress
*github.com/pion/ice/v4.AttrControl
*github.com/pion/ice/v4.AttrControlled
*github.com/pion/ice/v4.AttrControlling
*github.com/pion/ice/v4.PriorityAttr
*github.com/pion/turn/v4/internal/proto.ChannelNumber
*github.com/pion/turn/v4/internal/proto.ConnectionID
*github.com/pion/turn/v4/internal/proto.Data
*github.com/pion/turn/v4/internal/proto.DontFragment
*github.com/pion/turn/v4/internal/proto.EvenPort
*github.com/pion/turn/v4/internal/proto.Lifetime
*github.com/pion/turn/v4/internal/proto.PeerAddress
*github.com/pion/turn/v4/internal/proto.RelayedAddress
*github.com/pion/turn/v4/internal/proto.RequestedAddressFamily
*github.com/pion/turn/v4/internal/proto.RequestedTransport
*github.com/pion/turn/v4/internal/proto.ReservationToken
func (*Message).Parse(getters ...Getter) error
Handler handles state changes of transaction.
Handler is called on transaction state change.
Usage of e is valid only during call, user must
copy needed fields explicitly.
func NoopHandler() Handler
func NewAgent(h Handler) *Agent
func WithHandler(h Handler) ClientOption
func (*Agent).SetHandler(h Handler) error
func (*Client).Start(m *Message, h Handler) error
func ClientAgent.SetHandler(h Handler) error
MappedAddress represents MAPPED-ADDRESS attribute.
This attribute is used only by servers for achieving backwards
compatibility with RFC 3489 clients.
RFC 5389 Section 15.1
IP net.IP
Port int
AddTo adds MAPPED-ADDRESS to message.
AddToAs adds MAPPED-ADDRESS value to m as t attribute.
GetFrom decodes MAPPED-ADDRESS from message.
GetFromAs decodes MAPPED-ADDRESS value in message m as an attribute of type t.
( MappedAddress) String() string
*MappedAddress : Getter
*MappedAddress : Setter
MappedAddress : expvar.Var
MappedAddress : fmt.Stringer
Message represents a single STUN packet. It uses aggressive internal
buffering to enable zero-allocation encoding and decoding,
so there are some usage constraints:
Message, its fields, results of m.Get or any attribute a.GetFrom
are valid only until Message.Raw is not modified.
Attributes Attributes
// len(Raw) not including header
Raw []byte
TransactionID [12]byte
Type MessageType
Add appends new attribute to message. Not goroutine-safe.
Value of attribute is copied to internal buffer so
it is safe to reuse v.
AddTo sets b.TransactionID to m.TransactionID.
Implements Setter to aid in crafting responses.
Build resets message and applies setters to it in batch, returning on
first error. To prevent allocations, pass pointers to values.
Example:
var (
t = BindingRequest
username = NewUsername("username")
nonce = NewNonce("nonce")
realm = NewRealm("example.org")
)
m := new(Message)
m.Build(t, username, nonce, realm) // 4 allocations
m.Build(&t, &username, &nonce, &realm) // 0 allocations
See BenchmarkBuildOverhead.
Check applies checkers to message in batch, returning on first error.
CloneTo clones m to b securing any further m mutations.
Contains return true if message contain t attribute.
Decode decodes m.Raw into m.
Encode re-encodes message into m.Raw.
Equal returns true if Message b equals to m.
Ignores m.Raw.
ForEach is helper that iterates over message attributes allowing to call
Getter in f callback to get all attributes of type t and returning on first
f error.
The m.Get method inside f will be returning next attribute on each f call.
Does not error if there are no results.
Get returns byte slice that represents attribute value,
if there is no attribute with such type,
ErrAttributeNotFound is returned.
GobDecode implements the gob.GobDecoder interface.
GobEncode implements the gob.GobEncoder interface.
MarshalBinary implements the encoding.BinaryMarshaler interface.
NewTransactionID sets m.TransactionID to random value from crypto/rand
and returns error if any.
Parse applies getters to message in batch, returning on first error.
ReadFrom implements ReaderFrom. Reads message from r into m.Raw,
Decodes it and return error if any. If m.Raw is too small, will return
ErrUnexpectedEOF, ErrUnexpectedHeaderEOF or *DecodeErr.
Can return *DecodeErr while decoding too.
Reset resets Message, attributes and underlying buffer length.
SetType sets m.Type and writes it to m.Raw.
(*Message) String() string
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
Write decodes message and return error if any.
Any error is unrecoverable, but message could be partially decoded.
WriteAttributes encodes all m.Attributes to m.
WriteHeader writes header to underlying buffer. Not goroutine-safe.
WriteLength writes m.Length to m.Raw.
WriteTo implements WriterTo via calling Write(m.Raw) on w and returning
call result.
WriteTransactionID writes m.TransactionID to m.Raw.
WriteType writes m.Type to m.Raw.
*Message : Setter
*Message : github.com/gobwas/ws.HandshakeHeader
*Message : github.com/miekg/dns.Writer
Message : encoding.BinaryMarshaler
*Message : encoding.BinaryUnmarshaler
*Message : encoding/gob.GobDecoder
Message : encoding/gob.GobEncoder
*Message : expvar.Var
*Message : fmt.Stringer
*Message : internal/bisect.Writer
*Message : io.ReaderFrom
*Message : io.Writer
*Message : io.WriterTo
func Build(setters ...Setter) (*Message, error)
func MustBuild(setters ...Setter) *Message
func New() *Message
func Decode(data []byte, m *Message) error
func (*Agent).Process(m *Message) error
func (*AlternateServer).AddTo(m *Message) error
func (*AlternateServer).GetFrom(m *Message) error
func Checker.Check(m *Message) error
func (*Client).Do(m *Message, f func(Event)) error
func (*Client).Indicate(m *Message) error
func (*Client).Start(m *Message, h Handler) error
func ClientAgent.Process(*Message) error
func ErrorCode.AddTo(m *Message) error
func ErrorCodeAttribute.AddTo(m *Message) error
func (*ErrorCodeAttribute).GetFrom(m *Message) error
func FingerprintAttr.AddTo(m *Message) error
func FingerprintAttr.Check(m *Message) error
func Getter.GetFrom(m *Message) error
func (*MappedAddress).AddTo(m *Message) error
func (*MappedAddress).AddToAs(m *Message, t AttrType) error
func (*MappedAddress).GetFrom(m *Message) error
func (*MappedAddress).GetFromAs(m *Message, t AttrType) error
func (*Message).AddTo(b *Message) error
func (*Message).CloneTo(b *Message) error
func (*Message).Equal(b *Message) bool
func MessageIntegrity.AddTo(m *Message) error
func MessageIntegrity.Check(m *Message) error
func MessageType.AddTo(m *Message) error
func Nonce.AddTo(m *Message) error
func (*Nonce).GetFrom(m *Message) error
func (*OtherAddress).AddTo(m *Message) error
func (*OtherAddress).GetFrom(m *Message) error
func RawAttribute.AddTo(m *Message) error
func Realm.AddTo(m *Message) error
func (*Realm).GetFrom(m *Message) error
func (*ResponseOrigin).AddTo(m *Message) error
func (*ResponseOrigin).GetFrom(m *Message) error
func Setter.AddTo(m *Message) error
func Software.AddTo(m *Message) error
func (*Software).GetFrom(m *Message) error
func TextAttribute.AddToAs(m *Message, t AttrType, maxLen int) error
func (*TextAttribute).GetFromAs(m *Message, t AttrType) error
func UnknownAttributes.AddTo(m *Message) error
func (*UnknownAttributes).GetFrom(m *Message) error
func Username.AddTo(m *Message) error
func (*Username).GetFrom(m *Message) error
func XORMappedAddress.AddTo(m *Message) error
func XORMappedAddress.AddToAs(m *Message, t AttrType) error
func (*XORMappedAddress).GetFrom(m *Message) error
func (*XORMappedAddress).GetFromAs(m *Message, t AttrType) error
func github.com/pion/ice/v4.AttrControl.AddTo(m *Message) error
func github.com/pion/ice/v4.(*AttrControl).GetFrom(m *Message) error
func github.com/pion/ice/v4.AttrControlled.AddTo(m *Message) error
func github.com/pion/ice/v4.(*AttrControlled).GetFrom(m *Message) error
func github.com/pion/ice/v4.AttrControlling.AddTo(m *Message) error
func github.com/pion/ice/v4.(*AttrControlling).GetFrom(m *Message) error
func github.com/pion/ice/v4.PriorityAttr.AddTo(m *Message) error
func github.com/pion/ice/v4.(*PriorityAttr).GetFrom(m *Message) error
func github.com/pion/ice/v4.UseCandidateAttr.AddTo(m *Message) error
func github.com/pion/ice/v4.UseCandidateAttr.IsSet(m *Message) bool
func github.com/pion/ice/v4/internal/stun.AssertUsername(m *Message, expectedUsername string) error
func github.com/pion/turn/v4.(*Client).PerformTransaction(msg *Message, to net.Addr, ignoreResult bool) (client.TransactionResult, error)
func github.com/pion/turn/v4/internal/client.Client.PerformTransaction(msg *Message, to net.Addr, dontWait bool) (client.TransactionResult, error)
func github.com/pion/turn/v4/internal/proto.ChannelNumber.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*ChannelNumber).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.ConnectionID.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*ConnectionID).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.Data.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*Data).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.DontFragment.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*DontFragment).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.DontFragment.IsSet(m *Message) bool
func github.com/pion/turn/v4/internal/proto.EvenPort.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*EvenPort).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.Lifetime.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*Lifetime).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.PeerAddress.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*PeerAddress).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.RelayedAddress.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*RelayedAddress).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.RequestedAddressFamily.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*RequestedAddressFamily).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.RequestedTransport.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*RequestedTransport).GetFrom(m *Message) error
func github.com/pion/turn/v4/internal/proto.ReservationToken.AddTo(m *Message) error
func github.com/pion/turn/v4/internal/proto.(*ReservationToken).GetFrom(m *Message) error
MessageClass is 8-bit representation of 2-bit class of STUN Message Class.
( MessageClass) String() string
MessageClass : expvar.Var
MessageClass : fmt.Stringer
func NewType(method Method, class MessageClass) MessageType
const ClassErrorResponse
const ClassIndication
const ClassRequest
const ClassSuccessResponse
MessageIntegrity represents MESSAGE-INTEGRITY attribute.
AddTo and Check methods are using zero-allocation version of hmac, see
newHMAC function and internal/hmac/pool.go.
RFC 5389 Section 15.4
AddTo adds MESSAGE-INTEGRITY attribute to message.
CPU costly, see BenchmarkMessageIntegrity_AddTo.
Check checks MESSAGE-INTEGRITY attribute.
CPU costly, see BenchmarkMessageIntegrity_Check.
( MessageIntegrity) String() string
MessageIntegrity : Checker
MessageIntegrity : Setter
MessageIntegrity : expvar.Var
MessageIntegrity : fmt.Stringer
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity
func NewShortTermIntegrity(password string) MessageIntegrity
MessageType is STUN Message Type Field.
// e.g. request
// e.g. binding
AddTo sets m type to t.
ReadValue decodes uint16 into MessageType.
( MessageType) String() string
Value returns bit representation of messageType.
MessageType : Setter
MessageType : expvar.Var
MessageType : fmt.Stringer
func NewType(method Method, class MessageClass) MessageType
func github.com/pion/turn/v4/internal/proto.AllocateRequest() MessageType
func github.com/pion/turn/v4/internal/proto.CreatePermissionRequest() MessageType
func github.com/pion/turn/v4/internal/proto.RefreshRequest() MessageType
func github.com/pion/turn/v4/internal/proto.SendIndication() MessageType
func (*Message).SetType(t MessageType)
var BindingError
var BindingRequest
var BindingSuccess
Method is uint16 representation of 12-bit STUN method.
( Method) String() string
Method : expvar.Var
Method : fmt.Stringer
func NewType(method Method, class MessageClass) MessageType
const MethodAllocate
const MethodBinding
const MethodChannelBind
const MethodConnect
const MethodConnectionAttempt
const MethodConnectionBind
const MethodCreatePermission
const MethodData
const MethodRefresh
const MethodSend
Nonce represents NONCE attribute.
RFC 5389 Section 15.8
AddTo adds NONCE to message.
GetFrom gets NONCE from message.
( Nonce) String() string
*Nonce : Getter
Nonce : Setter
Nonce : expvar.Var
Nonce : fmt.Stringer
func NewNonce(nonce string) Nonce
OtherAddress represents OTHER-ADDRESS attribute.
RFC 5780 Section 7.4
IP net.IP
Port int
AddTo adds OTHER-ADDRESS attribute to message.
GetFrom decodes OTHER-ADDRESS from message.
( OtherAddress) String() string
*OtherAddress : Getter
*OtherAddress : Setter
OtherAddress : expvar.Var
OtherAddress : fmt.Stringer
ProtoType indicates the transport protocol type that is used in the ice.URL
structure.
( ProtoType) String() string
ProtoType : expvar.Var
ProtoType : fmt.Stringer
func NewProtoType(raw string) ProtoType
const ProtoTypeTCP
const ProtoTypeUDP
const ProtoTypeUnknown
const github.com/pion/ice/v4.ProtoTypeTCP
const github.com/pion/ice/v4.ProtoTypeUDP
RawAttribute is a Type-Length-Value (TLV) object that
can be added to a STUN message. Attributes are divided into two
types: comprehension-required and comprehension-optional. STUN
agents can safely ignore comprehension-optional attributes they
don't understand, but cannot successfully process a message if it
contains comprehension-required attributes that are not
understood.
// ignored while encoding
Type AttrType
Value []byte
AddTo implements Setter, adding attribute as a.Type with a.Value and ignoring
the Length field.
Equal returns true if a == b.
( RawAttribute) String() string
RawAttribute : Setter
RawAttribute : expvar.Var
RawAttribute : fmt.Stringer
func Attributes.Get(t AttrType) (RawAttribute, bool)
func RawAttribute.Equal(b RawAttribute) bool
Realm represents REALM attribute.
RFC 5389 Section 15.7
AddTo adds NONCE to message.
GetFrom gets REALM from message.
( Realm) String() string
*Realm : Getter
Realm : Setter
Realm : expvar.Var
Realm : fmt.Stringer
func NewRealm(realm string) Realm
func github.com/pion/turn/v4.(*Client).Realm() Realm
ResponseOrigin represents RESPONSE-ORIGIN attribute.
RFC 5780 Section 7.3
IP net.IP
Port int
AddTo adds RESPONSE-ORIGIN attribute to message.
GetFrom decodes RESPONSE-ORIGIN from message.
( ResponseOrigin) String() string
*ResponseOrigin : Getter
*ResponseOrigin : Setter
ResponseOrigin : expvar.Var
ResponseOrigin : fmt.Stringer
SchemeType indicates the type of server used in the ice.URL structure.
( SchemeType) String() string
SchemeType : expvar.Var
SchemeType : fmt.Stringer
func NewSchemeType(raw string) SchemeType
const SchemeTypeSTUN
const SchemeTypeSTUNS
const SchemeTypeTURN
const SchemeTypeTURNS
const SchemeTypeUnknown
const github.com/pion/ice/v4.SchemeTypeSTUN
const github.com/pion/ice/v4.SchemeTypeSTUNS
const github.com/pion/ice/v4.SchemeTypeTURN
const github.com/pion/ice/v4.SchemeTypeTURNS
Setter sets *Message attribute.
( Setter) AddTo(m *Message) error
*AlternateServer
ErrorCode
ErrorCodeAttribute
FingerprintAttr
*MappedAddress
*Message
MessageIntegrity
MessageType
Nonce
*OtherAddress
RawAttribute
Realm
*ResponseOrigin
Software
UnknownAttributes
Username
XORMappedAddress
github.com/pion/ice/v4.AttrControl
github.com/pion/ice/v4.AttrControlled
github.com/pion/ice/v4.AttrControlling
github.com/pion/ice/v4.PriorityAttr
github.com/pion/ice/v4.UseCandidateAttr
github.com/pion/turn/v4/internal/proto.ChannelNumber
github.com/pion/turn/v4/internal/proto.ConnectionID
github.com/pion/turn/v4/internal/proto.Data
github.com/pion/turn/v4/internal/proto.DontFragment
github.com/pion/turn/v4/internal/proto.EvenPort
github.com/pion/turn/v4/internal/proto.Lifetime
github.com/pion/turn/v4/internal/proto.PeerAddress
github.com/pion/turn/v4/internal/proto.RelayedAddress
github.com/pion/turn/v4/internal/proto.RequestedAddressFamily
github.com/pion/turn/v4/internal/proto.RequestedTransport
github.com/pion/turn/v4/internal/proto.ReservationToken
func NewTransactionIDSetter(value [12]byte) Setter
func github.com/pion/turn/v4/internal/allocation.(*Allocation).GetResponseCache() (id [12]byte, attrs []Setter)
func Build(setters ...Setter) (*Message, error)
func MustBuild(setters ...Setter) *Message
func (*Message).Build(setters ...Setter) error
func github.com/pion/turn/v4/internal/allocation.(*Allocation).SetResponseCache(transactionID [12]byte, attrs []Setter)
var TransactionID
Software is SOFTWARE attribute.
RFC 5389 Section 15.10
AddTo adds Software attribute to m.
GetFrom decodes Software from m.
( Software) String() string
*Software : Getter
Software : Setter
Software : expvar.Var
Software : fmt.Stringer
func NewSoftware(software string) Software
StopErr occurs when Client fails to stop transaction while
processing error.
// error that caused Stop() call
// value returned by Stop()
( StopErr) Error() string
StopErr : error
TextAttribute is helper for adding and getting text attributes.
AddToAs adds attribute with type t to m, checking maximum length. If maxLen
is less than 0, no check is performed.
GetFromAs gets t attribute from m and appends its value to reseted v.
UnknownAttributes represents UNKNOWN-ATTRIBUTES attribute.
RFC 5389 Section 15.9
AddTo adds UNKNOWN-ATTRIBUTES attribute to message.
GetFrom parses UNKNOWN-ATTRIBUTES from message.
( UnknownAttributes) String() string
*UnknownAttributes : Getter
UnknownAttributes : Setter
UnknownAttributes : expvar.Var
UnknownAttributes : fmt.Stringer
URI represents a STUN (rfc7064) or TURN (rfc7065) URI
Host string
Password string
Port int
Proto ProtoType
Scheme SchemeType
Username string
IsSecure returns whether the this URL's scheme describes secure scheme or not.
( URI) String() string
URI : expvar.Var
URI : fmt.Stringer
func ParseURI(raw string) (*URI, error)
func DialURI(uri *URI, cfg *DialConfig) (*Client, error)
Username represents USERNAME attribute.
RFC 5389 Section 15.3
AddTo adds USERNAME attribute to message.
GetFrom gets USERNAME from message.
( Username) String() string
*Username : Getter
Username : Setter
Username : expvar.Var
Username : fmt.Stringer
func NewUsername(username string) Username
func github.com/pion/turn/v4.(*Client).Username() Username
XORMappedAddress implements XOR-MAPPED-ADDRESS attribute.
RFC 5389 Section 15.2
IP net.IP
Port int
AddTo adds XOR-MAPPED-ADDRESS to m. Can return ErrBadIPLength
if len(a.IP) is invalid.
AddToAs adds XOR-MAPPED-ADDRESS value to m as t attribute.
GetFrom decodes XOR-MAPPED-ADDRESS attribute in message and returns
error if any. While decoding, a.IP is reused if possible and can be
rendered to invalid state (e.g. if a.IP was set to IPv6 and then
IPv4 value were decoded into it), be careful.
Example:
expectedIP := net.ParseIP("213.141.156.236")
expectedIP.String() // 213.141.156.236, 16 bytes, first 12 of them are zeroes
expectedPort := 21254
addr := &XORMappedAddress{
IP: expectedIP,
Port: expectedPort,
}
// addr were added to message that is decoded as newMessage
// ...
addr.GetFrom(newMessage)
addr.IP.String() // 213.141.156.236, net.IPv4Len
expectedIP.String() // d58d:9cec::ffff:d58d:9cec, 16 bytes, first 4 are IPv4
// now we have len(expectedIP) = 16 and len(addr.IP) = 4.
GetFromAs decodes XOR-MAPPED-ADDRESS attribute value in message
getting it as for t type.
( XORMappedAddress) String() string
*XORMappedAddress : Getter
XORMappedAddress : Setter
XORMappedAddress : expvar.Var
XORMappedAddress : fmt.Stringer
func github.com/pion/ice/v4.UniversalUDPMux.GetXORMappedAddr(stunAddr net.Addr, deadline time.Duration) (*XORMappedAddress, error)
func github.com/pion/ice/v4.(*UniversalUDPMuxDefault).GetXORMappedAddr(serverAddr net.Addr, deadline time.Duration) (*XORMappedAddress, error)
func github.com/pion/ice/v4/internal/stun.GetXORMappedAddr(conn net.PacketConn, serverAddr net.Addr, timeout time.Duration) (*XORMappedAddress, error)
Package-Level Functions (total 35)
Build wraps Message.Build method.
CheckOverflow returns ErrAttributeSizeOverflow if got is bigger that max.
CheckSize returns ErrAttrSizeInvalid if got is not equal to expected.
Decode decodes Message from data to m, returning error if any.
Dial connects to the address on the named network and then
initializes Client on that connection, returning error if any.
DialURI connect to the STUN/TURN URI and then
initializes Client on that connection, returning error if any.
FingerprintValue returns CRC-32 of b XOR-ed by 0x5354554e.
The value of the attribute is computed as the CRC-32 of the STUN message
up to (but excluding) the FINGERPRINT attribute itself, XOR'ed with
the 32-bit value 0x5354554e (the XOR helps in cases where an
application packet is also using CRC-32 in it).
IsAttrSizeInvalid returns true if error means that attribute size is invalid.
IsAttrSizeOverflow returns true if error means that attribute size is too big.
IsMessage returns true if b looks like STUN message.
Useful for multiplexing. IsMessage does not guarantee
that decoding will be successful.
MustBuild wraps Build call and panics on error.
New returns *Message with pre-allocated Raw.
NewAgent initializes and returns new Agent with provided handler.
If h is nil, the NoopHandler will be used.
NewClient initializes new Client from provided options,
starting internal goroutines and using default options fields
if necessary. Call Close method after using Client to close conn and
release resources.
The conn will be closed on Close call. Use WithNoConnClose option to
prevent that.
Note that user should handle the protocol multiplexing, client does not
provide any API for it, so if you need to read application data, wrap the
connection with your (de-)multiplexer and pass the wrapper as conn.
NewLongTermIntegrity returns new MessageIntegrity with key for long-term
credentials. Password, username, and realm must be SASL-prepared.
NewNonce returns new Nonce from string.
NewProtoType defines a procedure for creating a new ProtoType from a raw
string naming the transport protocol type.
NewRealm returns Realm with provided value.
Must be SASL-prepared.
NewSchemeType defines a procedure for creating a new SchemeType from a raw
string naming the scheme type.
NewShortTermIntegrity returns new MessageIntegrity with key for short-term
credentials. Password must be SASL-prepared.
NewSoftware returns *Software from string.
NewTransactionID returns new random transaction ID using crypto/rand
as source.
NewTransactionIDSetter returns new Setter that sets message transaction id
to provided value.
NewType returns new message type with provided method and class.
NewUsername returns Username with provided value.
NoopHandler just discards any event.
ParseURI parses a STUN or TURN urls following the ABNF syntax described in
https://tools.ietf.org/html/rfc7064 and https://tools.ietf.org/html/rfc7065
respectively.
WithAgent sets client STUN agent.
Defaults to agent implementation in current package,
see agent.go.
WithClock sets Clock of client, the source of current time.
Also clock is passed to default collector if set.
WithCollector rests client timeout collector, the implementation
of ticker which calls function on each tick.
WithHandler sets client handler which is called if Agent emits the Event
with TransactionID that is not currently registered by Client.
Useful for handling Data indications from TURN server.
WithNoConnClose prevents client from closing underlying connection when
the Close() method is called.
WithNoRetransmit disables retransmissions and sets RTO to
defaultMaxAttempts * defaultRTO which will be effectively time out
if not set.
Useful for TCP connections where transport handles RTO.
WithRTO sets client RTO as defined in STUN RFC.
WithTimeoutRate sets RTO timer minimum resolution.
Package-Level Variables (total 32)
Binding error response message type.
Binding request message type.
Binding success response message type
ErrAgentClosed indicates that agent is in closed state and is unable
to handle transactions.
ErrAttributeNotFound means that attribute with provided attribute
type does not exist in message.
ErrAttributeSizeInvalid means that decoded attribute size is invalid.
ErrAttributeSizeOverflow means that decoded attribute size is too big.
ErrBadIPLength means that len(IP) is not net.{IPv6len,IPv4len}.
ErrBadUnknownAttrsSize means that UNKNOWN-ATTRIBUTES attribute value
has invalid length.
ErrClientClosed indicates that client is closed.
ErrClientNotInitialized means that client connection or agent is nil.
ErrDecodeToNil occurs on Decode(data, nil) call.
ErrFingerprintBeforeIntegrity means that FINGERPRINT attribute is already in
message, so MESSAGE-INTEGRITY attribute cannot be added.
ErrFingerprintMismatch means that computed fingerprint differs from expected.
ErrHost indicates malformed hostname is provided.
ErrIntegrityMismatch means that computed HMAC differs from expected.
ErrInvalidQuery indicates an malformed query is provided.
ErrNoConnection means that ClientOptions.Connection is nil.
ErrNoDefaultReason means that default reason for provided error code
is not defined in RFC.
ErrPort indicates malformed port is provided.
ErrProtoType indicates an unsupported transport type was provided.
ErrSchemeType indicates the scheme type could not be parsed.
ErrSTUNQuery indicates query arguments are provided in a STUN URL.
ErrTransactionExists indicates that transaction with same id is already
registered.
ErrTransactionNotExists indicates that agent failed to find transaction.
ErrTransactionStopped indicates that transaction was manually stopped.
ErrTransactionTimeOut indicates that transaction has reached deadline.
ErrUnexpectedHeaderEOF means that there were not enough bytes in
m.Raw to read header.
ErrUnknownType indicates an error with Unknown info.
ErrUnsupportedURI is an error thrown if the user passes an unsupported STUN or TURN URI
Fingerprint is shorthand for FingerprintAttr.
Example:
m := New()
Fingerprint.AddTo(m)
TransactionID is Setter for m.TransactionID.
Package-Level Constants (total 83)
Attributes from RFC 8489 STUN.
Attributes from comprehension-optional range (0x8000-0xFFFF).
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from RFC 3489, removed by RFC 5389,
but still used by RFC5389-implementing software like Vovida.org, reTURNServer, etc.
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from RFC 5766 TURN.
Attributes from RFC 6062 TURN Extensions for TCP Allocations.
Attributes from RFC 5766 TURN.
Attributes from RFC 5766 TURN.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from RFC 5766 TURN.
Attributes from comprehension-optional range (0x8000-0xFFFF).
Attributes from RFC 5245 ICE.
Attributes from RFC 5245 ICE.
Attributes from RFC 5766 TURN.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from RFC 8489 STUN.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from An Origin Attribute for the STUN Protocol.
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from RFC 8489 STUN.
Attributes from RFC 8489 STUN.
Attributes from RFC 5245 ICE.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from RFC 6156 TURN IPv6.
Attributes from RFC 5766 TURN.
Attributes from RFC 5766 TURN.
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from RFC 5780 NAT Behavior Discovery
Attributes from comprehension-optional range (0x8000-0xFFFF).
Attributes from RFC 3489, removed by RFC 5389,
but still used by RFC5389-implementing software like Vovida.org, reTURNServer, etc.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from RFC 5245 ICE.
Attributes from RFC 8489 STUN.
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from comprehension-required range (0x0000-0x7FFF).
Attributes from RFC 5766 TURN.
Attributes from RFC 5766 TURN.
Possible values for message class in STUN Message Type.
Possible values for message class in STUN Message Type.
Possible values for message class in STUN Message Type.
Possible values for message class in STUN Message Type.
Error codes from RFC 6156.
RFC 6156 Section 10.2
Error codes from RFC 5766.
RFC 5766 Section 15
Error codes from RFC 5766.
RFC 5766 Section 15
Possible error codes.
Error codes from RFC 6062.
RFC 6062 Section 6.3
Error codes from RFC 6062.
RFC 6062 Section 6.3
Error codes from RFC 5766.
RFC 5766 Section 15
Error codes from RFC 5766.
RFC 5766 Section 15
Error codes from RFC 6156.
RFC 6156 Section 10.2
Possible error codes.
Possible error codes.
Possible error codes.
Possible error codes.
Possible error codes.
Error codes from RFC 5766.
RFC 5766 Section 15
Error codes from RFC 5766.
RFC 5766 Section 15
IANA assigned ports for "stun" protocol.
IANA assigned ports for "stun" protocol.
Possible methods for STUN Message.
Possible methods for STUN Message.
Possible methods for STUN Message.
Methods from RFC 6062.
Methods from RFC 6062.
Methods from RFC 6062.
Possible methods for STUN Message.
Possible methods for STUN Message.
Possible methods for STUN Message.
Possible methods for STUN Message.
ProtoTypeTCP indicates the URL uses a TCP transport.
ProtoTypeUDP indicates the URL uses a UDP transport.
ProtoTypeUnknown indicates an unknown or unsupported protocol.
SchemeTypeSTUN indicates the URL represents a STUN server.
SchemeTypeSTUNS indicates the URL represents a STUNS (secure) server.
SchemeTypeTURN indicates the URL represents a TURN server.
SchemeTypeTURNS indicates the URL represents a TURNS (secure) server.
SchemeTypeUnknown indicates an unknown or unsupported scheme.
TransactionIDSize is length of transaction id array (in bytes).
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |