daggen

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDummyNode error = errors.New("fake dummy Node")

Functions

func UnmarshalToBlocks added in v0.3.0

func UnmarshalToBlocks(in []byte) ([]blocks.Block, error)

UnmarshalToBlocks decodes a byte slice into a slice of blocks. The input byte slice is expected to represent compressed CBOR encoded binary data of directoryData.

The function first decompresses the input byte slice and then decodes it using CBOR to obtain directoryData which contains information about real and additional blocks. These blocks are then reconstructed and returned.

Parameters:

  • in: A byte slice representing the compressed CBOR encoded binary of the directoryData.

Returns:

  • A slice of blocks reconstructed from the input byte slice.
  • An error, if any occurred during the decompression, decoding or block reconstruction process.

Types

type DagServEntry added in v0.5.0

type DagServEntry struct {
	Cid       cid.Cid
	Data      []byte
	DummySize int32
	// contains filtered or unexported fields
}

type DirectoryData added in v0.1.0

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

DirectoryData represents a structured directory in a content-addressed file system. It manages the underlying data and provides methods for interacting with this data as a hierarchical directory structure.

Fields:

  • dir: The current representation of the directory, implementing the uio.Directory interface.
  • bstore: The blockstore used to store and retrieve blocks of data associated with the directory.
  • node: The cached format.Node representation of the current directory.
  • nodeDirty : A flag indicating whether the cached node representation is potentially outdated and needs to be refreshed from the internal directory representation.

func NewDirectoryData added in v0.1.0

func NewDirectoryData() DirectoryData

NewDirectoryData creates and initializes a new DirectoryData instance. This function:

  1. Creates a new in-memory map datastore.
  2. Initializes a new blockstore with the created datastore.
  3. Initializes a new DAG service with the blockstore.
  4. Creates a new directory with the DAG service and sets its CID (Content Identifier) builder.

Returns:

  • DirectoryData : A new DirectoryData instance with the initialized directory, blockstore, and a dirty node flag set to true.

func (*DirectoryData) AddBlocks added in v0.3.0

func (d *DirectoryData) AddBlocks(ctx context.Context, blks []blocks.Block)

AddBlocks adds an array of blocks to the underlying blockstore of the DirectoryData instance.

Parameters:

  • ctx: Context that allows for asynchronous task cancellation.
  • blks: An array of blocks that need to be added to the blockstore.

Returns:

  • error: The error encountered during the operation, if any.

This function is a wrapper that delegates the block adding task to the blockstore instance associated with the DirectoryData instance.

func (*DirectoryData) AddFile added in v0.3.0

func (d *DirectoryData) AddFile(ctx context.Context, name string, c cid.Cid, length uint64) error

AddFile adds a new file to the directory with the specified name, content identifier (CID), and length. It creates a new dummy node with the provided length and CID, and then adds this node as a child to the current directory under the given name.

Parameters:

  • ctx : Context used to control cancellations or timeouts.
  • name : Name of the file to be added to the directory.
  • c : Content Identifier (CID) of the file to be added.
  • length : The length of the file in bytes.

Returns:

error  : An error is returned if adding the child to the directory fails, otherwise it returns nil.
func (d *DirectoryData) AddFileFromLinks(ctx context.Context, name string, links []format.Link) (cid.Cid, error)

AddFileFromLinks constructs a new file from a set of links and adds it to the directory. It first assembles the file from the provided links, then adds this file as a child to the current directory with the specified name. The assembled file and its constituent blocks are stored in the associated blockstore.

Parameters:

  • ctx : Context used to control cancellations or timeouts.
  • name : Name of the file to be added to the directory.
  • links : Slice of format.Link that define the file to be assembled and added.

Returns:

  • cid.Cid : Content Identifier (CID) of the added file if successful.
  • error : An error is returned if assembling the file from links fails, adding the child to the directory fails, or putting blocks into the blockstore fails. Otherwise, it returns nil.

func (*DirectoryData) MarshalBinary added in v0.1.0

func (d *DirectoryData) MarshalBinary(ctx context.Context) ([]byte, error)

