storage

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Errors.

Functions

This section is empty.

Types

type DatabaseModule

type DatabaseModule interface {
	Start(mgr *mgr.Manager) error
	Stop(mgr *mgr.Manager) error
	Size() int
	Prune(keep int)
}

DatabaseModule is an interface to a managed storage backend.

type DomainMappingStorage

type DomainMappingStorage interface {
	GetMapping(domain string) (router netip.Addr, err error)
	QueryMappings(search string) ([]StoredMapping, error)
	SaveMapping(domain string, router netip.Addr) error
	DeleteMapping(domain string) error
}

DomainMappingStorage is an interface to a domain mapping storage.

type JSONFileStorage

type JSONFileStorage struct {
	MemStorage
	// contains filtered or unexported fields
}

JSONFileStorage is a simple storage implementation using a single json file that is read on start and writton when stopped.

func NewJSONFileStorage

func NewJSONFileStorage(filename string) (*JSONFileStorage, error)

NewJSONFileStorage loads the json file at the given location and returns a new storage.

func (*JSONFileStorage) Stop

func (s *JSONFileStorage) Stop(mgr *mgr.Manager) error

Stop writes to storage to file.

type JSONStorageFormat

type JSONStorageFormat struct {
	Routers  map[netip.Addr]*StoredRouter `json:"routers,omitempty"  yaml:"routers,omitempty"`
	Mappings map[string]StoredMapping     `json:"mappings,omitempty" yaml:"mappings,omitempty"`
}

JSONStorageFormat is the format in which the JSONFileStorage stores the state.

type MemStorage

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

MemStorage is a simple storage implementation using memory only.

func NewMemStorage

func NewMemStorage() *MemStorage

NewMemStorage returns an empty storage.

func (*MemStorage) DeleteMapping

func (s *MemStorage) DeleteMapping(domain string) error

DeleteMapping deletes a domain mapping from the storage.

func (*MemStorage) DeleteRouter

func (s *MemStorage) DeleteRouter(ip netip.Addr) error

DeleteRouter deletes a router from the storage.

func (*MemStorage) GetMapping

func (s *MemStorage) GetMapping(domain string) (router netip.Addr, err error)

GetMapping returns a domain mapping from the storage.

func (*MemStorage) GetRouter

func (s *MemStorage) GetRouter(ip netip.Addr) (*StoredRouter, error)

GetRouter returns a router from the storage.

func (*MemStorage) Prune

func (s *MemStorage) Prune(keep int)

Prune prunes the storage down to the specified amount of entries.

func (*MemStorage) QueryMappings

func (s *MemStorage) QueryMappings(search string) ([]StoredMapping, error)

QueryMappings queries the domain mappings with the given pattern.

func (*MemStorage) QueryRouters

func (s *MemStorage) QueryRouters(q *RouterQuery) error

QueryRouters queries the router storage.

func (*MemStorage) SaveMapping

func (s *MemStorage) SaveMapping(domain string, router netip.Addr) error

SaveMapping saves a domain mapping to the storage.

func (*MemStorage) SaveRouter

func (s *MemStorage) SaveRouter(info *StoredRouter) error

SaveRouter saves a router to the storage.

func (*MemStorage) Size

func (s *MemStorage) Size() int

Size returns the current size of the storage.

func (*MemStorage) Start

func (s *MemStorage) Start(*mgr.Manager) error

Start does nothing.

func (*MemStorage) Stop

func (s *MemStorage) Stop(*mgr.Manager) error

Stop does nothing.

type RouterQuery

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

RouterQuery is a query on the storage.

func NewRouterQuery

func NewRouterQuery(
	where func(a *StoredRouter) bool,
	sort func(a, b *StoredRouter) int,
	max int,
) *RouterQuery

NewRouterQuery returns a new router query.

func (*RouterQuery) Add

func (sq *RouterQuery) Add(entry *StoredRouter)

Add attempts to add the given query to the query result.

func (*RouterQuery) Result

func (sq *RouterQuery) Result() []*StoredRouter

Result returns the query result.

type RouterStorage

type RouterStorage interface {
	GetRouter(router netip.Addr) (*StoredRouter, error)
	QueryRouters(query *RouterQuery) error
	SaveRouter(router *StoredRouter) error
	DeleteRouter(router netip.Addr) error
}

RouterStorage is an interface to a router storage.

type Storage

Storage includes all storage interfaces.

type StoredMapping

type StoredMapping struct {
	Domain  string
	Router  netip.Addr
	Created time.Time
}

StoredMapping is the format used to store domain mappings.

type StoredRouter

type StoredRouter struct {
	Address    *m.PublicAddress `json:"address,omitempty"    yaml:"address,omitempty"`
	PublicInfo *m.RouterInfo    `json:"publicInfo,omitempty" yaml:"publicInfo,omitempty"`

	// Offline signifies that the router has announced it is going offline.
	Offline bool `json:"offline,omitempty" yaml:"offline,omitempty"`

	CreatedAt time.Time  `json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
	UpdatedAt time.Time  `json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
	UsedAt    *time.Time `json:"usedAt,omitempty"    yaml:"usedAt,omitempty"`
}

StoredRouter is the format used to store router information.

Jump to

Keyboard shortcuts

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