netid

package
v3.8.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFull       = errors.New("range is full")
	ErrNotInRange = errors.New("provided netid is not in the valid range")
	ErrAllocated  = errors.New("provided netid is already allocated")
)

Functions

This section is empty.

Types

type Allocator

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

func New

func New(r *NetIDRange, allocatorFactory allocator.AllocatorFactory) *Allocator

New creates a Allocator over a netid Range, calling allocatorFactory to construct the backing store.

func NewInMemory

func NewInMemory(r *NetIDRange) *Allocator

Helper that wraps New, for creating a range backed by an in-memory store.

func (*Allocator) Allocate

func (r *Allocator) Allocate(id uint32) error

Allocate attempts to reserve the provided netid. ErrNotInRange or ErrAllocated will be returned if the netid is not valid for this range or has already been reserved.

func (*Allocator) AllocateNext

func (r *Allocator) AllocateNext() (uint32, error)

AllocateNext reserves one of the netids from the pool. ErrFull may be returned if there are no netids left.

func (*Allocator) Free

func (r *Allocator) Free() int

Free returns the count of netid left in the range.

func (*Allocator) Has

func (r *Allocator) Has(id uint32) bool

Has returns true if the provided netid is already allocated and a call to Allocate(netid) would fail with ErrAllocated.

func (*Allocator) Release

func (r *Allocator) Release(id uint32) error

Release releases the netid back to the pool. Releasing an unallocated netid or a netid out of the range is a no-op and returns no error.

type Interface

type Interface interface {
	Allocate(uint32) error
	AllocateNext() (uint32, error)
	Release(uint32) error
	Has(uint32) bool
}

Interface manages the allocation of netids out of a range. Interface should be threadsafe.

type NetIDRange

type NetIDRange struct {
	Base uint32
	Size uint32
}

func NewNetIDRange

func NewNetIDRange(min, max uint32) (*NetIDRange, error)

func (*NetIDRange) Contains

func (r *NetIDRange) Contains(netid uint32) (bool, uint32)

Contains tests whether a given netid falls within the Range.

func (*NetIDRange) Set

func (r *NetIDRange) Set(base, size uint32) error

func (*NetIDRange) String

func (r *NetIDRange) String() string

Jump to

Keyboard shortcuts

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