Commit b8550cf5 authored by Eric Myhre's avatar Eric Myhre

Update traversal package to new linking system.

Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent 10442b3c
...@@ -3,33 +3,9 @@ package traversal ...@@ -3,33 +3,9 @@ package traversal
import ( import (
"context" "context"
cid "github.com/ipfs/go-cid"
ipld "github.com/ipld/go-ipld-prime" ipld "github.com/ipld/go-ipld-prime"
) )
// An example use of LinkContext in LinkLoader logic might be inspecting the
// LinkNode, and if it's using the type system, inspecting its Type property;
// then deciding on whether or not we want to load objects of that Type.
// This might be used to do a traversal which looks at all directory objects,
// but not file contents, for example.
type LinkContext struct {
LinkPath ipld.Path
LinkNode ipld.Node // has the cid again, but also might have type info // always zero for writing new nodes, for obvi reasons.
ParentNode ipld.Node
}
type LinkLoader func(context.Context, cid.Cid, LinkContext) (ipld.Node, error)
// One presumes implementations will also *save* the content somewhere.
// The LinkContext parameter is a nod to this -- none of those parameters
// are relevant to the generation of the Cid itself, but perhaps one might
// want to use them when deciding where to store some files, etc.
type LinkBuilder func(
ctx context.Context,
node ipld.Node, lnkCtx LinkContext,
multicodecType uint64, multihashType uint64, multihashLength int,
) (cid.Cid, error)
// VisitFn is a read-only visitor. // VisitFn is a read-only visitor.
type VisitFn func(TraversalProgress, ipld.Node) error type VisitFn func(TraversalProgress, ipld.Node) error
...@@ -45,14 +21,14 @@ type TraversalReason byte // enum = SelectionMatch | SelectionParent | Selection ...@@ -45,14 +21,14 @@ type TraversalReason byte // enum = SelectionMatch | SelectionParent | Selection
type TraversalProgress struct { type TraversalProgress struct {
*TraversalConfig *TraversalConfig
Path ipld.Path // Path is how we reached the current point in the traversal. Path ipld.Path // Path is how we reached the current point in the traversal.
LastBlock struct { // LastBlock stores the Path and CID of the last block edge we had to load. (It will always be zero in traversals with no linkloader.) LastBlock struct { // LastBlock stores the Path and Link of the last block edge we had to load. (It will always be zero in traversals with no linkloader.)
ipld.Path ipld.Path
cid.Cid ipld.Link
} }
} }
type TraversalConfig struct { type TraversalConfig struct {
Ctx context.Context // Context carried through a traversal. Optional; use it if you need cancellation. Ctx context.Context // Context carried through a traversal. Optional; use it if you need cancellation.
LinkLoader LinkLoader LinkLoader ipld.Loader // Loader used for automatic link traversal.
// `blockWriter func(Context, Node, multicodec(?)) (CID, error)` probably belongs here. LinkStorer ipld.Storer // Storer used if any mutation features (e.g. traversal.Transform) are used.
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment