Documentation ¶
Overview ¶
Package proto implements RFC 5766 Traversal Using Relays around NAT.
Merged from gortc/turn v0.80.
Index ¶
- Constants
- Variables
- func AllocateRequest() stun.MessageType
- func CreatePermissionRequest() stun.MessageType
- func IsChannelData(buf []byte) bool
- func RefreshRequest() stun.MessageType
- func SendIndication() stun.MessageType
- type Addr
- type ChannelData
- type ChannelNumber
- type ConnectionID
- type Data
- type DontFragment
- type DontFragmentAttr
- type EvenPort
- type FiveTuple
- type Lifetime
- type PeerAddress
- type Protocol
- type RelayedAddress
- type RequestedAddressFamily
- type RequestedTransport
- type ReservationToken
- type XORPeerAddress
- type XORRelayedAddress
Constants ¶
const ( MinChannelNumber = 0x4000 MaxChannelNumber = 0x7FFF )
See https://tools.ietf.org/html/rfc5766#section-11:
0x4000 through 0x7FFF: These values are the allowed channel numbers (16,383 possible values).
const ( // DefaultPort for TURN is same as STUN. DefaultPort = stun.DefaultPort // DefaultTLSPort is for TURN over TLS and is same as STUN. DefaultTLSPort = stun.DefaultTLSPort )
Default ports for TURN from RFC 5766 Section 4.
const DefaultLifetime = time.Minute * 10
DefaultLifetime in RFC 5766 is 10 minutes.
Variables ¶
var ErrBadChannelDataLength = errors.New("channelData length != len(Data)")
ErrBadChannelDataLength means that channel data length is not equal to actual data length.
var ErrInvalidChannelNumber = errors.New("channel number not in [0x4000, 0x7FFF]")
ErrInvalidChannelNumber means that channel number is not valid as by RFC 5766 Section 11.
Functions ¶
func AllocateRequest ¶
func AllocateRequest() stun.MessageType
AllocateRequest is shorthand for allocation request message type.
func CreatePermissionRequest ¶
func CreatePermissionRequest() stun.MessageType
CreatePermissionRequest is shorthand for create permission request type.
func IsChannelData ¶
IsChannelData returns true if buf looks like the ChannelData Message.
func RefreshRequest ¶
func RefreshRequest() stun.MessageType
RefreshRequest is shorthand for refresh request message type.
func SendIndication ¶
func SendIndication() stun.MessageType
SendIndication is shorthand for send indication message type.
Types ¶
type Addr ¶
Addr is ip:port.
func (*Addr) FromUDPAddr ¶
FromUDPAddr sets addr to UDPAddr.
type ChannelData ¶
type ChannelData struct { Data []byte // can be sub slice of Raw Length int // ignored while encoding, len(Data) is used Number ChannelNumber Raw []byte }
ChannelData represents The ChannelData Message.
func (*ChannelData) Decode ¶
func (c *ChannelData) Decode() error
Decode decodes The ChannelData Message from Raw.
func (*ChannelData) Encode ¶
func (c *ChannelData) Encode()
Encode encodes ChannelData Message to Raw.
func (*ChannelData) Equal ¶
func (c *ChannelData) Equal(b *ChannelData) bool
Equal returns true if b == c.
func (*ChannelData) WriteHeader ¶
func (c *ChannelData) WriteHeader()
WriteHeader writes channel number and length.
type ChannelNumber ¶
type ChannelNumber uint16 // encoded as uint16
ChannelNumber represents CHANNEL-NUMBER attribute.
The CHANNEL-NUMBER attribute contains the number of the channel.
func (ChannelNumber) AddTo ¶
func (n ChannelNumber) AddTo(m *stun.Message) error
AddTo adds CHANNEL-NUMBER to message.
func (*ChannelNumber) GetFrom ¶
func (n *ChannelNumber) GetFrom(m *stun.Message) error
GetFrom decodes CHANNEL-NUMBER from message.
func (ChannelNumber) String ¶
func (n ChannelNumber) String() string
func (ChannelNumber) Valid ¶
func (n ChannelNumber) Valid() bool
Valid returns true if channel number has correct value that complies RFC 5766 Section 11 range.
type ConnectionID ¶ added in v2.1.0
type ConnectionID uint32
ConnectionID represents CONNECTION-ID attribute.
The CONNECTION-ID attribute uniquely identifies a peer data connection. It is a 32-bit unsigned integral value.
type Data ¶
type Data []byte
Data represents DATA attribute.
The DATA attribute is present in all Send and Data indications. The value portion of this attribute is variable length and consists of the application data (that is, the data that would immediately follow the UDP header if the data was been sent directly between the client and the peer).
type DontFragment ¶ added in v2.1.0
type DontFragment struct{}
DontFragment represents DONT-FRAGMENT attribute.
This attribute is used by the client to request that the server set the DF (Don't Fragment) bit in the IP header when relaying the application data onward to the peer. This attribute has no value part and thus the attribute length field is 0.
func (DontFragment) AddTo ¶ added in v2.1.0
func (DontFragment) AddTo(m *stun.Message) error
AddTo adds DONT-FRAGMENT attribute to message.
type DontFragmentAttr ¶
type DontFragmentAttr = DontFragment
DontFragmentAttr is a deprecated alias for DontFragment Deprecated: Please use DontFragment
type EvenPort ¶
type EvenPort struct { // ReservePort means that the server is requested to reserve // the next-higher port number (on the same IP address) // for a subsequent allocation. ReservePort bool }
EvenPort represents EVEN-PORT attribute.
This attribute allows the client to request that the port in the relayed transport address be even, and (optionally) that the server reserve the next-higher port number.
type Lifetime ¶
Lifetime represents LIFETIME attribute.
The LIFETIME attribute represents the duration for which the server will maintain an allocation in the absence of a refresh. The value portion of this attribute is 4-bytes long and consists of a 32-bit unsigned integral value representing the number of seconds remaining until expiration.
type PeerAddress ¶
PeerAddress implements XOR-PEER-ADDRESS attribute.
The XOR-PEER-ADDRESS specifies the address and port of the peer as seen from the TURN server. (For example, the peer's server-reflexive transport address if the peer is behind a NAT.)
func (PeerAddress) AddTo ¶
func (a PeerAddress) AddTo(m *stun.Message) error
AddTo adds XOR-PEER-ADDRESS to message.
func (*PeerAddress) GetFrom ¶
func (a *PeerAddress) GetFrom(m *stun.Message) error
GetFrom decodes XOR-PEER-ADDRESS from message.
func (PeerAddress) String ¶
func (a PeerAddress) String() string
type Protocol ¶
type Protocol byte
Protocol is IANA assigned protocol number.
const ( // ProtoUDP is IANA assigned protocol number for UDP. ProtoUDP Protocol = 17 )
type RelayedAddress ¶
RelayedAddress implements XOR-RELAYED-ADDRESS attribute.
It specifies the address and port that the server allocated to the client. It is encoded in the same way as XOR-MAPPED-ADDRESS.
func (RelayedAddress) AddTo ¶
func (a RelayedAddress) AddTo(m *stun.Message) error
AddTo adds XOR-PEER-ADDRESS to message.
func (*RelayedAddress) GetFrom ¶
func (a *RelayedAddress) GetFrom(m *stun.Message) error
GetFrom decodes XOR-PEER-ADDRESS from message.
func (RelayedAddress) String ¶
func (a RelayedAddress) String() string
type RequestedAddressFamily ¶
type RequestedAddressFamily byte
RequestedAddressFamily represents the REQUESTED-ADDRESS-FAMILY Attribute as defined in RFC 6156 Section 4.1.1.
const ( RequestedFamilyIPv4 RequestedAddressFamily = 0x01 RequestedFamilyIPv6 RequestedAddressFamily = 0x02 )
Values for RequestedAddressFamily as defined in RFC 6156 Section 4.1.1.
func (RequestedAddressFamily) AddTo ¶
func (f RequestedAddressFamily) AddTo(m *stun.Message) error
AddTo adds REQUESTED-ADDRESS-FAMILY to message.
func (*RequestedAddressFamily) GetFrom ¶
func (f *RequestedAddressFamily) GetFrom(m *stun.Message) error
GetFrom decodes REQUESTED-ADDRESS-FAMILY from message.
func (RequestedAddressFamily) String ¶
func (f RequestedAddressFamily) String() string
type RequestedTransport ¶
type RequestedTransport struct {
Protocol Protocol
}
RequestedTransport represents REQUESTED-TRANSPORT attribute.
This attribute is used by the client to request a specific transport protocol for the allocated transport address. RFC 5766 only allows the use of code point 17 (User Datagram Protocol).
func (RequestedTransport) AddTo ¶
func (t RequestedTransport) AddTo(m *stun.Message) error
AddTo adds REQUESTED-TRANSPORT to message.
func (*RequestedTransport) GetFrom ¶
func (t *RequestedTransport) GetFrom(m *stun.Message) error
GetFrom decodes REQUESTED-TRANSPORT from message.
func (RequestedTransport) String ¶
func (t RequestedTransport) String() string
type ReservationToken ¶
type ReservationToken []byte
ReservationToken represents RESERVATION-TOKEN attribute.
The RESERVATION-TOKEN attribute contains a token that uniquely identifies a relayed transport address being held in reserve by the server. The server includes this attribute in a success response to tell the client about the token, and the client includes this attribute in a subsequent Allocate request to request the server use that relayed transport address for the allocation.
type XORPeerAddress ¶
type XORPeerAddress = PeerAddress
XORPeerAddress implements XOR-PEER-ADDRESS attribute.
The XOR-PEER-ADDRESS specifies the address and port of the peer as seen from the TURN server. (For example, the peer's server-reflexive transport address if the peer is behind a NAT.)
type XORRelayedAddress ¶
type XORRelayedAddress = RelayedAddress
XORRelayedAddress implements XOR-RELAYED-ADDRESS attribute.
It specifies the address and port that the server allocated to the client. It is encoded in the same way as XOR-MAPPED-ADDRESS.