daggen

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0, MIT Imports: 18 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(data []byte) (cid.Cid, []blocks.Block, error)

UnmarshalToBlocks deserializes binary data into a set of blocks and a root content identifier (CID). This function: 1. Decodes the input binary data. 2. Reads the CAR (Content Addressable Archives) header from the decoded data to obtain the root CID. 3. Iteratively reads CAR blocks from the data and constructs block objects from them.

Parameters:

data : Binary data representing a serialized set of blocks and a root CID.

Returns:

cid.Cid     : The root CID extracted from the CAR header, or an undefined CID if an error occurs.
[]blocks.Block : Slice of blocks.Block objects reconstructed from the input data, or nil if an error occurs.
error       : An error is returned if decoding the input data, reading the CAR header, or reading CAR blocks fails.
              Otherwise, it returns nil.

Types

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

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 serializes the current state of the DirectoryData object into a binary format. This method:

  1. Refreshes the internal representation of the directory (Node).
  2. Writes the CAR (Content Addressable Archives) header of the new Node to a buffer.
  3. If an old Node exists, it deletes the old Node from the blockstore.
  4. Puts the new Node into the blockstore.
  5. Iterates through all the keys in the blockstore, retrieves the corresponding data, and writes it as CAR blocks to the buffer.
  6. Returns the entire buffer content encoded.

Parameters:

ctx : Context used to control cancellations or timeouts.

Returns:

[]byte : Binary representation of the DirectoryData, or nil if an error occurs.
error  : An error is returned if refreshing the Node, writing the CAR header, deleting the old Node,
         putting

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, data []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 (t DirectoryTree) Cache() map[uint64]*DirectoryDetail

func (DirectoryTree) Get added in v0.3.0

func (t DirectoryTree) Get(dirID uint64) *DirectoryDetail

func (DirectoryTree) Has added in v0.3.0

func (t DirectoryTree) Has(dirID uint64) bool

func (DirectoryTree) Resolve added in v0.3.0

func (t DirectoryTree) Resolve(ctx context.Context, dirID uint64) (*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

Jump to

Keyboard shortcuts

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