ledger

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 5 Imported by: 0

README

Ledger Backend

The ledger backend is an append-only log that records all modifying operations of the passmngr vault. Each instance of the ledger contains an append-only log for each participating device. The current state of individual items is based on the most recent entry from any of the individual logs. In the event of a collision a current value can be chosen based on the ordering of the device ID.

Documentation

Index

Constants

View Source
const LengthLen = 8
View Source
const MinKeyLen = 1
View Source
const OperTimeLen = 8

Moves type size to the point of definition to make later modification easier

View Source
const OperTypeLen = 1

Used for binary marshaling unmarshaling. Moves the defintion of the size to the place the type is defined

Variables

View Source
var ErrorNotEnoughBytes = errors.New("data is not long enough to hold a ledger entry")

Functions

This section is empty.

Types

type Entries

type Entries []Entry

type Entry

type Entry struct {
	Operation
	DeviceID string // DeviceID is the ID of the device that made the change
	Epoch    uint64 // The monotonic ID of the ledger entry
}

type Ledger

type Ledger interface {
	Txn(fn func(tx LedgerTxn) error) error
}

type LedgerTxn

type LedgerTxn interface {
	// Append adds a new entry to the append-only log
	Append(op Operation) error
	// Filter returns all matching entries (determined by fn) sorted by timestamp
	Filter(fn func(ent Entry) (bool, error)) (Entries, error)

	// Compact compacts the local ledger deleting all entries for each key.
	// Only the most recent N entries for each key will be kept
	Compact(n int) error
}

type OperTime

type OperTime uint64

func (OperTime) Time

func (t OperTime) Time() time.Time

type OperType

type OperType byte
const (
	NoOpEntry OperType = iota
	SetEntry
	DeleteEntry
)

func (OperType) Valid

func (t OperType) Valid() bool

type Operation

type Operation struct {
	Time  uint64   // Timestamp of the operation
	Type  OperType // The type of operation being recorded
	Key   []byte   // The key being modified
	Value []byte   // The new value of the modified key (if a set operation)
}

func (Operation) MarshalBinary

func (o Operation) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Operation) UnmarshalBinary

func (o *Operation) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

Jump to

Keyboard shortcuts

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