client

package
v4.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client implements the API for a TURN client

Package client implements the API for a TURN client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllocationConfig

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

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.

func (*PeriodicTimer) Start

func (t *PeriodicTimer) Start() bool

Start starts the timer.

func (*PeriodicTimer) Stop

func (t *PeriodicTimer) Stop()

Stop stops the timer.

type PeriodicTimerTimeoutHandler

type PeriodicTimerTimeoutHandler func(timerID int)

PeriodicTimerTimeoutHandler is a handler called on timeout.

type TCPAllocation

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

func NewTCPAllocation(config *AllocationConfig) *TCPAllocation

NewTCPAllocation creates a new instance of TCPConn.

func (*TCPAllocation) Accept

func (a *TCPAllocation) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*TCPAllocation) AcceptTCP

func (a *TCPAllocation) AcceptTCP() (transport.TCPConn, error)

AcceptTCP accepts the next incoming call and returns the new connection.

func (*TCPAllocation) AcceptTCPWithConn

func (a *TCPAllocation) AcceptTCPWithConn(conn net.Conn) (*TCPConn, error)

AcceptTCPWithConn accepts the next incoming call and returns the new connection.

func (*TCPAllocation) Addr

func (a *TCPAllocation) Addr() net.Addr

Addr returns the relayed address of the allocation.

func (*TCPAllocation) BindConnection

func (a *TCPAllocation) BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error

BindConnection associates the provided connection.

func (*TCPAllocation) Close

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

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

func (a *TCPAllocation) CreatePermissions(addrs ...net.Addr) error

CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9

func (*TCPAllocation) Dial

func (a *TCPAllocation) Dial(network, rAddrStr string) (net.Conn, error)

Dial connects to the address on the named network.

func (*TCPAllocation) DialTCP

func (a *TCPAllocation) DialTCP(network string, lAddr, rAddr *net.TCPAddr) (*TCPConn, error)

DialTCP acts like Dial for TCP networks.

func (*TCPAllocation) DialTCPWithConn

func (a *TCPAllocation) DialTCPWithConn(conn net.Conn, _ string, rAddr *net.TCPAddr) (*TCPConn, error)

DialTCPWithConn acts like DialWithConn for TCP networks.

func (*TCPAllocation) DialWithConn

func (a *TCPAllocation) DialWithConn(conn net.Conn, network, rAddrStr string) (*TCPConn, error)

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

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

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

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

func (c *TCPConn) LocalAddr() net.Addr

LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.

func (*TCPConn) RemoteAddr

func (c *TCPConn) RemoteAddr() net.Addr

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) Close

func (t *Transaction) Close()

Close closes the 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

type TransactionResult struct {
	Msg     *stun.Message
	From    net.Addr
	Retries int
	Err     error
}

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.

func (*TryLock) Lock

func (c *TryLock) Lock() error

Lock tries to lock the try-lock. If successful, it returns true. Otherwise, it returns false immediately.

func (*TryLock) Unlock

func (c *TryLock) Unlock()

Unlock unlocks the try-lock.

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

func (c *UDPConn) Close() error

Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.

func (*UDPConn) CreatePermissions

func (a *UDPConn) CreatePermissions(addrs ...net.Addr) error

CreatePermissions Issues a CreatePermission request for the supplied addresses as described in https://datatracker.ietf.org/doc/html/rfc5766#section-9

func (*UDPConn) FindAddrByChannelNumber

func (c *UDPConn) FindAddrByChannelNumber(chNum uint16) (net.Addr, bool)

FindAddrByChannelNumber returns a peer address associated with the channel number on this UDPConn.

func (*UDPConn) HandleInbound

func (c *UDPConn) HandleInbound(data []byte, from net.Addr)

HandleInbound passes inbound data in UDPConn.

func (*UDPConn) LocalAddr

func (c *UDPConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*UDPConn) ReadFrom

func (c *UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

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

func (c *UDPConn) SetDeadline(t time.Time) error

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

func (c *UDPConn) SetReadDeadline(t time.Time) error

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

func (c *UDPConn) SetWriteDeadline(time.Time) error

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.

func (*UDPConn) WriteTo

func (c *UDPConn) WriteTo(payload []byte, addr net.Addr) (int, error)

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.

Jump to

Keyboard shortcuts

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