Skip to content

Commit

Permalink
feat(car): update for ipld linksystem
Browse files Browse the repository at this point in the history
updates to be compatible with ipld linksystem
  • Loading branch information
hannahhoward committed Mar 12, 2021
1 parent cb192ce commit 7afab98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/ipfs/go-ipld-cbor v0.0.5
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-merkledag v0.3.2
github.com/ipld/go-codec-dagpb v1.0.1
github.com/ipld/go-ipld-prime v0.7.1-0.20210305140706-7e6922442629
github.com/ipld/go-codec-dagpb v1.0.2-0.20210308154810-d05d02fa186e
github.com/ipld/go-ipld-prime v0.7.1-0.20210312004928-8a500e6b8a62
github.com/multiformats/go-multihash v0.0.14
github.com/stretchr/testify v1.7.0
)
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
github.com/ipld/go-codec-dagpb v1.0.1 h1:1bpbWKNyRGpCV2w9QIJPmmmFODjjNVhHiM9t/kT/HP8=
github.com/ipld/go-codec-dagpb v1.0.1/go.mod h1:3RKe7tCm89O2jWw5nQDQx0MMMxJUQbZzBHkleyttP3M=
github.com/ipld/go-codec-dagpb v1.0.2-0.20210308154810-d05d02fa186e h1:QXGG+qipDQaY7BT/n2gnDCS5Y6KNtdZNceTFHlPlEqE=
github.com/ipld/go-codec-dagpb v1.0.2-0.20210308154810-d05d02fa186e/go.mod h1:oYexiw3WkBIVD5UTNkVuOd0iyEcLxqytAQa90F3nH9M=
github.com/ipld/go-ipld-prime v0.7.0/go.mod h1:0xEgdD6MKbZ1vF0GC+YcR/C4SQCAlRuOjIJ2i0HxqzM=
github.com/ipld/go-ipld-prime v0.7.1-0.20210225173718-8fef5312eb12/go.mod h1:0xEgdD6MKbZ1vF0GC+YcR/C4SQCAlRuOjIJ2i0HxqzM=
github.com/ipld/go-ipld-prime v0.7.1-0.20210305140706-7e6922442629 h1:8OaclCESdhKZeTjY+13QRuflDhoD/1VX+o37DbWssho=
github.com/ipld/go-ipld-prime v0.7.1-0.20210305140706-7e6922442629/go.mod h1:k++jmk6A1k3gXVnW0XF1M1xBKnk7fGEjC2QDj9Zgvyg=
github.com/ipld/go-ipld-prime v0.7.1-0.20210312004928-8a500e6b8a62 h1:rYzj0eh2b6VWuF3yRdWugOcItYSI7Z4buf8Q9zxW1Yo=
github.com/ipld/go-ipld-prime v0.7.1-0.20210312004928-8a500e6b8a62/go.mod h1:ZwznT3awHhuBoB0SgGxSo8SZEg6XbQtsZ6WahL9r9z0=
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA=
Expand Down
13 changes: 7 additions & 6 deletions selectivecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func NewSelectiveCar(ctx context.Context, store ReadStore, dags []Dag) Selective
}

func (sc SelectiveCar) traverse(onCarHeader OnCarHeaderFunc, onNewCarBlock OnNewCarBlockFunc) (uint64, error) {
traverser := &selectiveCarTraverser{onCarHeader, onNewCarBlock, 0, cid.NewSet(), sc}

traverser := &selectiveCarTraverser{onCarHeader, onNewCarBlock, 0, cid.NewSet(), sc, cidlink.DefaultLinkSystem()}
traverser.lsys.StorageReadOpener = traverser.loader
return traverser.traverse()
}

Expand Down Expand Up @@ -177,6 +179,7 @@ type selectiveCarTraverser struct {
offset uint64
cidSet *cid.Set
sc SelectiveCar
lsys ipld.LinkSystem
}

func (sct *selectiveCarTraverser) traverse() (uint64, error) {
Expand Down Expand Up @@ -212,7 +215,7 @@ func (sct *selectiveCarTraverser) traverseHeader() error {
return sct.onCarHeader(header)
}

func (sct *selectiveCarTraverser) loader(lnk ipld.Link, ctx ipld.LinkContext) (io.Reader, error) {
func (sct *selectiveCarTraverser) loader(ctx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
cl, ok := lnk.(cidlink.Link)
if !ok {
return nil, errors.New("Incorrect Link Type")
Expand Down Expand Up @@ -257,16 +260,14 @@ func (sct *selectiveCarTraverser) traverseBlocks() error {
}
lnk := cidlink.Link{Cid: carDag.Root}
ns, _ := nsc(lnk, ipld.LinkContext{}) // nsc won't error
nb := ns.NewBuilder()
err = lnk.Load(sct.sc.ctx, ipld.LinkContext{}, nb, sct.loader)
nd, err := sct.lsys.Load(ipld.LinkContext{Ctx: sct.sc.ctx}, lnk, ns)
if err != nil {
return err
}
nd := nb.Build()
err = traversal.Progress{
Cfg: &traversal.Config{
Ctx: sct.sc.ctx,
LinkLoader: sct.loader,
LinkSystem: sct.lsys,
LinkTargetNodePrototypeChooser: nsc,
},
}.WalkAdv(nd, parsed, func(traversal.Progress, ipld.Node, traversal.VisitReason) error { return nil })
Expand Down

0 comments on commit 7afab98

Please sign in to comment.