storage

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyCreated is returned when the IP / clientID pair is already
	// stored
	ErrAlreadyCreated = errors.New("entry already available")

	// ErrClientMismatch is returned from Delete if the given client ID does
	// not match the one stored
	ErrClientMismatch = errors.New("expected client ID does not match")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is an IP or client not found error

func MustRegister

func MustRegister(name string, factory Factory)

MustRegister registeres a new storage factory and panics on error

func Register

func Register(name string, factory Factory) error

Register registeres a new storage factory

Types

type Database

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

Database implements lease.Database

func NewDatabase

func NewDatabase(store LeaseStorage) *Database

NewDatabase creates a new database that uses store for persistence

func (*Database) DeleteReservation

func (db *Database) DeleteReservation(ctx context.Context, ip net.IP, cli *lease.Client) error

DeleteReservation implements lease.Database

func (*Database) Lease

func (db *Database) Lease(ctx context.Context, ip net.IP, cli lease.Client, leaseTime time.Duration, renew bool) (time.Duration, error)

Lease implementes lease.Database

func (*Database) Leases

func (db *Database) Leases(ctx context.Context) ([]lease.Lease, error)

Leases returns all IP address leases

func (*Database) Release

func (db *Database) Release(ctx context.Context, ip net.IP) error

Release implements lease.Database

func (*Database) Reserve

func (db *Database) Reserve(ctx context.Context, ip net.IP, cli lease.Client) error

Reserve implements lease.Database

func (*Database) ReservedAddresses

func (db *Database) ReservedAddresses(ctx context.Context) (lease.ReservedAddressList, error)

ReservedAddresses returns all IP address leases

type ErrDuplicateClientID

type ErrDuplicateClientID struct {
	// ClientID is the client ID that is used multiple times
	ClientID string

	// IP may hold the IP address used by the client
	IP net.IP
}

ErrDuplicateClientID is returned if the client ID already has a IP lease assigned

func (*ErrDuplicateClientID) Error

func (ecid *ErrDuplicateClientID) Error() string

type ErrDuplicateIP

type ErrDuplicateIP struct {
	// IP holds the IP address that is used multiple times
	IP net.IP

	// ClientID may hold the ID of the client that has the IP assigned
	ClientID string
}

ErrDuplicateIP is returned by the storage if an IP address is already used in a lease

func (*ErrDuplicateIP) Error

func (eip *ErrDuplicateIP) Error() string

type ErrIPNotFound

type ErrIPNotFound struct {
	IP net.IP
}

ErrIPNotFound is returned when the IP in question is not available in the lease storage

func (*ErrIPNotFound) Error

func (ein *ErrIPNotFound) Error() string

type Factory

type Factory func(args map[string][]string) (LeaseStorage, error)

Factory creates a new LeaseStorage

type LeaseStorage

type LeaseStorage interface {
	// Create stores a unique IP address lease.
	// Implementation MUST check that  IP and client
	// are not already used inside the database
	Create(ctx context.Context, ip net.IP, clientID string, leased bool, expiration time.Time) error

	// Delete deletes an IP lease from the database.
	// If clientID is not empty, implementations should
	// check if the lease to be removed is for the same clientID
	Delete(ctx context.Context, ip net.IP, clientID string) error

	// Update updates `leased` and `expiration` of an
	// existing IP lease. The operation should only be performed
	// if clientID matches the stored one.
	Update(ctx context.Context, ip net.IP, clientID string, leased bool, expiration time.Time) error

	// FindByIP searches for an IP lease for the given IP
	FindByIP(ctx context.Context, ip net.IP) (clientID string, leased bool, expiration time.Time, err error)

	// FindByID searches for an IP lease for the given client ID
	FindByID(ctx context.Context, clientID string) (ip net.IP, leased bool, expiration time.Time, err error)

	// ListIPs returns a list of IPs that are available in the storage
	ListIPs(ctx context.Context) ([]net.IP, error)

	// ListIDs returns a list of client IDs that are available in the storage
	ListIDs(ctx context.Context) ([]string, error)
}

LeaseStorage provides persistence for IP addresses leased or reserved to clients. Implementations don't need to care about lease management mechanics and just need to provide a way to keep leases persistent across service and host restarts. This also means that storage implementations don't, and should not, interpret the leased and expiration members. They are only required to ensure IP addresses and clientIDs are not used more than once (unique index)

func Open

func Open(name string, args map[string][]string) (LeaseStorage, error)

Open opens a lease.Database using driver name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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