client

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

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 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 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 trasaction 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 immedidately.

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. comatible with net.PacketConn and net.Conn

func NewUDPConn

func NewUDPConn(config *UDPConnConfig) *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) 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(t 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(p []byte, addr net.Addr) (int, error)

WriteTo writes a packet with payload p 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.

type UDPConnConfig

type UDPConnConfig struct {
	Observer    UDPConnObserver
	RelayedAddr net.Addr
	Integrity   stun.MessageIntegrity
	Nonce       stun.Nonce
	Lifetime    time.Duration
	Log         logging.LeveledLogger
}

UDPConnConfig is a set of configuration params use by NewUDPConn

type UDPConnObserver

type UDPConnObserver interface {
	TURNServerAddr() net.Addr
	Username() stun.Username
	Realm() stun.Realm
	WriteTo(data []byte, to net.Addr) (int, error)
	PerformTransaction(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error)
	OnDeallocated(relayedAddr net.Addr)
}

UDPConnObserver is an interface to UDPConn observer

Jump to

Keyboard shortcuts

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