objecttree

package
v0.6.0-alpha.11 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderKey = "o"

	TreeKey  = "t"
	CollName = "changes"
)

Variables

View Source
var (
	ErrIncorrectSignature = errors.New("change has incorrect signature")
	ErrIncorrectCid       = errors.New("change has incorrect CID")
)
View Source
var (
	ErrHasInvalidChanges = errors.New("the change is invalid")
	ErrNoCommonSnapshot  = errors.New("trees doesn't have a common snapshot")
	ErrNoChangeInTree    = errors.New("no such change in tree")
	ErrMissingKey        = errors.New("missing current read key")
	ErrDerived           = errors.New("expect >= 2 changes in derived tree")
	ErrDeleted           = errors.New("object tree is deleted")
	ErrNoAclHead         = errors.New("no acl head")
)
View Source
var (
	ErrEmpty = errors.New("logs empty")
)
View Source
var ErrEmptyChange = errors.New("change payload should not be empty")
View Source
var ErrLoadBeforeRoot = errors.New("can't load before root")
View Source
var NoOpDescriptionParser = noopDescriptionParser{}

Functions

func CreateObjectTreeRoot

func CreateObjectTreeRoot(payload ObjectTreeCreatePayload, aclList list.AclList) (root *treechangeproto.RawTreeChangeWithId, err error)

func DeriveObjectTreeRoot added in v0.3.2

func DeriveObjectTreeRoot(payload ObjectTreeDerivePayload, aclList list.AclList) (root *treechangeproto.RawTreeChangeWithId, err error)

func DoSnapshot

func DoSnapshot(treeLen int) bool

func IsDerivedRoot added in v0.3.2

func IsDerivedRoot(root *treechangeproto.RawTreeChangeWithId) (derived bool, err error)

func IsEmptyDerivedTree added in v0.3.2

func IsEmptyDerivedTree(tree ObjectTree) bool

func IsEmptyTree added in v0.3.21

func IsEmptyTree(tree ObjectTree) bool

func UnmarshallRoot added in v0.5.23

func UnmarshallRoot(rawRoot *treechangeproto.RawTreeChangeWithId) (root *treechangeproto.RootChange, err error)

func ValidateRawTree

func ValidateRawTree(payload treestorage.TreeStorageCreatePayload, aclList list.AclList, store anystore.DB) (err error)

Types

type AddResult

type AddResult struct {
	OldHeads []string
	Heads    []string
	Added    []StorageChange

	Mode Mode
}

func (AddResult) RawChanges

func (a AddResult) RawChanges() []*treechangeproto.RawTreeChangeWithId

type AddResultSummary

type AddResultSummary int

type BuildObjectTreeFunc

type BuildObjectTreeFunc = func(storage Storage, aclList list.AclList) (ObjectTree, error)

type BuilderContent

type BuilderContent struct {
	TreeHeadIds    []string
	AclHeadId      string
	SnapshotBaseId string
	ReadKeyId      string
	IsSnapshot     bool
	PrivKey        crypto.PrivKey
	ReadKey        crypto.SymKey
	Content        []byte
	Timestamp      int64
	DataType       string
}

type Change

type Change struct {
	Next        []*Change
	PreviousIds []string
	Previous    []*Change
	AclHeadId   string
	Id          string
	SnapshotId  string
	Timestamp   int64
	ReadKeyId   string
	Identity    crypto.PubKey
	Data        []byte
	// TODO: add call one time comment
	Model           interface{}
	Signature       []byte
	DataType        string
	IsSnapshot      bool
	IsDerived       bool
	IsNew           bool
	OrderId         string
	SnapshotCounter int
	// contains filtered or unexported fields
}

Change is an abstract type for all types of changes

func NewChangeFromRoot

func NewChangeFromRoot(id string, identity crypto.PubKey, ch *treechangeproto.RootChange, signature []byte, isDerived bool) *Change

func (*Change) Cid

func (ch *Change) Cid() string

type ChangeBuilder

type ChangeBuilder interface {
	Unmarshall(rawIdChange *treechangeproto.RawTreeChangeWithId, verify bool) (ch *Change, err error)
	UnmarshallReduced(rawIdChange *treechangeproto.RawTreeChangeWithId) (ch *Change, err error)
	Build(payload BuilderContent) (ch *Change, raw *treechangeproto.RawTreeChangeWithId, err error)
	BuildRoot(payload InitialContent) (ch *Change, raw *treechangeproto.RawTreeChangeWithId, err error)
	BuildDerivedRoot(payload InitialDerivedContent) (ch *Change, raw *treechangeproto.RawTreeChangeWithId, err error)
	Marshall(ch *Change) (*treechangeproto.RawTreeChangeWithId, error)
}

