package turn
Import Path
github.com/pion/turn/v4 (on go.dev)
Dependency Relation
imports 22 packages, and imported by one package
Involved Source Files
client.go
errors.go
lt_cred.go
relay_address_generator_none.go
relay_address_generator_range.go
relay_address_generator_static.go
Package turn contains the public API for pion/turn, a toolkit for building TURN clients and servers
server_config.go
stun_conn.go
Package-Level Type Names (total 13)
AuthHandler is a callback used to handle incoming auth requests,
allowing users to customize Pion TURN with custom behavior.
func LongTermTURNRESTAuthHandler(sharedSecret string, logger logging.LeveledLogger) AuthHandler
func NewLongTermAuthHandler(sharedSecret string, logger logging.LeveledLogger) AuthHandler
Client is a STUN server client.
Allocate sends a TURN allocation request to the given transport address.
AllocateTCP creates a new TCP allocation at the TURN server.
Close closes this client.
CreatePermission Issues a CreatePermission request for the supplied addresses
as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9
HandleInbound handles data received.
This method handles incoming packet de-multiplex it by the source address
and the types of the message.
This return a boolean (handled or not) and if there was an error.
Caller should check if the packet was handled by this client or not.
If not handled, it is assumed that the packet is application data.
If an error is returned, the caller should discard the packet regardless.
Listen will have this client start listening on the conn provided via the config.
This is optional. If not used, you will need to call HandleInbound method
to supply incoming data, instead.
OnDeallocated is called when de-allocation of relay address has been complete.
(Called by UDPConn).
PerformTransaction performs STUN transaction.
Realm return realm.
STUNServerAddr return the STUN server address.
SendBindingRequest sends a new STUN request to the STUN server.
SendBindingRequestTo sends a new STUN request to the given transport address.
TURNServerAddr return the TURN server address.
Username returns username.
WriteTo sends data to the specified destination using the base socket.
*Client : github.com/pion/turn/v4/internal/client.Client
func NewClient(config *ClientConfig) (*Client, error)
ClientConfig is a bag of config parameters for Client.
// Listening socket (net.PacketConn)
LoggerFactory logging.LoggerFactory
Net transport.Net
Password string
RTO time.Duration
Realm string
// STUN server address (e.g. "stun.abc.com:3478")
Software string
// TURN server address (e.g. "turn.abc.com:3478")
Username string
func NewClient(config *ClientConfig) (*Client, error)
ListenerConfig is a single net.Listener to accept connections on.
This will be used for TCP, TLS and DTLS listeners.
Listener net.Listener
PermissionHandler is a callback to filter peer addresses. Can be set as nil, in which
case the DefaultPermissionHandler is automatically instantiated to admit all peer
connections
When an allocation is generated the RelayAddressGenerator
creates the net.PacketConn and returns the IP/Port it is available at
PacketConnConfig is a single net.PacketConn to listen/write on.
This will be used for UDP listeners.
PacketConn net.PacketConn
PermissionHandler is a callback to filter peer addresses. Can be set as nil, in which
case the DefaultPermissionHandler is automatically instantiated to admit all peer
connections
When an allocation is generated the RelayAddressGenerator
creates the net.PacketConn and returns the IP/Port it is available at
PermissionHandler is a callback to filter incoming CreatePermission and ChannelBindRequest
requests based on the client IP address and port and the peer IP address the client intends to
connect to. If the client is behind a NAT then the filter acts on the server reflexive
("mapped") address instead of the real client IP address and port. Note that TURN permissions
are per-allocation and per-peer-IP-address, to mimic the address-restricted filtering mechanism
of NATs that comply with [RFC4787], see https://tools.ietf.org/html/rfc5766#section-2.3.
RelayAddressGenerator is used to generate a RelayAddress when creating an allocation.
You can use one of the provided ones or provide your own.
Allocate a Conn (TCP) RelayAddress
Allocate a PacketConn (UDP) RelayAddress
Validate confirms that the RelayAddressGenerator is properly initialized
*RelayAddressGeneratorNone
*RelayAddressGeneratorPortRange
*RelayAddressGeneratorStatic
RelayAddressGeneratorNone returns the listener with no modifications.
Address is passed to Listen/ListenPacket when creating the Relay
Net transport.Net
AllocateConn generates a new Conn to receive traffic on and the IP/Port
to populate the allocation response with.
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port
to populate the allocation response with.
Validate is called on server startup and confirms the RelayAddressGenerator is properly configured.
*RelayAddressGeneratorNone : RelayAddressGenerator
RelayAddressGeneratorPortRange can be used to only allocate connections inside a defined port range.
Similar to the RelayAddressGeneratorStatic a static ip address can be set.
Address is passed to Listen/ListenPacket when creating the Relay
MaxPort the maximum (inclusive) port to allocate
MaxRetries the amount of tries to allocate a random port in the defined range
MinPort the minimum port to allocate
Net transport.Net
Rand the random source of numbers
RelayAddress is the IP returned to the user when the relay is created
AllocateConn generates a new Conn to receive traffic on and the IP/Port
to populate the allocation response with.
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port
to populate the allocation response with.
Validate is called on server startup and confirms the RelayAddressGenerator is properly configured.
*RelayAddressGeneratorPortRange : RelayAddressGenerator
RelayAddressGeneratorStatic can be used to return static IP address each time a relay is created.
This can be used when you have a single static IP address that you want to use.
Address is passed to Listen/ListenPacket when creating the Relay
Net transport.Net
RelayAddress is the IP returned to the user when the relay is created
AllocateConn generates a new Conn to receive traffic on and the IP/Port
to populate the allocation response with.
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port
to populate the allocation response with.
Validate is called on server startup and confirms the RelayAddressGenerator is properly configured.
*RelayAddressGeneratorStatic : RelayAddressGenerator
Server is an instance of the Pion TURN Server.
AllocationCount returns the number of active allocations.
It can be used to drain the server before closing.
Close stops the TURN Server.
It cleans up any associated state and closes all connections it is managing.
*Server : github.com/prometheus/common/expfmt.Closer
*Server : io.Closer
func NewServer(config ServerConfig) (*Server, error)
ServerConfig configures the Pion TURN Server.
AuthHandler is a callback used to handle incoming auth requests,
allowing users to customize Pion TURN with custom behavior
ChannelBindTimeout sets the lifetime of channel binding. Defaults to 10 minutes.
Sets the server inbound MTU(Maximum transmition unit). Defaults to 1600 bytes.
ListenerConfigs []ListenerConfig
LoggerFactory must be set for logging from this server.
PacketConnConfigs and ListenerConfigs are a list of all the turn listeners
Each listener can have custom behavior around the creation of Relays
Realm sets the realm for this server
func NewServer(config ServerConfig) (*Server, error)
STUNConn wraps a net.Conn and implements
net.PacketConn by being STUN aware and
packetizing the stream.
Close implements Close from net.PacketConn.
LocalAddr implements LocalAddr from net.PacketConn.
ReadFrom implements ReadFrom from net.PacketConn.
SetDeadline implements SetDeadline from net.PacketConn.
SetReadDeadline implements SetReadDeadline from net.PacketConn.
SetWriteDeadline implements SetWriteDeadline from net.PacketConn.
WriteTo implements WriteTo from net.PacketConn.
*STUNConn : github.com/pion/datachannel.ReadDeadliner
*STUNConn : github.com/pion/datachannel.WriteDeadliner
*STUNConn : github.com/prometheus/common/expfmt.Closer
*STUNConn : io.Closer
*STUNConn : net.PacketConn
func NewSTUNConn(nextConn net.Conn) *STUNConn
Package-Level Functions (total 9)
DefaultPermissionHandler is convince function that grants permission to all peers.
GenerateAuthKey is a convenience function to easily generate keys in the format used by AuthHandler.
GenerateLongTermCredentials can be used to create credentials valid for [duration] time.
GenerateLongTermTURNRESTCredentials can be used to create credentials valid for [duration] time.
LongTermTURNRESTAuthHandler returns a turn.AuthAuthHandler that can be used to authenticate
time-windowed ephemeral credentials generated by the TURN REST API as described in
https://datatracker.ietf.org/doc/html/draft-uberti-behave-turn-rest-00
The supported format of is timestamp:username, where username is an arbitrary user id and the
timestamp specifies the expiry of the credential.
NewClient returns a new Client instance. listeningAddress is the address and port to listen on,
default "0.0.0.0:0".
NewLongTermAuthHandler returns a turn.AuthAuthHandler used with Long Term (or Time Windowed) Credentials.
See: https://datatracker.ietf.org/doc/html/rfc8489#section-9.2
.
NewServer creates the Pion TURN server.
NewSTUNConn creates a STUNConn.
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |