Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPLD Prime In IPFS: Target Merge Branch #7976

Merged
merged 85 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4599218
feat(deps): use ipld-prime based go-merkledag
hannahhoward Feb 19, 2021
9749b93
fix(plugins): disable ipld-git-plugin-test
hannahhoward Feb 20, 2021
af8b7eb
kick off CI for go-merkledag's ipld-prime + codec-dagpb
mvdan Mar 5, 2021
56cc464
ported go-car
mvdan Mar 8, 2021
1b45bab
go-graphsync branch
mvdan Mar 8, 2021
4a6b02a
bump go-merkledag to dedup raw
mvdan Mar 8, 2021
fb63267
avoid seemingly unnecessary filestore+blockstore upgrades
mvdan Mar 9, 2021
2882df4
update go-merkledag for zero node fix
mvdan Mar 9, 2021
619b55c
feat(ipld): update deps for linksystem
hannahhoward Mar 12, 2021
127a354
feat(ipld): update to trusted store deps
hannahhoward Mar 26, 2021
91496b5
bump go-codec-dagpb version
mvdan Apr 5, 2021
52094b1
go-path integrated
Mar 25, 2021
e11af3a
use basic resolver in gateway (provides unixfs adl)
Mar 26, 2021
f5bfb04
resolve issues with error types from resolver
Mar 26, 2021
3f7626b
feat(path): update to latest go-path
hannahhoward Apr 1, 2021
a56fbf3
fix(deps): update to latest go-path
hannahhoward Apr 5, 2021
e3211c0
fix(deps): fix unixfsnode imple
hannahhoward Apr 5, 2021
5077fd3
feat(node): add fetcher config top level dependency
hannahhoward Apr 20, 2021
63b6593
fix(deps): update to latest go-path
hannahhoward Apr 21, 2021
bae6c8a
Merge pull request #8081 from ipfs/feat/fetcher-config-dependency
hannahhoward Apr 21, 2021
8d0ee3b
Merge pull request #8028 from ipfs/feat/update-ipld-go-path
hannahhoward Apr 24, 2021
579c768
feat(coreapi): implement node interface
hannahhoward Apr 2, 2021
fc26e27
fix(deps): update deps to latest
hannahhoward Apr 5, 2021
7f716a1
fix(deps): update deps and fix syntax
hannahhoward Apr 10, 2021
98b792a
Merge pull request #8046 from ipfs/feat/node-api
hannahhoward Apr 24, 2021
be297cc
fix(sharness): switch insecure hash function test
hannahhoward Apr 24, 2021
ecfae2c
Merge pull request #8090 from ipfs/feat/fix-sharness
Stebalien Apr 26, 2021
c326b8c
switch dag put cmd to directly use prime
willscott Apr 5, 2021
6ee21d2
enable codecs
willscott Apr 5, 2021
aa5600b
point api tests to ipld-in-ipfs branch
willscott Mar 24, 2021
71aa69c
partial update to sharness. update git plugin
willscott Apr 5, 2021
02a492c
fix lint
willscott Mar 25, 2021
fac2bac
correct codec name
willscott Mar 25, 2021
6fa35a7
add reasonable default mhType.
willscott Mar 25, 2021
bc309e1
fix input encoding
willscott Mar 26, 2021
9acfa84
update go-ipld-git to encode from basic nodes
willscott Apr 5, 2021
dab4bf4
fix some sharness test
willscott Mar 26, 2021
b22a327
nits
willscott Apr 5, 2021
8ad04a1
pb sharness update
willscott Apr 7, 2021
3b182aa
try with capitalized fields
willscott Apr 7, 2021
44a9b28
dag-json bytes
willscott Apr 9, 2021
002d405
use dag-cbor that can represent bytes
willscott Apr 12, 2021
1285a17
additional work on sharness
willscott Apr 14, 2021
fb5facd
fix dag-cbor fixture sharness test
willscott Apr 16, 2021
da88c16
Switch `ipfs dag get` to serialize to an IPLD-Prime codec and output …
willscott Jul 12, 2021
598388d
bump ipld-prime
willscott Jul 13, 2021
8d450f9
bump go-multicodec and use Code.Set
mvdan Jul 18, 2021
466201e
fix dag test fixtures for go-ipld-prime codecs
rvagg Jul 15, 2021
b070b91
Temporarily use rvagg/dagjsonsort branch of go-ipld-prime
rvagg Jul 16, 2021
119b9ab
Use current go-ipld-prime master with DAG-JSON sorting
rvagg Jul 21, 2021
1e80eec
Use mh.Set() for "hash" -> mhType
rvagg Jul 21, 2021
eb87dfb
Make git plugin test work again
rvagg Jul 21, 2021
b55fa6f
Default "hash" to sha2-256
rvagg Jul 21, 2021
b482272
Use hex value in test to match code
rvagg Jul 22, 2021
b9eab58
Update to latest go-ipld-git, reset sharness test paths to original
rvagg Jul 22, 2021
d7f4913
Use mc.ReservedStart from new go-multiformats
rvagg Jul 23, 2021
1bdcf68
Update deps
rvagg Jul 26, 2021
719a927
Node dag-cbor sorting TODO
rvagg Jul 26, 2021
70eed4e
Update go-ipld-prime, revert tests to sorted-cbor forms
rvagg Jul 27, 2021
bbc722b
Update go-ipld-git plugin, add more resolution tests
rvagg Aug 4, 2021
9a134b9
Remove custom branch of go-ipfs-api
rvagg Aug 10, 2021
61368f5
update pathing to allow ipld-based signaling
willscott Aug 10, 2021
b9c5a07
Update go-fetcher, clean up & clarify dag sharness
rvagg Aug 10, 2021
c052e72
Revert "Remove custom branch of go-ipfs-api"
rvagg Aug 10, 2021
95dd17d
Update go-ipld-prime, fix 0053 tests
rvagg Aug 10, 2021
c538512
add register method to ipld plugins
willscott Aug 11, 2021
7a70a13
Register git codec in plugin registry
willscott Aug 11, 2021
a13eef2
dep update
willscott Aug 11, 2021
f8baaea
fix fuse comments
willscott Aug 11, 2021
caec7ac
Merge branch 'master' into feat/iplf-in-ipfs
willscott Aug 11, 2021
08587dc
Fix up new-line `dag put` test - now passes, with correct CID
rvagg Aug 12, 2021
8cd4fa5
Fix plugin-git tests - remove base64 padding from dag-json bytes
rvagg Aug 12, 2021
c2dee13
Add initial v0.10.0 CHANGELOG entry
rvagg Aug 12, 2021
da36b01
update blockstore
willscott Aug 12, 2021
fd6676f
validate updated ipld-prime
willscott Aug 12, 2021
7271db3
restore testing against master of go-ipfs-api
aschmahmann Aug 12, 2021
d6deb42
update ipld-in-ipfs deps
aschmahmann Aug 12, 2021
5801c34
do not export fetcher or dagwriter via CoreAPI
aschmahmann Aug 12, 2021
1d9428f
remove unnecssary go-dagwriter. switch to using separate ipld and uni…
aschmahmann Aug 13, 2021
7a975b0
try bumping go-fetcher
aschmahmann Aug 13, 2021
a9cee8a
bump go-fetcher (and intermediate repos) to released versions.
warpfork Aug 16, 2021
ff280f9
Merge branch 'master' into feat/ipld-in-ipfs
warpfork Aug 16, 2021
0c1b6d7
update the changelog explanation of the IPLD plugin changes
aschmahmann Aug 17, 2021
f910871
bump go-ipfs-provider
aschmahmann Aug 17, 2021
9339e82
fix: dag get properly errors if the encoder fails
aschmahmann Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# go-ipfs changelog

