dag

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChunkSize = 2048 * 1024 // 2048 * 1024 bytes = 2 megabytes

Functions

func GenerateDummyDirectory

func GenerateDummyDirectory(path string, minItems, maxItems, minDepth, maxDepth int)

func GetHash

func GetHash(hash string) string

func GetLabel

func GetLabel(hash string) string

func HasLabel

func HasLabel(hash string) bool

func SetChunkSize

func SetChunkSize(size int)

Types

type ClassicTreeBranch

type ClassicTreeBranch struct {
	Leaf  string
	Proof *merkletree.Proof
}

type Dag

type Dag struct {
	Root  string
	Leafs map[string]*DagLeaf
}

func CreateDag

func CreateDag(path string, timestampRoot bool) (*Dag, error)

func CreateDagAdvanced

func CreateDagAdvanced(path string, additionalData map[string]string) (*Dag, error)

func FromCBOR

func FromCBOR(data []byte) (*Dag, error)

func FromJSON

func FromJSON(data []byte) (*Dag, error)

func FromSerializable

func FromSerializable(s *SerializableDag) *Dag

FromSerializable reconstructs a Dag from its serializable form

func ReadDag

func ReadDag(path string) (*Dag, error)

func (*Dag) CreateDirectory

func (dag *Dag) CreateDirectory(path string) error

func (*Dag) GetContentFromLeaf

func (dag *Dag) GetContentFromLeaf(leaf *DagLeaf) ([]byte, error)

func (*Dag) GetPartial

func (d *Dag) GetPartial(start, end int) (*Dag, error)

GetPartial returns a new DAG containing only the requested leaves and their verification paths

func (*Dag) IsPartial

func (d *Dag) IsPartial() bool

IsPartial returns true if this DAG is a partial DAG (has pruned links)

func (*Dag) IterateDag

func (d *Dag) IterateDag(processLeaf func(leaf *DagLeaf, parent *DagLeaf) error) error

func (*Dag) ToCBOR

func (dag *Dag) ToCBOR() ([]byte, error)

func (*Dag) ToJSON

func (dag *Dag) ToJSON() ([]byte, error)

func (*Dag) ToSerializable

func (dag *Dag) ToSerializable() *SerializableDag

ToSerializable converts a Dag to its serializable form

func (*Dag) Verify

func (d *Dag) Verify() error

Verify checks the integrity of the DAG, automatically choosing between full and partial verification

type DagBranch

type DagBranch struct {
	Leaf         *DagLeaf
	Path         []*DagLeaf
	MerkleProofs map[string]*ClassicTreeBranch
}

type DagBuilder

type DagBuilder struct {
	Leafs map[string]*DagLeaf
}

func CreateDagBuilder

func CreateDagBuilder() *DagBuilder

func (*DagBuilder) AddLeaf

func (b *DagBuilder) AddLeaf(leaf *DagLeaf, parentLeaf *DagLeaf) error

func (*DagBuilder) BuildDag

func (b *DagBuilder) BuildDag(root string) *Dag

func (*DagBuilder) GetLatestLabel

func (b *DagBuilder) GetLatestLabel() string

func (*DagBuilder) GetNextAvailableLabel

func (b *DagBuilder) GetNextAvailableLabel() string

type DagLeaf

type DagLeaf struct {
	Hash              string
	ItemName          string
	Type              LeafType
	ContentHash       []byte
	Content           []byte
	ClassicMerkleRoot []byte
	CurrentLinkCount  int
	LatestLabel       string
	LeafCount         int
	Links             map[string]string
	ParentHash        string
	AdditionalData    map[string]string
	MerkleTree        *merkletree.MerkleTree
	LeafMap           map[string]merkletree.DataBlock
	Proofs            map[string]*ClassicTreeBranch
}

func CreateDummyLeaf

func CreateDummyLeaf(name string) (*DagLeaf, error)

func FindRandomChild

func FindRandomChild(leaf *DagLeaf, leafs map[string]*DagLeaf) *DagLeaf
func (leaf *DagLeaf) AddLink(hash string)

func (*DagLeaf) Clone

func (leaf *DagLeaf) Clone() *DagLeaf

func (*DagLeaf) CreateDirectoryLeaf

func (leaf *DagLeaf) CreateDirectoryLeaf(path string, dag *Dag) error

func (*DagLeaf) GetBranch

func (leaf *DagLeaf) GetBranch(key string) (*ClassicTreeBranch, error)

func (*DagLeaf) GetIndexForKey

func (leaf *DagLeaf) GetIndexForKey(key string) (int, bool)
func (leaf *DagLeaf) HasLink(hash string) bool

func (*DagLeaf) SetLabel

func (leaf *DagLeaf) SetLabel(label string)

func (*DagLeaf) ToSerializable

func (leaf *DagLeaf) ToSerializable() *SerializableDagLeaf

ToSerializable converts a DagLeaf to its serializable form

func (*DagLeaf) VerifyBranch

func (leaf *DagLeaf) VerifyBranch(branch *ClassicTreeBranch) error

func (*DagLeaf) VerifyLeaf

func (leaf *DagLeaf) VerifyLeaf() error

func (*DagLeaf) VerifyRootLeaf

func (leaf *DagLeaf) VerifyRootLeaf() error

type DagLeafBuilder

type DagLeafBuilder struct {
	ItemName string
	Label    int64
	LeafType LeafType
	Data     []byte
	Links    map[string]string
}

func CreateDagLeafBuilder

func CreateDagLeafBuilder(name string) *DagLeafBuilder
func (b *DagLeafBuilder) AddLink(label string, hash string)

func (*DagLeafBuilder) BuildLeaf

func (b *DagLeafBuilder) BuildLeaf(additionalData map[string]string) (*DagLeaf, error)

func (*DagLeafBuilder) BuildRootLeaf

func (b *DagLeafBuilder) BuildRootLeaf(dag *DagBuilder, additionalData map[string]string) (*DagLeaf, error)

func (*DagLeafBuilder) SetData

func (b *DagLeafBuilder) SetData(data []byte)

func (*DagLeafBuilder) SetType

func (b *DagLeafBuilder) SetType(leafType LeafType)

type LeafType

type LeafType string
const (
	FileLeafType      LeafType = "file"
	ChunkLeafType     LeafType = "chunk"
	DirectoryLeafType LeafType = "directory"
)

type MetaData

type MetaData struct {
	Deleted []string
}

type SerializableDag

type SerializableDag struct {
	Root  string
	Leafs map[string]*SerializableDagLeaf
}

SerializableDag is a minimal version of Dag for efficient serialization

type SerializableDagLeaf

type SerializableDagLeaf struct {
	Hash              string
	ItemName          string
	Type              LeafType
	ContentHash       []byte
	Content           []byte
	ClassicMerkleRoot []byte
	CurrentLinkCount  int
	LatestLabel       string
	LeafCount         int
	Links             map[string]string
	AdditionalData    map[string]string
	StoredProofs      map[string]*ClassicTreeBranch `json:"stored_proofs,omitempty" cbor:"stored_proofs,omitempty"`
}

SerializableDagLeaf is a minimal version of DagLeaf for efficient serialization

Jump to

Keyboard shortcuts

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