allocation

package
v1.3.7-0...-4388ba3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TurnMinPort RFC 5766 : In all cases, the server SHOULD only allocate ports from the range   49152 - 65535
	TurnMinPort = 49152
)

Variables

This section is empty.

Functions

func GetRandomEvenPort

func GetRandomEvenPort() (int, error)

GetRandomEvenPort returns a random un-allocated udp4 port

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

func (a *Allocation) Close() error

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

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

type FiveTuple struct {
	Protocol
	SrcAddr, DstAddr net.Addr
}

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

func (f *FiveTuple) Equal(b *FiveTuple) bool

Equal asserts if two FiveTuples are equal

func (*FiveTuple) Fingerprint

func (f *FiveTuple) Fingerprint() string

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

NewManager creates a new instance of Manager.

func (*Manager) AddExternalIPMapping

func (m *Manager) AddExternalIPMapping(extIP, locIP net.IP)

AddExternalIPMapping add a external IP address mapping.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the manager and closes all allocations it manages

func (*Manager) CreateAllocation

func (m *Manager) CreateAllocation(
	fiveTuple *FiveTuple,
	turnSocket net.PacketConn,
	relayIP net.IP,
	requestedPort int,
	lifetime time.Duration) (*Allocation, error)

CreateAllocation creates a new allocation and starts relaying

func (*Manager) DeleteAllocation

func (m *Manager) DeleteAllocation(fiveTuple *FiveTuple)

DeleteAllocation removes an allocation

func (*Manager) GetAllocation

func (m *Manager) GetAllocation(fiveTuple *FiveTuple) *Allocation

GetAllocation fetches the allocation matching the passed FiveTuple

type ManagerConfig

type ManagerConfig struct {
	LeveledLogger logging.LeveledLogger
	Net           *vnet.Net
}

ManagerConfig a bag of config params for Manager.

type Permission

type Permission struct {
	Addr net.Addr
	// contains filtered or unexported fields
}

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

type Protocol

type Protocol uint8

Protocol is an enum for relay protocol

const (
	UDP Protocol = iota
	TCP
)

Network protocols for relay

type ReservationManager

type ReservationManager struct {
	// contains filtered or unexported fields
}

ReservationManager is used to manage reservations

func (*ReservationManager) CreateReservation

func (m *ReservationManager) CreateReservation(reservationToken string, port int)

CreateReservation stores the reservation for the token+port

func (*ReservationManager) GetReservation

func (m *ReservationManager) GetReservation(reservationToken string) (int, bool)

GetReservation returns the port for a given reservation if it exists

Jump to

Keyboard shortcuts

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