dag

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
const DefaultChunkSize = 2048 * 1024 // 2048 * 1024 bytes = 2 megabytes

Variables

View Source
var ChunkSize = DefaultChunkSize

Functions

func DisableChunking added in v1.2.4

func DisableChunking()

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)

func SetDefaultChunkSize added in v1.2.4

func SetDefaultChunkSize()

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 CreateDagCustom added in v1.2.3

func CreateDagCustom(path string, rootAdditionalData map[string]string, processor LeafProcessor) (*Dag, error)

CreateDagCustom creates a DAG with custom metadata for each leaf

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) ApplyAndVerifyTransmissionPacket added in v1.2.5

func (d *Dag) ApplyAndVerifyTransmissionPacket(packet *TransmissionPacket) error

ApplyAndVerifyTransmissionPacket verifies then applies a transmission packet

func (*Dag) ApplyTransmissionPacket added in v1.1.0

func (d *Dag) ApplyTransmissionPacket(packet *TransmissionPacket)

ApplyTransmissionPacket applies a transmission packet to the DAG

func (*Dag) CreateDirectory

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

func (*Dag) GetContentFromLeaf

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

func (*Dag) GetLeafSequence added in v1.1.0

func (d *Dag) GetLeafSequence() []*TransmissionPacket

GetLeafSequence returns an ordered sequence of leaves for transmission Each packet contains a leaf, its parent hash, and any proofs needed for verification

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 fewer leaves than the total count)

func (*Dag) IterateDag

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

func (*Dag) RemoveAllContent added in v1.2.4

func (d *Dag) RemoveAllContent()

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

func (*Dag) VerifyTransmissionPacket added in v1.2.5

func (d *Dag) VerifyTransmissionPacket(packet *TransmissionPacket) error

VerifyTransmissionPacket verifies a transmission packet independently

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 LeafProcessor added in v1.2.3

type LeafProcessor func(path string, relPath string, entry fs.DirEntry, isRoot bool, leafType LeafType) map[string]string

LeafProcessor is a function that generates metadata for a leaf path: The full path to the file/directory relPath: The relative path within the DAG entry: The file/directory entry information isRoot: Whether this is the root leaf leafType: The type of leaf (file, directory, chunk) Returns additional metadata to be added to the leaf

type LeafType

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

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

type SerializableTransmissionPacket added in v1.1.0

type SerializableTransmissionPacket struct {
	Leaf       *SerializableDagLeaf
	ParentHash string
	Proofs     map[string]*ClassicTreeBranch `json:"proofs,omitempty" cbor:"proofs,omitempty"`
}

SerializableTransmissionPacket is a minimal version of TransmissionPacket for efficient serialization

type TransmissionPacket added in v1.1.0

type TransmissionPacket struct {
	Leaf       *DagLeaf
	ParentHash string
	Proofs     map[string]*ClassicTreeBranch
}

func TransmissionPacketFromCBOR added in v1.1.0

func TransmissionPacketFromCBOR(data []byte) (*TransmissionPacket, error)

TransmissionPacketFromCBOR deserializes a TransmissionPacket from CBOR format

func TransmissionPacketFromJSON added in v1.1.0

func TransmissionPacketFromJSON(data []byte) (*TransmissionPacket, error)

TransmissionPacketFromJSON deserializes a TransmissionPacket from JSON format

func TransmissionPacketFromSerializable added in v1.1.0

func TransmissionPacketFromSerializable(s *SerializableTransmissionPacket) *TransmissionPacket

TransmissionPacketFromSerializable reconstructs a TransmissionPacket from its serializable form

func (*TransmissionPacket) ToCBOR added in v1.1.0

func (packet *TransmissionPacket) ToCBOR() ([]byte, error)

ToCBOR serializes a TransmissionPacket to CBOR format

func (*TransmissionPacket) ToJSON added in v1.1.0

func (packet *TransmissionPacket) ToJSON() ([]byte, error)

ToJSON serializes a TransmissionPacket to JSON format

func (*TransmissionPacket) ToSerializable added in v1.1.0

func (packet *TransmissionPacket) ToSerializable() *SerializableTransmissionPacket

ToSerializable converts a TransmissionPacket to its serializable form

Jump to

Keyboard shortcuts

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