func NewChangeBuilder

func NewChangeBuilder(keys crypto.KeyStorage, rootChange *treechangeproto.RawTreeChangeWithId) ChangeBuilder

func NewEmptyDataChangeBuilder added in v0.5.0

func NewEmptyDataChangeBuilder(keys crypto.KeyStorage, rootChange *treechangeproto.RawTreeChangeWithId) ChangeBuilder

type ChangeConvertFunc

type ChangeConvertFunc = func(change *Change, decrypted []byte) (any, error)

type ChangeDiffer

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

func NewChangeDiffer

func NewChangeDiffer(tree ReadableObjectTree, hasChanges hasChangesFunc) (*ChangeDiffer, error)

func (*ChangeDiffer) Add

func (d *ChangeDiffer) Add(changes ...*Change)

func (*ChangeDiffer) RemoveBefore

func (d *ChangeDiffer) RemoveBefore(ids []string, seenHeads []string) (removed []string, notFound []string, heads []string)

type ChangeIterateFunc

type ChangeIterateFunc = func(change *Change) bool

type ChangeValidator added in v0.5.1

type ChangeValidator = func(change StorageChange) error

type DebugInfo

type DebugInfo struct {
	TreeLen      int
	TreeString   string
	Graphviz     string
	Heads        []string
	SnapshotPath []string
}

type DescriptionParser

type DescriptionParser interface {
	ParseChange(ch *Change, isRoot bool) ([]string, error)
}

type DiffManager

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

func NewDiffManager

func NewDiffManager(initHeads, curHeads []string, treeBuilder treeBuilderFunc, onRemove onRemoveFunc) (*DiffManager, error)

func (*DiffManager) Add

func (d *DiffManager) Add(change *Change)

func (*DiffManager) Init

func (d *DiffManager) Init()

func (*DiffManager) Remove

func (d *DiffManager) Remove(ids []string)

func (*DiffManager) SeenHeads

func (d *DiffManager) SeenHeads() []string

func (*DiffManager) Update

func (d *DiffManager) Update(objTree ObjectTree)

type Flusher added in v0.5.1

type Flusher interface {
	MarkNewChange(ch *Change)
	FlushAfterBuild(t *objectTree) error
	Flush(t *objectTree) error
}

func MarkNewChangeFlusher added in v0.5.1

func MarkNewChangeFlusher() Flusher

type HistoryTree

type HistoryTree interface {
	ReadableObjectTree
}

func BuildHistoryTree

func BuildHistoryTree(params HistoryTreeParams) (HistoryTree, error)

func BuildNonVerifiableHistoryTree

func BuildNonVerifiableHistoryTree(params HistoryTreeParams) (HistoryTree, error)

type HistoryTreeParams

type HistoryTreeParams struct {
	Storage         Storage
	AclList         list.AclList
	Heads           []string
	IncludeBeforeId bool
}

type InitialContent

type InitialContent struct {
	AclHeadId     string
	PrivKey       crypto.PrivKey
	SpaceId       string
	Seed          []byte
	ChangeType    string
	ChangePayload []byte
	Timestamp     int64
}

type InitialDerivedContent added in v0.3.2

type InitialDerivedContent struct {
	SpaceId       string
	ChangeType    string
	ChangePayload []byte
}

type IteratorBatch added in v0.5.0

type IteratorBatch struct {
	Batch        []*treechangeproto.RawTreeChangeWithId
	Heads        []string
	SnapshotPath []string
	Root         *treechangeproto.RawTreeChangeWithId
}

type LoadIterator added in v0.5.0

type LoadIterator interface {
	NextBatch(maxSize int) (batch IteratorBatch, err error)
}

type MockChangeCreator

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

func NewMockChangeCreator

func NewMockChangeCreator(storeCreator func() anystore.DB) *MockChangeCreator

func (*MockChangeCreator) CreateDerivedRoot added in v0.3.2

func (c *MockChangeCreator) CreateDerivedRoot(id string, isDerived bool) *treechangeproto.RawTreeChangeWithId

func (*MockChangeCreator) CreateNewTreeStorage

func (c *MockChangeCreator) CreateNewTreeStorage(t *testing.T, treeId, aclHeadId string, isDerived bool) Storage

func (*MockChangeCreator) CreateRaw

func (c *MockChangeCreator) CreateRaw(id, aclId, snapshotId string, isSnapshot bool, prevIds ...string) *treechangeproto.RawTreeChangeWithId

func (*MockChangeCreator) CreateRawWithData

func (c *MockChangeCreator) CreateRawWithData(id, aclId, snapshotId string, isSnapshot bool, data []byte, prevIds ...string) *treechangeproto.RawTreeChangeWithId

