dag

package
v0.0.0-...-89def8d Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidNodeType = errors.New("invalid node type")

ErrInvalidNodeType indicates a node with type other than raw of proto was encountered.

View Source
var (
	// ErrStorageQuotaExhausted indicates the requested operation exceeds the storage allowance.
	ErrStorageQuotaExhausted = errors.New("storage quota exhausted")
)

Functions

func AddAndPinNodes

func AddAndPinNodes(ctx context.Context, ipfs iface.CoreAPI, nodes []ipld.Node) (context.Context, error)

AddAndPinNodes adds and pins nodes, accounting for sum bytes pinned for context.

func AddPinnedBytes

func AddPinnedBytes(ctx context.Context, delta int64) context.Context

AddPinnedBytes adds the provided delta to a running total for context.

func CopyDag

func CopyDag(
	ctx context.Context,
	ipfs iface.CoreAPI,
	buck *collection.Bucket,
	root ipld.Node,
	fromPath string,
	toPath string,
) (context.Context, path.Resolved, error)

CopyDag make a copy of a node, re-encrypting it if the source and destination paths have different file keys. The copied node will be pinned.

func CreateBucketPath

func CreateBucketPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	seed ipld.Node,
	key []byte,
) (context.Context, path.Resolved, error)

CreateBucketPath creates an IPFS path which only contains the seed file. The returned path will be pinned.

func CreateBucketPathWithCid

func CreateBucketPathWithCid(
	ctx context.Context,
	ipfs iface.CoreAPI,
	buckPath string,
	cid cid.Cid,
	linkKey,
	fileKey []byte,
	seed ipld.Node,
) (context.Context, path.Resolved, error)

CreateBucketPathWithCid creates an IPFS path from a UnixFS dag. with collection.SeedName seed file added to the root of the dag. The returned path will be pinned.

func DecryptData

func DecryptData(data, key []byte) ([]byte, error)

DecryptData decrypts data with key.

func DecryptNode

func DecryptNode(cn ipld.Node, key []byte) (ipld.Node, bool, error)

DecryptNode returns a decrypted version of node and whether or not it is a directory.

func EncryptDag

func EncryptDag(
	ctx context.Context,
	ipfs iface.CoreAPI,
	root ipld.Node,
	destPath string,
	linkKey []byte,
	currentFileKeys,
	newFileKeys map[string][]byte,
	newFileKey []byte,
	add *NamedNode,
) (map[cid.Cid]*NamedNode, error)

EncryptDag creates an encrypted version of root that includes all child nodes. Leaf nodes are encrypted and linked to parents, which are then encrypted and linked to their parents, and so on up to root. add will be added to the encrypted root node if not nil. This method returns a map of all nodes keyed by their _original_ plaintext cid, and a list of the root's direct links.

func EncryptData

func EncryptData(data, currentKey, newKey []byte) ([]byte, error)

EncryptData encrypts data with the new key, decrypting with current key if needed.

func EncryptFileNode

func EncryptFileNode(
	ctx context.Context,
	ipfs iface.CoreAPI,
	n ipld.Node,
	currentKey,
	newKey []byte,
) (ipld.Node, error)

EncryptFileNode encrypts node with the new key, decrypting with current key if needed.

func EncryptNode

func EncryptNode(n *mdag.ProtoNode, key []byte) (*mdag.ProtoNode, error)

EncryptNode returns the encrypted version of node if key is not nil.

func GetNodeAtPath

func GetNodeAtPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	pth path.Path,
	key []byte,
) (ipld.Node, error)

GetNodeAtPath returns the node at path by traversing and potentially decrypting parent nodes.

func GetPathSize

func GetPathSize(ctx context.Context, ipfs iface.CoreAPI, root path.Path) (int64, error)

GetPathSize returns the cummulative size of root. If root is nil, it returns 0.

func GetPinnedBytes

func GetPinnedBytes(ctx context.Context) int64

GetPinnedBytes returns the total pinned bytes for context.

func InsertNodeAtPath

func InsertNodeAtPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	child ipld.Node,
	pth path.Path,
	key []byte,
) (context.Context, path.Resolved, error)

InsertNodeAtPath inserts a node at the location of path. Key will be required if the path is encrypted.

func MakeBucketSeed