## v0.10.0 TBD

**IPLD Levels Up**

The handling of data serialization as well as many aspects of DAG traversal and pathing have been migrated from older libraries, including [go-merkledag](https://github.com/ipfs/go-merkledag) and [go-ipld-format](https://github.com/ipfs/go-ipld-format) to the new **[go-ipld-prime](https://github.com/ipld/go-ipld-prime)** library and its components. This allows us to use many of the newer tools afforded by go-ipld-prime, stricter and more uniform codec implementations, support for additional (pluggable) codecs, and some minor performance improvements.

This is significant refactor of a core component that touches many parts of IPFS, and does come with some **breaking changes**:

* **IPLD plugins** (those implementing the `PluginIPLD` interface) are not registered into go-ipld-prime. Such plugins should instead register their encoder and decoder functions in their initialization functions against the multicodec table. We demonstrate the change with the [bundled git plugin](./plugin/plugins/git/).
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
* **The semantics of `dag put` and `dag get` change**:
* `dag get` now takes the `format` option which accepts a multicodec name used to encode the output. By default this is `dag-json`. Users may notice differences from the previously plain Go JSON output, particularly where bytes are concerned which are now encoded using a form similar to CIDs: `{"/":{"bytes":"unpadded-base64-bytes"}}` rather than the previously Go-specific plain padded base64 string. See the [dag-json specification](https://ipld.io/specs/codecs/dag-json/spec/) for an explanation of these forms.
* `dag get` no longer prints an additional new-line character at the end of the encoded block output. This means that the output as presented by `dag get` are the exact bytes of the requested node. A round-trip of such bytes back in through `dag put` using the same codec should result in the same CID.
* `dag put` uses the `input-enc` option to specify the multicodec name of the format data is being provided in, and the `format` option to specify the multicodec multicodec name of the format the data should be stored in. These formerly defaulted to `json` and `cbor` respectively. They now default to `dag-json` and `dag-cbor` respectively but may be changed to any supported codec (bundled or loaded via plugin) by its [multicodec name](https://github.com/multiformats/multicodec/blob/master/table.csv).
* The `json` and `cbor` multicodec names (as used by `input-enc` and `format` options) are now no longer aliases for `dag-json` and `dag-cbor` respectively. Instead, they now refer to their proper [multicodec](https://github.com/multiformats/multicodec/blob/master/table.csv) types. `cbor` refers to a plain CBOR format, which will not encode CIDs and does not have strict deterministic encoding rules. `json` is a plain JSON format, which also won't encode CIDs and will encode bytes in the Go-specific padded base64 string format rather than the dag-json method of byte encoding. See https://ipld.io/specs/codecs/ for more information on IPLD codecs.
* The **dag-pb codec**, which is used to encode UnixFS data for IPFS, is now represented in a form via the `dag` API that mirrors the protobuf schema used to define the binary format and unifies the implementations and specification of dag-pb across the IPLD and IPFS stacks. Previously, additional layers of code within IPFS between protobuf serialization and UnixFS handling for file and directory data, obscured the forms that are described by the protobuf representation. Much of this code has now been replaced and there are fewer layers of transformation. This means that interacting with dag-pb data via the `dag` API will use different forms:
* Previously, using `dag get` on a dag-pb block would present the block serialized as JSON as `{"data":"padded-base64-bytes","links":[{"Name":"foo","Size":100,"Cid":{"/":"Qm..."}},...]}`.
* Using the dag-pb data model specification and the new default dag-json codec for output, this will now be serialized as: `{"Data":{"/":{"bytes":"unpadded-base64-bytes"}},"Links":[{"Name":"foo","Tsize":100,"Hash":{"/":"Qm..."}},...]}`. Aside from the change in byte formatting, most field names have changed: `data` → `Data`, `links` → `Links`, `Size` → `Tsize`, `Cid` → `Hash`. Note that this output can be changed now using the `--format` option to specify an alternative codec.
* Using `dag put` and a `format` option of `dag-pb` now requires that the input conform to this dag-pb specified form. Previously, input using `{"data":"...","links":[...]}` was accepted, now it must be `{"Data":"...","Links":[...]}`.
* Previously it was not possible to use paths to navigate to any of these properties of a dag-pb node, the only possible paths were named links, e.g. `dag get QmFoo/NamedLink` where `NamedLink` was one of the links whose name was `NamedLink`. This functionality remains the same, but by prefixing the path with `/ipld/` we enter data model pathing semantics and can `dag get /ipld/QmFoo/Links/0/Hash` to navigate to links or `/ipld/QmFoo/Data` to simply retrieve the data section of the node, for example.
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
* See the [dag-pb specification](https://ipld.io/specs/codecs/dag-pb/) for details on the codec and its data model representation.
* See this [detailed write-up](https://github.com/ipld/ipld/blob/master/design/tricky-choices/dag-pb-forms-impl-and-use.md) for further background on these changes.

## v0.9.1 2021-07-20

This is a small bug fix release resolving the following issues:
Expand Down
9 changes: 6 additions & 3 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ into an object of the specified format.
cmds.FileArg("object data", true, true, "The object to put").EnableStdin(),
},
Options: []cmds.Option{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just putting it here for tracking, but given that this PR has a number of breaking changes associated with it I'd like this PR to come with a proposal for what's going to go in the release notes about at (i.e. it'll likely live in the Highlights section of the Changelog for v0.10.0).

For the time being we can review this as a change to CHANGELOG.md that specifies v0.10.0 TBD and then adds some text to the highlights section. We can always decide not to actually merge it into the CHANGELOG.md file as part of the PR, but I'd like us to have the text in a reviewable form.

Seem reasonable? Anyone have a better suggestion?

cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("cbor"),
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("json"),
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("dag-cbor"),
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("dag-json"),
cmds.BoolOption("pin", "Pin this object when adding."),
cmds.StringOption("hash", "Hash function to use").WithDefault(""),
cmds.StringOption("hash", "Hash function to use").WithDefault("sha2-256"),
},
Run: dagPut,
Type: OutputObject{},
Expand Down Expand Up @@ -108,6 +108,9 @@ format.
Arguments: []cmds.Argument{
cmds.StringArg("ref", true, false, "The object to get").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption("format", "f", "Format that the object will be serialized as.").WithDefault("dag-json"),
},
Run: dagGet,
}

Expand Down
45 changes: 39 additions & 6 deletions core/commands/dag/get.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package dagcmd

import (
"strings"
"fmt"
"io"

"github.com/ipfs/go-ipfs/core/commands/cmdenv"
ipldlegacy "github.com/ipfs/go-ipld-legacy"
"github.com/ipfs/interface-go-ipfs-core/path"

"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/multicodec"
"github.com/ipld/go-ipld-prime/traversal"
mc "github.com/multiformats/go-multicodec"

cmds "github.com/ipfs/go-ipfs-cmds"
)

Expand All @@ -15,6 +22,12 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
return err
}

format, _ := req.Options["format"].(string)
var fCodec mc.Code
if err := fCodec.Set(format); err != nil {
return err
}

rp, err := api.ResolvePath(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
Expand All @@ -25,14 +38,34 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
return err
}

var out interface{} = obj
universal, ok := obj.(ipldlegacy.UniversalNode)
if !ok {
return fmt.Errorf("%T is not a valid IPLD node", obj)
}

finalNode := universal.(ipld.Node)

if len(rp.Remainder()) > 0 {
rem := strings.Split(rp.Remainder(), "/")
final, _, err := obj.Resolve(rem)
remainderPath := ipld.ParsePath(rp.Remainder())

finalNode, err = traversal.Get(finalNode, remainderPath)
if err != nil {
return err
}
out = final
}
return cmds.EmitOnce(res, &out)

encoder, err := multicodec.LookupEncoder(uint64(fCodec))
if err != nil {
return fmt.Errorf("invalid encoding: %s - %s", format, err)
}

r, w := io.Pipe()
go func() {
defer w.Close()
if err := encoder(finalNode, w); err != nil {
_ = res.CloseWithError(err)
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
}
}()

return res.Emit(r)
}
85 changes: 64 additions & 21 deletions core/commands/dag/put.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package dagcmd

import (
"bytes"
"fmt"
"math"

blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
"github.com/ipfs/go-ipfs/core/coredag"
ipldlegacy "github.com/ipfs/go-ipld-legacy"
"github.com/ipld/go-ipld-prime/multicodec"
basicnode "github.com/ipld/go-ipld-prime/node/basic"

cmds "github.com/ipfs/go-ipfs-cmds"
files "github.com/ipfs/go-ipfs-files"
ipld "github.com/ipfs/go-ipld-format"
mh "github.com/multiformats/go-multihash"
mc "github.com/multiformats/go-multicodec"

// Expected minimal set of available format/ienc codecs.
_ "github.com/ipld/go-codec-dagpb"
_ "github.com/ipld/go-ipld-prime/codec/cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
_ "github.com/ipld/go-ipld-prime/codec/dagjson"
_ "github.com/ipld/go-ipld-prime/codec/json"
_ "github.com/ipld/go-ipld-prime/codec/raw"
)

func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
Expand All @@ -24,16 +36,33 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
hash, _ := req.Options["hash"].(string)
dopin, _ := req.Options["pin"].(bool)

// mhType tells inputParser which hash should be used. MaxUint64 means 'use
// default hash' (sha256 for cbor, sha1 for git..)
mhType := uint64(math.MaxUint64)
var icodec mc.Code
if err := icodec.Set(ienc); err != nil {
return err
}
var fcodec mc.Code
if err := fcodec.Set(format); err != nil {
return err
}
var mhType mc.Code
if err := mhType.Set(hash); err != nil {
return err
}

if hash != "" {
var ok bool
mhType, ok = mh.Names[hash]
if !ok {
return fmt.Errorf("%s in not a valid multihash name", hash)
}
cidPrefix := cid.Prefix{
Version: 1,
Codec: uint64(fcodec),
MhType: uint64(mhType),
MhLength: -1,
}

decoder, err := multicodec.LookupDecoder(uint64(icodec))
if err != nil {
return err
}
encoder, err := multicodec.LookupEncoder(uint64(fcodec))
if err != nil {
return err
}

var adder ipld.NodeAdder = api.Dag()
Expand All @@ -48,22 +77,36 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
if file == nil {
return fmt.Errorf("expected a regular file")
}
nds, err := coredag.ParseInputs(ienc, format, file, mhType, -1)

node := basicnode.Prototype.Any.NewBuilder()
if err := decoder(node, file); err != nil {
return err
}
n := node.Build()

bd := bytes.NewBuffer([]byte{})
if err := encoder(n, bd); err != nil {
return err
}

blockCid, err := cidPrefix.Sum(bd.Bytes())
if err != nil {
return err
}
blk, err := blocks.NewBlockWithCid(bd.Bytes(), blockCid)
if err != nil {
return err
}
if len(nds) == 0 {
return fmt.Errorf("no node returned from ParseInputs")
ln := ipldlegacy.LegacyNode{
Block: blk,
Node: n,
}

for _, nd := range nds {
err := b.Add(req.Context, nd)
if err != nil {
return err
}
if err := b.Add(req.Context, &ln); err != nil {
return err
}

cid := nds[0].Cid()
cid := ln.Cid()
if err := res.Emit(&OutputObject{Cid: cid}); err != nil {
return err
}
Expand Down
27 changes: 14 additions & 13 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"github.com/ipfs/go-ipfs-pinner"

bserv "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-fetcher"
"github.com/ipfs/go-graphsync"
bstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
"github.com/ipfs/go-ipfs-provider"
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
mfs "github.com/ipfs/go-mfs"
resolver "github.com/ipfs/go-path/resolver"
goprocess "github.com/jbenet/goprocess"
connmgr "github.com/libp2p/go-libp2p-core/connmgr"
ic "github.com/libp2p/go-libp2p-core/crypto"
Expand Down Expand Up @@ -70,18 +70,19 @@ type IpfsNode struct {
PNetFingerprint libp2p.PNetFingerprint `optional:"true"` // fingerprint of private network

// Services
Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Filestore *filestore.Filestore `optional:"true"` // the filestore blockstore
BaseBlocks node.BaseBlocks // the raw blockstore, no filestore wrapping
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
Blocks bserv.BlockService // the block service, get/add blocks.
DAG ipld.DAGService // the merkle dag service, get/add objects.
Resolver *resolver.Resolver // the path resolution system
Reporter *metrics.BandwidthCounter `optional:"true"`
Discovery discovery.Service `optional:"true"`
FilesRoot *mfs.Root
RecordValidator record.Validator
Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
Blockstore bstore.GCBlockstore // the block store (lower level)
Filestore *filestore.Filestore `optional:"true"` // the filestore blockstore
BaseBlocks node.BaseBlocks // the raw blockstore, no filestore wrapping
GCLocker bstore.GCLocker // the locker used to protect the blockstore during gc
Blocks bserv.BlockService // the block service, get/add blocks.
DAG ipld.DAGService // the merkle dag service, get/add objects.
IPLDFetcherFactory fetcher.Factory `name:"ipldFetcher"` // fetcher that paths over the IPLD data model
UnixFSFetcherFactory fetcher.Factory `name:"unixfsFetcher"` // fetcher that interprets UnixFS data
Reporter *metrics.BandwidthCounter `optional:"true"`
Discovery discovery.Service `optional:"true"`
FilesRoot *mfs.Root
RecordValidator record.Validator

// Online
PeerHost p2phost.Host `optional:"true"` // the network host (server+client)
Expand Down
30 changes: 17 additions & 13 deletions core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
"fmt"

bserv "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-ipfs-blockstore"
"github.com/ipfs/go-ipfs-exchange-interface"
"github.com/ipfs/go-fetcher"
blockstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
offlinexch "github.com/ipfs/go-ipfs-exchange-offline"
"github.com/ipfs/go-ipfs-pinner"
"github.com/ipfs/go-ipfs-provider"
pin "github.com/ipfs/go-ipfs-pinner"
provider "github.com/ipfs/go-ipfs-provider"
offlineroute "github.com/ipfs/go-ipfs-routing/offline"
ipld "github.com/ipfs/go-ipld-format"
dag "github.com/ipfs/go-merkledag"
Expand Down Expand Up @@ -55,13 +56,14 @@ type CoreAPI struct {
baseBlocks blockstore.Blockstore
pinning pin.Pinner

blocks bserv.BlockService
dag ipld.DAGService

peerstore pstore.Peerstore
peerHost p2phost.Host
recordValidator record.Validator
exchange exchange.Interface
blocks bserv.BlockService
dag ipld.DAGService
ipldFetcherFactory fetcher.Factory
unixFSFetcherFactory fetcher.Factory
peerstore pstore.Peerstore
peerHost p2phost.Host
recordValidator record.Validator
exchange exchange.Interface

namesys namesys.NameSystem
routing routing.Routing
Expand Down Expand Up @@ -167,8 +169,10 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
baseBlocks: n.BaseBlocks,
pinning: n.Pinning,

blocks: n.Blocks,
dag: n.DAG,
blocks: n.Blocks,
dag: n.DAG,
ipldFetcherFactory: n.IPLDFetcherFactory,
unixFSFetcherFactory: n.UnixFSFetcherFactory,

peerstore: n.Peerstore,
peerHost: n.PeerHost,
Expand Down
24 changes: 10 additions & 14 deletions core/coreapi/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/ipfs/go-namesys/resolve"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-fetcher"
ipld "github.com/ipfs/go-ipld-format"
ipfspath "github.com/ipfs/go-path"
"github.com/ipfs/go-path/resolver"
uio "github.com/ipfs/go-unixfs/io"
ipfspathresolver "github.com/ipfs/go-path/resolver"
coreiface "github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
)
Expand Down Expand Up @@ -49,23 +49,19 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
return nil, err
}

var resolveOnce resolver.ResolveOnce

switch ipath.Segments()[0] {
case "ipfs":
resolveOnce = uio.ResolveUnixfsOnce
case "ipld":
resolveOnce = resolver.ResolveSingle
default:
if ipath.Segments()[0] != "ipfs" && ipath.Segments()[0] != "ipld" {
return nil, fmt.Errorf("unsupported path namespace: %s", p.Namespace())
}

r := &resolver.Resolver{
DAG: api.dag,
ResolveOnce: resolveOnce,
var dataFetcher fetcher.Factory
if ipath.Segments()[0] == "ipld" {
dataFetcher = api.ipldFetcherFactory
} else {
dataFetcher = api.unixFSFetcherFactory
}
resolver := ipfspathresolver.NewBasicResolver(dataFetcher)

node, rest, err := r.ResolveToLastNode(ctx, ipath)
node, rest, err := resolver.ResolveToLastNode(ctx, ipath)
if err != nil {
return nil, err
}
Expand Down
Loading