func (*MockChangeCreator) CreateRoot

func (c *MockChangeCreator) CreateRoot(id, aclId string) *treechangeproto.RawTreeChangeWithId

type Mode

type Mode int
const (
	Append Mode = iota
	Rebuild
	Nothing
)

type ObjectTree

type ObjectTree interface {
	ReadableObjectTree

	SnapshotPath() []string
	ChangesAfterCommonSnapshotLoader(snapshotPath, heads []string) (LoadIterator, error)

	Storage() Storage

	AddContent(ctx context.Context, content SignableChangeContent) (AddResult, error)
	AddContentWithValidator(ctx context.Context, content SignableChangeContent, validate ChangeValidator) (AddResult, error)
	AddRawChanges(ctx context.Context, changes RawChangesPayload) (AddResult, error)
	AddRawChangesWithUpdater(ctx context.Context, changes RawChangesPayload, updater Updater) (AddResult, error)

	UnpackChange(raw *treechangeproto.RawTreeChangeWithId) (data []byte, err error)
	PrepareChange(content SignableChangeContent) (res *treechangeproto.RawTreeChangeWithId, err error)

	Delete() error
	Close() error
	SetFlusher(flusher Flusher)
	TryClose(objectTTL time.Duration) (bool, error)
}

func BuildEmptyDataKeyFilterableObjectTree added in v0.5.13

func BuildEmptyDataKeyFilterableObjectTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildEmptyDataObjectTree

func BuildEmptyDataObjectTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildEmptyDataTestableTree

func BuildEmptyDataTestableTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildKeyFilterableObjectTree added in v0.3.21

func BuildKeyFilterableObjectTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildMigratableObjectTree

func BuildMigratableObjectTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildObjectTree

func BuildObjectTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func BuildTestableTree

func BuildTestableTree(storage Storage, aclList list.AclList) (ObjectTree, error)

func ValidateFilterRawTree added in v0.3.21

func ValidateFilterRawTree(payload treestorage.TreeStorageCreatePayload, storageCreator TreeStorageCreator, aclList list.AclList) (objTree ObjectTree, err error)

func ValidateRawTreeDefault added in v0.5.13

func ValidateRawTreeDefault(payload treestorage.TreeStorageCreatePayload, storageCreator TreeStorageCreator, aclList list.AclList) (objTree ObjectTree, err error)

type ObjectTreeCreatePayload

type ObjectTreeCreatePayload struct {
	PrivKey       crypto.PrivKey
	ChangeType    string
	ChangePayload []byte
	SpaceId       string
	IsEncrypted   bool
	Seed          []byte
	Timestamp     int64
}

type ObjectTreeDerivePayload added in v0.3.2

type ObjectTreeDerivePayload struct {
	ChangeType    string
	ChangePayload []byte
	SpaceId       string
	IsEncrypted   bool
}

type ObjectTreeValidator

type ObjectTreeValidator interface {
	// ValidateFullTree should always be entered while holding a read lock on AclList
	ValidateFullTree(tree *Tree, aclList list.AclList) error
	// ValidateNewChanges should always be entered while holding a read lock on AclList
	ValidateNewChanges(tree *Tree, aclList list.AclList, newChanges []*Change) error
	FilterChanges(aclList list.AclList, changes []*Change, snapshots []*Change, indexes []int) (filteredHeads bool, filtered, filteredSnapshots []*Change, newIndexes []int)
}

type RawChangesPayload

type RawChangesPayload struct {
	NewHeads     []string
	RawChanges   []*treechangeproto.RawTreeChangeWithId
	SnapshotPath []string
}

type ReadableObjectTree

type ReadableObjectTree interface {
	TryLocker

	Id() string
	Header() *treechangeproto.RawTreeChangeWithId
	UnmarshalledHeader() *Change
	ChangeInfo() *treechangeproto.TreeChangeInfo
	Heads() []string
	Root() *Change
	Len() int
	IsDerived() bool

	AclList() list.AclList

	HasChanges(...string) bool
	GetChange(string) (*Change, error)

	Debug(parser DescriptionParser) (DebugInfo, error)
	IterateRoot(convert ChangeConvertFunc, iterate ChangeIterateFunc) error
	IterateFrom(id string, convert ChangeConvertFunc, iterate ChangeIterateFunc) error
}

type SignableChangeContent