func MakeBucketSeed(key []byte) (ipld.Node, error)

MakeBucketSeed returns a raw ipld node containing a random seed.

func NewDirFromExistingPath

func NewDirFromExistingPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	pth path.Path,
	destPath string,
	linkKey,
	fileKey []byte,
	add ipld.Node,
	addName string,
) (ipld.Node, []ipld.Node, error)

NewDirFromExistingPath returns a new dir based on path. If keys are not nil, this method recursively walks the path, encrypting files and directories. If add is not nil, it will be included in the resulting (possibly encrypted) node under a link named addName. This method returns the root node and a list of all new nodes (which also includes the root).

func NewOwnerContext

func NewOwnerContext(ctx context.Context, owner *BucketOwner) context.Context

NewOwnerContext returns a new bucket owner context.

func NewResolvedPath

func NewResolvedPath(s string) (path.Resolved, error)

NewResolvedPath returns path.Resolved from a string.

func ParsePath

func ParsePath(p path.Path) (resolved path.Resolved, fpath string, err error)

ParsePath returns path.Resolved and a path remainder from path.Path.

func PinBlocks

func PinBlocks(ctx context.Context, ipfs iface.CoreAPI, nodes []ipld.Node) (context.Context, error)

PinBlocks pins blocks, accounting for sum bytes pinned for context.

func RemoveNodeAtPath

func RemoveNodeAtPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	pth path.Path,
	key []byte,
) (context.Context, path.Resolved, error)

RemoveNodeAtPath removes node at the location of path. Key will be required if the path is encrypted.

func ResolveNodeAtPath

func ResolveNodeAtPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	pth path.Resolved,
	key []byte,
) (ipld.Node, bool, error)

ResolveNodeAtPath returns the decrypted node at path and whether or not it is a directory.

func UnpinBranch

func UnpinBranch(ctx context.Context, ipfs iface.CoreAPI, p path.Resolved, key []byte) (context.Context, error)

UnpinBranch walks a the node at path, decrypting (if needed) and unpinning all nodes

func UnpinNodeAndBranch

func UnpinNodeAndBranch(
	ctx context.Context,
	ipfs iface.CoreAPI,
	pth path.Resolved,
	key []byte,
) (context.Context, error)

UnpinNodeAndBranch unpins a node and its entire branch, accounting for sum bytes pinned for context.

func UnpinPath

func UnpinPath(ctx context.Context, ipfs iface.CoreAPI, path path.Path) (context.Context, error)

UnpinPath unpins path and accounts for sum bytes pinned for context.

func UpdateOrAddPin

func UpdateOrAddPin(ctx context.Context, ipfs iface.CoreAPI, from, to path.Path) (context.Context, error)

UpdateOrAddPin moves the pin at from to to. If from is nil, a new pin as placed at to.

Types

type BucketOwner

type BucketOwner struct {
	StorageUsed      int64
	StorageAvailable int64
	StorageDelta     int64
}

BucketOwner provides owner context to the bucket service.

func OwnerFromContext

func OwnerFromContext(ctx context.Context) (*BucketOwner, bool)

OwnerFromContext returns a bucket owner from the context if available.

type NamedNode

type NamedNode struct {
	Name string
	Path string
	Node ipld.Node
	Cid  cid.Cid
}

NamedNode describes an encrypted node.

type NamedNodes

type NamedNodes struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

NamedNodes is a unique set of NamedNodes.

func (*NamedNodes) Get

func (nn *NamedNodes) Get(c cid.Cid) *NamedNode

Get node by its original plaintext cid.

func (*NamedNodes) Store

func (nn *NamedNodes) Store(c cid.Cid, n *NamedNode)

Store node by its original plaintext cid.

type PathNode

type PathNode struct {
	Old     path.Resolved
	New     ipld.Node
	Name    string
	IsJoint bool
}

func GetNodesToPath

func GetNodesToPath(
	ctx context.Context,
	ipfs iface.CoreAPI,
	base path.Resolved,
	pth string,
	key []byte,
) (nodes []PathNode, isDir bool, remainder string, err error)

GetNodesToPath returns a list of pathNodes that point to the path, The remaining path segment that was not resolvable is also returned.

Jump to

Keyboard shortcuts

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