Documentation ¶
Index ¶
- Variables
- type ErrPortAlreadyAllocated
- type PortAllocator
- func (p *PortAllocator) ReleaseAll() error
- func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int)
- func (p *PortAllocator) RequestPort(ip net.IP, proto string, port int) (int, error)
- func (p *PortAllocator) RequestPortInRange(ip net.IP, proto string, portStart, portEnd int) (int, error)
- func (p *PortAllocator) RequestPortsInRange(ips []net.IP, proto string, portStart, portEnd int) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAllPortsAllocated is returned when no more ports are available ErrAllPortsAllocated = errors.New("all ports are allocated") // ErrUnknownProtocol is returned when an unknown protocol was specified ErrUnknownProtocol = errors.New("unknown protocol") )
Functions ¶
This section is empty.
Types ¶
type ErrPortAlreadyAllocated ¶
type ErrPortAlreadyAllocated struct {
// contains filtered or unexported fields
}
ErrPortAlreadyAllocated is the returned error information when a requested port is already being used
func (ErrPortAlreadyAllocated) Error ¶
func (e ErrPortAlreadyAllocated) Error() string
Error is the implementation of error.Error interface
func (ErrPortAlreadyAllocated) IP ¶
func (e ErrPortAlreadyAllocated) IP() string
IP returns the address to which the used port is associated
func (ErrPortAlreadyAllocated) IPPort ¶
func (e ErrPortAlreadyAllocated) IPPort() string
IPPort returns the address and the port in the form ip:port
func (ErrPortAlreadyAllocated) Port ¶
func (e ErrPortAlreadyAllocated) Port() int
Port returns the value of the already used port
type PortAllocator ¶
PortAllocator manages the transport ports database
func (*PortAllocator) ReleaseAll ¶
func (p *PortAllocator) ReleaseAll() error
ReleaseAll releases all ports for all ips.
func (*PortAllocator) ReleasePort ¶
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int)
ReleasePort releases port from global ports pool for specified ip and proto.
func (*PortAllocator) RequestPort ¶
RequestPort requests new port from global ports pool for specified ip and proto. If port is 0 it returns first free port. Otherwise it checks port availability in proto's pool and returns that port or error if port is already busy.
func (*PortAllocator) RequestPortInRange ¶
func (p *PortAllocator) RequestPortInRange(ip net.IP, proto string, portStart, portEnd int) (int, error)
RequestPortInRange is equivalent to [RequestPortsInRange] with a single IP address.
If ip is nil, a port is instead requested for the defaultIP.
func (*PortAllocator) RequestPortsInRange ¶
func (p *PortAllocator) RequestPortsInRange(ips []net.IP, proto string, portStart, portEnd int) (int, error)
RequestPortsInRange requests new ports from the global ports pool, for proto and each of ips. If portStart and portEnd are 0 it returns the first free port in the default ephemeral range. If portStart != portEnd it returns the first free port in the requested range. Otherwise, (portStart == portEnd) it checks port availability in the requested proto's port-pool and returns that port or error if port is already busy.