networkdirectory

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package networkdirectory owns signed network snapshots, bounded refresh and durable rollback protection. It never imports built-in infrastructure.

Index

Constants

View Source
const (
	RefreshTimeout        = 6 * time.Second
	MirrorTimeout         = 2 * time.Second
	RefreshInterval       = 6 * time.Hour
	MinimumBackoff        = 30 * time.Second
	MaximumBackoff        = 30 * time.Minute
	MaximumTriggerBackoff = 5 * time.Minute
	ExplicitRetryCooldown = MinimumBackoff
	MaximumMirrors        = 8
	MirrorsPerRefresh     = 3
)

Variables

View Source
var ErrUnavailable = errors.New("built-in network unavailable")

Functions

This section is empty.

Types

type BlockingReason

type BlockingReason string
const (
	Unprovisioned        BlockingReason = "unprovisioned"
	InvalidConfiguration BlockingReason = "invalid_network_configuration"
	TrustStateUnreadable BlockingReason = "trust_state_unreadable"
	TrustStateInvalid    BlockingReason = "trust_state_invalid"
	TrustStateUnwritable BlockingReason = "trust_state_unwritable"
	SnapshotUnavailable  BlockingReason = "directory_unavailable"
)

type Cache

type Cache interface {
	Load(context.Context) (Record, error)
	Update(context.Context, func(Record) (Record, error)) (Record, error)
}

Cache commits the signed snapshot and rollback cursor together. Update's callback must run under the same lock as the read, including across processes.

type Config

type Config struct {
	Network         string
	Roots           []nodedirectory.Root
	Embedded        []byte
	Mirrors         []string
	FallbackMirrors []string
	Cache           Cache
	Fetch           func(context.Context, string) ([]byte, error)
	Now             func() time.Time
	Order           func(int) []int
	Diagnostics     diagnostics.Sink
}

type Directory

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

func New

func New(config Config) (*Directory, error)

func (*Directory) Close

func (directory *Directory) Close()

func (*Directory) NetworkChanged added in v0.1.5

func (directory *Directory) NetworkChanged()

NetworkChanged invalidates failure and unchanged-trigger backoff accumulated on a previous network generation so recovery does not wait behind stale outages.

func (*Directory) Refresh

func (directory *Directory) Refresh(ctx context.Context) error

Refresh coalesces user retries, unknown-alias resolution and periodic refresh. Caller cancellation stops waiting, not an update another task also needs.

func (*Directory) RefreshAliases added in v0.1.5

func (directory *Directory) RefreshAliases(ctx context.Context, aliases []string) error

RefreshAliases joins the current pass, including startup maintenance, and asks it to continue past usable snapshots that still lack these aliases.

func (*Directory) RetryAt

func (directory *Directory) RetryAt() time.Time

RetryAt exposes only active explicit failure cooldown. Periodic schedules and longer background backoff must not postpone an explicit retry or alias refresh.

func (*Directory) Snapshot

func (directory *Directory) Snapshot() (nodedirectory.Snapshot, bool)

func (*Directory) TriggerRefresh added in v0.1.5

func (directory *Directory) TriggerRefresh()

TriggerRefresh advances periodic maintenance after an all-cooled plan or admission refusal. Bursts coalesce into one fetch, and repeated triggered fetches that observe an unchanged cursor back off up to MaximumTriggerBackoff.

func (*Directory) Unavailability

func (directory *Directory) Unavailability() *UnavailableError

Unavailability ignores maintenance failures while a trusted snapshot is usable.

type FileCache

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

func NewFileCache

func NewFileCache(configPath, network string) *FileCache

Separate trust histories by network, including builds sharing the same user settings. A key rotation within a network must still respect its previous rollback cursor.

func (*FileCache) Load

func (cache *FileCache) Load(context.Context) (Record, error)

func (*FileCache) Update

func (cache *FileCache) Update(ctx context.Context, change func(Record) (Record, error)) (Record, error)

type MemoryCache

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

func (*MemoryCache) Load

func (cache *MemoryCache) Load(context.Context) (Record, error)

func (*MemoryCache) Update

func (cache *MemoryCache) Update(_ context.Context, change func(Record) (Record, error)) (Record, error)

type Record

type Record struct {
	Cursor   nodedirectory.Cursor `json:"cursor"`
	Envelope []byte               `json:"envelope"`
	Aliases  map[string]string    `json:"aliases"`
}

type UnavailableError

type UnavailableError struct {
	Reason  BlockingReason
	RetryAt time.Time
	Cause   error
}

UnavailableError carries the owner's recovery decision, independently of the diagnostic cause. RetryAt is the earliest permitted refresh, not a promise of connectivity or an instruction for applications to start another poller.

func (*UnavailableError) Error

func (err *UnavailableError) Error() string

func (*UnavailableError) Is

func (err *UnavailableError) Is(target error) bool

func (*UnavailableError) Unwrap

func (err *UnavailableError) Unwrap() error

Jump to

Keyboard shortcuts

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