profiledb

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package profiledb defines interfaces for databases of user profiles.

Index

Constants

View Source
const ErrDeviceNotFound errors.Error = "device not found"

ErrDeviceNotFound is an error returned by lookup methods when a device couldn't be found.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Storage returns the data for this profile DB.
	Storage Storage

	// CacheFilePath is the path to the profile cache file.  If cacheFilePath is
	// the string "none", filesystem cache is disabled.
	CacheFilePath string

	// FullSyncIvl is the interval between two full synchronizations with the
	// storage.
	FullSyncIvl time.Duration

	// FullSyncRetryIvl is the interval between two retries of full
	// synchronizations with the storage.
	FullSyncRetryIvl time.Duration

	// InitialTimeout is the timeout for initial refresh.
	InitialTimeout time.Duration
}

Config represents the profile database configuration.

type Default

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

Default is the default in-memory implementation of the Interface interface that can refresh itself from the provided storage.

func New

func New(conf *Config) (db *Default, err error)

New returns a new default in-memory profile database with a filesystem cache. The initial refresh is performed immediately with the given timeout, beyond which an empty profiledb is returned. If cacheFilePath is the string "none", filesystem cache is disabled. db is never nil.

func (*Default) ProfileByDedicatedIP

func (db *Default) ProfileByDedicatedIP(
	ctx context.Context,
	ip netip.Addr,
) (p *agd.Profile, d *agd.Device, err error)

ProfileByDedicatedIP implements the Interface interface for *Default. ip must be valid.

func (*Default) ProfileByDeviceID

func (db *Default) ProfileByDeviceID(
	ctx context.Context,
	id agd.DeviceID,
) (p *agd.Profile, d *agd.Device, err error)

ProfileByDeviceID implements the Interface interface for *Default.

func (*Default) ProfileByLinkedIP

func (db *Default) ProfileByLinkedIP(
	ctx context.Context,
	ip netip.Addr,
) (p *agd.Profile, d *agd.Device, err error)

ProfileByLinkedIP implements the Interface interface for *Default. ip must be valid.

func (*Default) Refresh

func (db *Default) Refresh(ctx context.Context) (err error)

Refresh implements the agdservice.Refresher interface for *Default. It updates the internal maps and the synchronization time using the data it receives from the storage.

TODO(a.garipov): Consider splitting the full refresh logic into a separate method.

type Disabled

type Disabled struct{}

Disabled is a profile database that panics on any call.

func (*Disabled) ProfileByDedicatedIP

func (d *Disabled) ProfileByDedicatedIP(
	_ context.Context, _ netip.Addr,
) (_ *agd.Profile, _ *agd.Device, _ error)

ProfileByDedicatedIP implements the Interface interface for *Disabled.

func (*Disabled) ProfileByDeviceID

func (d *Disabled) ProfileByDeviceID(
	_ context.Context,
	_ agd.DeviceID,
) (_ *agd.Profile, _ *agd.Device, _ error)

ProfileByDeviceID implements the Interface interface for *Disabled.

func (*Disabled) ProfileByLinkedIP

func (d *Disabled) ProfileByLinkedIP(
	_ context.Context,
	_ netip.Addr,
) (_ *agd.Profile, _ *agd.Device, _ error)

ProfileByLinkedIP implements the Interface interface for *Disabled.

type Interface

type Interface interface {
	// ProfileByDeviceID returns the profile and the device identified by id.
	ProfileByDeviceID(
		ctx context.Context,
		id agd.DeviceID,
	) (p *agd.Profile, d *agd.Device, err error)

	// ProfileByDedicatedIP returns the profile and the device identified by its
	// dedicated DNS server IP address.
	ProfileByDedicatedIP(
		ctx context.Context,
		ip netip.Addr,
	) (p *agd.Profile, d *agd.Device, err error)

	// ProfileByLinkedIP returns the profile and the device identified by its
	// linked IP address.
	ProfileByLinkedIP(ctx context.Context, ip netip.Addr) (p *agd.Profile, d *agd.Device, err error)
}

Interface is the local database of user profiles and devices.

type Storage

type Storage interface {
	// Profiles returns profile and device data that has changed since
	// req.SyncTime.  req must not be nil.
	Profiles(ctx context.Context, req *StorageRequest) (resp *StorageResponse, err error)
}

Storage is a storage from which an Default receives data about profiles and devices.

type StorageRequest

type StorageRequest struct {
	// SyncTime is the last time profiles were synced.
	SyncTime time.Time
}

StorageRequest is the request to Storage for profiles and devices.

type StorageResponse

type StorageResponse struct {
	// SyncTime is the time that should be saved and used as the next
	// [ProfilesRequest.SyncTime].
	SyncTime time.Time

	// Profiles are the profiles data from the [Storage].
	Profiles []*agd.Profile

	// Devices are the device data from the [Storage].
	Devices []*agd.Device
}

StorageResponse is the ProfileStorage.Profiles response.

Directories

Path Synopsis
Package internal contains common constants and types that all implementations of the default profile-cache use.
Package internal contains common constants and types that all implementations of the default profile-cache use.
filecachepb
Package filecachepb contains the protobuf structures for the profile cache.
Package filecachepb contains the protobuf structures for the profile cache.
profiledbtest
Package profiledbtest contains common helpers for profile-database tests.
Package profiledbtest contains common helpers for profile-database tests.

Jump to

Keyboard shortcuts

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