package client

Import Path
	github.com/pion/turn/v4/internal/client (on go.dev)

Dependency Relation
	imports 14 packages, and imported by one package

Involved Source Files allocation.go binding.go Package client implements the API for a TURN client errors.go periodic_timer.go permission.go tcp_alloc.go tcp_conn.go transaction.go trylock.go Package client implements the API for a TURN client
Package-Level Type Names (total 12)
/* sort by: | */
AllocationConfig is a set of configuration params use by NewUDPConn and NewTCPAllocation. Client Client Integrity stun.MessageIntegrity Lifetime time.Duration Log logging.LeveledLogger Net transport.Net Nonce stun.Nonce Realm stun.Realm RelayedAddr net.Addr ServerAddr net.Addr Username stun.Username func NewTCPAllocation(config *AllocationConfig) *TCPAllocation func NewUDPConn(config *AllocationConfig) *UDPConn
Client is an interface for the public turn.Client in order to break cyclic dependencies. ( Client) OnDeallocated(relayedAddr net.Addr) ( Client) PerformTransaction(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) ( Client) WriteTo(data []byte, to net.Addr) (int, error) *github.com/pion/turn/v4.Client
PeriodicTimer is a periodic timer. IsRunning tests if the timer is running. Debug purpose only. Start starts the timer. Stop stops the timer. func NewPeriodicTimer(id int, timeoutHandler PeriodicTimerTimeoutHandler, interval time.Duration) *PeriodicTimer
PeriodicTimerTimeoutHandler is a handler called on timeout. func NewPeriodicTimer(id int, timeoutHandler PeriodicTimerTimeoutHandler, interval time.Duration) *PeriodicTimer
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. Accept waits for and returns the next connection to the listener. AcceptTCP accepts the next incoming call and returns the new connection. AcceptTCPWithConn accepts the next incoming call and returns the new connection. Addr returns the relayed address of the allocation. BindConnection associates the provided connection. Close releases the allocation Any blocked Accept operations will be unblocked and return errors. Any opened connection via Dial/Accept will be closed. Connect sends a Connect request to the turn server and returns a chosen connection ID. CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9 Dial connects to the address on the named network. DialTCP acts like Dial for TCP networks. DialTCPWithConn acts like DialWithConn for TCP networks. 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. HandleConnectionAttempt is called by the TURN client when it receives a ConnectionAttempt indication. SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline. *TCPAllocation : github.com/pion/transport/v2.Dialer *TCPAllocation : github.com/pion/transport/v3.Dialer *TCPAllocation : github.com/pion/transport/v3.TCPListener *TCPAllocation : github.com/nats-io/nats.go.CustomDialer *TCPAllocation : github.com/prometheus/common/expfmt.Closer *TCPAllocation : golang.org/x/net/proxy.Dialer *TCPAllocation : io.Closer *TCPAllocation : net.Listener func NewTCPAllocation(config *AllocationConfig) *TCPAllocation func github.com/pion/turn/v4.(*Client).AllocateTCP() (*TCPAllocation, error)
TCPConn wraps a transport.TCPConn and returns the allocations relayed transport address in response to TCPConn.LocalAddress(). ConnectionID proto.ConnectionID TCPConn transport.TCPConn Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors. Close may or may not block until any buffered data is sent; for TCP connections see [*TCPConn.SetLinger]. CloseRead shuts down the reading side of the TCP connection. Most callers should just use Close. CloseWrite shuts down the writing side of the TCP connection. Most callers should just use Close. LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it. Read reads data from the connection. Read can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline. ReadFrom implements the io.ReaderFrom ReadFrom method. RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it. 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 instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future. If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded. An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls. A zero value for t means I/O operations will not time out. SetKeepAlive sets whether the operating system should send keep-alive messages on the connection. SetKeepAlivePeriod sets period between keep-alives. SetLinger sets the behavior of Close on a connection which still has data waiting to be sent or to be acknowledged. If sec < 0 (the default), the operating system finishes sending the data in the background. If sec == 0, the operating system discards any unsent or unacknowledged data. If sec > 0, the data is sent in the background as with sec < 0. On some operating systems after sec seconds have elapsed any remaining unsent data may be discarded. SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write. SetReadBuffer sets the size of the operating system's receive buffer associated with the connection. SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out. SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection. SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write 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 Write will not time out. Write writes data to the connection. Write can be made to time out and return an error after a fixed time limit; see SetDeadline and SetWriteDeadline. TCPConn : github.com/pion/datachannel.ReadDeadliner TCPConn : github.com/pion/datachannel.WriteDeadliner TCPConn : github.com/pion/stun.Connection TCPConn : github.com/pion/stun/v3.Connection *TCPConn : github.com/pion/transport/v2.TCPConn *TCPConn : github.com/pion/transport/v3.TCPConn TCPConn : github.com/miekg/dns.Writer TCPConn : github.com/prometheus/common/expfmt.Closer TCPConn : internal/bisect.Writer TCPConn : io.Closer TCPConn : io.ReadCloser TCPConn : io.Reader TCPConn : io.ReaderFrom TCPConn : io.ReadWriteCloser TCPConn : io.ReadWriter TCPConn : io.WriteCloser TCPConn : io.Writer *TCPConn : net.Conn func (*TCPAllocation).AcceptTCPWithConn(conn net.Conn) (*TCPConn, error) func (*TCPAllocation).DialTCP(network string, lAddr, rAddr *net.TCPAddr) (*TCPConn, error) func (*TCPAllocation).DialTCPWithConn(conn net.Conn, _ string, rAddr *net.TCPAddr) (*TCPConn, error) func (*TCPAllocation).DialWithConn(conn net.Conn, network, rAddrStr string) (*TCPConn, error) func (*TCPAllocation).BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error
Transaction represents a transaction. // Read-only // Read-only // Read-only Close closes the transaction. Retries returns the number of retransmission it has made. StartRtxTimer starts the transaction timer. StopRtxTimer stop the transaction timer. WaitForResult waits for the transaction result. WriteResult writes the result to the result channel. func NewTransaction(config *TransactionConfig) *Transaction func (*TransactionMap).Find(key string) (*Transaction, bool) func (*TransactionMap).Insert(key string, tr *Transaction) bool
TransactionConfig is a set of config params used by NewTransaction. // True to throw away the result of this transaction (it will not be readable using WaitForResult) Interval time.Duration Key string Raw []byte To net.Addr func NewTransaction(config *TransactionConfig) *Transaction
TransactionMap is a thread-safe transaction map. CloseAndDeleteAll closes and deletes all transactions. Delete deletes a transaction by its key. Find looks up a transaction by its key. Insert inserts a transaction to the map. Size returns the length of the transaction map. *TransactionMap : github.com/gogo/protobuf/proto.Sizer func NewTransactionMap() *TransactionMap
TransactionResult is a bag of result values of a transaction. Err error From net.Addr Msg *stun.Message Retries int func Client.PerformTransaction(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) func (*Transaction).WaitForResult() TransactionResult func github.com/pion/turn/v4.(*Client).PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult bool) (TransactionResult, error) func (*Transaction).WriteResult(res TransactionResult) bool
TryLock implement the classic "try-lock" operation. Lock tries to lock the try-lock. If successful, it returns true. Otherwise, it returns false immediately. Unlock unlocks the try-lock.
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. compatible with net.PacketConn and net.Conn. Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors. CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9 FindAddrByChannelNumber returns a peer address associated with the channel number on this UDPConn. HandleInbound passes inbound data in UDPConn. LocalAddr returns the local network address. 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. 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. 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. 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. WriteTo writes a packet with payload to addr. WriteTo can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline. On packet-oriented connections, write timeouts are rare. *UDPConn : github.com/pion/datachannel.ReadDeadliner *UDPConn : github.com/pion/datachannel.WriteDeadliner *UDPConn : github.com/prometheus/common/expfmt.Closer *UDPConn : io.Closer *UDPConn : net.PacketConn func NewUDPConn(config *AllocationConfig) *UDPConn
Package-Level Functions (total 5)
NewPeriodicTimer create a new timer.
NewTCPAllocation creates a new instance of TCPConn.
NewTransaction creates a new instance of Transaction.
NewTransactionMap create a new instance of the transaction map.
NewUDPConn creates a new instance of UDPConn.