From a49c07a1766c9786079ee9f79dd95ac2039d1371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 22 Jan 2019 15:00:41 +0100 Subject: [PATCH] Drop some coreunix code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- assets/assets.go | 48 ++++----- cmd/ipfswatch/main.go | 24 ++++- core/corehttp/gateway_test.go | 125 ++++++++++------------ core/coreunix/add.go | 86 --------------- core/coreunix/add_test.go | 20 ---- test/integration/addcat_test.go | 17 ++- test/integration/bench_cat_test.go | 17 ++- test/integration/three_legged_cat_test.go | 17 ++- 8 files changed, 123 insertions(+), 231 deletions(-) diff --git a/assets/assets.go b/assets/assets.go index b2618e2b692..b26e945e6e4 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -4,15 +4,17 @@ package assets import ( - "bytes" "fmt" "os" "path/filepath" "github.com/ipfs/go-ipfs/core" - "github.com/ipfs/go-ipfs/core/coreunix" + "github.com/ipfs/go-ipfs/core/coreapi" + "github.com/ipfs/go-ipfs/core/coreapi/interface" + "github.com/ipfs/go-ipfs/core/coreapi/interface/options" + cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid" - uio "gx/ipfs/QmSMJ4rZbCJaih3y82Ebq7BZqK6vU2FHsKcWKQiE1DPTpS/go-unixfs/io" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" // this import keeps gx from thinking the dep isn't used _ "gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html" @@ -45,7 +47,17 @@ func SeedInitDirIndex(nd *core.IpfsNode) (cid.Cid, error) { } func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) { - dirb := uio.NewDirectory(nd.DAG) + api, err := coreapi.NewCoreAPI(nd) + if err != nil { + return cid.Cid{}, err + } + + dirb, err := api.Object().New(nd.Context(), options.Object.Type("unixfs-dir")) + if err != nil { + return cid.Cid{}, err + } + + basePath := iface.IpfsPath(dirb.Cid()) for _, p := range l { d, err := Asset(p) @@ -53,40 +65,22 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) { return cid.Cid{}, fmt.Errorf("assets: could load Asset '%s': %s", p, err) } - s, err := coreunix.Add(nd, bytes.NewBuffer(d)) + fp, err := api.Unixfs().Add(nd.Context(), files.NewBytesFile(d)) if err != nil { - return cid.Cid{}, fmt.Errorf("assets: could not Add '%s': %s", p, err) + return cid.Cid{}, err } fname := filepath.Base(p) - c, err := cid.Decode(s) + basePath, err = api.Object().AddLink(nd.Context(), basePath, fname, fp) if err != nil { return cid.Cid{}, err } - - node, err := nd.DAG.Get(nd.Context(), c) - if err != nil { - return cid.Cid{}, err - } - - if err := dirb.AddChild(nd.Context(), fname, node); err != nil { - return cid.Cid{}, fmt.Errorf("assets: could not add '%s' as a child: %s", fname, err) - } } - dir, err := dirb.GetNode() - if err != nil { + if err := api.Pin().Add(nd.Context(), basePath); err != nil { return cid.Cid{}, err } - if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil { - return cid.Cid{}, fmt.Errorf("assets: Pinning on init-docu failed: %s", err) - } - - if err := nd.Pinning.Flush(); err != nil { - return cid.Cid{}, fmt.Errorf("assets: Pinning flush failed: %s", err) - } - - return dir.Cid(), nil + return basePath.Cid(), nil } diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 2275b370f55..3389115cb59 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -11,11 +11,12 @@ import ( commands "github.com/ipfs/go-ipfs/commands" core "github.com/ipfs/go-ipfs/core" + coreapi "github.com/ipfs/go-ipfs/core/coreapi" corehttp "github.com/ipfs/go-ipfs/core/corehttp" - coreunix "github.com/ipfs/go-ipfs/core/coreunix" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" config "gx/ipfs/QmcRKBUqc2p3L1ZraoJjbXfs9E6xzvEuyK9iypb5RGwfsr/go-ipfs-config" homedir "gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir" fsnotify "gx/ipfs/QmfNjggF4Pt6erqg3NDafD3MdvDHk1qqCVr8pL5hnPucS8/fsnotify" @@ -83,6 +84,11 @@ func run(ipfsPath, watchPath string) error { } defer node.Close() + api, err := coreapi.NewCoreAPI(node) + if err != nil { + return err + } + if *http { addr := "/ip4/127.0.0.1/tcp/5001" var opts = []corehttp.ServeOption{ @@ -130,9 +136,23 @@ func run(ipfsPath, watchPath string) error { file, err := os.Open(e.Name) if err != nil { log.Println(err) + return } defer file.Close() - k, err := coreunix.Add(node, file) + + st, err := file.Stat() + if err != nil { + log.Println(err) + return + } + + f, err := files.NewReaderPathFile(e.Name, file, st) + if err != nil { + log.Println(err) + return + } + + k, err := api.Unixfs().Add(node.Context(), f) if err != nil { log.Println(err) } diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 62ccaed6f0a..184ed0f6f58 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -13,15 +13,17 @@ import ( version "github.com/ipfs/go-ipfs" core "github.com/ipfs/go-ipfs/core" - coreunix "github.com/ipfs/go-ipfs/core/coreunix" + "github.com/ipfs/go-ipfs/core/coreapi" + "github.com/ipfs/go-ipfs/core/coreapi/interface" + "github.com/ipfs/go-ipfs/core/coreapi/interface/options" namesys "github.com/ipfs/go-ipfs/namesys" nsopts "github.com/ipfs/go-ipfs/namesys/opts" repo "github.com/ipfs/go-ipfs/repo" ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto" path "gx/ipfs/QmWqh9oob7ZHQRwU5CdTqpnC8ip8BEkFNrwXRxeNo5Y7vA/go-path" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" id "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/protocol/identify" - dag "gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag" config "gx/ipfs/QmcRKBUqc2p3L1ZraoJjbXfs9E6xzvEuyK9iypb5RGwfsr/go-ipfs-config" datastore "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore" syncds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/sync" @@ -117,7 +119,7 @@ func doWithoutRedirect(req *http.Request) (*http.Response, error) { return res, nil } -func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core.IpfsNode) { +func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface.CoreAPI, context.Context) { n, err := newNodeWithMockNamesys(ns) if err != nil { t.Fatal(err) @@ -144,23 +146,28 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core t.Fatal(err) } - return ts, n + api, err := coreapi.NewCoreAPI(n) + if err != nil { + t.Fatal(err) + } + + return ts, api, n.Context() } func TestGatewayGet(t *testing.T) { ns := mockNamesys{} - ts, n := newTestServerAndNode(t, ns) + ts, api, ctx := newTestServerAndNode(t, ns) defer ts.Close() - k, err := coreunix.Add(n, strings.NewReader("fnord")) + k, err := api.Unixfs().Add(ctx, files.NewBytesFile([]byte("fnord"))) if err != nil { t.Fatal(err) } - ns["/ipns/example.com"] = path.FromString("/ipfs/" + k) - ns["/ipns/working.example.com"] = path.FromString("/ipfs/" + k) + ns["/ipns/example.com"] = path.FromString(k.String()) + ns["/ipns/working.example.com"] = path.FromString(k.String()) ns["/ipns/double.example.com"] = path.FromString("/ipns/working.example.com") ns["/ipns/triple.example.com"] = path.FromString("/ipns/double.example.com") - ns["/ipns/broken.example.com"] = path.FromString("/ipns/" + k) + ns["/ipns/broken.example.com"] = path.FromString("/ipns/" + k.Cid().String()) // We picked .man because: // 1. It's a valid TLD. // 2. Go treats it as the file extension for "man" files (even though @@ -168,18 +175,18 @@ func TestGatewayGet(t *testing.T) { // // Unfortunately, this may not work on all platforms as file type // detection is platform dependent. - ns["/ipns/example.man"] = path.FromString("/ipfs/" + k) + ns["/ipns/example.man"] = path.FromString(k.String()) t.Log(ts.URL) - for _, test := range []struct { + for i, test := range []struct { host string path string status int text string }{ {"localhost:5001", "/", http.StatusNotFound, "404 page not found\n"}, - {"localhost:5001", "/" + k, http.StatusNotFound, "404 page not found\n"}, - {"localhost:5001", "/ipfs/" + k, http.StatusOK, "fnord"}, + {"localhost:5001", "/" + k.Cid().String(), http.StatusNotFound, "404 page not found\n"}, + {"localhost:5001", k.String(), http.StatusOK, "fnord"}, {"localhost:5001", "/ipns/nxdomain.example.com", http.StatusNotFound, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"}, {"localhost:5001", "/ipns/%0D%0A%0D%0Ahello", http.StatusNotFound, "ipfs resolve -r /ipns/%0D%0A%0D%0Ahello: " + namesys.ErrResolveFailed.Error() + "\n"}, {"localhost:5001", "/ipns/example.com", http.StatusOK, "fnord"}, @@ -188,9 +195,9 @@ func TestGatewayGet(t *testing.T) { {"working.example.com", "/", http.StatusOK, "fnord"}, {"double.example.com", "/", http.StatusOK, "fnord"}, {"triple.example.com", "/", http.StatusOK, "fnord"}, - {"working.example.com", "/ipfs/" + k, http.StatusNotFound, "ipfs resolve -r /ipns/working.example.com/ipfs/" + k + ": no link named \"ipfs\" under " + k + "\n"}, + {"working.example.com", k.String(), http.StatusNotFound, "ipfs resolve -r /ipns/working.example.com" + k.String() + ": no link named \"ipfs\" under " + k.Cid().String() + "\n"}, {"broken.example.com", "/", http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com/: " + namesys.ErrResolveFailed.Error() + "\n"}, - {"broken.example.com", "/ipfs/" + k, http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com/ipfs/" + k + ": " + namesys.ErrResolveFailed.Error() + "\n"}, + {"broken.example.com", k.String(), http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com" + k.String() + ": " + namesys.ErrResolveFailed.Error() + "\n"}, // This test case ensures we don't treat the TLD as a file extension. {"example.man", "/", http.StatusOK, "fnord"}, } { @@ -213,7 +220,7 @@ func TestGatewayGet(t *testing.T) { t.Errorf("expected content type to be text/plain, got %s", contentType) } if resp.StatusCode != test.status { - t.Errorf("got %d, expected %d from %s", resp.StatusCode, test.status, urlstr) + t.Errorf("(%d) got %d, expected %d from %s", i, resp.StatusCode, test.status, urlstr) continue } body, err := ioutil.ReadAll(resp.Body) @@ -232,39 +239,26 @@ func TestIPNSHostnameRedirect(t *testing.T) { defer cancel() ns := mockNamesys{} - ts, n := newTestServerAndNode(t, ns) + ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) defer ts.Close() // create /ipns/example.net/foo/index.html - _, dagn1, err := coreunix.AddWrapped(n, strings.NewReader("_"), "_") - if err != nil { - t.Fatal(err) - } - - _, dagn2, err := coreunix.AddWrapped(n, strings.NewReader("_"), "index.html") - if err != nil { - t.Fatal(err) - } - - dagn1.(*dag.ProtoNode).AddNodeLink("foo", dagn2) - if err != nil { - t.Fatal(err) - } - err = n.DAG.Add(ctx, dagn2) - if err != nil { - t.Fatal(err) - } + f1 := files.NewMapDirectory(map[string]files.Node{ + "_": files.NewBytesFile([]byte("_")), + "foo": files.NewMapDirectory(map[string]files.Node{ + "index.html": files.NewBytesFile([]byte("_")), + }), + }) - err = n.DAG.Add(ctx, dagn1) + k, err := api.Unixfs().Add(ctx, f1, options.Unixfs.Wrap(true)) if err != nil { t.Fatal(err) } - k := dagn1.Cid() t.Logf("k: %s\n", k) - ns["/ipns/example.net"] = path.FromString("/ipfs/" + k.String()) + ns["/ipns/example.net"] = path.FromString(k.String()) // make request to directory containing index.html req, err := http.NewRequest("GET", ts.URL+"/foo", nil) @@ -336,45 +330,38 @@ func TestIPNSHostnameBacklinks(t *testing.T) { defer cancel() ns := mockNamesys{} - ts, n := newTestServerAndNode(t, ns) + ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) defer ts.Close() + f1 := files.NewMapDirectory(map[string]files.Node{ + "file.txt": files.NewBytesFile([]byte("1")), + "foo? #<'": files.NewMapDirectory(map[string]files.Node{ + "file.txt": files.NewBytesFile([]byte("2")), + "bar": files.NewMapDirectory(map[string]files.Node{ + "file.txt": files.NewBytesFile([]byte("3")), + }), + }), + }) + // create /ipns/example.net/foo/ - _, dagn1, err := coreunix.AddWrapped(n, strings.NewReader("1"), "file.txt") - if err != nil { - t.Fatal(err) - } - _, dagn2, err := coreunix.AddWrapped(n, strings.NewReader("2"), "file.txt") - if err != nil { - t.Fatal(err) - } - _, dagn3, err := coreunix.AddWrapped(n, strings.NewReader("3"), "file.txt") - if err != nil { - t.Fatal(err) - } - dagn2.(*dag.ProtoNode).AddNodeLink("bar", dagn3) - dagn1.(*dag.ProtoNode).AddNodeLink("foo? #<'", dagn2) + k, err := api.Unixfs().Add(ctx, f1, options.Unixfs.Wrap(true)) if err != nil { t.Fatal(err) } - err = n.DAG.Add(ctx, dagn3) + k2, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'")) if err != nil { t.Fatal(err) } - err = n.DAG.Add(ctx, dagn2) - if err != nil { - t.Fatal(err) - } - err = n.DAG.Add(ctx, dagn1) + + k3, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'/bar")) if err != nil { t.Fatal(err) } - k := dagn1.Cid() t.Logf("k: %s\n", k) - ns["/ipns/example.net"] = path.FromString("/ipfs/" + k.String()) + ns["/ipns/example.net"] = path.FromString(k.String()) // make request to directory listing req, err := http.NewRequest("GET", ts.URL+"/foo%3F%20%23%3C%27/", nil) @@ -405,7 +392,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { if !strings.Contains(s, "") { t.Fatalf("expected file in directory listing") } - if !strings.Contains(s, dagn2.Cid().String()) { + if !strings.Contains(s, k2.Cid().String()) { t.Fatalf("expected hash in directory listing") } @@ -438,7 +425,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { if !strings.Contains(s, "") { t.Fatalf("expected file in directory listing") } - if !strings.Contains(s, dagn1.Cid().String()) { + if !strings.Contains(s, k.Cid().String()) { t.Fatalf("expected hash in directory listing") } @@ -471,7 +458,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { if !strings.Contains(s, "") { t.Fatalf("expected file in directory listing") } - if !strings.Contains(s, dagn3.Cid().String()) { + if !strings.Contains(s, k3.Cid().String()) { t.Fatalf("expected hash in directory listing") } @@ -505,7 +492,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { if !strings.Contains(s, "") { t.Fatalf("expected file in directory listing") } - if !strings.Contains(s, dagn1.Cid().String()) { + if !strings.Contains(s, k.Cid().String()) { t.Fatalf("expected hash in directory listing") } @@ -547,13 +534,13 @@ func TestIPNSHostnameBacklinks(t *testing.T) { if !strings.Contains(s, "") { t.Fatalf("expected file in directory listing") } - if !strings.Contains(s, dagn1.Cid().String()) { + if !strings.Contains(s, k.Cid().String()) { t.Fatalf("expected hash in directory listing") } } func TestCacheControlImmutable(t *testing.T) { - ts, _ := newTestServerAndNode(t, nil) + ts, _, _ := newTestServerAndNode(t, nil) t.Logf("test server url: %s", ts.URL) defer ts.Close() @@ -579,7 +566,7 @@ func TestCacheControlImmutable(t *testing.T) { } func TestGoGetSupport(t *testing.T) { - ts, _ := newTestServerAndNode(t, nil) + ts, _, _ := newTestServerAndNode(t, nil) t.Logf("test server url: %s", ts.URL) defer ts.Close() @@ -603,7 +590,7 @@ func TestVersion(t *testing.T) { version.CurrentCommit = "theshortcommithash" ns := mockNamesys{} - ts, _ := newTestServerAndNode(t, ns) + ts, _, _ := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) defer ts.Close() diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 51184d6c0bd..e985ea60652 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -7,10 +7,8 @@ import ( "io" "os" gopath "path" - "path/filepath" "strconv" - "github.com/ipfs/go-ipfs/core" coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface" "github.com/ipfs/go-ipfs/pin" @@ -276,90 +274,6 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error { } } -// Add builds a merkledag node from a reader, adds it to the blockstore, -// and returns the key representing that node. -// If you want to pin it, use NewAdder() and Adder.PinRoot(). -func Add(n *core.IpfsNode, r io.Reader) (string, error) { - return AddWithContext(n.Context(), n, r) -} - -// AddWithContext does the same as Add, but with a custom context. -func AddWithContext(ctx context.Context, n *core.IpfsNode, r io.Reader) (string, error) { - defer n.Blockstore.PinLock().Unlock() - - fileAdder, err := NewAdder(ctx, n.Pinning, n.Blockstore, n.DAG) - if err != nil { - return "", err - } - - node, err := fileAdder.add(r) - if err != nil { - return "", err - } - - return node.Cid().String(), nil -} - -// AddR recursively adds files in |path|. -func AddR(n *core.IpfsNode, root string) (key string, err error) { - defer n.Blockstore.PinLock().Unlock() - - stat, err := os.Lstat(root) - if err != nil { - return "", err - } - - f, err := files.NewSerialFile(root, false, stat) - if err != nil { - return "", err - } - defer f.Close() - - fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG) - if err != nil { - return "", err - } - - err = fileAdder.addFileNode(filepath.Base(root), f) - if err != nil { - return "", err - } - - nd, err := fileAdder.Finalize() - if err != nil { - return "", err - } - - return nd.String(), nil -} - -// AddWrapped adds data from a reader, and wraps it with a directory object -// to preserve the filename. -// Returns the path of the added file ("/filename"), the DAG node of -// the directory, and and error if any. -func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.Node, error) { - fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG) - if err != nil { - return "", nil, err - } - fileAdder.Wrap = true - - defer n.Blockstore.PinLock().Unlock() - - err = fileAdder.addFileNode(filename, files.NewReaderFile(r)) - if err != nil { - return "", nil, err - } - - dagnode, err := fileAdder.Finalize() - if err != nil { - return "", nil, err - } - - c := dagnode.Cid() - return gopath.Join(c.String(), filename), dagnode, nil -} - func (adder *Adder) addNode(node ipld.Node, path string) error { // patch it into the root if path == "" { diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index 9613f441b43..b9c26308ce7 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -30,26 +30,6 @@ import ( const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe" -func TestAddRecursive(t *testing.T) { - r := &repo.Mock{ - C: config.Config{ - Identity: config.Identity{ - PeerID: testPeerID, // required by offline node - }, - }, - D: syncds.MutexWrap(datastore.NewMapDatastore()), - } - node, err := core.NewNode(context.Background(), &core.BuildCfg{Repo: r}) - if err != nil { - t.Fatal(err) - } - if k, err := AddR(node, "test/data"); err != nil { - t.Fatal(err) - } else if k != "QmWCCga8AbTyfAQ7pTnGT6JgmRMAB3Qp8ZmTEFi5q5o8jC" { - t.Fatal("keys do not match: ", k) - } -} - func TestAddGCLive(t *testing.T) { r := &repo.Mock{ C: config.Config{ diff --git a/test/integration/addcat_test.go b/test/integration/addcat_test.go index 6fcc8729cac..85d0905ae4a 100644 --- a/test/integration/addcat_test.go +++ b/test/integration/addcat_test.go @@ -13,14 +13,13 @@ import ( "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreapi" - "github.com/ipfs/go-ipfs/core/coreapi/interface" - coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" "github.com/ipfs/go-ipfs/thirdparty/unit" testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil" pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore" random "gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock" logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log" ) @@ -120,6 +119,11 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error { } defer catter.Close() + adderApi, err := coreapi.NewCoreAPI(adder) + if err != nil { + return err + } + catterApi, err := coreapi.NewCoreAPI(catter) if err != nil { return err @@ -140,17 +144,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error { return err } - added, err := coreunix.Add(adder, bytes.NewReader(data)) - if err != nil { - return err - } - - ap, err := iface.ParsePath(added) + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data)) if err != nil { return err } - readerCatted, err := catterApi.Unixfs().Get(ctx, ap) + readerCatted, err := catterApi.Unixfs().Get(ctx, added) if err != nil { return err } diff --git a/test/integration/bench_cat_test.go b/test/integration/bench_cat_test.go index 58f6ec6d0f7..1b6630744e1 100644 --- a/test/integration/bench_cat_test.go +++ b/test/integration/bench_cat_test.go @@ -10,13 +10,12 @@ import ( "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreapi" - "github.com/ipfs/go-ipfs/core/coreapi/interface" - coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" "github.com/ipfs/go-ipfs/thirdparty/unit" testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil" pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock" ) @@ -66,6 +65,11 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error { } defer catter.Close() + adderApi, err := coreapi.NewCoreAPI(adder) + if err != nil { + return err + } + catterApi, err := coreapi.NewCoreAPI(catter) if err != nil { return err @@ -86,18 +90,13 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error { return err } - added, err := coreunix.Add(adder, bytes.NewReader(data)) - if err != nil { - return err - } - - ap, err := iface.ParsePath(added) + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data)) if err != nil { return err } b.StartTimer() - readerCatted, err := catterApi.Unixfs().Get(ctx, ap) + readerCatted, err := catterApi.Unixfs().Get(ctx, added) if err != nil { return err } diff --git a/test/integration/three_legged_cat_test.go b/test/integration/three_legged_cat_test.go index 77ad353ac4b..a71b119d903 100644 --- a/test/integration/three_legged_cat_test.go +++ b/test/integration/three_legged_cat_test.go @@ -11,13 +11,12 @@ import ( core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core/coreapi" - "github.com/ipfs/go-ipfs/core/coreapi/interface" - coreunix "github.com/ipfs/go-ipfs/core/coreunix" mock "github.com/ipfs/go-ipfs/core/mock" "github.com/ipfs/go-ipfs/thirdparty/unit" testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil" pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore" + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files" mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock" ) @@ -103,6 +102,11 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error { } defer catter.Close() + adderApi, err := coreapi.NewCoreAPI(adder) + if err != nil { + return err + } + catterApi, err := coreapi.NewCoreAPI(catter) if err != nil { return err @@ -119,17 +123,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error { return err } - added, err := coreunix.Add(adder, bytes.NewReader(data)) - if err != nil { - return err - } - - ap, err := iface.ParsePath(added) + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data)) if err != nil { return err } - readerCatted, err := catterApi.Unixfs().Get(ctx, ap) + readerCatted, err := catterApi.Unixfs().Get(ctx, added) if err != nil { return err }