type SignableChangeContent struct {
	// Data is a data provided by the client
	Data []byte
	// Key is the key which will be used to sign the change
	Key crypto.PrivKey
	// IsSnapshot tells if the change has snapshot of all previous data
	IsSnapshot bool
	// IsEncrypted tells if we encrypt the data with the relevant symmetric key
	IsEncrypted bool
	// Timestamp is a timestamp of change, if it is <= 0, then we use current timestamp
	Timestamp int64
	// DataType contains additional info about the data in the payload
	DataType string
}

SignableChangeContent is a payload to be passed when we are creating change

type Storage

type Storage interface {
	Id() string
	Root(ctx context.Context) (StorageChange, error)
	Heads(ctx context.Context) ([]string, error)
	CommonSnapshot(ctx context.Context) (string, error)
	Has(ctx context.Context, id string) (bool, error)
	Get(ctx context.Context, id string) (StorageChange, error)
	GetAfterOrder(ctx context.Context, orderId string, iter StorageIterator) error
	AddAll(ctx context.Context, changes []StorageChange, heads []string, commonSnapshot string) error
	Delete(ctx context.Context) error
	Close() error
}

func CreateStorage

func CreateStorage(ctx context.Context, root *treechangeproto.RawTreeChangeWithId, headStorage headstorage.HeadStorage, store anystore.DB) (Storage, error)

func NewStorage

func NewStorage(ctx context.Context, id string, headStorage headstorage.HeadStorage, store anystore.DB) (Storage, error)

type StorageChange

type StorageChange struct {
	RawChange       []byte
	PrevIds         []string
	Id              string
	SnapshotCounter int
	SnapshotId      string
	OrderId         string
	ChangeSize      int
	TreeId          string
}

func (StorageChange) RawTreeChangeWithId

func (c StorageChange) RawTreeChangeWithId() *treechangeproto.RawTreeChangeWithId

type StorageIterator

type StorageIterator = func(ctx context.Context, change StorageChange) (shouldContinue bool, err error)

type Tree

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

func (*Tree) Add

func (t *Tree) Add(changes ...*Change) (mode Mode, added []*Change)

func (*Tree) AddFast

func (t *Tree) AddFast(changes ...*Change) []*Change

func (*Tree) AddMergedHead

func (t *Tree) AddMergedHead(c *Change) error

func (*Tree) Get

func (t *Tree) Get(id string) *Change

func (*Tree) GetDuplicateEvents

func (t *Tree) GetDuplicateEvents() int

func (*Tree) Graph

func (t *Tree) Graph(parser DescriptionParser) (data string, err error)

func (*Tree) Hash

func (t *Tree) Hash() string

func (*Tree) Heads

func (t *Tree) Heads() []string

func (*Tree) HeadsChanges

func (t *Tree) HeadsChanges() []*Change

func (*Tree) IterateBranching

func (t *Tree) IterateBranching(startId string, f func(c *Change, branchLevel int) (isContinue bool))

func (*Tree) IterateSkip

func (t *Tree) IterateSkip(startId string, f func(c *Change) (isContinue bool))

func (*Tree) LeaveOnlyBefore

func (t *Tree) LeaveOnlyBefore(proposedHeads []string)

func (*Tree) Len

func (t *Tree) Len() int

func (*Tree) RemoveInvalidChange

func (t *Tree) RemoveInvalidChange(id string)

RemoveInvalidChange removes all the changes that are descendants of id

func (*Tree) ResetDuplicateEvents

func (t *Tree) ResetDuplicateEvents()

func (*Tree) Root

func (t *Tree) Root() *Change

func (*Tree) RootId

func (t *Tree) RootId() string

func (*Tree) String

func (t *Tree) String() string

type TreeMigrator

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

func NewTreeMigrator

func NewTreeMigrator(keyStorage crypto.KeyStorage, aclList list.AclList) *TreeMigrator

func (*TreeMigrator) MigrateTreeStorage

func (tm *TreeMigrator) MigrateTreeStorage(ctx context.Context, storage treeStorage, headStorage headstorage.HeadStorage, store anystore.DB) error

type TreeStorageCreator added in v0.5.13

type TreeStorageCreator interface {
	CreateTreeStorage(ctx context.Context, payload treestorage.TreeStorageCreatePayload) (Storage, error)
}

type TryLocker added in v0.4.18

type TryLocker interface {
	sync.Locker
	TryLock() bool
}

type Updater added in v0.5.1

type Updater = func(tree ObjectTree, md Mode) error

type ValidatorFunc added in v0.3.21

type ValidatorFunc func(payload treestorage.TreeStorageCreatePayload, storageCreator TreeStorageCreator, aclList list.AclList) (ret ObjectTree, err error)

Directories

Path Synopsis
Package mock_objecttree is a generated GoMock package.
Package mock_objecttree is a generated GoMock package.

Jump to

Keyboard shortcuts

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