gotvc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDescendentOf

func IsDescendentOf[T Snapshotable](ctx context.Context, s stores.Reading, x, a Snapshot[T]) (bool, error)

IsDescendentOf returns true if any of x's parents are equal to a.

Types

type Machine

type Machine[T Snapshotable] struct {
	// contains filtered or unexported fields
}

func NewMachine

func NewMachine[T Snapshotable](parse Parser[T], opts ...Option[T]) *Machine[T]

func (*Machine[T]) Check

func (a *Machine[T]) Check(ctx context.Context, s stores.Reading, snap Snapshot[T], checkRoot func(T) error) error

Check ensures that snapshot is valid.

func (*Machine[T]) ForEach

func (m *Machine[T]) ForEach(ctx context.Context, s stores.Reading, xs []Ref, fn func(Ref, Snapshot[T]) error) error

ForEach calls fn once for each Ref in the snapshot graph.

func (*Machine[T]) GetSnapshot

func (ag *Machine[T]) GetSnapshot(ctx context.Context, s stores.Reading, ref Ref) (*Snapshot[T], error)

GetSnapshot retrieves the snapshot referenced by ref from the store.

func (*Machine[T]) NewSnapshot

func (a *Machine[T]) NewSnapshot(ctx context.Context, s stores.Writing, sp SnapshotParams[T]) (*Snapshot[T], error)

func (*Machine[T]) NewZero

func (mach *Machine[T]) NewZero(ctx context.Context, s stores.Writing, sp SnapshotParams[T]) (*Snapshot[T], error)

NewZero creates a new snapshot with no parent

func (*Machine[T]) Populate

func (mach *Machine[T]) Populate(ctx context.Context, s stores.Reading, start Snapshot[T], set stores.Set, rootFn func(T) error) error

Populate adds all the blobcache.CIDs reachable from start to set. This will not include the CID for start itself, which has not yet been computed.

func (*Machine[T]) PostSnapshot

func (ag *Machine[T]) PostSnapshot(ctx context.Context, s stores.Writing, x Snapshot[T]) (*Ref, error)

PostSnapshot marshals the snapshot and posts it to the store

func (*Machine[T]) RefFromSnapshot

func (ag *Machine[T]) RefFromSnapshot(snap Snapshot[T]) Ref

RefFromSnapshot computes a ref for snap if it was posted to s. It only calls s.Hash and s.MaxSize; it does not mutate s.

func (*Machine[T]) Squash

func (ag *Machine[T]) Squash(ctx context.Context, s stores.RW, x Snapshot[T], n int) (*Snapshot[T], error)

Squash turns multiple snapshots into one. It preserves the latest version of the data, but destroys versioning granularity

func (*Machine[T]) Sync

func (m *Machine[T]) Sync(ctx context.Context, src stores.Reading, dst stores.Writing, snap Snapshot[T], syncp func(T) error) error

Sync ensures dst has all of the data reachable from snap.

type Option

type Option[T Snapshotable] = func(a *Machine[T])

func WithSalt

func WithSalt[T Snapshotable](salt *[32]byte) Option[T]

type Parser

type Parser[T any] = func([]byte) (T, error)

type Ref

type Ref = gdat.Ref

type Snapshot

type Snapshot[T Snapshotable] struct {
	// N is the critical distance to the root.
	// N is 0 if there are no parents.
	// N is the max of the parents' N + 1.
	N uint64
	// CreatedAt is the time the snapshot was created.
	CreatedAt tai64.TAI64
	Parents   []gdat.Ref
	// Creator is the ID of the user who created the snapshot.
	Creator inet256.ID

	// Payload is the thing being snapshotted.
	Payload T
}

func ParseSnapshot

func ParseSnapshot[T Snapshotable](data []byte, parser Parser[T]) (*Snapshot[T], error)

func (Snapshot[T]) Equals

func (a Snapshot[T]) Equals(b Snapshot[T]) bool

func (Snapshot[T]) Marshal

func (a Snapshot[T]) Marshal(out []byte) []byte

func (*Snapshot[T]) Unmarshal

func (a *Snapshot[T]) Unmarshal(data []byte, parsePayload Parser[T]) error

type SnapshotParams

type SnapshotParams[T Snapshotable] struct {
	Parents   []Snapshot[T]
	Creator   inet256.ID
	CreatedAt tai64.TAI64
	// Payload is the thing being snapshot
	Payload T
}

SnapshotParams are the parameters required to create a new snapshot.

type Snapshotable

type Snapshotable interface {
	Marshal(out []byte) []byte
}

Jump to

Keyboard shortcuts

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