Documentation ¶
Index ¶
- Constants
- Variables
- func AttrName(typ uint16) string
- func Discover(uri string) (net.PacketConn, net.Addr, error)
- func ErrorText(code int) string
- func ListenAndServe(network, laddr string, config *Config) error
- func LocalAddrs() []*net.IPAddr
- func MethodName(typ uint16) string
- func NewAddr(network string, ip net.IP, port int) net.Addr
- func NewTransaction() []byte
- func SockAddr(v net.Addr) (net.IP, int)
- type Agent
- func (a *Agent) RoundTrip(req *Message, to Transport) (res *Message, from Transport, err error)
- func (a *Agent) Send(msg *Message, tr Transport) (err error)
- func (a *Agent) ServeConn(c net.Conn) error
- func (a *Agent) ServePacket(c net.PacketConn) error
- func (a *Agent) ServeSTUN(msg *Message, tr Transport)
- func (a *Agent) ServeTransport(b []byte, tr Transport) (n int, err error)
- type Attr
- type AuthMethod
- type Config
- type Conn
- type Detector
- type Error
- type Handler
- type HandlerFunc
- type Listener
- type Marshaler
- type Message
- func (m *Message) Add(attr Attr)
- func (m *Message) CheckFingerprint() bool
- func (m *Message) CheckIntegrity(key []byte) bool
- func (m *Message) Del(typ uint16)
- func (m *Message) Get(typ uint16) (attr Attr)
- func (m *Message) GetAddr(network string, typ ...uint16) net.Addr
- func (m *Message) GetBytes(typ uint16) []byte
- func (m *Message) GetError() *Error
- func (m *Message) GetInt(typ uint16) (v uint64, ok bool)
- func (m *Message) GetString(typ uint16) string
- func (m *Message) Has(typ uint16) bool
- func (m *Message) Kind() uint16
- func (m *Message) Marshal(p []byte) []byte
- func (m *Message) Method() uint16
- func (m *Message) Set(attr Attr)
- func (m *Message) String() string
- func (m *Message) Unmarshal(b []byte) (n int, err error)
- type Server
- type Session
- type Transport
- type TransportHandler
Constants ¶
View Source
const ( IPv4 = 0x01 IPv6 = 0x02 )
IP address family
View Source
const ( ChangeIP uint64 = 0x04 ChangePort = 0x02 )
IP address family
View Source
const ( KindRequest uint16 = 0x0000 KindIndication uint16 = 0x0010 KindResponse uint16 = 0x0100 KindError uint16 = 0x0110 )
View Source
const ( EndpointIndependent = "endpoint-independent" AddressDependent = "address-dependent" AddressPortDependent = "address-port-dependent" )
View Source
const ( MethodBinding uint16 = 0x001 // RFC 5389 MethodAllocate uint16 = 0x003 // RFC 5766 MethodRefresh uint16 = 0x004 MethodSend uint16 = 0x006 MethodData uint16 = 0x007 MethodCreatePermission uint16 = 0x008 MethodChannelBind uint16 = 0x009 MethodConnect uint16 = 0x00a // RFC 6062 MethodConnectionBind uint16 = 0x00b MethodConnectionAttempt uint16 = 0x00c )
STUN methods.
View Source
const ( AttrMappedAddress uint16 = 0x0001 // RFC 5389 AttrChangeRequest uint16 = 0x0003 // RFC 5780 AttrUsername uint16 = 0x0006 // RFC 5389 AttrMessageIntegrity uint16 = 0x0008 AttrErrorCode uint16 = 0x0009 AttrUnknownAttributes uint16 = 0x000a AttrChannelNumber uint16 = 0x000c // RFC 5766 AttrLifetime uint16 = 0x000d AttrXorPeerAddress uint16 = 0x0012 AttrData uint16 = 0x0013 AttrRealm uint16 = 0x0014 // RFC 5389 AttrNonce uint16 = 0x0015 AttrXorRelayedAddress uint16 = 0x0016 // RFC 5766 AttrRequestedAddressFamily uint16 = 0x0017 // RFC 6156 AttrEvenPort uint16 = 0x0018 // RFC 5766 AttrRequestedTransport uint16 = 0x0019 AttrDontFragment uint16 = 0x001a AttrAccessToken uint16 = 0x001b // RFC 7635 AttrXorMappedAddress uint16 = 0x0020 // RFC 5389 AttrReservationToken uint16 = 0x0022 // RFC 5766 AttrPriority uint16 = 0x0024 // RFC 5245 AttrUseCandidate uint16 = 0x0025 AttrPadding uint16 = 0x0026 // RFC 5780 AttrResponsePort uint16 = 0x0027 AttrConnectionID uint16 = 0x002a // RFC 6062 AttrSoftware uint16 = 0x8022 // RFC 5389 AttrAlternateServer uint16 = 0x8023 AttrTransactionTransmitCounter uint16 = 0x8025 // RFC 7982 AttrCacheTimeout uint16 = 0x8027 // RFC 5780 AttrFingerprint uint16 = 0x8028 // RFC 5389 AttrIceControlled uint16 = 0x8029 // RFC 5245 AttrIceControlling uint16 = 0x802a AttrResponseOrigin uint16 = 0x802b // RFC 5780 AttrOtherAddress uint16 = 0x802c AttrEcnCheck uint16 = 0x802d // RFC 6679 AttrThirdPartyAuthorization uint16 = 0x802e // RFC 7635 AttrMobilityTicket uint16 = 0x8030 // RFC 8016 )
STUN attributes.
View Source
const ( AttrResponseAddress uint16 = 0x0002 AttrSourceAddress uint16 = 0x0004 AttrChangedAddress uint16 = 0x0005 AttrPassword uint16 = 0x0007 AttrReflectedFrom uint16 = 0x000b AttrBandwidth uint16 = 0x0010 AttrTimerVal uint16 = 0x0021 )
Deprecated: For backwards compatibility only.
View Source
const ( CodeTryAlternate int = 300 // RFC 5389 CodeBadRequest int = 400 CodeForbidden int = 403 // RFC 5766 CodeMobilityForbidden int = 405 // RFC 8016 CodeUnknownAttribute int = 420 // RFC 5389 CodeAllocationMismatch int = 437 // RFC 5766 CodeStaleNonce int = 438 // RFC 5389 CodeAddressFamilyNotSupported int = 440 // RFC 6156 CodeWrongCredentials int = 441 // RFC 5766 CodeUnsupportedTransportProtocol int = 442 CodePeerAddressFamilyMismatch int = 443 // RFC 6156 CodeConnectionAlreadyExists int = 446 // RFC 6062 CodeConnectionTimeoutOrFailure int = 447 CodeAllocationQuotaReached int = 486 // RFC 5766 CodeRoleConflict int = 487 // RFC 5245 CodeServerError int = 500 // RFC 5389 CodeInsufficientCapacity int = 508 // RFC 5766 )
STUN error codes.
Variables ¶
View Source
var DefaultConfig = &Config{ RetransmissionTimeout: 500 * time.Millisecond, TransactionTimeout: 39500 * time.Millisecond, Software: "pixelbender/go-stun", }
Functions ¶
func ErrorText ¶
ErrorText returns a text for the STUN error code. It returns the empty string if the code is unknown.
func ListenAndServe ¶
func LocalAddrs ¶
func MethodName ¶
func NewTransaction ¶
func NewTransaction() []byte
Types ¶
type Agent ¶
type Agent struct { Handler Handler // contains filtered or unexported fields }
func (*Agent) ServePacket ¶
func (a *Agent) ServePacket(c net.PacketConn) error
type Attr ¶
Attribute represents a STUN attribute.
var Fingerprint Attr = &fingerprint{}
func MessageIntegrity ¶
type AuthMethod ¶
func LongTermAuthMethod ¶
func LongTermAuthMethod(username, password string) AuthMethod
LongTermAuthMethod returns AuthMethod for long-term credentials. Key = MD5(username ":" realm ":" SASLprep(password)). SASLprep is defined in RFC 4013.
func ShortTermAuthMethod ¶
func ShortTermAuthMethod(password string) AuthMethod
ShotTermAuthMethod returns AuthMethod for short-term credentials. Key = SASLprep(password). SASLprep is defined in RFC 4013.
type Config ¶
type Config struct { // AuthMethod returns a key for MESSAGE-INTEGRITY attribute AuthMethod AuthMethod // Retransmission timeout, default is 500 milliseconds RetransmissionTimeout time.Duration // Transaction timeout, default is 39.5 seconds TransactionTimeout time.Duration // Fingerprint, if true all outgoing messages contain FINGERPRINT attribute Fingerprint bool // Software is a SOFTWARE attribute value for outgoing messages, if not empty Software string // Logf, if set all sent and received messages printed using Logf Logf func(format string, args ...interface{}) }
type Detector ¶
type Detector struct {
*Conn
}
func NewDetector ¶
func (*Detector) DiscoverChange ¶
func (*Detector) Hairpinning ¶
type HandlerFunc ¶
func (HandlerFunc) ServeSTUN ¶
func (h HandlerFunc) ServeSTUN(msg *Message, tr Transport)
type Message ¶
Message represents a STUN message.
func UnmarshalMessage ¶
func (*Message) CheckFingerprint ¶
func (*Message) CheckIntegrity ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ListenAndServe ¶
Click to show internal directories.
Click to hide internal directories.