MarshalBinary encodes the DirectoryData into a binary format using CBOR and then compresses the result.

The method reconstructs the directory using the DagService, determines which blocks have been visited, and constructs a representation containing both dummy and real data from the directory.

Parameters:

  • ctx: A context to allow for timeout or cancellation of operations.

Returns:

  • A byte slice representing the compressed CBOR encoded binary of the DirectoryData.
  • An error, if any occurred during the encoding or compression process.

func (*DirectoryData) Node added in v0.1.0

func (d *DirectoryData) Node() (format.Node, error)

Node retrieves the format.Node representation of the current DirectoryData. If the node representation is marked as dirty (meaning it is potentially outdated), this method:

  1. Calls GetNode on the internal directory to refresh the node representation.
  2. Updates the internal node field with this new node.
  3. Resets the dirty flag to false, indicating that the node is now up to date.

Returns:

  • format.Node : The current node representation of the directory, or nil if an error occurs.
  • error : An error is returned if getting the Node from the internal directory fails. Otherwise, it returns nil.

func (*DirectoryData) UnmarshalBinary added in v0.3.0

func (d *DirectoryData) UnmarshalBinary(ctx context.Context, in []byte) error

UnmarshalBinary deserializes binary data into the current DirectoryData object. This method:

  1. Creates a new blockstore and DAG service.
  2. Checks if the input data is empty. If it is, initializes the DirectoryData with a new empty directory and returns.
  3. Otherwise, it unmarshalls the input data into blocks and a root CID.
  4. Puts these blocks into the blockstore.
  5. Retrieves the root directory node from the DAG service using the root CID.
  6. Constructs a new directory from the retrieved node and sets this as the current directory.

Parameters:

  • data : Binary data representing a serialized DirectoryData object.

Returns:

  • error : An error is returned if unmarshalling the data, putting blocks into blockstore, retrieving the root directory node, or creating a new directory from the node fails. Otherwise, it returns nil.

type DirectoryDetail added in v0.3.0

type DirectoryDetail struct {
	Dir  *model.Directory
	Data *DirectoryData
}

type DirectoryTree added in v0.3.0

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

func NewDirectoryTree added in v0.3.0

func NewDirectoryTree() DirectoryTree

func (DirectoryTree) Add added in v0.3.0

func (t DirectoryTree) Add(ctx context.Context, dir *model.Directory) error

Add inserts a new directory into the DirectoryTree.

Parameters:

  • ctx: Context that allows for asynchronous task cancellation.
  • dir: A pointer to a model.Directory object that needs to be added to the tree.

Returns:

  • error: The error encountered during the operation, if any

func (DirectoryTree) Cache added in v0.3.0

func (DirectoryTree) Get added in v0.3.0

func (DirectoryTree) Has added in v0.3.0

func (t DirectoryTree) Has(dirID model.DirectoryID) bool

func (DirectoryTree) Resolve added in v0.3.0

func (t DirectoryTree) Resolve(ctx context.Context, dirID model.DirectoryID) (*format.Link, error)

Resolve recursively constructs the IPLD (InterPlanetary Linked Data) structure for a directory and its subdirectories, and returns a link pointing to the root of this structure.

Parameters:

  • ctx: Context that allows for asynchronous task cancellation.
  • dirID: The ID of the directory that needs to be resolved.

Returns:

  • *format.Link: A link that points to the root of the IPLD structure for the directory.
  • error: The error encountered during the operation, if any.

type DummyNode

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

func NewDummyNode

func NewDummyNode(size uint64, cid cid.Cid) *DummyNode

func (DummyNode) Cid

func (f DummyNode) Cid() cid.Cid

func (DummyNode) Copy

func (f DummyNode) Copy() ipld.Node
func (f DummyNode) Links() []*ipld.Link

func (DummyNode) Loggable

func (f DummyNode) Loggable() map[string]any

func (DummyNode) RawData

func (f DummyNode) RawData() []byte

func (DummyNode) Resolve

func (f DummyNode) Resolve(path []string) (any, []string, error)
func (f DummyNode) ResolveLink(path []string) (*ipld.Link, []string, error)

