Documentation
¶
Index ¶
- Variables
- func NewServiceAllocatorAdapter(alloc Allocator[bool]) ipallocator.Interface
- type Allocator
- type HashAllocator
- func (a *HashAllocator[T]) Alloc(ip netip.Addr, val T) error
- func (a *HashAllocator[T]) AllocAny(val T) (netip.Addr, error)
- func (a *HashAllocator[T]) ForEach(fn func(addr netip.Addr, val T) error) error
- func (a *HashAllocator[T]) Free(ip netip.Addr) error
- func (a *HashAllocator[T]) Get(ip netip.Addr) (T, bool)
- func (a *HashAllocator[T]) Range() (from, to netip.Addr)
- func (a *HashAllocator[T]) Stats() (allocated uint64, available *big.Int)
- func (a *HashAllocator[T]) Update(ip netip.Addr, val T) error
- type ServiceAllocatorAdapter
- func (saa *ServiceAllocatorAdapter) Allocate(ip net.IP) error
- func (saa *ServiceAllocatorAdapter) AllocateNext() (net.IP, error)
- func (saa *ServiceAllocatorAdapter) CIDR() net.IPNet
- func (saa *ServiceAllocatorAdapter) ForEach(fn func(net.IP))
- func (saa *ServiceAllocatorAdapter) Has(ip net.IP) bool
- func (saa *ServiceAllocatorAdapter) Release(ip net.IP) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrFull = errors.New("cannot allocate IP, no more IPs available") ErrOutOfRange = errors.New("the requested IP is out of the allocators range") ErrInUse = errors.New("the requested IP is already allocated") ErrNotFound = errors.New("the requested IP cannot be found") ErrBadLoop = errors.New("allocator detected a potentially infinite loop and broke free") )
Functions ¶
func NewServiceAllocatorAdapter ¶
func NewServiceAllocatorAdapter(alloc Allocator[bool]) ipallocator.Interface
NewServiceAllocatorAdapter creates a new ServiceAllocatorAdapter.
Types ¶
type Allocator ¶
type Allocator[T any] interface { // AllocAny allocates an available IP and associates value `val` to it. The caller has no control over the // exact IP that is allocated. The chosen IP is returned or error is non-nil. AllocAny(val T) (netip.Addr, error) // Alloc attempts to allocated the specific `ip` and associate value `val`. Allocation succeeded if the returned // error is nil. Alloc(ip netip.Addr, val T) error // Update updates the value `val` associated with the allocated `ip`. Update(ip netip.Addr, val T) error // Free de-allocates the given `ip` so its available once again. Free(ip netip.Addr) error // Get returns the value for the given `ip` if it has been allocated. Otherwise the default value for `T` is // returned. The boolean indicates if the `ip` has found. Get(ip netip.