networkdirectory

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 17 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
	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
	Cache    Cache
	Fetch    func(context.Context, string) ([]byte, error)
	Now      func() time.Time
	Order    func(int) []int
}

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) 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) RetryAt

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

RetryAt exposes only failure backoff. Successful periodic maintenance must never postpone an explicit retry or unknown-alias refresh.

func (*Directory) Snapshot

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

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