turn

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: MIT Imports: 16 Imported by: 10

README

Pion TURN
Pion TURN

An extendable TURN server written in Go

Pion TURN Slack Widget Waffle board
Build Status GoDoc Coverage Status Go Report Card Codacy Badge


A TURN server written in Go that is designed to be scalable, extendable and embeddable out of the box. For simple use cases it only requires downloading 1 static binary, and setting 3 options.

See DESIGN.md for the the features it offers, and future goals.

Quick Start

If you want just a simple TURN server with a few static usernames simple-turn will perfectly suit your purposes. If you have custom requirements such as a database proceed to extending.

simple-turn is a single static binary, and all config is driven by environment variables. On a fresh Linux AWS instance these are all the steps you would need.

$ wget -q https://github.com/pion/turn/releases/download/1.0.3/simple-turn-linux-amd64
$ chmod +x simple-turn-linux-amd64
$ export USERS='user=password foo=bar'
$ export REALM=my-server.com
$ export UDP_PORT=3478
$ ./simple-turn-linux-amd64

To explain what every step does

  • Download simple-turn for Linux x64, see release for other platforms
  • Make it executable
  • Configure auth, in the form of USERNAME=PASSWORD USERNAME=PASSWORD with no limits
  • Set your realm, this is the public URL or name of your server
  • Set the port you listen on, 3478 is the default port for TURN

That is it! Then to use your new TURN server your WebRTC config would look like

{ iceServers: [{
  urls: "turn:YOUR_SERVER"
  username: "user",
  credential: "password"
}]

If you are using Windows you would set these values in Powershell by doing. Also make sure your firewall is configured properly.

> $env:USERS = "user=password foo=bar"
> $env:REALM = "my-server.com"
> $env:UDP_PORT = 3478

Extending

See simple-turn

pion-turn can be configured by implementing these callbacks and by passing these arguments

All that simple-turn does is take environment variables, and then uses the same API.

Developing

For developing a Dockerfile is available with features like hot-reloads, and is meant to be volume mounted. Make sure you also have github.com/pion/pkg in your path, or you can exclude the second volume mount.

This is only meant for development, see demo-conference to see TURN usage as a user.

docker build -t turn .
docker run -v $(pwd):/usr/local/src/github.com/pion/turn -v $(pwd)/../pkg:/usr/local/src/github.com/pion/pkg turn

Currently only Linux is supported until Docker supports full (host <-> container) networking on Windows/OSX

RFCs

Implemented

Planned

Community

Pion has an active community on the Golang Slack. Sign up and join the #pion channel for discussions and support. You can also use Pion mailing list.

We are always looking to support your projects. Please reach out if you have something to build!

Contributing

Check out the CONTRIBUTING.md to join the group of amazing people making this project possible:

License

MIT License - see LICENSE.md for full text

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthHandler added in v1.2.0

type AuthHandler func(username string, srcAddr net.Addr) (password string, ok bool)

AuthHandler is a callback used to handle incoming auth requests, allowing users to customize Pion TURN with custom behavior

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a STUN server client

func NewClient added in v1.2.0

func NewClient(config *ClientConfig) (*Client, error)

NewClient returns a new Client instance. listeningAddress is the address and port to listen on, default "0.0.0.0:0"

func (*Client) SendSTUNRequest

func (c *Client) SendSTUNRequest(serverIP net.IP, serverPort int) (net.Addr, error)

SendSTUNRequest sends a new STUN request to the serverIP with serverPort

type ClientConfig added in v1.2.0

type ClientConfig struct {
	ListeningAddress string
	LoggerFactory    logging.LoggerFactory
	Net              *vnet.Net
}

ClientConfig is a bag of config parameters for Client.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an instance of the Pion TURN server

func NewServer added in v1.2.0

func NewServer(config *ServerConfig) *Server

NewServer creates the Pion TURN server

func (*Server) AddListeningIPAddr added in v1.2.0

func (s *Server) AddListeningIPAddr(addrStr string) error

AddListeningIPAddr adds a listening IP address. This method must be called before calling Start().

func (*Server) Close added in v1.2.0

func (s *Server) Close() error

Close closes the connection.

func (*Server) Start added in v1.2.0

func (s *Server) Start() error

Start starts the server.

type ServerConfig added in v1.2.0

type ServerConfig struct {
	Realm              string
	AuthHandler        AuthHandler
	ChannelBindTimeout time.Duration
	ListeningPort      int
	LoggerFactory      logging.LoggerFactory
	Net                *vnet.Net
}

ServerConfig is a bag of config parameters for Server.

Directories

Path Synopsis
cmd
client command
simple-turn command
internal

Jump to

Keyboard shortcuts

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