func (DummyNode) Size

func (f DummyNode) Size() (uint64, error)

func (DummyNode) Stat

func (f DummyNode) Stat() (*ipld.NodeStat, error)

func (DummyNode) String

func (f DummyNode) String() string

func (DummyNode) Tree

func (f DummyNode) Tree(path string, depth int) []string

type RecordedDagService added in v0.5.0

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

RecordedDagService is a DAGService that records all blocks that are used. This struct is only meant to be used internally which achieves * Tracks the blocks that are used * Directly supports DummyNode

func NewRecordedDagService added in v0.5.0

func NewRecordedDagService() *RecordedDagService

func (*RecordedDagService) Add added in v0.5.0

func (r *RecordedDagService) Add(ctx context.Context, node format.Node) error

Add adds a block to the RecordedDagService's blockstore.

If the node is of type *DummyNode, it is added to the blockstore with its size and marked as a dummy. Otherwise, the node's raw data is added to the blockstore.

Parameters:

  • ctx: A context to allow for timeout or cancellation of operations.
  • node: The format.Node representing the block to be added to the blockstore.

Returns:

  • An error if any issues arise during the addition process; otherwise, it returns nil.

func (*RecordedDagService) AddMany added in v0.5.0

func (r *RecordedDagService) AddMany(ctx context.Context, nodes []format.Node) error

func (*RecordedDagService) Get added in v0.5.0

func (r *RecordedDagService) Get(ctx context.Context, c cid.Cid) (format.Node, error)

Get retrieves a format.Node based on a given CID from the RecordedDagService.

The RecordedDagService keeps track of blocks with their visitation status. If a block with the provided CID is found and hasn't been visited yet, it's marked as visited. If the block is a dummy block, a dummy node is returned; otherwise, the raw data of the block is decoded into a format.Node using the IPLD legacy decoder.

Parameters:

  • ctx: A context to allow for timeout or cancellation of operations.
  • c: A CID representing the content identifier of the desired block.

Returns:

  • A format.Node representing the block associated with the given CID. This could be a dummy node or a decoded version of the actual block data.
  • An error if the CID does not match any blocks in the service's blockstore or if other issues arise. If the CID is not found, format.ErrNotFound with the CID is returned.

func (*RecordedDagService) GetMany added in v0.5.0

func (r *RecordedDagService) GetMany(ctx context.Context, cids []cid.Cid) <-chan *format.NodeOption

GetMany fetches multiple nodes from the RecordedDagService's blockstore concurrently.

This method returns a channel where the caller can consume the results. Each result is wrapped in a *format.NodeOption which contains the format.Node and an error, if any occurred while fetching the node.

Parameters:

  • ctx: A context to allow for timeout or cancellation of operations.
  • cids: A slice of cid.Cid representing the identifiers of the nodes to be fetched.

Returns:

  • A channel of *format.NodeOption. Each *format.NodeOption contains a fetched node and an error indicating any issues that occurred while fetching.

func (*RecordedDagService) Remove added in v0.5.0

func (r *RecordedDagService) Remove(ctx context.Context, c cid.Cid) error

func (*RecordedDagService) RemoveMany added in v0.5.0

func (r *RecordedDagService) RemoveMany(ctx context.Context, cids []cid.Cid) error

func (*RecordedDagService) ResetVisited added in v0.5.0

func (r *RecordedDagService) ResetVisited()

func (*RecordedDagService) Visit added in v0.5.0

func (r *RecordedDagService) Visit(ctx context.Context, c cid.Cid)

Visit marks a block with a given CID as visited in the RecordedDagService's blockstore.

The purpose of this function is to track the visitation status of blocks. If a block with the provided CID exists in the blockstore and hasn't been visited yet, this method will mark it as visited. If the block is already marked as visited or doesn't exist, the method does nothing.

Parameters:

  • ctx: A context to allow for timeout or cancellation of operations.
  • c: A CID representing the content identifier of the block to be marked as visited.

Jump to

Keyboard shortcuts

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