objecttree

package
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 ValidateFilterRawTree added in v0.3.21

func ValidateFilterRawTree(payload treestorage.TreeStorageCreatePayload, aclList list.AclList) (retPayload treestorage.TreeStorageCreatePayload, err error)

func ValidateRawTree

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

func ValidateRawTreeBuildFunc added in v0.3.20

func ValidateRawTreeBuildFunc(payload treestorage.TreeStorageCreatePayload, buildFunc BuildObjectTreeFunc, aclList list.AclList) (newPayload treestorage.TreeStorageCreatePayload, err error)

Types

type AddResult

type AddResult struct {
	OldHeads []string
	Heads    []string
	Added    []*treechangeproto.RawTreeChangeWithId

	Mode Mode
}

type AddResultSummary

type AddResultSummary int

type BuildObjectTreeFunc

type BuildObjectTreeFunc = func(treeStorage treestorage.TreeStorage, 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
	AclHeadId   string
	Id          string
	SnapshotId  string
	Timestamp   int64
	ReadKeyId   string
	Identity    crypto.PubKey
	Data        []byte
	Model       interface{}
	Signature   []byte
	DataType    string
	IsSnapshot  bool
	IsDerived   bool
	// contains filtered or unexported fields
}

Change is an abstract type for all types of changes

func NewChange

func NewChange(id string, identity crypto.PubKey, ch *treechangeproto.TreeChange, signature []byte) *Change

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

type ChangeConvertFunc

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

type ChangeIterateFunc

type ChangeIterateFunc = func(change *Change) bool

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 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 {
	TreeStorage     treestorage.TreeStorage
	AclList         list.AclList
	BeforeId        string
	IncludeBeforeId bool
	BuildFullTree   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 MockChangeCreator

type MockChangeCreator struct{}

func NewMockChangeCreator

func NewMockChangeCreator() *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(treeId, aclHeadId string, isDerived bool) treestorage.TreeStorage

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
	ChangesAfterCommonSnapshot(snapshotPath, heads []string) ([]*treechangeproto.RawTreeChangeWithId, error)

	Storage() treestorage.TreeStorage

	AddContent(ctx context.Context, content SignableChangeContent) (AddResult, error)
	AddRawChanges(ctx context.Context, changes RawChangesPayload) (AddResult, error)

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

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

func BuildEmptyDataObjectTree

func BuildEmptyDataObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error)

func BuildEmptyDataTestableTree

func BuildEmptyDataTestableTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error)

func BuildKeyFilterableObjectTree added in v0.3.21

func BuildKeyFilterableObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error)

func BuildObjectTree

func BuildObjectTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, error)

func BuildTestableTree

func BuildTestableTree(treeStorage treestorage.TreeStorage, aclList list.AclList) (ObjectTree, 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
}

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

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

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, skipBeforeId string, f func(c *Change) (isContinue bool))

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 TryLocker added in v0.4.18

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

type ValidatorFunc added in v0.3.21

type ValidatorFunc func(payload treestorage.TreeStorageCreatePayload, buildFunc BuildObjectTreeFunc, aclList list.AclList) (retPayload treestorage.TreeStorageCreatePayload, 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