Documentation ¶
Overview ¶
Package client implements the API for a TURN client
Package client implements the API for a TURN client
Index ¶
- type AllocationConfig
- type Client
- type PeriodicTimer
- type PeriodicTimerTimeoutHandler
- type TCPAllocation
- func (a *TCPAllocation) Accept() (net.Conn, error)
- func (a *TCPAllocation) AcceptTCP() (transport.TCPConn, error)
- func (a *TCPAllocation) AcceptTCPWithConn(conn net.Conn) (*TCPConn, error)
- func (a *TCPAllocation) Addr() net.Addr
- func (a *TCPAllocation) BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error
- func (a *TCPAllocation) Close() error
- func (a *TCPAllocation) Connect(peer net.Addr) (proto.ConnectionID, error)
- func (a *TCPAllocation) CreatePermissions(addrs ...net.Addr) error
- func (a *TCPAllocation) Dial(network, rAddrStr string) (net.Conn, error)
- func (a *TCPAllocation) DialTCP(network string, lAddr, rAddr *net.TCPAddr) (*TCPConn, error)
- func (a *TCPAllocation) DialTCPWithConn(conn net.Conn, _ string, rAddr *net.TCPAddr) (*TCPConn, error)
- func (a *TCPAllocation) DialWithConn(conn net.Conn, network, rAddrStr string) (*TCPConn, error)
- func (a *TCPAllocation) HandleConnectionAttempt(from *net.TCPAddr, cid proto.ConnectionID)
- func (a *TCPAllocation) SetDeadline(t time.Time) error
- type TCPConn
- type Transaction
- type TransactionConfig
- type TransactionMap
- type TransactionResult
- type TryLock
- type UDPConn
- func (c *UDPConn) Close() error
- func (a *UDPConn) CreatePermissions(addrs ...net.Addr) error
- func (c *UDPConn) FindAddrByChannelNumber(chNum uint16) (net.Addr, bool)
- func (c *UDPConn) HandleInbound(data []byte, from net.Addr)
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteDeadline(time.Time) error
- func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllocationConfig ¶ added in v2.1.1
type AllocationConfig struct { Client Client RelayedAddr net.Addr ServerAddr net.Addr Integrity stun.MessageIntegrity Nonce stun.Nonce Username stun.Username Realm stun.Realm Lifetime time.Duration Net transport.Net Log logging.LeveledLogger }
AllocationConfig is a set of configuration params use by NewUDPConn and NewTCPAllocation
type Client ¶ added in v2.1.1
type Client interface { WriteTo(data []byte, to net.Addr) (int, error) PerformTransaction(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) OnDeallocated(relayedAddr net.Addr) }
Client is an interface for the public turn.Client in order to break cyclic dependencies
type PeriodicTimer ¶
type PeriodicTimer struct {
// contains filtered or unexported fields
}
PeriodicTimer is a periodic timer
func NewPeriodicTimer ¶
func NewPeriodicTimer(id int, timeoutHandler PeriodicTimerTimeoutHandler, interval time.Duration) *PeriodicTimer
NewPeriodicTimer create a new timer
func (*PeriodicTimer) IsRunning ¶
func (t *PeriodicTimer) IsRunning() bool
IsRunning tests if the timer is running. Debug purpose only
type PeriodicTimerTimeoutHandler ¶
type PeriodicTimerTimeoutHandler func(timerID int)
PeriodicTimerTimeoutHandler is a handler called on timeout
type TCPAllocation ¶ added in v2.1.1
type TCPAllocation struct {
// contains filtered or unexported fields
}
TCPAllocation is an active TCP allocation on the TURN server as specified by RFC 6062. The allocation can be used to Dial/Accept relayed outgoing/incoming TCP connections.
func NewTCPAllocation ¶ added in v2.1.1
func NewTCPAllocation(config *AllocationConfig) *TCPAllocation
NewTCPAllocation creates a new instance of TCPConn
func (*TCPAllocation) Accept ¶ added in v2.1.1
func (a *TCPAllocation) Accept() (net.Conn, error)
Accept waits for and returns the next connection to the listener.
func (*TCPAllocation) AcceptTCP ¶ added in v2.1.1
func (a *TCPAllocation) AcceptTCP() (transport.TCPConn, error)
AcceptTCP accepts the next incoming call and returns the new connection.
func (*TCPAllocation) AcceptTCPWithConn ¶ added in v2.1.1
func (a *TCPAllocation) AcceptTCPWithConn(conn net.Conn) (*TCPConn, error)
AcceptTCPWithConn accepts the next incoming call and returns the new connection.
func (*TCPAllocation) Addr ¶ added in v2.1.1
func (a *TCPAllocation) Addr() net.Addr
Addr returns the relayed address of the allocation
func (*TCPAllocation) BindConnection ¶ added in v2.1.1
func (a *TCPAllocation) BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error
BindConnection associates the provided connection
func (*TCPAllocation) Close ¶ added in v2.1.1
func (a *TCPAllocation) Close() error
Close releases the allocation Any blocked Accept operations will be unblocked and return errors. Any opened connection via Dial/Accept will be closed.
func (*TCPAllocation) Connect ¶ added in v2.1.1
func (a *TCPAllocation) Connect(peer net.Addr) (proto.ConnectionID, error)
Connect sends a Connect request to the turn server and returns a chosen connection ID
func (*TCPAllocation) CreatePermissions ¶ added in v2.1.1
CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9
func (*TCPAllocation) Dial ¶ added in v2.1.1
func (a *TCPAllocation) Dial(network, rAddrStr string) (net.Conn, error)
Dial connects to the address on the named network.
func (*TCPAllocation) DialTCPWithConn ¶ added in v2.1.1
func (a *TCPAllocation) DialTCPWithConn(conn net.Conn, _ string, rAddr *net.TCPAddr) (*TCPConn, error)
DialTCPWithConn acts like DialWithConn for TCP networks.
func (*TCPAllocation) DialWithConn ¶ added in v2.1.1
DialWithConn connects to the address on the named network with an already existing connection. The provided connection must be an already connected TCP connection to the TURN server.
func (*TCPAllocation) HandleConnectionAttempt ¶ added in v2.1.1
func (a *TCPAllocation) HandleConnectionAttempt(from *net.TCPAddr, cid proto.ConnectionID)
HandleConnectionAttempt is called by the TURN client when it receives a ConnectionAttempt indication.
func (*TCPAllocation) SetDeadline ¶ added in v2.1.1
func (a *TCPAllocation) SetDeadline(t time.Time) error
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
type TCPConn ¶ added in v2.1.1
type TCPConn struct { transport.TCPConn ConnectionID proto.ConnectionID // contains filtered or unexported fields }
TCPConn wraps a transport.TCPConn and returns the allocations relayed transport address in response to TCPConn.LocalAddress()
func (*TCPConn) LocalAddr ¶ added in v2.1.1
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*TCPConn) RemoteAddr ¶ added in v2.1.1
RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
type Transaction ¶
type Transaction struct { Key string // Read-only Raw []byte // Read-only To net.Addr // Read-only // contains filtered or unexported fields }
Transaction represents a transaction
func NewTransaction ¶
func NewTransaction(config *TransactionConfig) *Transaction
NewTransaction creates a new instance of Transaction
func (*Transaction) Retries ¶
func (t *Transaction) Retries() int
Retries returns the number of retransmission it has made
func (*Transaction) StartRtxTimer ¶
func (t *Transaction) StartRtxTimer(onTimeout func(trKey string, nRtx int))
StartRtxTimer starts the transaction timer
func (*Transaction) StopRtxTimer ¶
func (t *Transaction) StopRtxTimer()
StopRtxTimer stop the transaction timer
func (*Transaction) WaitForResult ¶
func (t *Transaction) WaitForResult() TransactionResult
WaitForResult waits for the transaction result
func (*Transaction) WriteResult ¶
func (t *Transaction) WriteResult(res TransactionResult) bool
WriteResult writes the result to the result channel
type TransactionConfig ¶
type TransactionConfig struct { Key string Raw []byte To net.Addr Interval time.Duration IgnoreResult bool // True to throw away the result of this transaction (it will not be readable using WaitForResult) }
TransactionConfig is a set of config params used by NewTransaction
type TransactionMap ¶
type TransactionMap struct {
// contains filtered or unexported fields
}
TransactionMap is a thread-safe transaction map
func NewTransactionMap ¶
func NewTransactionMap() *TransactionMap
NewTransactionMap create a new instance of the transaction map
func (*TransactionMap) CloseAndDeleteAll ¶
func (m *TransactionMap) CloseAndDeleteAll()
CloseAndDeleteAll closes and deletes all transactions
func (*TransactionMap) Delete ¶
func (m *TransactionMap) Delete(key string)
Delete deletes a transaction by its key
func (*TransactionMap) Find ¶
func (m *TransactionMap) Find(key string) (*Transaction, bool)
Find looks up a transaction by its key
func (*TransactionMap) Insert ¶
func (m *TransactionMap) Insert(key string, tr *Transaction) bool
Insert inserts a transaction to the map
func (*TransactionMap) Size ¶
func (m *TransactionMap) Size() int
Size returns the length of the transaction map
type TransactionResult ¶
TransactionResult is a bag of result values of a transaction
type TryLock ¶
type TryLock struct {
// contains filtered or unexported fields
}
TryLock implement the classic "try-lock" operation.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. compatible with net.PacketConn and net.Conn
func NewUDPConn ¶
func NewUDPConn(config *AllocationConfig) *UDPConn
NewUDPConn creates a new instance of UDPConn
func (*UDPConn) Close ¶
Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
func (*UDPConn) CreatePermissions ¶ added in v2.0.7
CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9
func (*UDPConn) FindAddrByChannelNumber ¶
FindAddrByChannelNumber returns a peer address associated with the channel number on this UDPConn
func (*UDPConn) HandleInbound ¶
HandleInbound passes inbound data in UDPConn
func (*UDPConn) ReadFrom ¶
ReadFrom reads a packet from the connection, copying the payload into p. It returns the number of bytes copied into p and the return address that was on the packet. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Callers should always process the n > 0 bytes returned before considering the error err. ReadFrom can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*UDPConn) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to ReadFrom or WriteTo. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.
A zero value for t means I/O operations will not time out.
func (*UDPConn) SetReadDeadline ¶
SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.
func (*UDPConn) SetWriteDeadline ¶
SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.