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 60 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -229,7 +229,7 @@ jobs:
- run:
name: Cloning
command: |
git clone https://github.com/ipfs/go-ipfs-api.git
git clone -b ipld-in-ipfs https://github.com/ipfs/go-ipfs-api.git
Copy link
Contributor

Choose a reason for hiding this comment

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

what's up here?

Copy link
Contributor

Choose a reason for hiding this comment

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

good point. this is reflecting the changed codec names for the dag put subcommand. Opened the change there as ipfs/go-ipfs-api#248

There's no go.mod or versioning there, but we'll i guess merge that PR at the same time, and remove this branch before merging?

git -C go-ipfs-api log -1
- run:
name: Starting the daemon
Expand Down
9 changes: 6 additions & 3 deletions core/commands/dag/dag.go
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
@@ -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)
}
93 changes: 72 additions & 21 deletions core/commands/dag/put.go
@@ -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
}

cidPrefix := cid.Prefix{
Version: 1,
Codec: uint64(fcodec),
MhType: uint64(mhType),
MhLength: -1,
}

if hash != "" {
var ok bool
mhType, ok = mh.Names[hash]
if !ok {
return fmt.Errorf("%s in not a valid multihash name", hash)
}
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,44 @@ 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
}
/*
for _, nd := range nds {
err := b.Add(req.Context, nd)
if err != nil {
return err
}
}
*/
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved

cid := nds[0].Cid()
cid := ln.Cid()
if err := res.Emit(&OutputObject{Cid: cid}); err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions core/core.go
Expand Up @@ -17,6 +17,7 @@ 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"
Expand Down Expand Up @@ -77,6 +78,7 @@ type IpfsNode struct {
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
FetcherFactory fetcher.Factory // an implementation of the fetcher
Reporter *metrics.BandwidthCounter `optional:"true"`
Discovery discovery.Service `optional:"true"`
FilesRoot *mfs.Root
Expand Down
41 changes: 32 additions & 9 deletions core/coreapi/coreapi.go
Expand Up @@ -19,14 +19,18 @@ 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-dagwriter"
bsdagwriter "github.com/ipfs/go-dagwriter/impl/blockservice"
"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"
"github.com/ipfs/go-path/resolver"
coreiface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
ci "github.com/libp2p/go-libp2p-core/crypto"
Expand Down Expand Up @@ -54,9 +58,11 @@ type CoreAPI struct {
baseBlocks blockstore.Blockstore
pinning pin.Pinner

blocks bserv.BlockService
dag ipld.DAGService

blocks bserv.BlockService
dag ipld.DAGService
fetcherFactory fetcher.Factory
dagWriter dagwriter.DagWritingService
resolver *resolver.Resolver
peerstore pstore.Peerstore
peerHost p2phost.Host
recordValidator record.Validator
Expand Down Expand Up @@ -105,6 +111,19 @@ func (api *CoreAPI) Dag() coreiface.APIDagService {
}
}

type nodeAPI struct {
fetcher.Factory
dagwriter.DagWritingService
}

// Node returns the Node interface implementation backed by the go-ipfs node
func (api *CoreAPI) Node() coreiface.NodeAPI {
return &nodeAPI{
api.fetcherFactory,
api.dagWriter,
}
}

// Name returns the NameAPI interface implementation backed by the go-ipfs node
func (api *CoreAPI) Name() coreiface.NameAPI {
return (*NameAPI)(api)
Expand Down Expand Up @@ -165,8 +184,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,
resolver: n.Resolver,
fetcherFactory: n.FetcherFactory,

peerstore: n.Peerstore,
peerHost: n.PeerHost,
Expand All @@ -183,6 +204,8 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
parentOpts: settings,
}

subApi.dagWriter = bsdagwriter.NewDagWriter(subApi.blocks)

subApi.checkOnline = func(allowOffline bool) error {
if !n.IsOnline && !allowOffline {
return coreiface.ErrOffline
Expand Down
18 changes: 2 additions & 16 deletions core/coreapi/path.go
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/ipfs/go-cid"
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"
coreiface "github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
)
Expand Down Expand Up @@ -49,23 +47,11 @@ 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,
}

node, rest, err := r.ResolveToLastNode(ctx, ipath)
node, rest, err := api.resolver.ResolveToLastNode(ctx, ipath)
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down