Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package store pkg/dmsg/discovery/store/entry_cache.go c1-net-dmsg

Package store pkg/dmsg/discovery/store/redis.go c1-net-dmsg

Package store pkg/dmsg/discovery/store/storer.go c1-net-dmsg

Package store pkg/dmsg/discovery/store/testing.go c1-net-dmsg

Index

Constants

View Source
const (
	DefaultURL     = "redis://localhost:6379"
	DefaultTimeout = time.Minute * 3
)

Config defaults.

Variables

View Source
var (
	// ErrTooFewArgs is returned on attempt to create a Redis store without passing its URL.
	ErrTooFewArgs = errors.New("too few args")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	URL      string        // database URI
	Password string        // database password
	Timeout  time.Duration // database entry timeout (0 == none)
	PoolSize int           // redis connection pool size (0 == the client default)
}

Config configures the Store object.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a config with default values.

type EntryEnumerator

type EntryEnumerator interface {
	// CountEntries returns numbers of servers and clients.
	CountEntries(ctx context.Context) (int64, int64, error)

	// AllEntries returns all clients PKs.
	AllEntries(ctx context.Context) ([]string, error)

	// AllVisorEntries returns all clients PKs.
	AllVisorEntries(ctx context.Context) ([]string, error)

	// AllClientEntries returns all full client entries.
	AllClientEntries(ctx context.Context) ([]*disc.Entry, error)
}

EntryEnumerator provides bulk entry access.

type EntryStore

type EntryStore interface {
	// Entry obtains a single dmsg instance entry.
	Entry(ctx context.Context, staticPubKey cipher.PubKey) (*disc.Entry, error)

	// SetEntry set's an entry.
	// This is unsafe and does not check signature.
	SetEntry(ctx context.Context, entry *disc.Entry, timeout time.Duration) error

	// DelEntry delete's an entry.
	DelEntry(ctx context.Context, staticPubKey cipher.PubKey) error
}

EntryStore provides basic CRUD for discovery entries.

type MockStore

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

MockStore implements a storer mock

func (*MockStore) AllClientEntries

func (ms *MockStore) AllClientEntries(_ context.Context) ([]*disc.Entry, error)

AllClientEntries implements Storer AllClientEntries method for MockStore

func (*MockStore) AllEntries

func (ms *MockStore) AllEntries(_ context.Context) ([]string, error)

AllEntries implements Storer CountEntries method for MockStore

func (*MockStore) AllServers

func (ms *MockStore) AllServers(_ context.Context) ([]*disc.Entry, error)

AllServers implements Storer AllServers method for MockStore

func (*MockStore) AllVisorEntries

func (ms *MockStore) AllVisorEntries(_ context.Context) ([]string, error)

AllVisorEntries implements Storer CountEntries method for MockStore

func (*MockStore) AvailableServers

func (ms *MockStore) AvailableServers(_ context.Context, _ int) ([]*disc.Entry, error)

AvailableServers implements Storer AvailableServers method for MockStore

func (*MockStore) Clear

func (ms *MockStore) Clear()

Clear its a mock-only method to clear the mock store data

func (*MockStore) CountEntries

func (ms *MockStore) CountEntries(_ context.Context) (int64, int64, error)

CountEntries implements Storer CountEntries method for MockStore

func (*MockStore) DelEntry

func (ms *MockStore) DelEntry(_ context.Context, staticPubKey cipher.PubKey) error

DelEntry implements Storer DelEntry method for MockStore

func (*MockStore) Entry

func (ms *MockStore) Entry(_ context.Context, staticPubKey cipher.PubKey) (*disc.Entry, error)

Entry implements Storer Entry method for MockStore

func (*MockStore) GetAllVisorSummaries

func (ms *MockStore) GetAllVisorSummaries(_ context.Context, _ bool, _ bool) ([]VisorSummary, error)

func (*MockStore) GetDailyTimeline

func (ms *MockStore) GetDailyTimeline(_ context.Context, _ string, _ time.Time) map[string]string

func (*MockStore) RecordHeartbeat

func (ms *MockStore) RecordHeartbeat(_ context.Context, _ cipher.PubKey, _ string) error

func (*MockStore) RemoveOldServerEntries

func (ms *MockStore) RemoveOldServerEntries(_ context.Context) error

RemoveOldServerEntries implements Storer RemoveOldServerEntries method for MockStore

func (*MockStore) RemoveStaleClientEntries

func (ms *MockStore) RemoveStaleClientEntries(_ context.Context, _ time.Duration) (int, int, error)

RemoveStaleClientEntries implements Storer for MockStore (no-op).

func (*MockStore) SetEntry

func (ms *MockStore) SetEntry(_ context.Context, entry *disc.Entry, _ time.Duration) error

SetEntry implements Storer SetEntry method for MockStore

type ServerLister

type ServerLister interface {
	// AvailableServers discovers available dmsg servers.
	AvailableServers(ctx context.Context, maxCount int) ([]*disc.Entry, error)

	// AllServers discovers available dmsg servers.
	AllServers(ctx context.Context) ([]*disc.Entry, error)
}

ServerLister provides server enumeration.

type Storer

type Storer interface {
	EntryStore
	ServerLister
	EntryEnumerator
	UptimeTracker

	// RemoveOldServerEntries check and remove old server entries that left on redis because of unexpected server shutdown
	RemoveOldServerEntries(ctx context.Context) error

	// RemoveStaleClientEntries removes client entries with expired keys from the
	// "clients" set and applies defaultTTL to legacy entries that have no expiration.
	RemoveStaleClientEntries(ctx context.Context, defaultTTL time.Duration) (removed, ttlSet int, err error)
}

Storer is an interface which allows to implement different kinds of stores and choose which one to use in the server

func NewMock

func NewMock() Storer

NewMock returns a mock storer.

func NewStore

func NewStore(ctx context.Context, name string, conf *Config, log *logging.Logger) (Storer, error)

NewStore returns an initialized store, name represents which store to initialize

type UptimeTracker

type UptimeTracker interface {
	RecordHeartbeat(ctx context.Context, pk cipher.PubKey, version string) error
	GetAllVisorSummaries(ctx context.Context, v2 bool, timeline bool) ([]VisorSummary, error)
	GetDailyTimeline(ctx context.Context, pkHex string, now time.Time) map[string]string
}

UptimeTracker provides integrated uptime tracking for dmsg entries.

type VisorSummary

type VisorSummary struct {
	PK       cipher.PubKey     `json:"pk"`
	Online   bool              `json:"on"`
	Version  string            `json:"version,omitempty"`
	Daily    map[string]string `json:"daily,omitempty"`
	Timeline map[string]string `json:"timeline,omitempty"`
}

VisorSummary holds a visor's uptime data. Format matches the TPD and uptime tracker response.

Jump to

Keyboard shortcuts

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