goturn

package module
v0.0.0-...-19f4127 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2017 License: BSD-3-Clause Imports: 5 Imported by: 4

README

Go TURN

GoDoc

This is a library providing a Go interface compatible with the golang proxy package which connects through a TURN relay.

This package provides parsing and encoding support for STUN and TURN protocols.

Installation

go get github.com/willscott/goturn

Full Example

package main

import (
	"io/ioutil"
	"log"
	"net"
	"net/http"

	"github.com/willscott/goturn/client"
)

func main() {
	// Connect to the stun/turn server
	conn, err := net.Dial("tcp", "127.0.0.1:19302")
	if err != nil {
		log.Fatal("error dialing TURN server: ", err)
	}
	defer conn.Close()

	credentials := client.LongtermCredentials("username", "password")
	dialer, err := client.NewDialer(&credentials, conn)
	if err != nil {
		log.Fatal("failed to obtain dialer: ", err)
	}

	httpClient := &http.Client{Transport: &http.Transport{Dial: dialer.Dial}}
	httpResp, err := httpClient.Get("http://www.google.com/")
	if err != nil {
		log.Fatal("error performing http request: ", err)
	}
	defer httpResp.Body.Close()

	httpBody, err := ioutil.ReadAll(httpResp.Body)
	if err != nil {
		log.Fatal("error reading http response: ", err)
	}
	log.Printf("received %d bytes", len(httpBody))
}

Documentation

Overview

Package goturn is a native go language interface to STUN and TURN.

Index

Constants

View Source
const (
	BindingRequest       common.HeaderType = 0x0001
	SharedSecretRequest                    = 0x0002
	BindingResponse                        = 0x0101
	SharedSecretResponse                   = 0x0102
	BindingError                           = 0x0111
	SharedSecretError                      = 0x0112
)

STUN (RFC 5389) defined message types.

View Source
const (
	AllocateRequest             common.HeaderType = 0x0003
	RefreshRequest                                = 0x0004
	CreatePermissionRequest                       = 0x0008
	ChannelBindRequest                            = 0x0009
	ConnectRequest                                = 0x000a
	ConnectionBindRequest                         = 0x000b
	SendIndication                                = 0x0016
	DataIndication                                = 0x0017
	ConnectionAttemptIndication                   = 0x001c
	AllocateResponse                              = 0x0103
	RefreshResponse                               = 0x0104
	CreatePermissionResponse                      = 0x0108
	ChannelBindResponse                           = 0x0109
	ConnectResponse                               = 0x010a
	ConnectionBindResponse                        = 0x010b
	AllocateError                                 = 0x0113
	RefreshError                                  = 0x0114
	CreatePermissionError                         = 0x0118
	ChannelBindError                              = 0x0119
	ConnectError                                  = 0x011a
	ConnectionBindError                           = 0x011b
)

TURN (RFC 5766) defined message types.

View Source
const (
	EvenPort         common.AttributeType = 0x18
	DontFragment                          = 0x1A
	ReservationToken                      = 0x22
)

Deprecated: Should live in individual turn attribute implementations.

View Source
const (
	AlternateServer common.AttributeType = 0x8023
)

Deprecated: Should live in individual stun attribute implementations.

Variables

This section is empty.

Functions

func NewAllocateRequest

func NewAllocateRequest(network string, authenticated bool) (*common.Message, error)

NewAllocateRequest creates a new message requesting authorization with a remote server. The allocation request specifies the type of remote network that the client wishes interact with.

func NewBindingRequest

func NewBindingRequest() (*common.Message, error)

NewBindingRequest creates a STUN message for a client binding request.

func NewConnectRequest

func NewConnectRequest(to net.Addr) (*common.Message, error)

NewConnectRequest creates a message representing a request to create a new TCP connection for exchanging data with a remote address, Per RFC 6062.

func NewConnectionBindRequest

func NewConnectionBindRequest(connectionID uint32) (*common.Message, error)

NewConnectionBindRequest creates a message representing a request to turn the current connection with the server into a TCP connection relayed to a remote peer specified by a previously generated ConnectionID. Per RFC 6062.

func NewPermissionRequest

func NewPermissionRequest(to net.Addr) (*common.Message, error)

NewPermissionRequest creates a message requesting permission from the server to allow sending and receiving data with a remote Address.

func NewSendIndication

func NewSendIndication(host net.IP, port uint16, data []byte) (*common.Message, error)

NewSendIndication creates a message representing a request to send a message of data over an existing allocation.

func ParseStun

func ParseStun(data []byte) (*common.Message, error)

ParseStun parses a message in RFC 5389 STUN format. Attributes defined in subsequent standards will not be parsed.

func ParseTurn

func ParseTurn(data []byte, credentials *common.Credentials) (*common.Message, error)

ParseTurn Parses data per the RFC 5766 TURN specification. Undefined attribute types will be left un-parsed. Credentials, when provided, are used to validate provided message integrity (used for authenticity) of the parsed message.

Types

This section is empty.

Directories

Path Synopsis
Package client provides a high-level interface for connecting and querying STUN and TURN services.
Package client provides a high-level interface for connecting and querying STUN and TURN services.
Package stun represents the common data structures used in creating and parsing STUN messages.
Package stun represents the common data structures used in creating and parsing STUN messages.
examples
getIP
Package main Example requesting STUN binding from a remote server.
Package main Example requesting STUN binding from a remote server.
reflexiveTurn
Package main Example relays a message through a TURN server using the low-level interface.
Package main Example relays a message through a TURN server using the low-level interface.
tcpTurn
Package main Example uses net.Http over a TURN connection.
Package main Example uses net.Http over a TURN connection.
Package stun represents the attributes defined in the STUN RFC Standard.
Package stun represents the attributes defined in the STUN RFC Standard.
Package turn represents the attributes defined in the TURN RFC Standard.
Package turn represents the attributes defined in the TURN RFC Standard.

Jump to

Keyboard shortcuts

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