Documentation ¶
Index ¶
- Variables
- type DatabaseModule
- type DomainMappingStorage
- type JSONFileStorage
- type JSONStorageFormat
- type MemStorage
- func (s *MemStorage) DeleteMapping(domain string) error
- func (s *MemStorage) DeleteRouter(ip netip.Addr) error
- func (s *MemStorage) GetMapping(domain string) (router netip.Addr, err error)
- func (s *MemStorage) GetRouter(ip netip.Addr) (*StoredRouter, error)
- func (s *MemStorage) Prune(keep int)
- func (s *MemStorage) QueryMappings(search string) ([]StoredMapping, error)
- func (s *MemStorage) QueryRouters(q *RouterQuery) error
- func (s *MemStorage) SaveMapping(domain string, router netip.Addr) error
- func (s *MemStorage) SaveRouter(info *StoredRouter) error
- func (s *MemStorage) Size() int
- func (s *MemStorage) Start(*mgr.Manager) error
- func (s *MemStorage) Stop(*mgr.Manager) error
- type RouterQuery
- type RouterStorage
- type Storage
- type StoredMapping
- type StoredRouter
Constants ¶
This section is empty.
Variables ¶
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.
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 (*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.
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 ¶
type Storage interface { DatabaseModule RouterStorage DomainMappingStorage }
Storage includes all storage interfaces.
type StoredMapping ¶
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.