Documentation ¶
Overview ¶
Package allocation contains all CRUD operations for allocations
Index ¶
- type Allocation
- func (a *Allocation) AddChannelBind(c *ChannelBind, lifetime time.Duration) error
- func (a *Allocation) AddPermission(p *Permission)
- func (a *Allocation) Close() error
- func (a *Allocation) GetChannelByAddr(addr net.Addr) *ChannelBind
- func (a *Allocation) GetChannelByNumber(number proto.ChannelNumber) *ChannelBind
- func (a *Allocation) GetPermission(addr net.Addr) *Permission
- func (a *Allocation) GetResponseCache() (id [stun.TransactionIDSize]byte, attrs []stun.Setter)
- func (a *Allocation) Refresh(lifetime time.Duration)
- func (a *Allocation) RemoveChannelBind(number proto.ChannelNumber) bool
- func (a *Allocation) RemovePermission(addr net.Addr)
- func (a *Allocation) SetResponseCache(transactionID [stun.TransactionIDSize]byte, attrs []stun.Setter)
- type ChannelBind
- type FiveTuple
- type Manager
- func (m *Manager) AllocationCount() int
- func (m *Manager) Close() error
- func (m *Manager) CreateAllocation(fiveTuple *FiveTuple, turnSocket net.PacketConn, requestedPort int, ...) (*Allocation, error)
- func (m *Manager) CreateReservation(reservationToken string, port int)
- func (m *Manager) DeleteAllocation(fiveTuple *FiveTuple)
- func (m *Manager) GetAllocation(fiveTuple *FiveTuple) *Allocation
- func (m *Manager) GetRandomEvenPort() (int, error)
- func (m *Manager) GetReservation(reservationToken string) (int, bool)
- func (m *Manager) GrantPermission(sourceAddr net.Addr, peerIP net.IP) error
- type ManagerConfig
- type Permission
- type Protocol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Allocation ¶
type Allocation struct { RelayAddr net.Addr Protocol Protocol TurnSocket net.PacketConn RelaySocket net.PacketConn // contains filtered or unexported fields }
Allocation is tied to a FiveTuple and relays traffic use CreateAllocation and GetAllocation to operate
func NewAllocation ¶
func NewAllocation(turnSocket net.PacketConn, fiveTuple *FiveTuple, log logging.LeveledLogger) *Allocation
NewAllocation creates a new instance of NewAllocation.
func (*Allocation) AddChannelBind ¶
func (a *Allocation) AddChannelBind(c *ChannelBind, lifetime time.Duration) error
AddChannelBind adds a new ChannelBind to the allocation, it also updates the permissions needed for this ChannelBind
func (*Allocation) AddPermission ¶
func (a *Allocation) AddPermission(p *Permission)
AddPermission adds a new permission to the allocation
func (*Allocation) GetChannelByAddr ¶
func (a *Allocation) GetChannelByAddr(addr net.Addr) *ChannelBind
GetChannelByAddr gets the ChannelBind from this allocation by net.Addr
func (*Allocation) GetChannelByNumber ¶
func (a *Allocation) GetChannelByNumber(number proto.ChannelNumber) *ChannelBind
GetChannelByNumber gets the ChannelBind from this allocation by id
func (*Allocation) GetPermission ¶
func (a *Allocation) GetPermission(addr net.Addr) *Permission
GetPermission gets the Permission from the allocation
func (*Allocation) GetResponseCache ¶ added in v2.0.8
func (a *Allocation) GetResponseCache() (id [stun.TransactionIDSize]byte, attrs []stun.Setter)
GetResponseCache return response cache for retransmit allocation request
func (*Allocation) Refresh ¶
func (a *Allocation) Refresh(lifetime time.Duration)
Refresh updates the allocations lifetime
func (*Allocation) RemoveChannelBind ¶
func (a *Allocation) RemoveChannelBind(number proto.ChannelNumber) bool
RemoveChannelBind removes the ChannelBind from this allocation by id
func (*Allocation) RemovePermission ¶
func (a *Allocation) RemovePermission(addr net.Addr)
RemovePermission removes the net.Addr's fingerprint from the allocation's permissions
func (*Allocation) SetResponseCache ¶ added in v2.0.8
func (a *Allocation) SetResponseCache(transactionID [stun.TransactionIDSize]byte, attrs []stun.Setter)
SetResponseCache cache allocation response for retransmit allocation request
type ChannelBind ¶
type ChannelBind struct { Peer net.Addr Number proto.ChannelNumber // contains filtered or unexported fields }
ChannelBind represents a TURN Channel https://tools.ietf.org/html/rfc5766#section-2.5
func NewChannelBind ¶
func NewChannelBind(number proto.ChannelNumber, peer net.Addr, log logging.LeveledLogger) *ChannelBind
NewChannelBind creates a new ChannelBind
type FiveTuple ¶
FiveTuple is the combination (client IP address and port, server IP address and port, and transport protocol (currently one of UDP, TCP, or TLS)) used to communicate between the client and the server. The 5-tuple uniquely identifies this communication stream. The 5-tuple also uniquely identifies the Allocation on the server.
func (*FiveTuple) Fingerprint ¶
Fingerprint is the identity of a FiveTuple
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is used to hold active allocations
func NewManager ¶
func NewManager(config ManagerConfig) (*Manager, error)
NewManager creates a new instance of Manager.
func (*Manager) AllocationCount ¶ added in v2.0.6
AllocationCount returns the number of existing allocations
func (*Manager) CreateAllocation ¶
func (m *Manager) CreateAllocation(fiveTuple *FiveTuple, turnSocket net.PacketConn, requestedPort int, lifetime time.Duration) (*Allocation, error)
CreateAllocation creates a new allocation and starts relaying
func (*Manager) CreateReservation ¶
CreateReservation stores the reservation for the token+port
func (*Manager) DeleteAllocation ¶
DeleteAllocation removes an allocation
func (*Manager) GetAllocation ¶
func (m *Manager) GetAllocation(fiveTuple *FiveTuple) *Allocation
GetAllocation fetches the allocation matching the passed FiveTuple
func (*Manager) GetRandomEvenPort ¶
GetRandomEvenPort returns a random un-allocated udp4 port
func (*Manager) GetReservation ¶
GetReservation returns the port for a given reservation if it exists
type ManagerConfig ¶
type ManagerConfig struct { LeveledLogger logging.LeveledLogger AllocatePacketConn func(network string, requestedPort int) (net.PacketConn, net.Addr, error) AllocateConn func(network string, requestedPort int) (net.Conn, net.Addr, error) PermissionHandler func(sourceAddr net.Addr, peerIP net.IP) bool }
ManagerConfig a bag of config params for Manager.
type Permission ¶
Permission represents a TURN permission. TURN permissions mimic the address-restricted filtering mechanism of NATs that comply with [RFC4787]. https://tools.ietf.org/html/rfc5766#section-2.3
func NewPermission ¶
func NewPermission(addr net.Addr, log logging.LeveledLogger) *Permission
NewPermission create a new Permission