Documentation ¶
Index ¶
- Variables
- func IsNotFound(err error) bool
- func MustRegister(name string, factory Factory)
- func Register(name string, factory Factory) error
- type Database
- func (db *Database) DeleteReservation(ctx context.Context, ip net.IP, cli *lease.Client) error
- func (db *Database) Lease(ctx context.Context, ip net.IP, cli lease.Client, leaseTime time.Duration, ...) (time.Duration, error)
- func (db *Database) Leases(ctx context.Context) ([]lease.Lease, error)
- func (db *Database) Release(ctx context.Context, ip net.IP) error
- func (db *Database) Reserve(ctx context.Context, ip net.IP, cli lease.Client) error
- func (db *Database) ReservedAddresses(ctx context.Context) (lease.ReservedAddressList, error)
- type ErrDuplicateClientID
- type ErrDuplicateIP
- type ErrIPNotFound
- type Factory
- type LeaseStorage
Constants ¶
This section is empty.
Variables ¶
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 ¶
IsNotFound returns true if err is an IP or client not found error
func MustRegister ¶
MustRegister registeres a new storage factory and panics on error
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 ¶
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) ReservedAddresses ¶
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 ¶
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)