Documentation ¶
Overview ¶
Package turn contains the public API for pion/turn, a toolkit for building TURN clients and servers
Index ¶
- func GenerateAuthKey(username, realm, password string) []byte
- func GenerateLongTermCredentials(sharedSecret string, duration time.Duration) (string, string, error)
- type AuthHandler
- type Client
- func (c *Client) Allocate() (net.PacketConn, error)
- func (c *Client) Close()
- func (c *Client) CreatePermission(addrs ...net.Addr) error
- func (c *Client) HandleInbound(data []byte, from net.Addr) (bool, error)
- func (c *Client) Listen() error
- func (c *Client) OnDeallocated(relayedAddr net.Addr)
- func (c *Client) PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult bool) (client.TransactionResult, error)
- func (c *Client) Realm() stun.Realm
- func (c *Client) STUNServerAddr() net.Addr
- func (c *Client) SendBindingRequest() (net.Addr, error)
- func (c *Client) SendBindingRequestTo(to net.Addr) (net.Addr, error)
- func (c *Client) TURNServerAddr() net.Addr
- func (c *Client) Username() stun.Username
- func (c *Client) WriteTo(data []byte, to net.Addr) (int, error)
- type ClientConfig
- type ListenerConfig
- type PacketConnConfig
- type RelayAddressGenerator
- type RelayAddressGeneratorNone
- type RelayAddressGeneratorPortRange
- func (r *RelayAddressGeneratorPortRange) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error)
- func (r *RelayAddressGeneratorPortRange) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error)
- func (r *RelayAddressGeneratorPortRange) Validate() error
- type RelayAddressGeneratorStatic
- type STUNConn
- func (s *STUNConn) Close() error
- func (s *STUNConn) LocalAddr() net.Addr
- func (s *STUNConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (s *STUNConn) SetDeadline(t time.Time) error
- func (s *STUNConn) SetReadDeadline(t time.Time) error
- func (s *STUNConn) SetWriteDeadline(t time.Time) error
- func (s *STUNConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type Server
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAuthKey ¶
GenerateAuthKey is a convince function to easily generate keys in the format used by AuthHandler
Types ¶
type AuthHandler ¶
AuthHandler is a callback used to handle incoming auth requests, allowing users to customize Pion TURN with custom behavior
func NewLongTermAuthHandler ¶ added in v2.0.5
func NewLongTermAuthHandler(sharedSecret string, l logging.LeveledLogger) AuthHandler
NewLongTermAuthHandler returns a turn.AuthAuthHandler used with Long Term (or Time Windowed) Credentials. https://tools.ietf.org/search/rfc5389#section-10.2
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a STUN server client
func NewClient ¶
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) Allocate ¶
func (c *Client) Allocate() (net.PacketConn, error)
Allocate sends a TURN allocation request to the given transport address
func (*Client) CreatePermission ¶ added in v2.0.7
CreatePermission Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9
func (*Client) HandleInbound ¶
HandleInbound handles data received. This method handles incoming packet demultiplex it by the source address and the types of the message. This return a booleen (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.
func (*Client) Listen ¶
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.
func (*Client) OnDeallocated ¶
OnDeallocated is called when deallocation of relay address has been complete. (Called by UDPConn)
func (*Client) PerformTransaction ¶
func (c *Client) PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult bool) (client.TransactionResult, error)
PerformTransaction performs STUN transaction
func (*Client) STUNServerAddr ¶
STUNServerAddr return the STUN server address
func (*Client) SendBindingRequest ¶
SendBindingRequest sends a new STUN request to the STUN server
func (*Client) SendBindingRequestTo ¶
SendBindingRequestTo sends a new STUN request to the given transport address
func (*Client) TURNServerAddr ¶
TURNServerAddr return the TURN server address
type ClientConfig ¶
type ClientConfig struct { STUNServerAddr string // STUN server address (e.g. "stun.abc.com:3478") TURNServerAddr string // TURN server addrees (e.g. "turn.abc.com:3478") Username string Password string Realm string Software string RTO time.Duration Conn net.PacketConn // Listening socket (net.PacketConn) LoggerFactory logging.LoggerFactory Net *vnet.Net }
ClientConfig is a bag of config parameters for Client.
type ListenerConfig ¶
type ListenerConfig struct { Listener net.Listener // When an allocation is generated the RelayAddressGenerator // creates the net.PacketConn and returns the IP/Port it is available at RelayAddressGenerator RelayAddressGenerator }
ListenerConfig is a single net.Listener to accept connections on. This will be used for TCP, TLS and DTLS listeners
type PacketConnConfig ¶
type PacketConnConfig struct { PacketConn net.PacketConn // When an allocation is generated the RelayAddressGenerator // creates the net.PacketConn and returns the IP/Port it is available at RelayAddressGenerator RelayAddressGenerator }
PacketConnConfig is a single net.PacketConn to listen/write on. This will be used for UDP listeners
type RelayAddressGenerator ¶
type RelayAddressGenerator interface { // Validate confirms that the RelayAddressGenerator is properly initialized Validate() error // Allocate a PacketConn (UDP) RelayAddress AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error) // Allocate a Conn (TCP) RelayAddress AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error) }
RelayAddressGenerator is used to generate a RelayAddress when creating an allocation. You can use one of the provided ones or provide your own.
type RelayAddressGeneratorNone ¶
type RelayAddressGeneratorNone struct { // Address is passed to Listen/ListenPacket when creating the Relay Address string Net *vnet.Net }
RelayAddressGeneratorNone returns the listener with no modifications
func (*RelayAddressGeneratorNone) AllocateConn ¶
func (r *RelayAddressGeneratorNone) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error)
AllocateConn generates a new Conn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorNone) AllocatePacketConn ¶
func (r *RelayAddressGeneratorNone) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error)
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorNone) Validate ¶
func (r *RelayAddressGeneratorNone) Validate() error
Validate is caled on server startup and confirms the RelayAddressGenerator is properly configured
type RelayAddressGeneratorPortRange ¶ added in v2.0.5
type RelayAddressGeneratorPortRange struct { // RelayAddress is the IP returned to the user when the relay is created RelayAddress net.IP // MinPort the minimum port to allocate MinPort uint16 // MaxPort the maximum (inclusive) port to allocate MaxPort uint16 // MaxRetries the amount of tries to allocate a random port in the defined range MaxRetries int // Rand the random source of numbers Rand randutil.MathRandomGenerator // Address is passed to Listen/ListenPacket when creating the Relay Address string Net *vnet.Net }
RelayAddressGeneratorPortRange can be used to only allocate connections inside a defined port range. Similar to the RelayAddressGeneratorStatic a static ip address can be set.
func (*RelayAddressGeneratorPortRange) AllocateConn ¶ added in v2.0.5
func (r *RelayAddressGeneratorPortRange) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error)
AllocateConn generates a new Conn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorPortRange) AllocatePacketConn ¶ added in v2.0.5
func (r *RelayAddressGeneratorPortRange) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error)
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorPortRange) Validate ¶ added in v2.0.5
func (r *RelayAddressGeneratorPortRange) Validate() error
Validate is called on server startup and confirms the RelayAddressGenerator is properly configured
type RelayAddressGeneratorStatic ¶
type RelayAddressGeneratorStatic struct { // RelayAddress is the IP returned to the user when the relay is created RelayAddress net.IP // Address is passed to Listen/ListenPacket when creating the Relay Address string Net *vnet.Net }
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
func (*RelayAddressGeneratorStatic) AllocateConn ¶
func (r *RelayAddressGeneratorStatic) AllocateConn(network string, requestedPort int) (net.Conn, net.Addr, error)
AllocateConn generates a new Conn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorStatic) AllocatePacketConn ¶
func (r *RelayAddressGeneratorStatic) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error)
AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port to populate the allocation response with
func (*RelayAddressGeneratorStatic) Validate ¶
func (r *RelayAddressGeneratorStatic) Validate() error
Validate is caled on server startup and confirms the RelayAddressGenerator is properly configured
type STUNConn ¶
type STUNConn struct {
// contains filtered or unexported fields
}
STUNConn wraps a net.Conn and implements net.PacketConn by being STUN aware and packetizing the stream
func (*STUNConn) SetDeadline ¶
SetDeadline implements SetDeadline from net.PacketConn
func (*STUNConn) SetReadDeadline ¶
SetReadDeadline implements SetReadDeadline from net.PacketConn
func (*STUNConn) SetWriteDeadline ¶
SetWriteDeadline implements SetWriteDeadline from net.PacketConn
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an instance of the Pion TURN Server
func NewServer ¶
func NewServer(config ServerConfig) (*Server, error)
NewServer creates the Pion TURN server
func (*Server) AllocationCount ¶ added in v2.0.6
AllocationCount returns the number of active allocations. It can be used to drain the server before closing
type ServerConfig ¶
type ServerConfig struct { // PacketConnConfigs and ListenerConfigs are a list of all the turn listeners // Each listener can have custom behavior around the creation of Relays PacketConnConfigs []PacketConnConfig ListenerConfigs []ListenerConfig // LoggerFactory must be set for logging from this server. LoggerFactory logging.LoggerFactory // Realm sets the realm for this server Realm string // AuthHandler is a callback used to handle incoming auth requests, allowing users to customize Pion TURN with custom behavior AuthHandler AuthHandler // ChannelBindTimeout sets the lifetime of channel binding. Defaults to 10 minutes. ChannelBindTimeout time.Duration // Sets the server inbound MTU(Maximum transmition unit). Defaults to 1600 bytes. InboundMTU int }
ServerConfig configures the Pion TURN Server
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
internal
|
|
allocation
Package allocation contains all CRUD operations for allocations
|
Package allocation contains all CRUD operations for allocations |
client
Package client implements the API for a TURN client
|
Package client implements the API for a TURN client |
ipnet
Package ipnet contains helper functions around net and IP
|
Package ipnet contains helper functions around net and IP |
proto
Package proto implements RFC 5766 Traversal Using Relays around NAT.
|
Package proto implements RFC 5766 Traversal Using Relays around NAT. |
server
Package server implements the private API to implement a TURN server
|
Package server implements the private API to implement a TURN server |