turn

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Build Status Build status GoDoc Coverage Status Go Report

TURN

Package turn implements Traversal Using Relays around NAT.

Work in progress.

RFCs

The package aims to implement the follwing RFCs. Note that the requirement status is based on the WebRTC spec, focusing on data channels for now.

rfc status requirement description
RFC5766 status status Traversal Using Relays around NAT
RFC6156 status status TURN Extension for IPv6
(TLS-over-)TCP status status Sending over TCP or TLS-over-TCP

Benchmarks

goos: linux
goarch: amd64
pkg: github.com/gortc/turn
PASS
benchmark                                iter     time/iter   bytes alloc        allocs
---------                                ----     ---------   -----------        ------
BenchmarkChannelNumber/AddTo-12     100000000   12.50 ns/op        0 B/op   0 allocs/op
BenchmarkChannelNumber/GetFrom-12   200000000    7.30 ns/op        0 B/op   0 allocs/op
BenchmarkData/AddTo-12              100000000   18.40 ns/op        0 B/op   0 allocs/op
BenchmarkData/AddToRaw-12           100000000   16.00 ns/op        0 B/op   0 allocs/op
BenchmarkLifetime/AddTo-12          100000000   14.60 ns/op        0 B/op   0 allocs/op
BenchmarkLifetime/GetFrom-12        200000000    7.28 ns/op        0 B/op   0 allocs/op
ok  	github.com/gortc/turn	10.606s

Documentation

Overview

Package turn implements RFC 5766 Traversal Using Relays around NAT.

Index

Examples

Constants

View Source
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.

View Source
const DefaultLifetime = time.Minute * 10

DefaultLifetime in RFC 5766 is 10 minutes.

RFC 5766 Section 2.2

Variables

View Source
var (
	// AllocateRequest is shorthand for allocation request message type.
	AllocateRequest = stun.NewType(stun.MethodAllocate, stun.ClassRequest)
	// CreatePermissionRequest is shorthand for create permission request type.
	CreatePermissionRequest = stun.NewType(stun.MethodCreatePermission, stun.ClassRequest)
	// SendIndication is shorthand for send indication message type.
	SendIndication = stun.NewType(stun.MethodSend, stun.ClassIndication)
	// RefreshRequest is shorthand for refresh request message type.
	RefreshRequest = stun.NewType(stun.MethodRefresh, stun.ClassRequest)
)
View Source
var RequestedTransportUDP stun.Setter = RequestedTransport{
	Protocol: ProtoUDP,
}

RequestedTransportUDP is setter for requested transport attribute with value ProtoUDP (17).

View Source
var ZeroLifetime stun.Setter = Lifetime{}

ZeroLifetime is shorthand for setting zero lifetime that indicates to close allocation.

Functions

This section is empty.

Types

type BadAttrLength

type BadAttrLength struct {
	Attr     stun.AttrType
	Got      int
	Expected int
}

BadAttrLength means that length for attribute is invalid.

func (BadAttrLength) Error

func (e BadAttrLength) Error() string

type ChannelNumber

type ChannelNumber int // encoded as uint16

ChannelNumber represents CHANNEL-NUMBER attribute.

The CHANNEL-NUMBER attribute contains the number of the channel.

RFC 5766 Section 14.1

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

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).

RFC 5766 Section 14.4

func (Data) AddTo

func (d Data) AddTo(m *stun.Message) error

AddTo adds DATA to message.

func (*Data) GetFrom

func (d *Data) GetFrom(m *stun.Message) error

GetFrom decodes DATA from message.

type DontFragmentAttr

type DontFragmentAttr bool

DontFragmentAttr represents DONT-FRAGMENT attribute.

var DontFragment DontFragmentAttr = true

DontFragment is shorthand for DontFragmentAttr.

func (DontFragmentAttr) AddTo

func (DontFragmentAttr) AddTo(m *stun.Message) error

AddTo adds DONT-FRAGMENT attribute to message.

func (DontFragmentAttr) IsSet

func (DontFragmentAttr) IsSet(m *stun.Message) bool

IsSet returns true if DONT-FRAGMENT attribute is set.

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.

RFC 5766 Section 14.6

func (EvenPort) AddTo

func (p EvenPort) AddTo(m *stun.Message) error

AddTo adds EVEN-PORT to message.

func (*EvenPort) GetFrom

func (p *EvenPort) GetFrom(m *stun.Message) error

GetFrom decodes EVEN-PORT from message.

func (EvenPort) String

func (p EvenPort) String() string

type Lifetime

type Lifetime struct {
	time.Duration
}

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.

RFC 5766 Section 14.2

Example
// Encoding lifetime to message.
m := new(stun.Message)
Lifetime{time.Minute}.AddTo(m)
m.WriteHeader()

// Decoding message.
mDec := new(stun.Message)
if _, err := m.WriteTo(mDec); err != nil {
	panic(err)
}
// Decoding lifetime from message.
l := Lifetime{}
l.GetFrom(m)
fmt.Println("Decoded:", l)
Output:
Decoded: 1m0s

func (Lifetime) AddTo

func (l Lifetime) AddTo(m *stun.Message) error

AddTo adds LIFETIME to message.

func (*Lifetime) GetFrom

func (l *Lifetime) GetFrom(m *stun.Message) error

GetFrom decodes LIFETIME from message.

type PeerAddress

type PeerAddress struct {
	IP   net.IP
	Port int
}

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.)

RFC 5766 Section 14.3

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
)

func (Protocol) String

func (p Protocol) String() string

type RelayedAddress

type RelayedAddress struct {
	IP   net.IP
	Port int
}

RelayedAddress implements XOR-RELAYED-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.)

RFC 5766 Section 14.5

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 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 codepoint 17 (User Datagram Protocol).

RFC 5766 Section 14.7

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.

RFC 5766 Section 14.9

func (ReservationToken) AddTo

func (t ReservationToken) AddTo(m *stun.Message) error

AddTo adds RESERVATION-TOKEN to message.

func (*ReservationToken) GetFrom

func (t *ReservationToken) GetFrom(m *stun.Message) error

GetFrom decodes RESERVATION-TOKEN from message.

Directories

Path Synopsis
cmd
turn-client command

Jump to

Keyboard shortcuts

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