@cryptotaxi247 / kubo / commits / 28fdee7fc

Extract dagservice, move dagutils to top level

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jul 28, 2018 at 00:50 UTC 28fdee7fcec69900db627228d6855388a323f5a7
84 files changed +78 -4116
Rules.mk
-3
@@ -50,9 +50,6 @@ endif
50 dir := unixfs/pb
51 include $(dir)/Rules.mk
52
53 -dir := merkledag/pb
54 -include $(dir)/Rules.mk
55 -
53 dir := pin/internal/pb
54 include $(dir)/Rules.mk
55
core/builder.go
+1 -1
@@ -10,7 +10,6 @@ import (
10 "time"
11
12 filestore "github.com/ipfs/go-ipfs/filestore"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
13 resolver "github.com/ipfs/go-ipfs/path/resolver"
14 pin "github.com/ipfs/go-ipfs/pin"
15 repo "github.com/ipfs/go-ipfs/repo"
@@ -18,6 +17,7 @@ import (
17 "github.com/ipfs/go-ipfs/thirdparty/verifbs"
18 uio "github.com/ipfs/go-ipfs/unixfs/io"
19 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
20 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
21
22 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
23 goprocessctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
core/commands/add.go
+2 -2
@@ -10,11 +10,11 @@ import (
10 core "github.com/ipfs/go-ipfs/core"
11 "github.com/ipfs/go-ipfs/core/coreunix"
12 filestore "github.com/ipfs/go-ipfs/filestore"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
14 - dagtest "github.com/ipfs/go-ipfs/merkledag/test"
13 mfs "github.com/ipfs/go-ipfs/mfs"
14 ft "github.com/ipfs/go-ipfs/unixfs"
15 blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
16 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
17 + dagtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
18
19 cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
20 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
core/commands/dht.go
+1 -1
@@ -10,8 +10,8 @@ import (
10
11 cmds "github.com/ipfs/go-ipfs/commands"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
13 path "github.com/ipfs/go-ipfs/path"
14 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
15
16 b58 "gx/ipfs/QmWFAMPqsEyUX7gDUsRVmMWz59FxSpJ1b2v6bJ1yYzo7jY/go-base58-fast/base58"
17 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/commands/files.go
+1 -1
@@ -15,13 +15,13 @@ import (
15 lgc "github.com/ipfs/go-ipfs/commands/legacy"
16 core "github.com/ipfs/go-ipfs/core"
17 e "github.com/ipfs/go-ipfs/core/commands/e"
18 - dag "github.com/ipfs/go-ipfs/merkledag"
18 mfs "github.com/ipfs/go-ipfs/mfs"
19 path "github.com/ipfs/go-ipfs/path"
20 resolver "github.com/ipfs/go-ipfs/path/resolver"
21 ft "github.com/ipfs/go-ipfs/unixfs"
22 uio "github.com/ipfs/go-ipfs/unixfs/io"
23 bservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
24 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
25
26 cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
27 humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
core/commands/get.go
+1 -1
@@ -11,9 +11,9 @@ import (
11
12 core "github.com/ipfs/go-ipfs/core"
13 e "github.com/ipfs/go-ipfs/core/commands/e"
14 - dag "github.com/ipfs/go-ipfs/merkledag"
14 path "github.com/ipfs/go-ipfs/path"
15 uarchive "github.com/ipfs/go-ipfs/unixfs/archive"
16 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
17
18 "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
19 "gx/ipfs/QmPtj12fdwuAqj9sBSTNUxBNu8kCGNp8b3o8yUzMm5GHpq/pb"
core/commands/ls.go
+1 -1
@@ -9,13 +9,13 @@ import (
9 cmds "github.com/ipfs/go-ipfs/commands"
10 core "github.com/ipfs/go-ipfs/core"
11 e "github.com/ipfs/go-ipfs/core/commands/e"
12 - merkledag "github.com/ipfs/go-ipfs/merkledag"
12 path "github.com/ipfs/go-ipfs/path"
13 resolver "github.com/ipfs/go-ipfs/path/resolver"
14 unixfs "github.com/ipfs/go-ipfs/unixfs"
15 uio "github.com/ipfs/go-ipfs/unixfs/io"
16 unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
17 blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
18 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
19
20 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
21 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/commands/object/object.go
+1 -1
@@ -17,10 +17,10 @@ import (
17 lgc "github.com/ipfs/go-ipfs/commands/legacy"
18 core "github.com/ipfs/go-ipfs/core"
19 e "github.com/ipfs/go-ipfs/core/commands/e"
20 - dag "github.com/ipfs/go-ipfs/merkledag"
20 path "github.com/ipfs/go-ipfs/path"
21 pin "github.com/ipfs/go-ipfs/pin"
22 ft "github.com/ipfs/go-ipfs/unixfs"
23 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
24
25 cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
26 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/commands/object/patch.go
+1 -1
@@ -11,9 +11,9 @@ import (
11 core "github.com/ipfs/go-ipfs/core"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 "github.com/ipfs/go-ipfs/dagutils"
14 - dag "github.com/ipfs/go-ipfs/merkledag"
14 path "github.com/ipfs/go-ipfs/path"
15 ft "github.com/ipfs/go-ipfs/unixfs"
16 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
17
18 cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
19 logging "gx/ipfs/QmcVVHfdyv15GVPk7NrxdWjh2hLVccXnoD8j2tyQShiXJb/go-log"
core/commands/pin.go
+1 -1
@@ -11,12 +11,12 @@ import (
11 core "github.com/ipfs/go-ipfs/core"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
14 - dag "github.com/ipfs/go-ipfs/merkledag"
14 path "github.com/ipfs/go-ipfs/path"
15 resolver "github.com/ipfs/go-ipfs/path/resolver"
16 pin "github.com/ipfs/go-ipfs/pin"
17 uio "github.com/ipfs/go-ipfs/unixfs/io"
18 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
19 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
20
21 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
22 "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
core/commands/tar.go
+1 -1
@@ -8,9 +8,9 @@ import (
8 core "github.com/ipfs/go-ipfs/core"
9 e "github.com/ipfs/go-ipfs/core/commands/e"
10 "github.com/ipfs/go-ipfs/core/coreunix"
11 - dag "github.com/ipfs/go-ipfs/merkledag"
11 path "github.com/ipfs/go-ipfs/path"
12 tar "github.com/ipfs/go-ipfs/tar"
13 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
14
15 "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
16 )
core/commands/unixfs/ls.go
+1 -1
@@ -12,12 +12,12 @@ import (
12 cmds "github.com/ipfs/go-ipfs/commands"
13 core "github.com/ipfs/go-ipfs/core"
14 e "github.com/ipfs/go-ipfs/core/commands/e"
15 - merkledag "github.com/ipfs/go-ipfs/merkledag"
15 path "github.com/ipfs/go-ipfs/path"
16 resolver "github.com/ipfs/go-ipfs/path/resolver"
17 unixfs "github.com/ipfs/go-ipfs/unixfs"
18 uio "github.com/ipfs/go-ipfs/unixfs/io"
19 unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
20 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
21 )
22
23 type LsLink struct {
core/core.go
+1 -1
@@ -23,7 +23,6 @@ import (
23 rp "github.com/ipfs/go-ipfs/exchange/reprovide"
24 filestore "github.com/ipfs/go-ipfs/filestore"
25 mount "github.com/ipfs/go-ipfs/fuse/mount"
26 - merkledag "github.com/ipfs/go-ipfs/merkledag"
26 mfs "github.com/ipfs/go-ipfs/mfs"
27 namesys "github.com/ipfs/go-ipfs/namesys"
28 ipnsrp "github.com/ipfs/go-ipfs/namesys/republisher"
@@ -34,6 +33,7 @@ import (
33 config "github.com/ipfs/go-ipfs/repo/config"
34 ft "github.com/ipfs/go-ipfs/unixfs"
35 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
36 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
37 bitswap "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap"
38 bsnet "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap/network"
39
core/coreapi/object.go
+1 -1
@@ -14,8 +14,8 @@ import (
14 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
15 caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
16 "github.com/ipfs/go-ipfs/dagutils"
17 - dag "github.com/ipfs/go-ipfs/merkledag"
17 ft "github.com/ipfs/go-ipfs/unixfs"
18 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
19
20 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
21 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
core/coreapi/pin.go
+1 -1
@@ -7,8 +7,8 @@ import (
7 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
8 caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
10 - merkledag "github.com/ipfs/go-ipfs/merkledag"
10 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
11 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
12
13 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
14 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/coreapi/unixfs_test.go
+1 -1
@@ -15,10 +15,10 @@ import (
15 options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
16 coreunix "github.com/ipfs/go-ipfs/core/coreunix"
17 keystore "github.com/ipfs/go-ipfs/keystore"
18 - mdag "github.com/ipfs/go-ipfs/merkledag"
18 repo "github.com/ipfs/go-ipfs/repo"
19 config "github.com/ipfs/go-ipfs/repo/config"
20 unixfs "github.com/ipfs/go-ipfs/unixfs"
21 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
22
23 cbor "gx/ipfs/QmWrbExtUaQQHjJ8FVVDAWj5o1MRAELDUV3VmoQsZHHb6L/go-ipld-cbor"
24 peer "gx/ipfs/QmdVrMn1LhB4ybb8hMVaMLXnA8XRSewMnK6YqXKXoTcRvN/go-libp2p-peer"
core/coredag/dagpb.go
+1 -1
@@ -5,7 +5,7 @@ import (
5 "io/ioutil"
6 "math"
7
8 - "github.com/ipfs/go-ipfs/merkledag"
8 + "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9
10 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
11 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/coredag/raw.go
+1 -1
@@ -5,7 +5,7 @@ import (
5 "io/ioutil"
6 "math"
7
8 - "github.com/ipfs/go-ipfs/merkledag"
8 + "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9
10 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
11 block "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
core/corehttp/gateway_handler.go
+1 -1
@@ -16,11 +16,11 @@ import (
16 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
17 "github.com/ipfs/go-ipfs/dagutils"
18 "github.com/ipfs/go-ipfs/importer"
19 - dag "github.com/ipfs/go-ipfs/merkledag"
19 path "github.com/ipfs/go-ipfs/path"
20 resolver "github.com/ipfs/go-ipfs/path/resolver"
21 ft "github.com/ipfs/go-ipfs/unixfs"
22 uio "github.com/ipfs/go-ipfs/unixfs/io"
23 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
24
25 humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
26 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
core/corehttp/gateway_test.go
+1 -1
@@ -13,12 +13,12 @@ import (
13
14 core "github.com/ipfs/go-ipfs/core"
15 coreunix "github.com/ipfs/go-ipfs/core/coreunix"
16 - dag "github.com/ipfs/go-ipfs/merkledag"
16 namesys "github.com/ipfs/go-ipfs/namesys"
17 nsopts "github.com/ipfs/go-ipfs/namesys/opts"
18 path "github.com/ipfs/go-ipfs/path"
19 repo "github.com/ipfs/go-ipfs/repo"
20 config "github.com/ipfs/go-ipfs/repo/config"
21 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
22
23 id "gx/ipfs/QmY51bqSM5XgxQZqsBrQcRkKTnCb8EKpJpR9K6Qax7Njco/go-libp2p/p2p/protocol/identify"
24 ci "gx/ipfs/Qme1knMqwt1hKZbc1BmQFmnm9f36nyQGwXxPGVpVJ9rMK5/go-libp2p-crypto"
core/coreunix/add.go
+1 -1
@@ -14,10 +14,10 @@ import (
14 balanced "github.com/ipfs/go-ipfs/importer/balanced"
15 ihelper "github.com/ipfs/go-ipfs/importer/helpers"
16 trickle "github.com/ipfs/go-ipfs/importer/trickle"
17 - dag "github.com/ipfs/go-ipfs/merkledag"
17 mfs "github.com/ipfs/go-ipfs/mfs"
18 "github.com/ipfs/go-ipfs/pin"
19 unixfs "github.com/ipfs/go-ipfs/unixfs"
20 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
21
22 posinfo "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
23 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
core/coreunix/add_test.go
+1 -1
@@ -11,11 +11,11 @@ import (
11 "time"
12
13 "github.com/ipfs/go-ipfs/core"
14 - dag "github.com/ipfs/go-ipfs/merkledag"
14 "github.com/ipfs/go-ipfs/pin/gc"
15 "github.com/ipfs/go-ipfs/repo"
16 "github.com/ipfs/go-ipfs/repo/config"
17 "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
18 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
19
20 pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
21 blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
core/coreunix/metadata.go
+1 -1
@@ -2,8 +2,8 @@ package coreunix
2
3 import (
4 core "github.com/ipfs/go-ipfs/core"
5 - dag "github.com/ipfs/go-ipfs/merkledag"
5 ft "github.com/ipfs/go-ipfs/unixfs"
6 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
7 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
8 )
9
core/coreunix/metadata_test.go
+1 -1
@@ -8,10 +8,10 @@ import (
8
9 core "github.com/ipfs/go-ipfs/core"
10 importer "github.com/ipfs/go-ipfs/importer"
11 - merkledag "github.com/ipfs/go-ipfs/merkledag"
11 ft "github.com/ipfs/go-ipfs/unixfs"
12 uio "github.com/ipfs/go-ipfs/unixfs/io"
13 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
14 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
15
16 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
17 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
dagutils/diff.go
+1 -1
@@ -5,7 +5,7 @@ import (
5 "fmt"
6 "path"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
8 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9
10 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
11 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
dagutils/diffenum.go
+1 -1
@@ -4,7 +4,7 @@ import (
4 "context"
5 "fmt"
6
7 - mdag "github.com/ipfs/go-ipfs/merkledag"
7 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
8
9 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
10 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
dagutils/diffenum_test.go
+2 -2
@@ -5,8 +5,8 @@ import (
5 "fmt"
6 "testing"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
9 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
8 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
10
11 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
12 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
dagutils/utils.go
+1 -1
@@ -4,9 +4,9 @@ import (
4 "context"
5 "errors"
6
7 - dag "github.com/ipfs/go-ipfs/merkledag"
7 path "github.com/ipfs/go-ipfs/path"
8 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
9 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
10
11 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
12 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
dagutils/utils_test.go
+2 -2
@@ -4,9 +4,9 @@ import (
4 "context"
5 "testing"
6
7 - dag "github.com/ipfs/go-ipfs/merkledag"
8 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
7 path "github.com/ipfs/go-ipfs/path"
8 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
10
11 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
12 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
exchange/reprovide/providers.go
+1 -1
@@ -3,9 +3,9 @@ package reprovide
3 import (
4 "context"
5
6 - merkledag "github.com/ipfs/go-ipfs/merkledag"
6 pin "github.com/ipfs/go-ipfs/pin"
7
8 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
10 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
11 blocks "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
filestore/filestore_test.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 "math/rand"
8 "testing"
9
10 - dag "github.com/ipfs/go-ipfs/merkledag"
10 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11
12 posinfo "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
13 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
fuse/ipns/ipns_unix.go
+1 -1
@@ -12,11 +12,11 @@ import (
12 "os"
13
14 core "github.com/ipfs/go-ipfs/core"
15 - dag "github.com/ipfs/go-ipfs/merkledag"
15 mfs "github.com/ipfs/go-ipfs/mfs"
16 namesys "github.com/ipfs/go-ipfs/namesys"
17 path "github.com/ipfs/go-ipfs/path"
18 ft "github.com/ipfs/go-ipfs/unixfs"
19 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
20
21 fuse "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse"
22 fs "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs"
fuse/readonly/ipfs_test.go
+1 -1
@@ -17,8 +17,8 @@ import (
17 coreunix "github.com/ipfs/go-ipfs/core/coreunix"
18 coremock "github.com/ipfs/go-ipfs/core/mock"
19 importer "github.com/ipfs/go-ipfs/importer"
20 - dag "github.com/ipfs/go-ipfs/merkledag"
20 uio "github.com/ipfs/go-ipfs/unixfs/io"
21 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
22
23 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
24 fstest "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
fuse/readonly/readonly_unix.go
+1 -1
@@ -11,10 +11,10 @@ import (
11 "syscall"
12
13 core "github.com/ipfs/go-ipfs/core"
14 - mdag "github.com/ipfs/go-ipfs/merkledag"
14 path "github.com/ipfs/go-ipfs/path"
15 uio "github.com/ipfs/go-ipfs/unixfs/io"
16 ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
17 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
18
19 lgbl "gx/ipfs/QmRPkGkHLB72caXgdDYnoaWigXNWx95BcYDKV1n3KTEpaG/go-libp2p-loggables"
20 fuse "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse"
importer/balanced/balanced_test.go
+2 -2
@@ -10,9 +10,9 @@ import (
10 "testing"
11
12 h "github.com/ipfs/go-ipfs/importer/helpers"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
14 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
13 uio "github.com/ipfs/go-ipfs/unixfs/io"
14 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
15 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
16
17 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
18 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
importer/helpers/dagbuilder.go
+1 -1
@@ -5,9 +5,9 @@ import (
5 "io"
6 "os"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
8 ft "github.com/ipfs/go-ipfs/unixfs"
9 pb "github.com/ipfs/go-ipfs/unixfs/pb"
10 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11
12 pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
13 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
importer/helpers/helpers.go
+1 -1
@@ -5,8 +5,8 @@ import (
5 "fmt"
6 "os"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
8 ft "github.com/ipfs/go-ipfs/unixfs"
9 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
10
11 pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
12 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
importer/importer_test.go
+1 -1
@@ -7,8 +7,8 @@ import (
7 "io/ioutil"
8 "testing"
9
10 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
10 uio "github.com/ipfs/go-ipfs/unixfs/io"
11 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
12
13 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
14 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
importer/trickle/trickle_test.go
+2 -2
@@ -10,10 +10,10 @@ import (
10 "testing"
11
12 h "github.com/ipfs/go-ipfs/importer/helpers"
13 - merkledag "github.com/ipfs/go-ipfs/merkledag"
14 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 uio "github.com/ipfs/go-ipfs/unixfs/io"
15 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
16 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
17
18 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
19 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
importer/trickle/trickledag.go
+1 -1
@@ -21,8 +21,8 @@ import (
21 "fmt"
22
23 h "github.com/ipfs/go-ipfs/importer/helpers"
24 - dag "github.com/ipfs/go-ipfs/merkledag"
24 ft "github.com/ipfs/go-ipfs/unixfs"
25 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
26
27 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
28 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
merkledag/coding.go deleted
-137
@@ -1,137 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "fmt"
5 - "sort"
6 - "strings"
7 -
8 - "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
9 -
10 - pb "github.com/ipfs/go-ipfs/merkledag/pb"
11 -
12 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
13 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
14 -)
15 -
16 -// for now, we use a PBNode intermediate thing.
17 -// because native go objects are nice.
18 -
19 -// unmarshal decodes raw data into a *Node instance.
20 -// The conversion uses an intermediate PBNode.
21 -func (n *ProtoNode) unmarshal(encoded []byte) error {
22 - var pbn pb.PBNode
23 - if err := pbn.Unmarshal(encoded); err != nil {
24 - return fmt.Errorf("unmarshal failed. %v", err)
25 - }
26 -
27 - pbnl := pbn.GetLinks()
28 - n.links = make([]*ipld.Link, len(pbnl))
29 - for i, l := range pbnl {
30 - n.links[i] = &ipld.Link{Name: l.GetName(), Size: l.GetTsize()}
31 - c, err := cid.Cast(l.GetHash())
32 - if err != nil {
33 - return fmt.Errorf("link hash #%d is not valid multihash. %v", i, err)
34 - }
35 - n.links[i].Cid = c
36 - }
37 - sort.Stable(LinkSlice(n.links)) // keep links sorted
38 -
39 - n.data = pbn.GetData()
40 - n.encoded = encoded
41 - return nil
42 -}
43 -
44 -// Marshal encodes a *Node instance into a new byte slice.
45 -// The conversion uses an intermediate PBNode.
46 -func (n *ProtoNode) Marshal() ([]byte, error) {
47 - pbn := n.getPBNode()
48 - data, err := pbn.Marshal()
49 - if err != nil {
50 - return data, fmt.Errorf("marshal failed. %v", err)
51 - }
52 - return data, nil
53 -}
54 -
55 -func (n *ProtoNode) getPBNode() *pb.PBNode {
56 - pbn := &pb.PBNode{}
57 - if len(n.links) > 0 {
58 - pbn.Links = make([]*pb.PBLink, len(n.links))
59 - }
60 -
61 - sort.Stable(LinkSlice(n.links)) // keep links sorted
62 - for i, l := range n.links {
63 - pbn.Links[i] = &pb.PBLink{}
64 - pbn.Links[i].Name = &l.Name
65 - pbn.Links[i].Tsize = &l.Size
66 - if l.Cid != nil {
67 - pbn.Links[i].Hash = l.Cid.Bytes()
68 - }
69 - }
70 -
71 - if len(n.data) > 0 {
72 - pbn.Data = n.data
73 - }
74 - return pbn
75 -}
76 -
77 -// EncodeProtobuf returns the encoded raw data version of a Node instance.
78 -// It may use a cached encoded version, unless the force flag is given.
79 -func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
80 - sort.Stable(LinkSlice(n.links)) // keep links sorted
81 - if n.encoded == nil || force {
82 - n.cached = nil
83 - var err error
84 - n.encoded, err = n.Marshal()
85 - if err != nil {
86 - return nil, err
87 - }
88 - }
89 -
90 - if n.cached == nil {
91 - if n.Prefix.Codec == 0 { // unset
92 - n.Prefix = v0CidPrefix
93 - }
94 - c, err := n.Prefix.Sum(n.encoded)
95 - if err != nil {
96 - return nil, err
97 - }
98 -
99 - n.cached = c
100 - }
101 -
102 - return n.encoded, nil
103 -}
104 -
105 -// DecodeProtobuf decodes raw data and returns a new Node instance.
106 -func DecodeProtobuf(encoded []byte) (*ProtoNode, error) {
107 - n := new(ProtoNode)
108 - err := n.unmarshal(encoded)
109 - if err != nil {
110 - return nil, fmt.Errorf("incorrectly formatted merkledag node: %s", err)
111 - }
112 - return n, nil
113 -}
114 -
115 -// DecodeProtobufBlock is a block decoder for protobuf IPLD nodes conforming to
116 -// node.DecodeBlockFunc
117 -func DecodeProtobufBlock(b blocks.Block) (ipld.Node, error) {
118 - c := b.Cid()
119 - if c.Type() != cid.DagProtobuf {
120 - return nil, fmt.Errorf("this function can only decode protobuf nodes")
121 - }
122 -
123 - decnd, err := DecodeProtobuf(b.RawData())
124 - if err != nil {
125 - if strings.Contains(err.Error(), "Unmarshal failed") {
126 - return nil, fmt.Errorf("the block referred to by '%s' was not a valid merkledag node", c)
127 - }
128 - return nil, fmt.Errorf("failed to decode Protocol Buffers: %v", err)
129 - }
130 -
131 - decnd.cached = c
132 - decnd.Prefix = c.Prefix()
133 - return decnd, nil
134 -}
135 -
136 -// Type assertion
137 -var _ ipld.DecodeBlockFunc = DecodeProtobufBlock
merkledag/errservice.go deleted
-47
@@ -1,47 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "context"
5 -
6 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
7 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
8 -)
9 -
10 -// ErrorService implements ipld.DAGService, returning 'Err' for every call.
11 -type ErrorService struct {
12 - Err error
13 -}
14 -
15 -var _ ipld.DAGService = (*ErrorService)(nil)
16 -
17 -// Add returns the cs.Err.
18 -func (cs *ErrorService) Add(ctx context.Context, nd ipld.Node) error {
19 - return cs.Err
20 -}
21 -
22 -// AddMany returns the cs.Err.
23 -func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error {
24 - return cs.Err
25 -}
26 -
27 -// Get returns the cs.Err.
28 -func (cs *ErrorService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
29 - return nil, cs.Err
30 -}
31 -
32 -// GetMany many returns the cs.Err.
33 -func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
34 - ch := make(chan *ipld.NodeOption)
35 - close(ch)
36 - return ch
37 -}
38 -
39 -// Remove returns the cs.Err.
40 -func (cs *ErrorService) Remove(ctx context.Context, c *cid.Cid) error {
41 - return cs.Err
42 -}
43 -
44 -// RemoveMany returns the cs.Err.
45 -func (cs *ErrorService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
46 - return cs.Err
47 -}
merkledag/merkledag.go deleted
-392
@@ -1,392 +0,0 @@
1 -// Package merkledag implements the IPFS Merkle DAG data structures.
2 -package merkledag
3 -
4 -import (
5 - "context"
6 - "fmt"
7 - "sync"
8 -
9 - bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
10 -
11 - blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
12 - ipldcbor "gx/ipfs/QmWrbExtUaQQHjJ8FVVDAWj5o1MRAELDUV3VmoQsZHHb6L/go-ipld-cbor"
13 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
14 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
15 -)
16 -
17 -// TODO: We should move these registrations elsewhere. Really, most of the IPLD
18 -// functionality should go in a `go-ipld` repo but that will take a lot of work
19 -// and design.
20 -func init() {
21 - ipld.Register(cid.DagProtobuf, DecodeProtobufBlock)
22 - ipld.Register(cid.Raw, DecodeRawBlock)
23 - ipld.Register(cid.DagCBOR, ipldcbor.DecodeBlock)
24 -}
25 -
26 -// contextKey is a type to use as value for the ProgressTracker contexts.
27 -type contextKey string
28 -
29 -const progressContextKey contextKey = "progress"
30 -
31 -// NewDAGService constructs a new DAGService (using the default implementation).
32 -// Note that the default implementation is also an ipld.LinkGetter.
33 -func NewDAGService(bs bserv.BlockService) *dagService {
34 - return &dagService{Blocks: bs}
35 -}
36 -
37 -// dagService is an IPFS Merkle DAG service.
38 -// - the root is virtual (like a forest)
39 -// - stores nodes' data in a BlockService
40 -// TODO: should cache Nodes that are in memory, and be
41 -// able to free some of them when vm pressure is high
42 -type dagService struct {
43 - Blocks bserv.BlockService
44 -}
45 -
46 -// Add adds a node to the dagService, storing the block in the BlockService
47 -func (n *dagService) Add(ctx context.Context, nd ipld.Node) error {
48 - if n == nil { // FIXME remove this assertion. protect with constructor invariant
49 - return fmt.Errorf("dagService is nil")
50 - }
51 -
52 - return n.Blocks.AddBlock(nd)
53 -}
54 -
55 -func (n *dagService) AddMany(ctx context.Context, nds []ipld.Node) error {
56 - blks := make([]blocks.Block, len(nds))
57 - for i, nd := range nds {
58 - blks[i] = nd
59 - }
60 - return n.Blocks.AddBlocks(blks)
61 -}
62 -
63 -// Get retrieves a node from the dagService, fetching the block in the BlockService
64 -func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
65 - if n == nil {
66 - return nil, fmt.Errorf("dagService is nil")
67 - }
68 -
69 - ctx, cancel := context.WithCancel(ctx)
70 - defer cancel()
71 -
72 - b, err := n.Blocks.GetBlock(ctx, c)
73 - if err != nil {
74 - if err == bserv.ErrNotFound {
75 - return nil, ipld.ErrNotFound
76 - }
77 - return nil, fmt.Errorf("failed to get block for %s: %v", c, err)
78 - }
79 -
80 - return ipld.Decode(b)
81 -}
82 -
83 -// GetLinks return the links for the node, the node doesn't necessarily have
84 -// to exist locally.
85 -func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
86 - if c.Type() == cid.Raw {
87 - return nil, nil
88 - }
89 - node, err := n.Get(ctx, c)
90 - if err != nil {
91 - return nil, err
92 - }
93 - return node.Links(), nil
94 -}
95 -
96 -func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
97 - return n.Blocks.DeleteBlock(c)
98 -}
99 -
100 -// RemoveMany removes multiple nodes from the DAG. It will likely be faster than
101 -// removing them individually.
102 -//
103 -// This operation is not atomic. If it returns an error, some nodes may or may
104 -// not have been removed.
105 -func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
106 - // TODO(#4608): make this batch all the way down.
107 - for _, c := range cids {
108 - if err := n.Blocks.DeleteBlock(c); err != nil {
109 - return err
110 - }
111 - }
112 - return nil
113 -}
114 -
115 -// GetLinksDirect creates a function to get the links for a node, from
116 -// the node, bypassing the LinkService. If the node does not exist
117 -// locally (and can not be retrieved) an error will be returned.
118 -func GetLinksDirect(serv ipld.NodeGetter) GetLinks {
119 - return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
120 - nd, err := serv.Get(ctx, c)
121 - if err != nil {
122 - if err == bserv.ErrNotFound {
123 - err = ipld.ErrNotFound
124 - }
125 - return nil, err
126 - }
127 - return nd.Links(), nil
128 - }
129 -}
130 -
131 -type sesGetter struct {
132 - bs *bserv.Session
133 -}
134 -
135 -// Get gets a single node from the DAG.
136 -func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
137 - blk, err := sg.bs.GetBlock(ctx, c)
138 - switch err {
139 - case bserv.ErrNotFound:
140 - return nil, ipld.ErrNotFound
141 - default:
142 - return nil, err
143 - case nil:
144 - // noop
145 - }
146 -
147 - return ipld.Decode(blk)
148 -}
149 -
150 -// GetMany gets many nodes at once, batching the request if possible.
151 -func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
152 - return getNodesFromBG(ctx, sg.bs, keys)
153 -}
154 -
155 -// Session returns a NodeGetter using a new session for block fetches.
156 -func (n *dagService) Session(ctx context.Context) ipld.NodeGetter {
157 - return &sesGetter{bserv.NewSession(ctx, n.Blocks)}
158 -}
159 -
160 -// FetchGraph fetches all nodes that are children of the given node
161 -func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error {
162 - var ng ipld.NodeGetter = serv
163 - ds, ok := serv.(*dagService)
164 - if ok {
165 - ng = &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
166 - }
167 -
168 - v, _ := ctx.Value(progressContextKey).(*ProgressTracker)
169 - if v == nil {
170 - return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, cid.NewSet().Visit)
171 - }
172 - set := cid.NewSet()
173 - visit := func(c *cid.Cid) bool {
174 - if set.Visit(c) {
175 - v.Increment()
176 - return true
177 - }
178 - return false
179 - }
180 - return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, visit)
181 -}
182 -
183 -// GetMany gets many nodes from the DAG at once.
184 -//
185 -// This method may not return all requested nodes (and may or may not return an
186 -// error indicating that it failed to do so. It is up to the caller to verify
187 -// that it received all nodes.
188 -func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
189 - return getNodesFromBG(ctx, n.Blocks, keys)
190 -}
191 -
192 -func dedupKeys(keys []*cid.Cid) []*cid.Cid {
193 - set := cid.NewSet()
194 - for _, c := range keys {
195 - set.Add(c)
196 - }
197 - if set.Len() == len(keys) {
198 - return keys
199 - }
200 - return set.Keys()
201 -}
202 -
203 -func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
204 - keys = dedupKeys(keys)
205 -
206 - out := make(chan *ipld.NodeOption, len(keys))
207 - blocks := bs.GetBlocks(ctx, keys)
208 - var count int
209 -
210 - go func() {
211 - defer close(out)
212 - for {
213 - select {
214 - case b, ok := <-blocks:
215 - if !ok {
216 - if count != len(keys) {
217 - out <- &ipld.NodeOption{Err: fmt.Errorf("failed to fetch all nodes")}
218 - }
219 - return
220 - }
221 -
222 - nd, err := ipld.Decode(b)
223 - if err != nil {
224 - out <- &ipld.NodeOption{Err: err}
225 - return
226 - }
227 -
228 - out <- &ipld.NodeOption{Node: nd}
229 - count++
230 -
231 - case <-ctx.Done():
232 - out <- &ipld.NodeOption{Err: ctx.Err()}
233 - return
234 - }
235 - }
236 - }()
237 - return out
238 -}
239 -
240 -// GetLinks is the type of function passed to the EnumerateChildren function(s)
241 -// for getting the children of an IPLD node.
242 -type GetLinks func(context.Context, *cid.Cid) ([]*ipld.Link, error)
243 -
244 -// GetLinksWithDAG returns a GetLinks function that tries to use the given
245 -// NodeGetter as a LinkGetter to get the children of a given IPLD node. This may
246 -// allow us to traverse the DAG without actually loading and parsing the node in
247 -// question (if we already have the links cached).
248 -func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks {
249 - return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
250 - return ipld.GetLinks(ctx, ng, c)
251 - }
252 -}
253 -
254 -// EnumerateChildren will walk the dag below the given root node and add all
255 -// unseen children to the passed in set.
256 -// TODO: parallelize to avoid disk latency perf hits?
257 -func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
258 - links, err := getLinks(ctx, root)
259 - if err != nil {
260 - return err
261 - }
262 - for _, lnk := range links {
263 - c := lnk.Cid
264 - if visit(c) {
265 - err = EnumerateChildren(ctx, getLinks, c, visit)
266 - if err != nil {
267 - return err
268 - }
269 - }
270 - }
271 - return nil
272 -}
273 -
274 -// ProgressTracker is used to show progress when fetching nodes.
275 -type ProgressTracker struct {
276 - Total int
277 - lk sync.Mutex
278 -}
279 -
280 -// DeriveContext returns a new context with value "progress" derived from
281 -// the given one.
282 -func (p *ProgressTracker) DeriveContext(ctx context.Context) context.Context {
283 - return context.WithValue(ctx, progressContextKey, p)
284 -}
285 -
286 -// Increment adds one to the total progress.
287 -func (p *ProgressTracker) Increment() {
288 - p.lk.Lock()
289 - defer p.lk.Unlock()
290 - p.Total++
291 -}
292 -
293 -// Value returns the current progress.
294 -func (p *ProgressTracker) Value() int {
295 - p.lk.Lock()
296 - defer p.lk.Unlock()
297 - return p.Total
298 -}
299 -
300 -// FetchGraphConcurrency is total number of concurrent fetches that
301 -// 'fetchNodes' will start at a time
302 -var FetchGraphConcurrency = 8
303 -
304 -// EnumerateChildrenAsync is equivalent to EnumerateChildren *except* that it
305 -// fetches children in parallel.
306 -//
307 -// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
308 -func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error {
309 - feed := make(chan *cid.Cid)
310 - out := make(chan []*ipld.Link)
311 - done := make(chan struct{})
312 -
313 - var setlk sync.Mutex
314 -
315 - errChan := make(chan error)
316 - fetchersCtx, cancel := context.WithCancel(ctx)
317 -
318 - defer cancel()
319 -
320 - for i := 0; i < FetchGraphConcurrency; i++ {
321 - go func() {
322 - for ic := range feed {
323 - setlk.Lock()
324 - shouldVisit := visit(ic)
325 - setlk.Unlock()
326 -
327 - if shouldVisit {
328 - links, err := getLinks(ctx, ic)
329 - if err != nil {
330 - errChan <- err
331 - return
332 - }
333 -
334 - select {
335 - case out <- links:
336 - case <-fetchersCtx.Done():
337 - return
338 - }
339 - }
340 - select {
341 - case done <- struct{}{}:
342 - case <-fetchersCtx.Done():
343 - }
344 - }
345 - }()
346 - }
347 - defer close(feed)
348 -
349 - send := feed
350 - var todobuffer []*cid.Cid
351 - var inProgress int
352 -
353 - next := c
354 - for {
355 - select {
356 - case send <- next:
357 - inProgress++
358 - if len(todobuffer) > 0 {
359 - next = todobuffer[0]
360 - todobuffer = todobuffer[1:]
361 - } else {
362 - next = nil
363 - send = nil
364 - }
365 - case <-done:
366 - inProgress--
367 - if inProgress == 0 && next == nil {
368 - return nil
369 - }
370 - case links := <-out:
371 - for _, lnk := range links {
372 - if next == nil {
373 - next = lnk.Cid
374 - send = feed
375 - } else {
376 - todobuffer = append(todobuffer, lnk.Cid)
377 - }
378 - }
379 - case err := <-errChan:
380 - return err
381 -
382 - case <-ctx.Done():
383 - return ctx.Err()
384 - }
385 - }
386 -
387 -}
388 -
389 -var _ ipld.LinkGetter = &dagService{}
390 -var _ ipld.NodeGetter = &dagService{}
391 -var _ ipld.NodeGetter = &sesGetter{}
392 -var _ ipld.DAGService = &dagService{}
merkledag/merkledag_test.go deleted
-705
@@ -1,705 +0,0 @@
1 -package merkledag_test
2 -
3 -import (
4 - "bytes"
5 - "context"
6 - "errors"
7 - "fmt"
8 - "io"
9 - "io/ioutil"
10 - "math/rand"
11 - "strings"
12 - "sync"
13 - "testing"
14 - "time"
15 -
16 - . "github.com/ipfs/go-ipfs/merkledag"
17 - mdpb "github.com/ipfs/go-ipfs/merkledag/pb"
18 - dstest "github.com/ipfs/go-ipfs/merkledag/test"
19 - bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
20 - bstest "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice/test"
21 -
22 - u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
23 - offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
24 - blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
25 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
26 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
27 -)
28 -
29 -func TestNode(t *testing.T) {
30 -
31 - n1 := NodeWithData([]byte("beep"))
32 - n2 := NodeWithData([]byte("boop"))
33 - n3 := NodeWithData([]byte("beep boop"))
34 - if err := n3.AddNodeLink("beep-link", n1); err != nil {
35 - t.Error(err)
36 - }
37 - if err := n3.AddNodeLink("boop-link", n2); err != nil {
38 - t.Error(err)
39 - }
40 -
41 - printn := func(name string, n *ProtoNode) {
42 - fmt.Println(">", name)
43 - fmt.Println("data:", string(n.Data()))
44 -
45 - fmt.Println("links:")
46 - for _, l := range n.Links() {
47 - fmt.Println("-", l.Name, l.Size, l.Cid)
48 - }
49 -
50 - e, err := n.EncodeProtobuf(false)
51 - if err != nil {
52 - t.Error(err)
53 - } else {
54 - fmt.Println("encoded:", e)
55 - }
56 -
57 - h := n.Multihash()
58 - k := n.Cid().Hash()
59 - if k.String() != h.String() {
60 - t.Error("Key is not equivalent to multihash")
61 - } else {
62 - fmt.Println("key: ", k)
63 - }
64 -
65 - SubtestNodeStat(t, n)
66 - }
67 -
68 - printn("beep", n1)
69 - printn("boop", n2)
70 - printn("beep boop", n3)
71 -}
72 -
73 -func SubtestNodeStat(t *testing.T, n *ProtoNode) {
74 - enc, err := n.EncodeProtobuf(true)
75 - if err != nil {
76 - t.Error("n.EncodeProtobuf(true) failed")
77 - return
78 - }
79 -
80 - cumSize, err := n.Size()
81 - if err != nil {
82 - t.Error("n.Size() failed")
83 - return
84 - }
85 -
86 - k := n.Cid()
87 -
88 - expected := ipld.NodeStat{
89 - NumLinks: len(n.Links()),
90 - BlockSize: len(enc),
91 - LinksSize: len(enc) - len(n.Data()), // includes framing.
92 - DataSize: len(n.Data()),
93 - CumulativeSize: int(cumSize),
94 - Hash: k.String(),
95 - }
96 -
97 - actual, err := n.Stat()
98 - if err != nil {
99 - t.Error("n.Stat() failed")
100 - return
101 - }
102 -
103 - if expected != *actual {
104 - t.Errorf("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
105 - } else {
106 - fmt.Printf("n.Stat correct: %s\n", actual)
107 - }
108 -}
109 -
110 -type devZero struct{}
111 -
112 -func (_ devZero) Read(b []byte) (int, error) {
113 - for i := range b {
114 - b[i] = 0
115 - }
116 - return len(b), nil
117 -}
118 -
119 -func TestBatchFetch(t *testing.T) {
120 - read := io.LimitReader(u.NewTimeSeededRand(), 1024*32)
121 - runBatchFetchTest(t, read)
122 -}
123 -
124 -func TestBatchFetchDupBlock(t *testing.T) {
125 - read := io.LimitReader(devZero{}, 1024*32)
126 - runBatchFetchTest(t, read)
127 -}
128 -
129 -// makeTestDAG creates a simple DAG from the data in a reader.
130 -// First, a node is created from each 512 bytes of data from the reader
131 -// (like a the Size chunker would do). Then all nodes are added as children
132 -// to a root node, which is returned.
133 -func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node {
134 - p := make([]byte, 512)
135 - nodes := []*ProtoNode{}
136 -
137 - for {
138 - n, err := io.ReadFull(read, p)
139 - if err == io.EOF {
140 - break
141 - }
142 -
143 - if err != nil {
144 - t.Fatal(err)
145 - }
146 -
147 - if n != len(p) {
148 - t.Fatal("should have read 512 bytes from the reader")
149 - }
150 -
151 - protoNode := NodeWithData(p)
152 - nodes = append(nodes, protoNode)
153 - }
154 -
155 - ctx := context.Background()
156 - // Add a root referencing all created nodes
157 - root := NodeWithData(nil)
158 - for _, n := range nodes {
159 - root.AddNodeLink(n.Cid().String(), n)
160 - err := ds.Add(ctx, n)
161 - if err != nil {
162 - t.Fatal(err)
163 - }
164 - }
165 - err := ds.Add(ctx, root)
166 - if err != nil {
167 - t.Fatal(err)
168 - }
169 - return root
170 -}
171 -
172 -// makeTestDAGReader takes the root node as returned by makeTestDAG and
173 -// provides a reader that reads all the RawData from that node and its children.
174 -func makeTestDAGReader(t *testing.T, root ipld.Node, ds ipld.DAGService) io.Reader {
175 - ctx := context.Background()
176 - buf := new(bytes.Buffer)
177 - buf.Write(root.RawData())
178 - for _, l := range root.Links() {
179 - n, err := ds.Get(ctx, l.Cid)
180 - if err != nil {
181 - t.Fatal(err)
182 - }
183 - _, err = buf.Write(n.RawData())
184 - if err != nil {
185 - t.Fatal(err)
186 - }
187 - }
188 - return buf
189 -}
190 -
191 -func runBatchFetchTest(t *testing.T, read io.Reader) {
192 - ctx := context.Background()
193 - var dagservs []ipld.DAGService
194 - for _, bsi := range bstest.Mocks(5) {
195 - dagservs = append(dagservs, NewDAGService(bsi))
196 - }
197 -
198 - root := makeTestDAG(t, read, dagservs[0])
199 -
200 - t.Log("finished setup.")
201 -
202 - dagr := makeTestDAGReader(t, root, dagservs[0])
203 -
204 - expected, err := ioutil.ReadAll(dagr)
205 - if err != nil {
206 - t.Fatal(err)
207 - }
208 -
209 - err = dagservs[0].Add(ctx, root)
210 - if err != nil {
211 - t.Fatal(err)
212 - }
213 -
214 - t.Log("Added file to first node.")
215 -
216 - c := root.Cid()
217 -
218 - wg := sync.WaitGroup{}
219 - errs := make(chan error)
220 -
221 - for i := 1; i < len(dagservs); i++ {
222 - wg.Add(1)
223 - go func(i int) {
224 - defer wg.Done()
225 - first, err := dagservs[i].Get(ctx, c)
226 - if err != nil {
227 - errs <- err
228 - }
229 - fmt.Println("Got first node back.")
230 -
231 - firstpb, ok := first.(*ProtoNode)
232 - if !ok {
233 - errs <- ErrNotProtobuf
234 - }
235 - read := makeTestDAGReader(t, firstpb, dagservs[i])
236 - datagot, err := ioutil.ReadAll(read)
237 - if err != nil {
238 - errs <- err
239 - }
240 -
241 - if !bytes.Equal(datagot, expected) {
242 - errs <- errors.New("got bad data back")
243 - }
244 - }(i)
245 - }
246 -
247 - go func() {
248 - wg.Wait()
249 - close(errs)
250 - }()
251 -
252 - for err := range errs {
253 - if err != nil {
254 - t.Fatal(err)
255 - }
256 - }
257 -}
258 -
259 -func TestCantGet(t *testing.T) {
260 - ds := dstest.Mock()
261 - a := NodeWithData([]byte("A"))
262 -
263 - c := a.Cid()
264 - _, err := ds.Get(context.Background(), c)
265 - if !strings.Contains(err.Error(), "not found") {
266 - t.Fatal("expected err not found, got: ", err)
267 - }
268 -}
269 -
270 -func TestFetchGraph(t *testing.T) {
271 - var dservs []ipld.DAGService
272 - bsis := bstest.Mocks(2)
273 - for _, bsi := range bsis {
274 - dservs = append(dservs, NewDAGService(bsi))
275 - }
276 -
277 - read := io.LimitReader(u.NewTimeSeededRand(), 1024*32)
278 - root := makeTestDAG(t, read, dservs[0])
279 -
280 - err := FetchGraph(context.TODO(), root.Cid(), dservs[1])
281 - if err != nil {
282 - t.Fatal(err)
283 - }
284 -
285 - // create an offline dagstore and ensure all blocks were fetched
286 - bs := bserv.New(bsis[1].Blockstore(), offline.Exchange(bsis[1].Blockstore()))
287 -
288 - offlineDS := NewDAGService(bs)
289 -
290 - err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ *cid.Cid) bool { return true })
291 - if err != nil {
292 - t.Fatal(err)
293 - }
294 -}
295 -
296 -func TestEnumerateChildren(t *testing.T) {
297 - bsi := bstest.Mocks(1)
298 - ds := NewDAGService(bsi[0])
299 -
300 - read := io.LimitReader(u.NewTimeSeededRand(), 1024*1024)
301 - root := makeTestDAG(t, read, ds)
302 -
303 - set := cid.NewSet()
304 -
305 - err := EnumerateChildren(context.Background(), ds.GetLinks, root.Cid(), set.Visit)
306 - if err != nil {
307 - t.Fatal(err)
308 - }
309 -
310 - var traverse func(n ipld.Node)
311 - traverse = func(n ipld.Node) {
312 - // traverse dag and check
313 - for _, lnk := range n.Links() {
314 - c := lnk.Cid
315 - if !set.Has(c) {
316 - t.Fatal("missing key in set! ", lnk.Cid.String())
317 - }
318 - child, err := ds.Get(context.Background(), c)
319 - if err != nil {
320 - t.Fatal(err)
321 - }
322 - traverse(child)
323 - }
324 - }
325 -
326 - traverse(root)
327 -}
328 -
329 -func TestFetchFailure(t *testing.T) {
330 - ctx := context.Background()
331 -
332 - ds := dstest.Mock()
333 - ds_bad := dstest.Mock()
334 -
335 - top := new(ProtoNode)
336 - for i := 0; i < 10; i++ {
337 - nd := NodeWithData([]byte{byte('a' + i)})
338 - err := ds.Add(ctx, nd)
339 - if err != nil {
340 - t.Fatal(err)
341 - }
342 -
343 - err = top.AddNodeLink(fmt.Sprintf("AA%d", i), nd)
344 - if err != nil {
345 - t.Fatal(err)
346 - }
347 - }
348 -
349 - for i := 0; i < 10; i++ {
350 - nd := NodeWithData([]byte{'f', 'a' + byte(i)})
351 - err := ds_bad.Add(ctx, nd)
352 - if err != nil {
353 - t.Fatal(err)
354 - }
355 -
356 - err = top.AddNodeLink(fmt.Sprintf("BB%d", i), nd)
357 - if err != nil {
358 - t.Fatal(err)
359 - }
360 - }
361 -
362 - getters := ipld.GetDAG(ctx, ds, top)
363 - for i, getter := range getters {
364 - _, err := getter.Get(ctx)
365 - if err != nil && i < 10 {
366 - t.Fatal(err)
367 - }
368 - if err == nil && i >= 10 {
369 - t.Fatal("should have failed request")
370 - }
371 - }
372 -}
373 -
374 -func TestUnmarshalFailure(t *testing.T) {
375 - badData := []byte("hello world")
376 -
377 - _, err := DecodeProtobuf(badData)
378 - if err == nil {
379 - t.Fatal("shouldnt succeed to parse this")
380 - }
381 -
382 - // now with a bad link
383 - pbn := &mdpb.PBNode{Links: []*mdpb.PBLink{{Hash: []byte("not a multihash")}}}
384 - badlink, err := pbn.Marshal()
385 - if err != nil {
386 - t.Fatal(err)
387 - }
388 -
389 - _, err = DecodeProtobuf(badlink)
390 - if err == nil {
391 - t.Fatal("should have failed to parse node with bad link")
392 - }
393 -
394 - n := &ProtoNode{}
395 - n.Marshal()
396 -}
397 -
398 -func TestBasicAddGet(t *testing.T) {
399 - ctx := context.Background()
400 -
401 - ds := dstest.Mock()
402 - nd := new(ProtoNode)
403 -
404 - err := ds.Add(ctx, nd)
405 - if err != nil {
406 - t.Fatal(err)
407 - }
408 -
409 - out, err := ds.Get(ctx, nd.Cid())
410 - if err != nil {
411 - t.Fatal(err)
412 - }
413 -
414 - if !nd.Cid().Equals(out.Cid()) {
415 - t.Fatal("output didnt match input")
416 - }
417 -}
418 -
419 -func TestGetRawNodes(t *testing.T) {
420 - ctx := context.Background()
421 -
422 - rn := NewRawNode([]byte("test"))
423 -
424 - ds := dstest.Mock()
425 -
426 - err := ds.Add(ctx, rn)
427 - if err != nil {
428 - t.Fatal(err)
429 - }
430 -
431 - if !rn.Cid().Equals(rn.Cid()) {
432 - t.Fatal("output cids didnt match")
433 - }
434 -
435 - out, err := ds.Get(ctx, rn.Cid())
436 - if err != nil {
437 - t.Fatal(err)
438 - }
439 -
440 - if !bytes.Equal(out.RawData(), []byte("test")) {
441 - t.Fatal("raw block should match input data")
442 - }
443 -
444 - if out.Links() != nil {
445 - t.Fatal("raw blocks shouldnt have links")
446 - }
447 -
448 - if out.Tree("", -1) != nil {
449 - t.Fatal("tree should return no paths in a raw block")
450 - }
451 -
452 - size, err := out.Size()
453 - if err != nil {
454 - t.Fatal(err)
455 - }
456 - if size != 4 {
457 - t.Fatal("expected size to be 4")
458 - }
459 -
460 - ns, err := out.Stat()
461 - if err != nil {
462 - t.Fatal(err)
463 - }
464 -
465 - if ns.DataSize != 4 {
466 - t.Fatal("expected size to be 4, got: ", ns.DataSize)
467 - }
468 -
469 - _, _, err = out.Resolve([]string{"foo"})
470 - if err != ErrLinkNotFound {
471 - t.Fatal("shouldnt find links under raw blocks")
472 - }
473 -}
474 -
475 -func TestProtoNodeResolve(t *testing.T) {
476 -
477 - nd := new(ProtoNode)
478 - nd.SetLinks([]*ipld.Link{{Name: "foo"}})
479 -
480 - lnk, left, err := nd.ResolveLink([]string{"foo", "bar"})
481 - if err != nil {
482 - t.Fatal(err)
483 - }
484 -
485 - if len(left) != 1 || left[0] != "bar" {
486 - t.Fatal("expected the single path element 'bar' to remain")
487 - }
488 -
489 - if lnk.Name != "foo" {
490 - t.Fatal("how did we get anything else?")
491 - }
492 -
493 - tvals := nd.Tree("", -1)
494 - if len(tvals) != 1 || tvals[0] != "foo" {
495 - t.Fatal("expected tree to return []{\"foo\"}")
496 - }
497 -}
498 -
499 -func TestCidRetention(t *testing.T) {
500 - ctx := context.Background()
501 -
502 - nd := new(ProtoNode)
503 - nd.SetData([]byte("fooooo"))
504 -
505 - pref := nd.Cid().Prefix()
506 - pref.Version = 1
507 -
508 - c2, err := pref.Sum(nd.RawData())
509 - if err != nil {
510 - t.Fatal(err)
511 - }
512 -
513 - blk, err := blocks.NewBlockWithCid(nd.RawData(), c2)
514 - if err != nil {
515 - t.Fatal(err)
516 - }
517 -
518 - bs := dstest.Bserv()
519 - err = bs.AddBlock(blk)
520 - if err != nil {
521 - t.Fatal(err)
522 - }
523 -
524 - ds := NewDAGService(bs)
525 - out, err := ds.Get(ctx, c2)
526 - if err != nil {
527 - t.Fatal(err)
528 - }
529 -
530 - if !out.Cid().Equals(c2) {
531 - t.Fatal("output cid didnt match")
532 - }
533 -}
534 -
535 -func TestCidRawDoesnNeedData(t *testing.T) {
536 - srv := NewDAGService(dstest.Bserv())
537 - nd := NewRawNode([]byte("somedata"))
538 -
539 - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
540 - defer cancel()
541 -
542 - // there is no data for this node in the blockservice
543 - // so dag service can't load it
544 - links, err := srv.GetLinks(ctx, nd.Cid())
545 - if err != nil {
546 - t.Fatal(err)
547 - }
548 - if len(links) != 0 {
549 - t.Fatal("raw node shouldn't have any links")
550 - }
551 -}
552 -
553 -func TestGetManyDuplicate(t *testing.T) {
554 - ctx := context.Background()
555 -
556 - srv := NewDAGService(dstest.Bserv())
557 -
558 - nd := NodeWithData([]byte("foo"))
559 - if err := srv.Add(ctx, nd); err != nil {
560 - t.Fatal(err)
561 - }
562 - nds := srv.GetMany(ctx, []*cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
563 - out, ok := <-nds
564 - if !ok {
565 - t.Fatal("expecting node foo")
566 - }
567 - if out.Err != nil {
568 - t.Fatal(out.Err)
569 - }
570 - if !out.Node.Cid().Equals(nd.Cid()) {
571 - t.Fatal("got wrong node")
572 - }
573 - out, ok = <-nds
574 - if ok {
575 - if out.Err != nil {
576 - t.Fatal(out.Err)
577 - } else {
578 - t.Fatal("expecting no more nodes")
579 - }
580 - }
581 -}
582 -
583 -func TestEnumerateAsyncFailsNotFound(t *testing.T) {
584 - ctx := context.Background()
585 -
586 - a := NodeWithData([]byte("foo1"))
587 - b := NodeWithData([]byte("foo2"))
588 - c := NodeWithData([]byte("foo3"))
589 - d := NodeWithData([]byte("foo4"))
590 -
591 - ds := dstest.Mock()
592 - for _, n := range []ipld.Node{a, b, c} {
593 - err := ds.Add(ctx, n)
594 - if err != nil {
595 - t.Fatal(err)
596 - }
597 - }
598 -
599 - parent := new(ProtoNode)
600 - if err := parent.AddNodeLink("a", a); err != nil {
601 - t.Fatal(err)
602 - }
603 -
604 - if err := parent.AddNodeLink("b", b); err != nil {
605 - t.Fatal(err)
606 - }
607 -
608 - if err := parent.AddNodeLink("c", c); err != nil {
609 - t.Fatal(err)
610 - }
611 -
612 - if err := parent.AddNodeLink("d", d); err != nil {
613 - t.Fatal(err)
614 - }
615 -
616 - err := ds.Add(ctx, parent)
617 - if err != nil {
618 - t.Fatal(err)
619 - }
620 -
621 - cset := cid.NewSet()
622 - err = EnumerateChildrenAsync(ctx, GetLinksDirect(ds), parent.Cid(), cset.Visit)
623 - if err == nil {
624 - t.Fatal("this should have failed")
625 - }
626 -}
627 -
628 -func TestProgressIndicator(t *testing.T) {
629 - testProgressIndicator(t, 5)
630 -}
631 -
632 -func TestProgressIndicatorNoChildren(t *testing.T) {
633 - testProgressIndicator(t, 0)
634 -}
635 -
636 -func testProgressIndicator(t *testing.T, depth int) {
637 - ds := dstest.Mock()
638 -
639 - top, numChildren := mkDag(ds, depth)
640 -
641 - v := new(ProgressTracker)
642 - ctx := v.DeriveContext(context.Background())
643 -
644 - err := FetchGraph(ctx, top, ds)
645 - if err != nil {
646 - t.Fatal(err)
647 - }
648 -
649 - if v.Value() != numChildren+1 {
650 - t.Errorf("wrong number of children reported in progress indicator, expected %d, got %d",
651 - numChildren+1, v.Value())
652 - }
653 -}
654 -
655 -func mkDag(ds ipld.DAGService, depth int) (*cid.Cid, int) {
656 - ctx := context.Background()
657 -
658 - totalChildren := 0
659 - f := func() *ProtoNode {
660 - p := new(ProtoNode)
661 - buf := make([]byte, 16)
662 - rand.Read(buf)
663 -
664 - p.SetData(buf)
665 - err := ds.Add(ctx, p)
666 - if err != nil {
667 - panic(err)
668 - }
669 - return p
670 - }
671 -
672 - for i := 0; i < depth; i++ {
673 - thisf := f
674 - f = func() *ProtoNode {
675 - pn := mkNodeWithChildren(thisf, 10)
676 - err := ds.Add(ctx, pn)
677 - if err != nil {
678 - panic(err)
679 - }
680 - totalChildren += 10
681 - return pn
682 - }
683 - }
684 -
685 - nd := f()
686 - err := ds.Add(ctx, nd)
687 - if err != nil {
688 - panic(err)
689 - }
690 -
691 - return nd.Cid(), totalChildren
692 -}
693 -
694 -func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode {
695 - cur := new(ProtoNode)
696 -
697 - for i := 0; i < width; i++ {
698 - c := getChild()
699 - if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil {
700 - panic(err)
701 - }
702 - }
703 -
704 - return cur
705 -}
merkledag/node.go deleted
-380
@@ -1,380 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "context"
5 - "encoding/json"
6 - "fmt"
7 -
8 - mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
9 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
10 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
11 -)
12 -
13 -// Common errors
14 -var (
15 - ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
16 - ErrLinkNotFound = fmt.Errorf("no link by that name")
17 -)
18 -
19 -// ProtoNode represents a node in the IPFS Merkle DAG.
20 -// nodes have opaque data and a set of navigable links.
21 -type ProtoNode struct {
22 - links []*ipld.Link
23 - data []byte
24 -
25 - // cache encoded/marshaled value
26 - encoded []byte
27 -
28 - cached *cid.Cid
29 -
30 - // Prefix specifies cid version and hashing function
31 - Prefix cid.Prefix
32 -}
33 -
34 -var v0CidPrefix = cid.Prefix{
35 - Codec: cid.DagProtobuf,
36 - MhLength: -1,
37 - MhType: mh.SHA2_256,
38 - Version: 0,
39 -}
40 -
41 -var v1CidPrefix = cid.Prefix{
42 - Codec: cid.DagProtobuf,
43 - MhLength: -1,
44 - MhType: mh.SHA2_256,
45 - Version: 1,
46 -}
47 -
48 -// V0CidPrefix returns a prefix for CIDv0
49 -func V0CidPrefix() cid.Prefix { return v0CidPrefix }
50 -
51 -// V1CidPrefix returns a prefix for CIDv1 with the default settings
52 -func V1CidPrefix() cid.Prefix { return v1CidPrefix }
53 -
54 -// PrefixForCidVersion returns the Protobuf prefix for a given CID version
55 -func PrefixForCidVersion(version int) (cid.Prefix, error) {
56 - switch version {
57 - case 0:
58 - return v0CidPrefix, nil
59 - case 1:
60 - return v1CidPrefix, nil
61 - default:
62 - return cid.Prefix{}, fmt.Errorf("unknown CID version: %d", version)
63 - }
64 -}
65 -
66 -// SetPrefix sets the CID prefix if it is non nil, if prefix is nil then
67 -// it resets it the default value
68 -func (n *ProtoNode) SetPrefix(prefix *cid.Prefix) {
69 - if prefix == nil {
70 - n.Prefix = v0CidPrefix
71 - } else {
72 - n.Prefix = *prefix
73 - n.Prefix.Codec = cid.DagProtobuf
74 - n.encoded = nil
75 - n.cached = nil
76 - }
77 -}
78 -
79 -// LinkSlice is a slice of ipld.Links
80 -type LinkSlice []*ipld.Link
81 -
82 -func (ls LinkSlice) Len() int { return len(ls) }
83 -func (ls LinkSlice) Swap(a, b int) { ls[a], ls[b] = ls[b], ls[a] }
84 -func (ls LinkSlice) Less(a, b int) bool { return ls[a].Name < ls[b].Name }
85 -
86 -// NodeWithData builds a new Protonode with the given data.
87 -func NodeWithData(d []byte) *ProtoNode {
88 - return &ProtoNode{data: d}
89 -}
90 -
91 -// AddNodeLink adds a link to another node.
92 -func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error {
93 - n.encoded = nil
94 -
95 - lnk, err := ipld.MakeLink(that)
96 - if err != nil {
97 - return err
98 - }
99 -
100 - lnk.Name = name
101 -
102 - n.AddRawLink(name, lnk)
103 -
104 - return nil
105 -}
106 -
107 -// AddRawLink adds a copy of a link to this node
108 -func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error {
109 - n.encoded = nil
110 - n.links = append(n.links, &ipld.Link{
111 - Name: name,
112 - Size: l.Size,
113 - Cid: l.Cid,
114 - })
115 -
116 - return nil
117 -}
118 -
119 -// RemoveNodeLink removes a link on this node by the given name.
120 -func (n *ProtoNode) RemoveNodeLink(name string) error {
121 - n.encoded = nil
122 - good := make([]*ipld.Link, 0, len(n.links))
123 - var found bool
124 -
125 - for _, l := range n.links {
126 - if l.Name != name {
127 - good = append(good, l)
128 - } else {
129 - found = true
130 - }
131 - }
132 - n.links = good
133 -
134 - if !found {
135 - return ipld.ErrNotFound
136 - }
137 -
138 - return nil
139 -}
140 -
141 -// GetNodeLink returns a copy of the link with the given name.
142 -func (n *ProtoNode) GetNodeLink(name string) (*ipld.Link, error) {
143 - for _, l := range n.links {
144 - if l.Name == name {
145 - return &ipld.Link{
146 - Name: l.Name,
147 - Size: l.Size,
148 - Cid: l.Cid,
149 - }, nil
150 - }
151 - }
152 - return nil, ErrLinkNotFound
153 -}
154 -
155 -// GetLinkedProtoNode returns a copy of the ProtoNode with the given name.
156 -func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds ipld.DAGService, name string) (*ProtoNode, error) {
157 - nd, err := n.GetLinkedNode(ctx, ds, name)
158 - if err != nil {
159 - return nil, err
160 - }
161 -
162 - pbnd, ok := nd.(*ProtoNode)
163 - if !ok {
164 - return nil, ErrNotProtobuf
165 - }
166 -
167 - return pbnd, nil
168 -}
169 -
170 -// GetLinkedNode returns a copy of the IPLD Node with the given name.
171 -func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds ipld.DAGService, name string) (ipld.Node, error) {
172 - lnk, err := n.GetNodeLink(name)
173 - if err != nil {
174 - return nil, err
175 - }
176 -
177 - return lnk.GetNode(ctx, ds)
178 -}
179 -
180 -// Copy returns a copy of the node.
181 -// NOTE: Does not make copies of Node objects in the links.
182 -func (n *ProtoNode) Copy() ipld.Node {
183 - nnode := new(ProtoNode)
184 - if len(n.data) > 0 {
185 - nnode.data = make([]byte, len(n.data))
186 - copy(nnode.data, n.data)
187 - }
188 -
189 - if len(n.links) > 0 {
190 - nnode.links = make([]*ipld.Link, len(n.links))
191 - copy(nnode.links, n.links)
192 - }
193 -
194 - nnode.Prefix = n.Prefix
195 -
196 - return nnode
197 -}
198 -
199 -// RawData returns the protobuf-encoded version of the node.
200 -func (n *ProtoNode) RawData() []byte {
201 - out, _ := n.EncodeProtobuf(false)
202 - return out
203 -}
204 -
205 -// Data returns the data stored by this node.
206 -func (n *ProtoNode) Data() []byte {
207 - return n.data
208 -}
209 -
210 -// SetData stores data in this nodes.
211 -func (n *ProtoNode) SetData(d []byte) {
212 - n.encoded = nil
213 - n.cached = nil
214 - n.data = d
215 -}
216 -
217 -// UpdateNodeLink return a copy of the node with the link name set to point to
218 -// that. If a link of the same name existed, it is removed.
219 -func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error) {
220 - newnode := n.Copy().(*ProtoNode)
221 - _ = newnode.RemoveNodeLink(name) // ignore error
222 - err := newnode.AddNodeLink(name, that)
223 - return newnode, err
224 -}
225 -
226 -// Size returns the total size of the data addressed by node,
227 -// including the total sizes of references.
228 -func (n *ProtoNode) Size() (uint64, error) {
229 - b, err := n.EncodeProtobuf(false)
230 - if err != nil {
231 - return 0, err
232 - }
233 -
234 - s := uint64(len(b))
235 - for _, l := range n.links {
236 - s += l.Size
237 - }
238 - return s, nil
239 -}
240 -
241 -// Stat returns statistics on the node.
242 -func (n *ProtoNode) Stat() (*ipld.NodeStat, error) {
243 - enc, err := n.EncodeProtobuf(false)
244 - if err != nil {
245 - return nil, err
246 - }
247 -
248 - cumSize, err := n.Size()
249 - if err != nil {
250 - return nil, err
251 - }
252 -
253 - return &ipld.NodeStat{
254 - Hash: n.Cid().String(),
255 - NumLinks: len(n.links),
256 - BlockSize: len(enc),
257 - LinksSize: len(enc) - len(n.data), // includes framing.
258 - DataSize: len(n.data),
259 - CumulativeSize: int(cumSize),
260 - }, nil
261 -}
262 -
263 -// Loggable implements the ipfs/go-log.Loggable interface.
264 -func (n *ProtoNode) Loggable() map[string]interface{} {
265 - return map[string]interface{}{
266 - "node": n.String(),
267 - }
268 -}
269 -
270 -// UnmarshalJSON reads the node fields from a JSON-encoded byte slice.
271 -func (n *ProtoNode) UnmarshalJSON(b []byte) error {
272 - s := struct {
273 - Data []byte `json:"data"`
274 - Links []*ipld.Link `json:"links"`
275 - }{}
276 -
277 - err := json.Unmarshal(b, &s)
278 - if err != nil {
279 - return err
280 - }
281 -
282 - n.data = s.Data
283 - n.links = s.Links
284 - return nil
285 -}
286 -
287 -// MarshalJSON returns a JSON representation of the node.
288 -func (n *ProtoNode) MarshalJSON() ([]byte, error) {
289 - out := map[string]interface{}{
290 - "data": n.data,
291 - "links": n.links,
292 - }
293 -
294 - return json.Marshal(out)
295 -}
296 -
297 -// Cid returns the node's Cid, calculated according to its prefix
298 -// and raw data contents.
299 -func (n *ProtoNode) Cid() *cid.Cid {
300 - if n.encoded != nil && n.cached != nil {
301 - return n.cached
302 - }
303 -
304 - if n.Prefix.Codec == 0 {
305 - n.SetPrefix(nil)
306 - }
307 -
308 - c, err := n.Prefix.Sum(n.RawData())
309 - if err != nil {
310 - // programmer error
311 - err = fmt.Errorf("invalid CID of length %d: %x: %v", len(n.RawData()), n.RawData(), err)
312 - panic(err)
313 - }
314 -
315 - n.cached = c
316 - return c
317 -}
318 -
319 -// String prints the node's Cid.
320 -func (n *ProtoNode) String() string {
321 - return n.Cid().String()
322 -}
323 -
324 -// Multihash hashes the encoded data of this node.
325 -func (n *ProtoNode) Multihash() mh.Multihash {
326 - // NOTE: EncodeProtobuf generates the hash and puts it in n.cached.
327 - _, err := n.EncodeProtobuf(false)
328 - if err != nil {
329 - // Note: no possibility exists for an error to be returned through here
330 - panic(err)
331 - }
332 -
333 - return n.cached.Hash()
334 -}
335 -
336 -// Links returns the node links.
337 -func (n *ProtoNode) Links() []*ipld.Link {
338 - return n.links
339 -}
340 -
341 -// SetLinks replaces the node links with the given ones.
342 -func (n *ProtoNode) SetLinks(links []*ipld.Link) {
343 - n.links = links
344 -}
345 -
346 -// Resolve is an alias for ResolveLink.
347 -func (n *ProtoNode) Resolve(path []string) (interface{}, []string, error) {
348 - return n.ResolveLink(path)
349 -}
350 -
351 -// ResolveLink consumes the first element of the path and obtains the link
352 -// corresponding to it from the node. It returns the link
353 -// and the path without the consumed element.
354 -func (n *ProtoNode) ResolveLink(path []string) (*ipld.Link, []string, error) {
355 - if len(path) == 0 {
356 - return nil, nil, fmt.Errorf("end of path, no more links to resolve")
357 - }
358 -
359 - lnk, err := n.GetNodeLink(path[0])
360 - if err != nil {
361 - return nil, nil, err
362 - }
363 -
364 - return lnk, path[1:], nil
365 -}
366 -
367 -// Tree returns the link names of the ProtoNode.
368 -// ProtoNodes are only ever one path deep, so anything different than an empty
369 -// string for p results in nothing. The depth parameter is ignored.
370 -func (n *ProtoNode) Tree(p string, depth int) []string {
371 - if p != "" {
372 - return nil
373 - }
374 -
375 - out := make([]string, 0, len(n.links))
376 - for _, lnk := range n.links {
377 - out = append(out, lnk.Name)
378 - }
379 - return out
380 -}
merkledag/node_test.go deleted
-165
@@ -1,165 +0,0 @@
1 -package merkledag_test
2 -
3 -import (
4 - "bytes"
5 - "context"
6 - "testing"
7 -
8 - . "github.com/ipfs/go-ipfs/merkledag"
9 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
10 -
11 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
12 -)
13 -
14 -func TestRemoveLink(t *testing.T) {
15 - nd := &ProtoNode{}
16 - nd.SetLinks([]*ipld.Link{
17 - {Name: "a"},
18 - {Name: "b"},
19 - {Name: "a"},
20 - {Name: "a"},
21 - {Name: "c"},
22 - {Name: "a"},
23 - })
24 -
25 - err := nd.RemoveNodeLink("a")
26 - if err != nil {
27 - t.Fatal(err)
28 - }
29 -
30 - if len(nd.Links()) != 2 {
31 - t.Fatal("number of links incorrect")
32 - }
33 -
34 - if nd.Links()[0].Name != "b" {
35 - t.Fatal("link order wrong")
36 - }
37 -
38 - if nd.Links()[1].Name != "c" {
39 - t.Fatal("link order wrong")
40 - }
41 -
42 - // should fail
43 - err = nd.RemoveNodeLink("a")
44 - if err != ipld.ErrNotFound {
45 - t.Fatal("should have failed to remove link")
46 - }
47 -
48 - // ensure nothing else got touched
49 - if len(nd.Links()) != 2 {
50 - t.Fatal("number of links incorrect")
51 - }
52 -
53 - if nd.Links()[0].Name != "b" {
54 - t.Fatal("link order wrong")
55 - }
56 -
57 - if nd.Links()[1].Name != "c" {
58 - t.Fatal("link order wrong")
59 - }
60 -}
61 -
62 -func TestFindLink(t *testing.T) {
63 - ctx := context.Background()
64 -
65 - ds := mdtest.Mock()
66 - ndEmpty := new(ProtoNode)
67 - err := ds.Add(ctx, ndEmpty)
68 - if err != nil {
69 - t.Fatal(err)
70 - }
71 -
72 - kEmpty := ndEmpty.Cid()
73 -
74 - nd := &ProtoNode{}
75 - nd.SetLinks([]*ipld.Link{
76 - {Name: "a", Cid: kEmpty},
77 - {Name: "c", Cid: kEmpty},
78 - {Name: "b", Cid: kEmpty},
79 - })
80 -
81 - err = ds.Add(ctx, nd)
82 - if err != nil {
83 - t.Fatal(err)
84 - }
85 -
86 - lnk, err := nd.GetNodeLink("b")
87 - if err != nil {
88 - t.Fatal(err)
89 - }
90 -
91 - if lnk.Name != "b" {
92 - t.Fatal("got wrong link back")
93 - }
94 -
95 - _, err = nd.GetNodeLink("f")
96 - if err != ErrLinkNotFound {
97 - t.Fatal("shouldnt have found link")
98 - }
99 -
100 - _, err = nd.GetLinkedNode(context.Background(), ds, "b")
101 - if err != nil {
102 - t.Fatal(err)
103 - }
104 -
105 - outnd, err := nd.UpdateNodeLink("b", nd)
106 - if err != nil {
107 - t.Fatal(err)
108 - }
109 -
110 - olnk, err := outnd.GetNodeLink("b")
111 - if err != nil {
112 - t.Fatal(err)
113 - }
114 -
115 - if olnk.Cid.String() == kEmpty.String() {
116 - t.Fatal("new link should have different hash")
117 - }
118 -}
119 -
120 -func TestNodeCopy(t *testing.T) {
121 - nd := &ProtoNode{}
122 - nd.SetLinks([]*ipld.Link{
123 - {Name: "a"},
124 - {Name: "c"},
125 - {Name: "b"},
126 - })
127 -
128 - nd.SetData([]byte("testing"))
129 -
130 - ond := nd.Copy().(*ProtoNode)
131 - ond.SetData(nil)
132 -
133 - if nd.Data() == nil {
134 - t.Fatal("should be different objects")
135 - }
136 -}
137 -
138 -func TestJsonRoundtrip(t *testing.T) {
139 - nd := new(ProtoNode)
140 - nd.SetLinks([]*ipld.Link{
141 - {Name: "a"},
142 - {Name: "c"},
143 - {Name: "b"},
144 - })
145 - nd.SetData([]byte("testing"))
146 -
147 - jb, err := nd.MarshalJSON()
148 - if err != nil {
149 - t.Fatal(err)
150 - }
151 -
152 - nn := new(ProtoNode)
153 - err = nn.UnmarshalJSON(jb)
154 - if err != nil {
155 - t.Fatal(err)
156 - }
157 -
158 - if !bytes.Equal(nn.Data(), nd.Data()) {
159 - t.Fatal("data wasnt the same")
160 - }
161 -
162 - if !nn.Cid().Equals(nd.Cid()) {
163 - t.Fatal("objects differed after marshaling")
164 - }
165 -}
merkledag/pb/Rules.mk deleted
-8
@@ -1,8 +0,0 @@
1 -include mk/header.mk
2 -
3 -PB_$(d) = $(wildcard $(d)/*.proto)
4 -TGTS_$(d) = $(PB_$(d):.proto=.pb.go)
5 -
6 -#DEPS_GO += $(TGTS_$(d))
7 -
8 -include mk/footer.mk
merkledag/pb/merkledag.pb.go deleted
-801
@@ -1,801 +0,0 @@
1 -// Code generated by protoc-gen-gogo.
2 -// source: merkledag.proto
3 -// DO NOT EDIT!
4 -
5 -/*
6 - Package merkledag_pb is a generated protocol buffer package.
7 -
8 - It is generated from these files:
9 - merkledag.proto
10 -
11 - It has these top-level messages:
12 - PBLink
13 - PBNode
14 -*/
15 -package merkledag_pb
16 -
17 -import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
18 -import math "math"
19 -
20 -// discarding unused import gogoproto "code.google.com/p/gogoprotobuf/gogoproto/gogo.pb"
21 -
22 -import io "io"
23 -import fmt "fmt"
24 -import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
25 -
26 -import strings "strings"
27 -import reflect "reflect"
28 -
29 -import sort "sort"
30 -import strconv "strconv"
31 -
32 -import bytes "bytes"
33 -
34 -// Reference imports to suppress errors if they are not otherwise used.
35 -var _ = proto.Marshal
36 -var _ = math.Inf
37 -
38 -// An IPFS MerkleDAG Link
39 -type PBLink struct {
40 - // multihash of the target object
41 - Hash []byte `protobuf:"bytes,1,opt" json:"Hash,omitempty"`
42 - // utf string name. should be unique per object
43 - Name *string `protobuf:"bytes,2,opt" json:"Name,omitempty"`
44 - // cumulative size of target object
45 - Tsize *uint64 `protobuf:"varint,3,opt" json:"Tsize,omitempty"`
46 - XXX_unrecognized []byte `json:"-"`
47 -}
48 -
49 -func (m *PBLink) Reset() { *m = PBLink{} }
50 -func (*PBLink) ProtoMessage() {}
51 -
52 -func (m *PBLink) GetHash() []byte {
53 - if m != nil {
54 - return m.Hash
55 - }
56 - return nil
57 -}
58 -
59 -func (m *PBLink) GetName() string {
60 - if m != nil && m.Name != nil {
61 - return *m.Name
62 - }
63 - return ""
64 -}
65 -
66 -func (m *PBLink) GetTsize() uint64 {
67 - if m != nil && m.Tsize != nil {
68 - return *m.Tsize
69 - }
70 - return 0
71 -}
72 -
73 -// An IPFS MerkleDAG Node
74 -type PBNode struct {
75 - // refs to other objects
76 - Links []*PBLink `protobuf:"bytes,2,rep" json:"Links,omitempty"`
77 - // opaque user data
78 - Data []byte `protobuf:"bytes,1,opt" json:"Data,omitempty"`
79 - XXX_unrecognized []byte `json:"-"`
80 -}
81 -
82 -func (m *PBNode) Reset() { *m = PBNode{} }
83 -func (*PBNode) ProtoMessage() {}
84 -
85 -func (m *PBNode) GetLinks() []*PBLink {
86 - if m != nil {
87 - return m.Links
88 - }
89 - return nil
90 -}
91 -
92 -func (m *PBNode) GetData() []byte {
93 - if m != nil {
94 - return m.Data
95 - }
96 - return nil
97 -}
98 -
99 -func init() {
100 -}
101 -func (m *PBLink) Unmarshal(data []byte) error {
102 - l := len(data)
103 - index := 0
104 - for index < l {
105 - var wire uint64
106 - for shift := uint(0); ; shift += 7 {
107 - if index >= l {
108 - return io.ErrUnexpectedEOF
109 - }
110 - b := data[index]
111 - index++
112 - wire |= (uint64(b) & 0x7F) << shift
113 - if b < 0x80 {
114 - break
115 - }
116 - }
117 - fieldNum := int32(wire >> 3)
118 - wireType := int(wire & 0x7)
119 - switch fieldNum {
120 - case 1:
121 - if wireType != 2 {
122 - return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
123 - }
124 - var byteLen int
125 - for shift := uint(0); ; shift += 7 {
126 - if index >= l {
127 - return io.ErrUnexpectedEOF
128 - }
129 - b := data[index]
130 - index++
131 - byteLen |= (int(b) & 0x7F) << shift
132 - if b < 0x80 {
133 - break
134 - }
135 - }
136 - postIndex := index + byteLen
137 - if postIndex > l {
138 - return io.ErrUnexpectedEOF
139 - }
140 - m.Hash = append([]byte{}, data[index:postIndex]...)
141 - index = postIndex
142 - case 2:
143 - if wireType != 2 {
144 - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
145 - }
146 - var stringLen uint64
147 - for shift := uint(0); ; shift += 7 {
148 - if index >= l {
149 - return io.ErrUnexpectedEOF
150 - }
151 - b := data[index]
152 - index++
153 - stringLen |= (uint64(b) & 0x7F) << shift
154 - if b < 0x80 {
155 - break
156 - }
157 - }
158 - postIndex := index + int(stringLen)
159 - if postIndex > l {
160 - return io.ErrUnexpectedEOF
161 - }
162 - s := string(data[index:postIndex])
163 - m.Name = &s
164 - index = postIndex
165 - case 3:
166 - if wireType != 0 {
167 - return fmt.Errorf("proto: wrong wireType = %d for field Tsize", wireType)
168 - }
169 - var v uint64
170 - for shift := uint(0); ; shift += 7 {
171 - if index >= l {
172 - return io.ErrUnexpectedEOF
173 - }
174 - b := data[index]
175 - index++
176 - v |= (uint64(b) & 0x7F) << shift
177 - if b < 0x80 {
178 - break
179 - }
180 - }
181 - m.Tsize = &v
182 - default:
183 - var sizeOfWire int
184 - for {
185 - sizeOfWire++
186 - wire >>= 7
187 - if wire == 0 {
188 - break
189 - }
190 - }
191 - index -= sizeOfWire
192 - skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
193 - if err != nil {
194 - return err
195 - }
196 - if (index + skippy) > l {
197 - return io.ErrUnexpectedEOF
198 - }
199 - m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...)
200 - index += skippy
201 - }
202 - }
203 - return nil
204 -}
205 -func (m *PBNode) Unmarshal(data []byte) error {
206 - l := len(data)
207 - index := 0
208 - for index < l {
209 - var wire uint64
210 - for shift := uint(0); ; shift += 7 {
211 - if index >= l {
212 - return io.ErrUnexpectedEOF
213 - }
214 - b := data[index]
215 - index++
216 - wire |= (uint64(b) & 0x7F) << shift
217 - if b < 0x80 {
218 - break
219 - }
220 - }
221 - fieldNum := int32(wire >> 3)
222 - wireType := int(wire & 0x7)
223 - switch fieldNum {
224 - case 2:
225 - if wireType != 2 {
226 - return fmt.Errorf("proto: wrong wireType = %d for field Links", wireType)
227 - }
228 - var msglen int
229 - for shift := uint(0); ; shift += 7 {
230 - if index >= l {
231 - return io.ErrUnexpectedEOF
232 - }
233 - b := data[index]
234 - index++
235 - msglen |= (int(b) & 0x7F) << shift
236 - if b < 0x80 {
237 - break
238 - }
239 - }
240 - postIndex := index + msglen
241 - if postIndex > l {
242 - return io.ErrUnexpectedEOF
243 - }
244 - m.Links = append(m.Links, &PBLink{})
245 - m.Links[len(m.Links)-1].Unmarshal(data[index:postIndex])
246 - index = postIndex
247 - case 1:
248 - if wireType != 2 {
249 - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
250 - }
251 - var byteLen int
252 - for shift := uint(0); ; shift += 7 {
253 - if index >= l {
254 - return io.ErrUnexpectedEOF
255 - }
256 - b := data[index]
257 - index++
258 - byteLen |= (int(b) & 0x7F) << shift
259 - if b < 0x80 {
260 - break
261 - }
262 - }
263 - postIndex := index + byteLen
264 - if postIndex > l {
265 - return io.ErrUnexpectedEOF
266 - }
267 - m.Data = append([]byte{}, data[index:postIndex]...)
268 - index = postIndex
269 - default:
270 - var sizeOfWire int
271 - for {
272 - sizeOfWire++
273 - wire >>= 7
274 - if wire == 0 {
275 - break
276 - }
277 - }
278 - index -= sizeOfWire
279 - skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
280 - if err != nil {
281 - return err
282 - }
283 - if (index + skippy) > l {
284 - return io.ErrUnexpectedEOF
285 - }
286 - m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...)
287 - index += skippy
288 - }
289 - }
290 - return nil
291 -}
292 -func (this *PBLink) String() string {
293 - if this == nil {
294 - return "nil"
295 - }
296 - s := strings.Join([]string{`&PBLink{`,
297 - `Hash:` + valueToStringMerkledag(this.Hash) + `,`,
298 - `Name:` + valueToStringMerkledag(this.Name) + `,`,
299 - `Tsize:` + valueToStringMerkledag(this.Tsize) + `,`,
300 - `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
301 - `}`,
302 - }, "")
303 - return s
304 -}
305 -func (this *PBNode) String() string {
306 - if this == nil {
307 - return "nil"
308 - }
309 - s := strings.Join([]string{`&PBNode{`,
310 - `Links:` + strings.Replace(fmt.Sprintf("%v", this.Links), "PBLink", "PBLink", 1) + `,`,
311 - `Data:` + valueToStringMerkledag(this.Data) + `,`,
312 - `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
313 - `}`,
314 - }, "")
315 - return s
316 -}
317 -func valueToStringMerkledag(v interface{}) string {
318 - rv := reflect.ValueOf(v)
319 - if rv.IsNil() {
320 - return "nil"
321 - }
322 - pv := reflect.Indirect(rv).Interface()
323 - return fmt.Sprintf("*%v", pv)
324 -}
325 -func (m *PBLink) Size() (n int) {
326 - var l int
327 - _ = l
328 - if m.Hash != nil {
329 - l = len(m.Hash)
330 - n += 1 + l + sovMerkledag(uint64(l))
331 - }
332 - if m.Name != nil {
333 - l = len(*m.Name)
334 - n += 1 + l + sovMerkledag(uint64(l))
335 - }
336 - if m.Tsize != nil {
337 - n += 1 + sovMerkledag(uint64(*m.Tsize))
338 - }
339 - if m.XXX_unrecognized != nil {
340 - n += len(m.XXX_unrecognized)
341 - }
342 - return n
343 -}
344 -
345 -func (m *PBNode) Size() (n int) {
346 - var l int
347 - _ = l
348 - if len(m.Links) > 0 {
349 - for _, e := range m.Links {
350 - l = e.Size()
351 - n += 1 + l + sovMerkledag(uint64(l))
352 - }
353 - }
354 - if m.Data != nil {
355 - l = len(m.Data)
356 - n += 1 + l + sovMerkledag(uint64(l))
357 - }
358 - if m.XXX_unrecognized != nil {
359 - n += len(m.XXX_unrecognized)
360 - }
361 - return n
362 -}
363 -
364 -func sovMerkledag(x uint64) (n int) {
365 - for {
366 - n++
367 - x >>= 7
368 - if x == 0 {
369 - break
370 - }
371 - }
372 - return n
373 -}
374 -func sozMerkledag(x uint64) (n int) {
375 - return sovMerkledag(uint64((x << 1) ^ uint64((int64(x) >> 63))))
376 -}
377 -func NewPopulatedPBLink(r randyMerkledag, easy bool) *PBLink {
378 - this := &PBLink{}
379 - if r.Intn(10) != 0 {
380 - v1 := r.Intn(100)
381 - this.Hash = make([]byte, v1)
382 - for i := 0; i < v1; i++ {
383 - this.Hash[i] = byte(r.Intn(256))
384 - }
385 - }
386 - if r.Intn(10) != 0 {
387 - v2 := randStringMerkledag(r)
388 - this.Name = &v2
389 - }
390 - if r.Intn(10) != 0 {
391 - v3 := uint64(r.Uint32())
392 - this.Tsize = &v3
393 - }
394 - if !easy && r.Intn(10) != 0 {
395 - this.XXX_unrecognized = randUnrecognizedMerkledag(r, 4)
396 - }
397 - return this
398 -}
399 -
400 -func NewPopulatedPBNode(r randyMerkledag, easy bool) *PBNode {
401 - this := &PBNode{}
402 - if r.Intn(10) != 0 {
403 - v4 := r.Intn(10)
404 - this.Links = make([]*PBLink, v4)
405 - for i := 0; i < v4; i++ {
406 - this.Links[i] = NewPopulatedPBLink(r, easy)
407 - }
408 - }
409 - if r.Intn(10) != 0 {
410 - v5 := r.Intn(100)
411 - this.Data = make([]byte, v5)
412 - for i := 0; i < v5; i++ {
413 - this.Data[i] = byte(r.Intn(256))
414 - }
415 - }
416 - if !easy && r.Intn(10) != 0 {
417 - this.XXX_unrecognized = randUnrecognizedMerkledag(r, 3)
418 - }
419 - return this
420 -}
421 -
422 -type randyMerkledag interface {
423 - Float32() float32
424 - Float64() float64
425 - Int63() int64
426 - Int31() int32
427 - Uint32() uint32
428 - Intn(n int) int
429 -}
430 -
431 -func randUTF8RuneMerkledag(r randyMerkledag) rune {
432 - return rune(r.Intn(126-43) + 43)
433 -}
434 -func randStringMerkledag(r randyMerkledag) string {
435 - v6 := r.Intn(100)
436 - tmps := make([]rune, v6)
437 - for i := 0; i < v6; i++ {
438 - tmps[i] = randUTF8RuneMerkledag(r)
439 - }
440 - return string(tmps)
441 -}
442 -func randUnrecognizedMerkledag(r randyMerkledag, maxFieldNumber int) (data []byte) {
443 - l := r.Intn(5)
444 - for i := 0; i < l; i++ {
445 - wire := r.Intn(4)
446 - if wire == 3 {
447 - wire = 5
448 - }
449 - fieldNumber := maxFieldNumber + r.Intn(100)
450 - data = randFieldMerkledag(data, r, fieldNumber, wire)
451 - }
452 - return data
453 -}
454 -func randFieldMerkledag(data []byte, r randyMerkledag, fieldNumber int, wire int) []byte {
455 - key := uint32(fieldNumber)<<3 | uint32(wire)
456 - switch wire {
457 - case 0:
458 - data = encodeVarintPopulateMerkledag(data, uint64(key))
459 - v7 := r.Int63()
460 - if r.Intn(2) == 0 {
461 - v7 *= -1
462 - }
463 - data = encodeVarintPopulateMerkledag(data, uint64(v7))
464 - case 1:
465 - data = encodeVarintPopulateMerkledag(data, uint64(key))
466 - data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
467 - case 2:
468 - data = encodeVarintPopulateMerkledag(data, uint64(key))
469 - ll := r.Intn(100)
470 - data = encodeVarintPopulateMerkledag(data, uint64(ll))
471 - for j := 0; j < ll; j++ {
472 - data = append(data, byte(r.Intn(256)))
473 - }
474 - default:
475 - data = encodeVarintPopulateMerkledag(data, uint64(key))
476 - data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
477 - }
478 - return data
479 -}
480 -func encodeVarintPopulateMerkledag(data []byte, v uint64) []byte {
481 - for v >= 1<<7 {
482 - data = append(data, uint8(uint64(v)&0x7f|0x80))
483 - v >>= 7
484 - }
485 - data = append(data, uint8(v))
486 - return data
487 -}
488 -func (m *PBLink) Marshal() (data []byte, err error) {
489 - size := m.Size()
490 - data = make([]byte, size)
491 - n, err := m.MarshalTo(data)
492 - if err != nil {
493 - return nil, err
494 - }
495 - return data[:n], nil
496 -}
497 -
498 -func (m *PBLink) MarshalTo(data []byte) (n int, err error) {
499 - var i int
500 - _ = i
501 - var l int
502 - _ = l
503 - if m.Hash != nil {
504 - data[i] = 0xa
505 - i++
506 - i = encodeVarintMerkledag(data, i, uint64(len(m.Hash)))
507 - i += copy(data[i:], m.Hash)
508 - }
509 - if m.Name != nil {
510 - data[i] = 0x12
511 - i++
512 - i = encodeVarintMerkledag(data, i, uint64(len(*m.Name)))
513 - i += copy(data[i:], *m.Name)
514 - }
515 - if m.Tsize != nil {
516 - data[i] = 0x18
517 - i++
518 - i = encodeVarintMerkledag(data, i, uint64(*m.Tsize))
519 - }
520 - if m.XXX_unrecognized != nil {
521 - i += copy(data[i:], m.XXX_unrecognized)
522 - }
523 - return i, nil
524 -}
525 -
526 -func (m *PBNode) Marshal() (data []byte, err error) {
527 - size := m.Size()
528 - data = make([]byte, size)
529 - n, err := m.MarshalTo(data)
530 - if err != nil {
531 - return nil, err
532 - }
533 - return data[:n], nil
534 -}
535 -
536 -func (m *PBNode) MarshalTo(data []byte) (n int, err error) {
537 - var i int
538 - _ = i
539 - var l int
540 - _ = l
541 - if len(m.Links) > 0 {
542 - for _, msg := range m.Links {
543 - data[i] = 0x12
544 - i++
545 - i = encodeVarintMerkledag(data, i, uint64(msg.Size()))
546 - n, err := msg.MarshalTo(data[i:])
547 - if err != nil {
548 - return 0, err
549 - }
550 - i += n
551 - }
552 - }
553 - if m.Data != nil {
554 - data[i] = 0xa
555 - i++
556 - i = encodeVarintMerkledag(data, i, uint64(len(m.Data)))
557 - i += copy(data[i:], m.Data)
558 - }
559 - if m.XXX_unrecognized != nil {
560 - i += copy(data[i:], m.XXX_unrecognized)
561 - }
562 - return i, nil
563 -}
564 -
565 -func encodeFixed64Merkledag(data []byte, offset int, v uint64) int {
566 - data[offset] = uint8(v)
567 - data[offset+1] = uint8(v >> 8)
568 - data[offset+2] = uint8(v >> 16)
569 - data[offset+3] = uint8(v >> 24)
570 - data[offset+4] = uint8(v >> 32)
571 - data[offset+5] = uint8(v >> 40)
572 - data[offset+6] = uint8(v >> 48)
573 - data[offset+7] = uint8(v >> 56)
574 - return offset + 8
575 -}
576 -func encodeFixed32Merkledag(data []byte, offset int, v uint32) int {
577 - data[offset] = uint8(v)
578 - data[offset+1] = uint8(v >> 8)
579 - data[offset+2] = uint8(v >> 16)
580 - data[offset+3] = uint8(v >> 24)
581 - return offset + 4
582 -}
583 -func encodeVarintMerkledag(data []byte, offset int, v uint64) int {
584 - for v >= 1<<7 {
585 - data[offset] = uint8(v&0x7f | 0x80)
586 - v >>= 7
587 - offset++
588 - }
589 - data[offset] = uint8(v)
590 - return offset + 1
591 -}
592 -func (this *PBLink) GoString() string {
593 - if this == nil {
594 - return "nil"
595 - }
596 - s := strings.Join([]string{`&merkledag_pb.PBLink{` +
597 - `Hash:` + valueToGoStringMerkledag(this.Hash, "byte"),
598 - `Name:` + valueToGoStringMerkledag(this.Name, "string"),
599 - `Tsize:` + valueToGoStringMerkledag(this.Tsize, "uint64"),
600 - `XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
601 - return s
602 -}
603 -func (this *PBNode) GoString() string {
604 - if this == nil {
605 - return "nil"
606 - }
607 - s := strings.Join([]string{`&merkledag_pb.PBNode{` +
608 - `Links:` + fmt.Sprintf("%#v", this.Links),
609 - `Data:` + valueToGoStringMerkledag(this.Data, "byte"),
610 - `XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
611 - return s
612 -}
613 -func valueToGoStringMerkledag(v interface{}, typ string) string {
614 - rv := reflect.ValueOf(v)
615 - if rv.IsNil() {
616 - return "nil"
617 - }
618 - pv := reflect.Indirect(rv).Interface()
619 - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
620 -}
621 -func extensionToGoStringMerkledag(e map[int32]github_com_gogo_protobuf_proto.Extension) string {
622 - if e == nil {
623 - return "nil"
624 - }
625 - s := "map[int32]proto.Extension{"
626 - keys := make([]int, 0, len(e))
627 - for k := range e {
628 - keys = append(keys, int(k))
629 - }
630 - sort.Ints(keys)
631 - ss := []string{}
632 - for _, k := range keys {
633 - ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString())
634 - }
635 - s += strings.Join(ss, ",") + "}"
636 - return s
637 -}
638 -func (this *PBLink) VerboseEqual(that interface{}) error {
639 - if that == nil {
640 - if this == nil {
641 - return nil
642 - }
643 - return fmt.Errorf("that == nil && this != nil")
644 - }
645 -
646 - that1, ok := that.(*PBLink)
647 - if !ok {
648 - return fmt.Errorf("that is not of type *PBLink")
649 - }
650 - if that1 == nil {
651 - if this == nil {
652 - return nil
653 - }
654 - return fmt.Errorf("that is type *PBLink but is nil && this != nil")
655 - } else if this == nil {
656 - return fmt.Errorf("that is type *PBLinkbut is not nil && this == nil")
657 - }
658 - if !bytes.Equal(this.Hash, that1.Hash) {
659 - return fmt.Errorf("Hash this(%v) Not Equal that(%v)", this.Hash, that1.Hash)
660 - }
661 - if this.Name != nil && that1.Name != nil {
662 - if *this.Name != *that1.Name {
663 - return fmt.Errorf("Name this(%v) Not Equal that(%v)", *this.Name, *that1.Name)
664 - }
665 - } else if this.Name != nil {
666 - return fmt.Errorf("this.Name == nil && that.Name != nil")
667 - } else if that1.Name != nil {
668 - return fmt.Errorf("Name this(%v) Not Equal that(%v)", this.Name, that1.Name)
669 - }
670 - if this.Tsize != nil && that1.Tsize != nil {
671 - if *this.Tsize != *that1.Tsize {
672 - return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", *this.Tsize, *that1.Tsize)
673 - }
674 - } else if this.Tsize != nil {
675 - return fmt.Errorf("this.Tsize == nil && that.Tsize != nil")
676 - } else if that1.Tsize != nil {
677 - return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", this.Tsize, that1.Tsize)
678 - }
679 - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
680 - return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
681 - }
682 - return nil
683 -}
684 -func (this *PBLink) Equal(that interface{}) bool {
685 - if that == nil {
686 - if this == nil {
687 - return true
688 - }
689 - return false
690 - }
691 -
692 - that1, ok := that.(*PBLink)
693 - if !ok {
694 - return false
695 - }
696 - if that1 == nil {
697 - if this == nil {
698 - return true
699 - }
700 - return false
701 - } else if this == nil {
702 - return false
703 - }
704 - if !bytes.Equal(this.Hash, that1.Hash) {
705 - return false
706 - }
707 - if this.Name != nil && that1.Name != nil {
708 - if *this.Name != *that1.Name {
709 - return false
710 - }
711 - } else if this.Name != nil {
712 - return false
713 - } else if that1.Name != nil {
714 - return false
715 - }
716 - if this.Tsize != nil && that1.Tsize != nil {
717 - if *this.Tsize != *that1.Tsize {
718 - return false
719 - }
720 - } else if this.Tsize != nil {
721 - return false
722 - } else if that1.Tsize != nil {
723 - return false
724 - }
725 - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
726 - return false
727 - }
728 - return true
729 -}
730 -func (this *PBNode) VerboseEqual(that interface{}) error {
731 - if that == nil {
732 - if this == nil {
733 - return nil
734 - }
735 - return fmt.Errorf("that == nil && this != nil")
736 - }
737 -
738 - that1, ok := that.(*PBNode)
739 - if !ok {
740 - return fmt.Errorf("that is not of type *PBNode")
741 - }
742 - if that1 == nil {
743 - if this == nil {
744 - return nil
745 - }
746 - return fmt.Errorf("that is type *PBNode but is nil && this != nil")
747 - } else if this == nil {
748 - return fmt.Errorf("that is type *PBNodebut is not nil && this == nil")
749 - }
750 - if len(this.Links) != len(that1.Links) {
751 - return fmt.Errorf("Links this(%v) Not Equal that(%v)", len(this.Links), len(that1.Links))
752 - }
753 - for i := range this.Links {
754 - if !this.Links[i].Equal(that1.Links[i]) {
755 - return fmt.Errorf("Links this[%v](%v) Not Equal that[%v](%v)", i, this.Links[i], i, that1.Links[i])
756 - }
757 - }
758 - if !bytes.Equal(this.Data, that1.Data) {
759 - return fmt.Errorf("Data this(%v) Not Equal that(%v)", this.Data, that1.Data)
760 - }
761 - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
762 - return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
763 - }
764 - return nil
765 -}
766 -func (this *PBNode) Equal(that interface{}) bool {
767 - if that == nil {
768 - if this == nil {
769 - return true
770 - }
771 - return false
772 - }
773 -
774 - that1, ok := that.(*PBNode)
775 - if !ok {
776 - return false
777 - }
778 - if that1 == nil {
779 - if this == nil {
780 - return true
781 - }
782 - return false
783 - } else if this == nil {
784 - return false
785 - }
786 - if len(this.Links) != len(that1.Links) {
787 - return false
788 - }
789 - for i := range this.Links {
790 - if !this.Links[i].Equal(that1.Links[i]) {
791 - return false
792 - }
793 - }
794 - if !bytes.Equal(this.Data, that1.Data) {
795 - return false
796 - }
797 - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
798 - return false
799 - }
800 - return true
801 -}
merkledag/pb/merkledag.proto deleted
-39
@@ -1,39 +0,0 @@
1 -package merkledag.pb;
2 -
3 -import "code.google.com/p/gogoprotobuf/gogoproto/gogo.proto";
4 -
5 -option (gogoproto.gostring_all) = true;
6 -option (gogoproto.equal_all) = true;
7 -option (gogoproto.verbose_equal_all) = true;
8 -option (gogoproto.goproto_stringer_all) = false;
9 -option (gogoproto.stringer_all) = true;
10 -option (gogoproto.populate_all) = true;
11 -option (gogoproto.testgen_all) = true;
12 -option (gogoproto.benchgen_all) = true;
13 -option (gogoproto.marshaler_all) = true;
14 -option (gogoproto.sizer_all) = true;
15 -option (gogoproto.unmarshaler_all) = true;
16 -
17 -
18 -// An IPFS MerkleDAG Link
19 -message PBLink {
20 -
21 - // multihash of the target object
22 - optional bytes Hash = 1;
23 -
24 - // utf string name. should be unique per object
25 - optional string Name = 2;
26 -
27 - // cumulative size of target object
28 - optional uint64 Tsize = 3;
29 -}
30 -
31 -// An IPFS MerkleDAG Node
32 -message PBNode {
33 -
34 - // refs to other objects
35 - repeated PBLink Links = 2;
36 -
37 - // opaque user data
38 - optional bytes Data = 1;
39 -}
merkledag/pb/merkledagpb_test.go deleted
-450
@@ -1,450 +0,0 @@
1 -// Code generated by protoc-gen-gogo.
2 -// source: merkledag.proto
3 -// DO NOT EDIT!
4 -
5 -/*
6 -Package merkledag_pb is a generated protocol buffer package.
7 -
8 -It is generated from these files:
9 - merkledag.proto
10 -
11 -It has these top-level messages:
12 - PBLink
13 - PBNode
14 -*/
15 -package merkledag_pb
16 -
17 -import testing "testing"
18 -import math_rand "math/rand"
19 -import time "time"
20 -import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
21 -import encoding_json "encoding/json"
22 -import fmt "fmt"
23 -import go_parser "go/parser"
24 -
25 -func TestPBLinkProto(t *testing.T) {
26 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
27 - p := NewPopulatedPBLink(popr, false)
28 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
29 - if err != nil {
30 - panic(err)
31 - }
32 - msg := &PBLink{}
33 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
34 - panic(err)
35 - }
36 - for i := range data {
37 - data[i] = byte(popr.Intn(256))
38 - }
39 - if err := p.VerboseEqual(msg); err != nil {
40 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
41 - }
42 - if !p.Equal(msg) {
43 - t.Fatalf("%#v !Proto %#v", msg, p)
44 - }
45 -}
46 -
47 -func TestPBLinkMarshalTo(t *testing.T) {
48 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
49 - p := NewPopulatedPBLink(popr, false)
50 - size := p.Size()
51 - data := make([]byte, size)
52 - for i := range data {
53 - data[i] = byte(popr.Intn(256))
54 - }
55 - _, err := p.MarshalTo(data)
56 - if err != nil {
57 - panic(err)
58 - }
59 - msg := &PBLink{}
60 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
61 - panic(err)
62 - }
63 - for i := range data {
64 - data[i] = byte(popr.Intn(256))
65 - }
66 - if err := p.VerboseEqual(msg); err != nil {
67 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
68 - }
69 - if !p.Equal(msg) {
70 - t.Fatalf("%#v !Proto %#v", msg, p)
71 - }
72 -}
73 -
74 -func BenchmarkPBLinkProtoMarshal(b *testing.B) {
75 - popr := math_rand.New(math_rand.NewSource(616))
76 - total := 0
77 - pops := make([]*PBLink, 10000)
78 - for i := 0; i < 10000; i++ {
79 - pops[i] = NewPopulatedPBLink(popr, false)
80 - }
81 - b.ResetTimer()
82 - for i := 0; i < b.N; i++ {
83 - data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
84 - if err != nil {
85 - panic(err)
86 - }
87 - total += len(data)
88 - }
89 - b.SetBytes(int64(total / b.N))
90 -}
91 -
92 -func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
93 - popr := math_rand.New(math_rand.NewSource(616))
94 - total := 0
95 - datas := make([][]byte, 10000)
96 - for i := 0; i < 10000; i++ {
97 - data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
98 - if err != nil {
99 - panic(err)
100 - }
101 - datas[i] = data
102 - }
103 - msg := &PBLink{}
104 - b.ResetTimer()
105 - for i := 0; i < b.N; i++ {
106 - total += len(datas[i%10000])
107 - if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
108 - panic(err)
109 - }
110 - }
111 - b.SetBytes(int64(total / b.N))
112 -}
113 -
114 -func TestPBNodeProto(t *testing.T) {
115 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
116 - p := NewPopulatedPBNode(popr, false)
117 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
118 - if err != nil {
119 - panic(err)
120 - }
121 - msg := &PBNode{}
122 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
123 - panic(err)
124 - }
125 - for i := range data {
126 - data[i] = byte(popr.Intn(256))
127 - }
128 - if err := p.VerboseEqual(msg); err != nil {
129 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
130 - }
131 - if !p.Equal(msg) {
132 - t.Fatalf("%#v !Proto %#v", msg, p)
133 - }
134 -}
135 -
136 -func TestPBNodeMarshalTo(t *testing.T) {
137 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
138 - p := NewPopulatedPBNode(popr, false)
139 - size := p.Size()
140 - data := make([]byte, size)
141 - for i := range data {
142 - data[i] = byte(popr.Intn(256))
143 - }
144 - _, err := p.MarshalTo(data)
145 - if err != nil {
146 - panic(err)
147 - }
148 - msg := &PBNode{}
149 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
150 - panic(err)
151 - }
152 - for i := range data {
153 - data[i] = byte(popr.Intn(256))
154 - }
155 - if err := p.VerboseEqual(msg); err != nil {
156 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
157 - }
158 - if !p.Equal(msg) {
159 - t.Fatalf("%#v !Proto %#v", msg, p)
160 - }
161 -}
162 -
163 -func BenchmarkPBNodeProtoMarshal(b *testing.B) {
164 - popr := math_rand.New(math_rand.NewSource(616))
165 - total := 0
166 - pops := make([]*PBNode, 10000)
167 - for i := 0; i < 10000; i++ {
168 - pops[i] = NewPopulatedPBNode(popr, false)
169 - }
170 - b.ResetTimer()
171 - for i := 0; i < b.N; i++ {
172 - data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
173 - if err != nil {
174 - panic(err)
175 - }
176 - total += len(data)
177 - }
178 - b.SetBytes(int64(total / b.N))
179 -}
180 -
181 -func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
182 - popr := math_rand.New(math_rand.NewSource(616))
183 - total := 0
184 - datas := make([][]byte, 10000)
185 - for i := 0; i < 10000; i++ {
186 - data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
187 - if err != nil {
188 - panic(err)
189 - }
190 - datas[i] = data
191 - }
192 - msg := &PBNode{}
193 - b.ResetTimer()
194 - for i := 0; i < b.N; i++ {
195 - total += len(datas[i%10000])
196 - if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
197 - panic(err)
198 - }
199 - }
200 - b.SetBytes(int64(total / b.N))
201 -}
202 -
203 -func TestPBLinkJSON(t *testing.T) {
204 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
205 - p := NewPopulatedPBLink(popr, true)
206 - jsondata, err := encoding_json.Marshal(p)
207 - if err != nil {
208 - panic(err)
209 - }
210 - msg := &PBLink{}
211 - err = encoding_json.Unmarshal(jsondata, msg)
212 - if err != nil {
213 - panic(err)
214 - }
215 - if err := p.VerboseEqual(msg); err != nil {
216 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
217 - }
218 - if !p.Equal(msg) {
219 - t.Fatalf("%#v !Json Equal %#v", msg, p)
220 - }
221 -}
222 -func TestPBNodeJSON(t *testing.T) {
223 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
224 - p := NewPopulatedPBNode(popr, true)
225 - jsondata, err := encoding_json.Marshal(p)
226 - if err != nil {
227 - panic(err)
228 - }
229 - msg := &PBNode{}
230 - err = encoding_json.Unmarshal(jsondata, msg)
231 - if err != nil {
232 - panic(err)
233 - }
234 - if err := p.VerboseEqual(msg); err != nil {
235 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
236 - }
237 - if !p.Equal(msg) {
238 - t.Fatalf("%#v !Json Equal %#v", msg, p)
239 - }
240 -}
241 -func TestPBLinkProtoText(t *testing.T) {
242 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
243 - p := NewPopulatedPBLink(popr, true)
244 - data := github_com_gogo_protobuf_proto.MarshalTextString(p)
245 - msg := &PBLink{}
246 - if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
247 - panic(err)
248 - }
249 - if err := p.VerboseEqual(msg); err != nil {
250 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
251 - }
252 - if !p.Equal(msg) {
253 - t.Fatalf("%#v !Proto %#v", msg, p)
254 - }
255 -}
256 -
257 -func TestPBLinkProtoCompactText(t *testing.T) {
258 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
259 - p := NewPopulatedPBLink(popr, true)
260 - data := github_com_gogo_protobuf_proto.CompactTextString(p)
261 - msg := &PBLink{}
262 - if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
263 - panic(err)
264 - }
265 - if err := p.VerboseEqual(msg); err != nil {
266 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
267 - }
268 - if !p.Equal(msg) {
269 - t.Fatalf("%#v !Proto %#v", msg, p)
270 - }
271 -}
272 -
273 -func TestPBNodeProtoText(t *testing.T) {
274 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
275 - p := NewPopulatedPBNode(popr, true)
276 - data := github_com_gogo_protobuf_proto.MarshalTextString(p)
277 - msg := &PBNode{}
278 - if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
279 - panic(err)
280 - }
281 - if err := p.VerboseEqual(msg); err != nil {
282 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
283 - }
284 - if !p.Equal(msg) {
285 - t.Fatalf("%#v !Proto %#v", msg, p)
286 - }
287 -}
288 -
289 -func TestPBNodeProtoCompactText(t *testing.T) {
290 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
291 - p := NewPopulatedPBNode(popr, true)
292 - data := github_com_gogo_protobuf_proto.CompactTextString(p)
293 - msg := &PBNode{}
294 - if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
295 - panic(err)
296 - }
297 - if err := p.VerboseEqual(msg); err != nil {
298 - t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
299 - }
300 - if !p.Equal(msg) {
301 - t.Fatalf("%#v !Proto %#v", msg, p)
302 - }
303 -}
304 -
305 -func TestPBLinkStringer(t *testing.T) {
306 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
307 - p := NewPopulatedPBLink(popr, false)
308 - s1 := p.String()
309 - s2 := fmt.Sprintf("%v", p)
310 - if s1 != s2 {
311 - t.Fatalf("String want %v got %v", s1, s2)
312 - }
313 -}
314 -func TestPBNodeStringer(t *testing.T) {
315 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
316 - p := NewPopulatedPBNode(popr, false)
317 - s1 := p.String()
318 - s2 := fmt.Sprintf("%v", p)
319 - if s1 != s2 {
320 - t.Fatalf("String want %v got %v", s1, s2)
321 - }
322 -}
323 -func TestPBLinkSize(t *testing.T) {
324 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
325 - p := NewPopulatedPBLink(popr, true)
326 - size2 := github_com_gogo_protobuf_proto.Size(p)
327 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
328 - if err != nil {
329 - panic(err)
330 - }
331 - size := p.Size()
332 - if len(data) != size {
333 - t.Fatalf("size %v != marshalled size %v", size, len(data))
334 - }
335 - if size2 != size {
336 - t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
337 - }
338 - size3 := github_com_gogo_protobuf_proto.Size(p)
339 - if size3 != size {
340 - t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
341 - }
342 -}
343 -
344 -func BenchmarkPBLinkSize(b *testing.B) {
345 - popr := math_rand.New(math_rand.NewSource(616))
346 - total := 0
347 - pops := make([]*PBLink, 1000)
348 - for i := 0; i < 1000; i++ {
349 - pops[i] = NewPopulatedPBLink(popr, false)
350 - }
351 - b.ResetTimer()
352 - for i := 0; i < b.N; i++ {
353 - total += pops[i%1000].Size()
354 - }
355 - b.SetBytes(int64(total / b.N))
356 -}
357 -
358 -func TestPBNodeSize(t *testing.T) {
359 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
360 - p := NewPopulatedPBNode(popr, true)
361 - size2 := github_com_gogo_protobuf_proto.Size(p)
362 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
363 - if err != nil {
364 - panic(err)
365 - }
366 - size := p.Size()
367 - if len(data) != size {
368 - t.Fatalf("size %v != marshalled size %v", size, len(data))
369 - }
370 - if size2 != size {
371 - t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
372 - }
373 - size3 := github_com_gogo_protobuf_proto.Size(p)
374 - if size3 != size {
375 - t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
376 - }
377 -}
378 -
379 -func BenchmarkPBNodeSize(b *testing.B) {
380 - popr := math_rand.New(math_rand.NewSource(616))
381 - total := 0
382 - pops := make([]*PBNode, 1000)
383 - for i := 0; i < 1000; i++ {
384 - pops[i] = NewPopulatedPBNode(popr, false)
385 - }
386 - b.ResetTimer()
387 - for i := 0; i < b.N; i++ {
388 - total += pops[i%1000].Size()
389 - }
390 - b.SetBytes(int64(total / b.N))
391 -}
392 -
393 -func TestPBLinkGoString(t *testing.T) {
394 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
395 - p := NewPopulatedPBLink(popr, false)
396 - s1 := p.GoString()
397 - s2 := fmt.Sprintf("%#v", p)
398 - if s1 != s2 {
399 - t.Fatalf("GoString want %v got %v", s1, s2)
400 - }
401 - _, err := go_parser.ParseExpr(s1)
402 - if err != nil {
403 - panic(err)
404 - }
405 -}
406 -func TestPBNodeGoString(t *testing.T) {
407 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
408 - p := NewPopulatedPBNode(popr, false)
409 - s1 := p.GoString()
410 - s2 := fmt.Sprintf("%#v", p)
411 - if s1 != s2 {
412 - t.Fatalf("GoString want %v got %v", s1, s2)
413 - }
414 - _, err := go_parser.ParseExpr(s1)
415 - if err != nil {
416 - panic(err)
417 - }
418 -}
419 -func TestPBLinkVerboseEqual(t *testing.T) {
420 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
421 - p := NewPopulatedPBLink(popr, false)
422 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
423 - if err != nil {
424 - panic(err)
425 - }
426 - msg := &PBLink{}
427 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
428 - panic(err)
429 - }
430 - if err := p.VerboseEqual(msg); err != nil {
431 - t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
432 - }
433 -}
434 -func TestPBNodeVerboseEqual(t *testing.T) {
435 - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
436 - p := NewPopulatedPBNode(popr, false)
437 - data, err := github_com_gogo_protobuf_proto.Marshal(p)
438 - if err != nil {
439 - panic(err)
440 - }
441 - msg := &PBNode{}
442 - if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
443 - panic(err)
444 - }
445 - if err := p.VerboseEqual(msg); err != nil {
446 - t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
447 - }
448 -}
449 -
450 -//These tests are generated by github.com/gogo/protobuf/plugin/testgen
merkledag/raw.go deleted
-101
@@ -1,101 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "fmt"
5 - "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
6 -
7 - u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
8 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
9 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
10 -)
11 -
12 -// RawNode represents a node which only contains data.
13 -type RawNode struct {
14 - blocks.Block
15 -}
16 -
17 -// NewRawNode creates a RawNode using the default sha2-256 hash function.
18 -func NewRawNode(data []byte) *RawNode {
19 - h := u.Hash(data)
20 - c := cid.NewCidV1(cid.Raw, h)
21 - blk, _ := blocks.NewBlockWithCid(data, c)
22 -
23 - return &RawNode{blk}
24 -}
25 -
26 -// DecodeRawBlock is a block decoder for raw IPLD nodes conforming to `node.DecodeBlockFunc`.
27 -func DecodeRawBlock(block blocks.Block) (ipld.Node, error) {
28 - if block.Cid().Type() != cid.Raw {
29 - return nil, fmt.Errorf("raw nodes cannot be decoded from non-raw blocks: %d", block.Cid().Type())
30 - }
31 - // Once you "share" a block, it should be immutable. Therefore, we can just use this block as-is.
32 - return &RawNode{block}, nil
33 -}
34 -
35 -var _ ipld.DecodeBlockFunc = DecodeRawBlock
36 -
37 -// NewRawNodeWPrefix creates a RawNode with the hash function
38 -// specified in prefix.
39 -func NewRawNodeWPrefix(data []byte, prefix cid.Prefix) (*RawNode, error) {
40 - prefix.Codec = cid.Raw
41 - if prefix.Version == 0 {
42 - prefix.Version = 1
43 - }
44 - c, err := prefix.Sum(data)
45 - if err != nil {
46 - return nil, err
47 - }
48 - blk, err := blocks.NewBlockWithCid(data, c)
49 - if err != nil {
50 - return nil, err
51 - }
52 - return &RawNode{blk}, nil
53 -}
54 -
55 -// Links returns nil.
56 -func (rn *RawNode) Links() []*ipld.Link {
57 - return nil
58 -}
59 -
60 -// ResolveLink returns an error.
61 -func (rn *RawNode) ResolveLink(path []string) (*ipld.Link, []string, error) {
62 - return nil, nil, ErrLinkNotFound
63 -}
64 -
65 -// Resolve returns an error.
66 -func (rn *RawNode) Resolve(path []string) (interface{}, []string, error) {
67 - return nil, nil, ErrLinkNotFound
68 -}
69 -
70 -// Tree returns nil.
71 -func (rn *RawNode) Tree(p string, depth int) []string {
72 - return nil
73 -}
74 -
75 -// Copy performs a deep copy of this node and returns it as an ipld.Node
76 -func (rn *RawNode) Copy() ipld.Node {
77 - copybuf := make([]byte, len(rn.RawData()))
78 - copy(copybuf, rn.RawData())
79 - nblk, err := blocks.NewBlockWithCid(rn.RawData(), rn.Cid())
80 - if err != nil {
81 - // programmer error
82 - panic("failure attempting to clone raw block: " + err.Error())
83 - }
84 -
85 - return &RawNode{nblk}
86 -}
87 -
88 -// Size returns the size of this node
89 -func (rn *RawNode) Size() (uint64, error) {
90 - return uint64(len(rn.RawData())), nil
91 -}
92 -
93 -// Stat returns some Stats about this node.
94 -func (rn *RawNode) Stat() (*ipld.NodeStat, error) {
95 - return &ipld.NodeStat{
96 - CumulativeSize: len(rn.RawData()),
97 - DataSize: len(rn.RawData()),
98 - }, nil
99 -}
100 -
101 -var _ ipld.Node = (*RawNode)(nil)
merkledag/readonly.go deleted
-20
@@ -1,20 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "fmt"
5 -
6 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
7 -)
8 -
9 -// ErrReadOnly is used when a read-only datastructure is written to.
10 -var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")
11 -
12 -// NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService
13 -// implementation that returns ErrReadOnly when its 'write' methods are
14 -// invoked.
15 -func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService {
16 - return &ComboService{
17 - Read: ng,
18 - Write: &ErrorService{ErrReadOnly},
19 - }
20 -}
merkledag/readonly_test.go deleted
-64
@@ -1,64 +0,0 @@
1 -package merkledag_test
2 -
3 -import (
4 - "context"
5 - "testing"
6 -
7 - . "github.com/ipfs/go-ipfs/merkledag"
8 - dstest "github.com/ipfs/go-ipfs/merkledag/test"
9 -
10 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
11 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
12 -)
13 -
14 -func TestReadonlyProperties(t *testing.T) {
15 - ds := dstest.Mock()
16 - ro := NewReadOnlyDagService(ds)
17 -
18 - ctx := context.Background()
19 - nds := []ipld.Node{
20 - NewRawNode([]byte("foo1")),
21 - NewRawNode([]byte("foo2")),
22 - NewRawNode([]byte("foo3")),
23 - NewRawNode([]byte("foo4")),
24 - }
25 - cids := []*cid.Cid{
26 - nds[0].Cid(),
27 - nds[1].Cid(),
28 - nds[2].Cid(),
29 - nds[3].Cid(),
30 - }
31 -
32 - // add to the actual underlying datastore
33 - if err := ds.Add(ctx, nds[2]); err != nil {
34 - t.Fatal(err)
35 - }
36 - if err := ds.Add(ctx, nds[3]); err != nil {
37 - t.Fatal(err)
38 - }
39 -
40 - if err := ro.Add(ctx, nds[0]); err != ErrReadOnly {
41 - t.Fatal("expected ErrReadOnly")
42 - }
43 - if err := ro.Add(ctx, nds[2]); err != ErrReadOnly {
44 - t.Fatal("expected ErrReadOnly")
45 - }
46 -
47 - if err := ro.AddMany(ctx, nds[0:1]); err != ErrReadOnly {
48 - t.Fatal("expected ErrReadOnly")
49 - }
50 -
51 - if err := ro.Remove(ctx, cids[3]); err != ErrReadOnly {
52 - t.Fatal("expected ErrReadOnly")
53 - }
54 - if err := ro.RemoveMany(ctx, cids[1:2]); err != ErrReadOnly {
55 - t.Fatal("expected ErrReadOnly")
56 - }
57 -
58 - if _, err := ro.Get(ctx, cids[0]); err != ipld.ErrNotFound {
59 - t.Fatal("expected ErrNotFound")
60 - }
61 - if _, err := ro.Get(ctx, cids[3]); err != nil {
62 - t.Fatal(err)
63 - }
64 -}
merkledag/rwservice.go deleted
-47
@@ -1,47 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "context"
5 -
6 - cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
7 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
8 -)
9 -
10 -// ComboService implements ipld.DAGService, using 'Read' for all fetch methods,
11 -// and 'Write' for all methods that add new objects.
12 -type ComboService struct {
13 - Read ipld.NodeGetter
14 - Write ipld.DAGService
15 -}
16 -
17 -var _ ipld.DAGService = (*ComboService)(nil)
18 -
19 -// Add writes a new node using the Write DAGService.
20 -func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error {
21 - return cs.Write.Add(ctx, nd)
22 -}
23 -
24 -// AddMany adds nodes using the Write DAGService.
25 -func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error {
26 - return cs.Write.AddMany(ctx, nds)
27 -}
28 -
29 -// Get fetches a node using the Read DAGService.
30 -func (cs *ComboService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
31 - return cs.Read.Get(ctx, c)
32 -}
33 -
34 -// GetMany fetches nodes using the Read DAGService.
35 -func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
36 - return cs.Read.GetMany(ctx, cids)
37 -}
38 -
39 -// Remove deletes a node using the Write DAGService.
40 -func (cs *ComboService) Remove(ctx context.Context, c *cid.Cid) error {
41 - return cs.Write.Remove(ctx, c)
42 -}
43 -
44 -// RemoveMany deletes nodes using the Write DAGService.
45 -func (cs *ComboService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
46 - return cs.Write.RemoveMany(ctx, cids)
47 -}
merkledag/session.go deleted
-21
@@ -1,21 +0,0 @@
1 -package merkledag
2 -
3 -import (
4 - "context"
5 -
6 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
7 -)
8 -
9 -// SessionMaker is an object that can generate a new fetching session.
10 -type SessionMaker interface {
11 - Session(context.Context) ipld.NodeGetter
12 -}
13 -
14 -// NewSession returns a session backed NodeGetter if the given NodeGetter
15 -// implements SessionMaker.
16 -func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter {
17 - if sm, ok := g.(SessionMaker); ok {
18 - return sm.Session(ctx)
19 - }
20 - return g
21 -}
merkledag/test/utils.go deleted
-23
@@ -1,23 +0,0 @@
1 -package mdutils
2 -
3 -import (
4 - dag "github.com/ipfs/go-ipfs/merkledag"
5 - bsrv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
6 -
7 - offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
8 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
9 - blockstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
10 - ds "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore"
11 - dssync "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore/sync"
12 -)
13 -
14 -// Mock returns a new thread-safe, mock DAGService.
15 -func Mock() ipld.DAGService {
16 - return dag.NewDAGService(Bserv())
17 -}
18 -
19 -// Bserv returns a new, thread-safe, mock BlockService.
20 -func Bserv() bsrv.BlockService {
21 - bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
22 - return bsrv.New(bstore, offline.Exchange(bstore))
23 -}
merkledag/traverse/traverse.go deleted
-223
@@ -1,223 +0,0 @@
1 -// Package traverse provides merkledag traversal functions
2 -package traverse
3 -
4 -import (
5 - "context"
6 - "errors"
7 -
8 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
9 -)
10 -
11 -// Order is an identifier for traversal algorithm orders
12 -type Order int
13 -
14 -// These constants define different traversing methods
15 -const (
16 - // DFSPre defines depth-first pre-order
17 - DFSPre Order = iota
18 - // DFSPost defines depth-first post-order
19 - DFSPost
20 - // BFS defines breadth-first order
21 - BFS
22 -)
23 -
24 -// Options specifies a series of traversal options
25 -type Options struct {
26 - DAG ipld.NodeGetter // the dagservice to fetch nodes
27 - Order Order // what order to traverse in
28 - Func Func // the function to perform at each step
29 - ErrFunc ErrFunc // see ErrFunc. Optional
30 -
31 - SkipDuplicates bool // whether to skip duplicate nodes
32 -}
33 -
34 -// State is a current traversal state
35 -type State struct {
36 - Node ipld.Node
37 - Depth int
38 -}
39 -
40 -type traversal struct {
41 - opts Options
42 - seen map[string]struct{}
43 -}
44 -
45 -func (t *traversal) shouldSkip(n ipld.Node) (bool, error) {
46 - if t.opts.SkipDuplicates {
47 - k := n.Cid()
48 - if _, found := t.seen[k.KeyString()]; found {
49 - return true, nil
50 - }
51 - t.seen[k.KeyString()] = struct{}{}
52 - }
53 -
54 - return false, nil
55 -}
56 -
57 -func (t *traversal) callFunc(next State) error {
58 - return t.opts.Func(next)
59 -}
60 -
61 -// getNode returns the node for link. If it return an error,
62 -// stop processing. if it returns a nil node, just skip it.
63 -//
64 -// the error handling is a little complicated.
65 -func (t *traversal) getNode(link *ipld.Link) (ipld.Node, error) {
66 -
67 - getNode := func(l *ipld.Link) (ipld.Node, error) {
68 - next, err := l.GetNode(context.TODO(), t.opts.DAG)
69 - if err != nil {
70 - return nil, err
71 - }
72 -
73 - skip, err := t.shouldSkip(next)
74 - if skip {
75 - next = nil
76 - }
77 - return next, err
78 - }
79 -
80 - next, err := getNode(link)
81 - if err != nil && t.opts.ErrFunc != nil { // attempt recovery.
82 - err = t.opts.ErrFunc(err)
83 - next = nil // skip regardless
84 - }
85 - return next, err
86 -}
87 -
88 -// Func is the type of the function called for each dag.Node visited by Traverse.
89 -// The traversal argument contains the current traversal state.
90 -// If an error is returned, processing stops.
91 -type Func func(current State) error
92 -
93 -// ErrFunc is provided to handle problems when walking to the Node. Traverse
94 -// will call ErrFunc with the error encountered. ErrFunc can decide how to
95 -// handle that error, and return an error back to Traversal with how to proceed:
96 -// * nil - skip the Node and its children, but continue processing
97 -// * all other errors halt processing immediately.
98 -//
99 -// If ErrFunc is nil, Traversal will stop, as if:
100 -//
101 -// opts.ErrFunc = func(err error) { return err }
102 -//
103 -type ErrFunc func(err error) error
104 -
105 -// Traverse initiates a DAG traversal with the given options starting at
106 -// the given root.
107 -func Traverse(root ipld.Node, o Options) error {
108 - t := traversal{
109 - opts: o,
110 - seen: map[string]struct{}{},
111 - }
112 -
113 - state := State{
114 - Node: root,
115 - Depth: 0,
116 - }
117 -
118 - switch o.Order {
119 - default:
120 - return dfsPreTraverse(state, &t)
121 - case DFSPre:
122 - return dfsPreTraverse(state, &t)
123 - case DFSPost:
124 - return dfsPostTraverse(state, &t)
125 - case BFS:
126 - return bfsTraverse(state, &t)
127 - }
128 -}
129 -
130 -type dfsFunc func(state State, t *traversal) error
131 -
132 -func dfsPreTraverse(state State, t *traversal) error {
133 - if err := t.callFunc(state); err != nil {
134 - return err
135 - }
136 - return dfsDescend(dfsPreTraverse, state, t)
137 -}
138 -
139 -func dfsPostTraverse(state State, t *traversal) error {
140 - if err := dfsDescend(dfsPostTraverse, state, t); err != nil {
141 - return err
142 - }
143 - return t.callFunc(state)
144 -}
145 -
146 -func dfsDescend(df dfsFunc, curr State, t *traversal) error {
147 - for _, l := range curr.Node.Links() {
148 - node, err := t.getNode(l)
149 - if err != nil {
150 - return err
151 - }
152 - if node == nil { // skip
153 - continue
154 - }
155 -
156 - next := State{
157 - Node: node,
158 - Depth: curr.Depth + 1,
159 - }
160 - if err := df(next, t); err != nil {
161 - return err
162 - }
163 - }
164 - return nil
165 -}
166 -
167 -func bfsTraverse(root State, t *traversal) error {
168 -
169 - if skip, err := t.shouldSkip(root.Node); skip || err != nil {
170 - return err
171 - }
172 -
173 - var q queue
174 - q.enq(root)
175 - for q.len() > 0 {
176 - curr := q.deq()
177 - if curr.Node == nil {
178 - return errors.New("failed to dequeue though queue not empty")
179 - }
180 -
181 - // call user's func
182 - if err := t.callFunc(curr); err != nil {
183 - return err
184 - }
185 -
186 - for _, l := range curr.Node.Links() {
187 - node, err := t.getNode(l)
188 - if err != nil {
189 - return err
190 - }
191 - if node == nil { // skip
192 - continue
193 - }
194 -
195 - q.enq(State{
196 - Node: node,
197 - Depth: curr.Depth + 1,
198 - })
199 - }
200 - }
201 - return nil
202 -}
203 -
204 -type queue struct {
205 - s []State
206 -}
207 -
208 -func (q *queue) enq(n State) {
209 - q.s = append(q.s, n)
210 -}
211 -
212 -func (q *queue) deq() State {
213 - if len(q.s) < 1 {
214 - return State{}
215 - }
216 - n := q.s[0]
217 - q.s = q.s[1:]
218 - return n
219 -}
220 -
221 -func (q *queue) len() int {
222 - return len(q.s)
223 -}
merkledag/traverse/traverse_test.go deleted
-418
@@ -1,418 +0,0 @@
1 -package traverse
2 -
3 -import (
4 - "bytes"
5 - "context"
6 - "fmt"
7 - "testing"
8 -
9 - mdag "github.com/ipfs/go-ipfs/merkledag"
10 - mdagtest "github.com/ipfs/go-ipfs/merkledag/test"
11 -
12 - ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
13 -)
14 -
15 -func TestDFSPreNoSkip(t *testing.T) {
16 - ds := mdagtest.Mock()
17 - opts := Options{Order: DFSPre, DAG: ds}
18 -
19 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
20 -0 /a
21 -1 /a/aa
22 -1 /a/ab
23 -1 /a/ac
24 -1 /a/ad
25 -`))
26 -
27 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
28 -0 /a
29 -1 /a/aa
30 -2 /a/aa/aaa
31 -3 /a/aa/aaa/aaaa
32 -4 /a/aa/aaa/aaaa/aaaaa
33 -`))
34 -
35 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
36 -0 /a
37 -1 /a/aa
38 -2 /a/aa/aaa
39 -2 /a/aa/aab
40 -1 /a/ab
41 -2 /a/ab/aba
42 -2 /a/ab/abb
43 -`))
44 -
45 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
46 -0 /a
47 -1 /a/aa
48 -2 /a/aa/aaa
49 -3 /a/aa/aaa/aaaa
50 -4 /a/aa/aaa/aaaa/aaaaa
51 -4 /a/aa/aaa/aaaa/aaaaa
52 -3 /a/aa/aaa/aaaa
53 -4 /a/aa/aaa/aaaa/aaaaa
54 -4 /a/aa/aaa/aaaa/aaaaa
55 -2 /a/aa/aaa
56 -3 /a/aa/aaa/aaaa
57 -4 /a/aa/aaa/aaaa/aaaaa
58 -4 /a/aa/aaa/aaaa/aaaaa
59 -3 /a/aa/aaa/aaaa
60 -4 /a/aa/aaa/aaaa/aaaaa
61 -4 /a/aa/aaa/aaaa/aaaaa
62 -1 /a/aa
63 -2 /a/aa/aaa
64 -3 /a/aa/aaa/aaaa
65 -4 /a/aa/aaa/aaaa/aaaaa
66 -4 /a/aa/aaa/aaaa/aaaaa
67 -3 /a/aa/aaa/aaaa
68 -4 /a/aa/aaa/aaaa/aaaaa
69 -4 /a/aa/aaa/aaaa/aaaaa
70 -2 /a/aa/aaa
71 -3 /a/aa/aaa/aaaa
72 -4 /a/aa/aaa/aaaa/aaaaa
73 -4 /a/aa/aaa/aaaa/aaaaa
74 -3 /a/aa/aaa/aaaa
75 -4 /a/aa/aaa/aaaa/aaaaa
76 -4 /a/aa/aaa/aaaa/aaaaa
77 -`))
78 -}
79 -
80 -func TestDFSPreSkip(t *testing.T) {
81 - ds := mdagtest.Mock()
82 - opts := Options{Order: DFSPre, SkipDuplicates: true, DAG: ds}
83 -
84 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
85 -0 /a
86 -1 /a/aa
87 -1 /a/ab
88 -1 /a/ac
89 -1 /a/ad
90 -`))
91 -
92 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
93 -0 /a
94 -1 /a/aa
95 -2 /a/aa/aaa
96 -3 /a/aa/aaa/aaaa
97 -4 /a/aa/aaa/aaaa/aaaaa
98 -`))
99 -
100 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
101 -0 /a
102 -1 /a/aa
103 -2 /a/aa/aaa
104 -2 /a/aa/aab
105 -1 /a/ab
106 -2 /a/ab/aba
107 -2 /a/ab/abb
108 -`))
109 -
110 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
111 -0 /a
112 -1 /a/aa
113 -2 /a/aa/aaa
114 -3 /a/aa/aaa/aaaa
115 -4 /a/aa/aaa/aaaa/aaaaa
116 -`))
117 -}
118 -
119 -func TestDFSPostNoSkip(t *testing.T) {
120 - ds := mdagtest.Mock()
121 - opts := Options{Order: DFSPost, DAG: ds}
122 -
123 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
124 -1 /a/aa
125 -1 /a/ab
126 -1 /a/ac
127 -1 /a/ad
128 -0 /a
129 -`))
130 -
131 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
132 -4 /a/aa/aaa/aaaa/aaaaa
133 -3 /a/aa/aaa/aaaa
134 -2 /a/aa/aaa
135 -1 /a/aa
136 -0 /a
137 -`))
138 -
139 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
140 -2 /a/aa/aaa
141 -2 /a/aa/aab
142 -1 /a/aa
143 -2 /a/ab/aba
144 -2 /a/ab/abb
145 -1 /a/ab
146 -0 /a
147 -`))
148 -
149 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
150 -4 /a/aa/aaa/aaaa/aaaaa
151 -4 /a/aa/aaa/aaaa/aaaaa
152 -3 /a/aa/aaa/aaaa
153 -4 /a/aa/aaa/aaaa/aaaaa
154 -4 /a/aa/aaa/aaaa/aaaaa
155 -3 /a/aa/aaa/aaaa
156 -2 /a/aa/aaa
157 -4 /a/aa/aaa/aaaa/aaaaa
158 -4 /a/aa/aaa/aaaa/aaaaa
159 -3 /a/aa/aaa/aaaa
160 -4 /a/aa/aaa/aaaa/aaaaa
161 -4 /a/aa/aaa/aaaa/aaaaa
162 -3 /a/aa/aaa/aaaa
163 -2 /a/aa/aaa
164 -1 /a/aa
165 -4 /a/aa/aaa/aaaa/aaaaa
166 -4 /a/aa/aaa/aaaa/aaaaa
167 -3 /a/aa/aaa/aaaa
168 -4 /a/aa/aaa/aaaa/aaaaa
169 -4 /a/aa/aaa/aaaa/aaaaa
170 -3 /a/aa/aaa/aaaa
171 -2 /a/aa/aaa
172 -4 /a/aa/aaa/aaaa/aaaaa
173 -4 /a/aa/aaa/aaaa/aaaaa
174 -3 /a/aa/aaa/aaaa
175 -4 /a/aa/aaa/aaaa/aaaaa
176 -4 /a/aa/aaa/aaaa/aaaaa
177 -3 /a/aa/aaa/aaaa
178 -2 /a/aa/aaa
179 -1 /a/aa
180 -0 /a
181 -`))
182 -}
183 -
184 -func TestDFSPostSkip(t *testing.T) {
185 - ds := mdagtest.Mock()
186 - opts := Options{Order: DFSPost, SkipDuplicates: true, DAG: ds}
187 -
188 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
189 -1 /a/aa
190 -1 /a/ab
191 -1 /a/ac
192 -1 /a/ad
193 -0 /a
194 -`))
195 -
196 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
197 -4 /a/aa/aaa/aaaa/aaaaa
198 -3 /a/aa/aaa/aaaa
199 -2 /a/aa/aaa
200 -1 /a/aa
201 -0 /a
202 -`))
203 -
204 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
205 -2 /a/aa/aaa
206 -2 /a/aa/aab
207 -1 /a/aa
208 -2 /a/ab/aba
209 -2 /a/ab/abb
210 -1 /a/ab
211 -0 /a
212 -`))
213 -
214 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
215 -4 /a/aa/aaa/aaaa/aaaaa
216 -3 /a/aa/aaa/aaaa
217 -2 /a/aa/aaa
218 -1 /a/aa
219 -0 /a
220 -`))
221 -}
222 -
223 -func TestBFSNoSkip(t *testing.T) {
224 - ds := mdagtest.Mock()
225 - opts := Options{Order: BFS, DAG: ds}
226 -
227 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
228 -0 /a
229 -1 /a/aa
230 -1 /a/ab
231 -1 /a/ac
232 -1 /a/ad
233 -`))
234 -
235 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
236 -0 /a
237 -1 /a/aa
238 -2 /a/aa/aaa
239 -3 /a/aa/aaa/aaaa
240 -4 /a/aa/aaa/aaaa/aaaaa
241 -`))
242 -
243 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
244 -0 /a
245 -1 /a/aa
246 -1 /a/ab
247 -2 /a/aa/aaa
248 -2 /a/aa/aab
249 -2 /a/ab/aba
250 -2 /a/ab/abb
251 -`))
252 -
253 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
254 -0 /a
255 -1 /a/aa
256 -1 /a/aa
257 -2 /a/aa/aaa
258 -2 /a/aa/aaa
259 -2 /a/aa/aaa
260 -2 /a/aa/aaa
261 -3 /a/aa/aaa/aaaa
262 -3 /a/aa/aaa/aaaa
263 -3 /a/aa/aaa/aaaa
264 -3 /a/aa/aaa/aaaa
265 -3 /a/aa/aaa/aaaa
266 -3 /a/aa/aaa/aaaa
267 -3 /a/aa/aaa/aaaa
268 -3 /a/aa/aaa/aaaa
269 -4 /a/aa/aaa/aaaa/aaaaa
270 -4 /a/aa/aaa/aaaa/aaaaa
271 -4 /a/aa/aaa/aaaa/aaaaa
272 -4 /a/aa/aaa/aaaa/aaaaa
273 -4 /a/aa/aaa/aaaa/aaaaa
274 -4 /a/aa/aaa/aaaa/aaaaa
275 -4 /a/aa/aaa/aaaa/aaaaa
276 -4 /a/aa/aaa/aaaa/aaaaa
277 -4 /a/aa/aaa/aaaa/aaaaa
278 -4 /a/aa/aaa/aaaa/aaaaa
279 -4 /a/aa/aaa/aaaa/aaaaa
280 -4 /a/aa/aaa/aaaa/aaaaa
281 -4 /a/aa/aaa/aaaa/aaaaa
282 -4 /a/aa/aaa/aaaa/aaaaa
283 -4 /a/aa/aaa/aaaa/aaaaa
284 -4 /a/aa/aaa/aaaa/aaaaa
285 -`))
286 -}
287 -
288 -func TestBFSSkip(t *testing.T) {
289 - ds := mdagtest.Mock()
290 - opts := Options{Order: BFS, SkipDuplicates: true, DAG: ds}
291 -
292 - testWalkOutputs(t, newFan(t, ds), opts, []byte(`
293 -0 /a
294 -1 /a/aa
295 -1 /a/ab
296 -1 /a/ac
297 -1 /a/ad
298 -`))
299 -
300 - testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
301 -0 /a
302 -1 /a/aa
303 -2 /a/aa/aaa
304 -3 /a/aa/aaa/aaaa
305 -4 /a/aa/aaa/aaaa/aaaaa
306 -`))
307 -
308 - testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
309 -0 /a
310 -1 /a/aa
311 -1 /a/ab
312 -2 /a/aa/aaa
313 -2 /a/aa/aab
314 -2 /a/ab/aba
315 -2 /a/ab/abb
316 -`))
317 -
318 - testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
319 -0 /a
320 -1 /a/aa
321 -2 /a/aa/aaa
322 -3 /a/aa/aaa/aaaa
323 -4 /a/aa/aaa/aaaa/aaaaa
324 -`))
325 -}
326 -
327 -func testWalkOutputs(t *testing.T, root ipld.Node, opts Options, expect []byte) {
328 - expect = bytes.TrimLeft(expect, "\n")
329 -
330 - buf := new(bytes.Buffer)
331 - walk := func(current State) error {
332 - s := fmt.Sprintf("%d %s\n", current.Depth, current.Node.(*mdag.ProtoNode).Data())
333 - t.Logf("walk: %s", s)
334 - buf.Write([]byte(s))
335 - return nil
336 - }
337 -
338 - opts.Func = walk
339 - if err := Traverse(root, opts); err != nil {
340 - t.Error(err)
341 - return
342 - }
343 -
344 - actual := buf.Bytes()
345 - if !bytes.Equal(actual, expect) {
346 - t.Error("error: outputs differ")
347 - t.Logf("expect:\n%s", expect)
348 - t.Logf("actual:\n%s", actual)
349 - } else {
350 - t.Logf("expect matches actual:\n%s", expect)
351 - }
352 -}
353 -
354 -func newFan(t *testing.T, ds ipld.DAGService) ipld.Node {
355 - a := mdag.NodeWithData([]byte("/a"))
356 - addLink(t, ds, a, child(t, ds, a, "aa"))
357 - addLink(t, ds, a, child(t, ds, a, "ab"))
358 - addLink(t, ds, a, child(t, ds, a, "ac"))
359 - addLink(t, ds, a, child(t, ds, a, "ad"))
360 - return a
361 -}
362 -
363 -func newLinkedList(t *testing.T, ds ipld.DAGService) ipld.Node {
364 - a := mdag.NodeWithData([]byte("/a"))
365 - aa := child(t, ds, a, "aa")
366 - aaa := child(t, ds, aa, "aaa")
367 - aaaa := child(t, ds, aaa, "aaaa")
368 - aaaaa := child(t, ds, aaaa, "aaaaa")
369 - addLink(t, ds, aaaa, aaaaa)
370 - addLink(t, ds, aaa, aaaa)
371 - addLink(t, ds, aa, aaa)
372 - addLink(t, ds, a, aa)
373 - return a
374 -}
375 -
376 -func newBinaryTree(t *testing.T, ds ipld.DAGService) ipld.Node {
377 - a := mdag.NodeWithData([]byte("/a"))
378 - aa := child(t, ds, a, "aa")
379 - ab := child(t, ds, a, "ab")
380 - addLink(t, ds, aa, child(t, ds, aa, "aaa"))
381 - addLink(t, ds, aa, child(t, ds, aa, "aab"))
382 - addLink(t, ds, ab, child(t, ds, ab, "aba"))
383 - addLink(t, ds, ab, child(t, ds, ab, "abb"))
384 - addLink(t, ds, a, aa)
385 - addLink(t, ds, a, ab)
386 - return a
387 -}
388 -
389 -func newBinaryDAG(t *testing.T, ds ipld.DAGService) ipld.Node {
390 - a := mdag.NodeWithData([]byte("/a"))
391 - aa := child(t, ds, a, "aa")
392 - aaa := child(t, ds, aa, "aaa")
393 - aaaa := child(t, ds, aaa, "aaaa")
394 - aaaaa := child(t, ds, aaaa, "aaaaa")
395 - addLink(t, ds, aaaa, aaaaa)
396 - addLink(t, ds, aaaa, aaaaa)
397 - addLink(t, ds, aaa, aaaa)
398 - addLink(t, ds, aaa, aaaa)
399 - addLink(t, ds, aa, aaa)
400 - addLink(t, ds, aa, aaa)
401 - addLink(t, ds, a, aa)
402 - addLink(t, ds, a, aa)
403 - return a
404 -}
405 -
406 -func addLink(t *testing.T, ds ipld.DAGService, a, b ipld.Node) {
407 - to := string(a.(*mdag.ProtoNode).Data()) + "2" + string(b.(*mdag.ProtoNode).Data())
408 - if err := ds.Add(context.Background(), b); err != nil {
409 - t.Error(err)
410 - }
411 - if err := a.(*mdag.ProtoNode).AddNodeLink(to, b.(*mdag.ProtoNode)); err != nil {
412 - t.Error(err)
413 - }
414 -}
415 -
416 -func child(t *testing.T, ds ipld.DAGService, a ipld.Node, name string) ipld.Node {
417 - return mdag.NodeWithData([]byte(string(a.(*mdag.ProtoNode).Data()) + "/" + name))
418 -}
mfs/dir.go
+1 -1
@@ -9,10 +9,10 @@ import (
9 "sync"
10 "time"
11
12 - dag "github.com/ipfs/go-ipfs/merkledag"
12 ft "github.com/ipfs/go-ipfs/unixfs"
13 uio "github.com/ipfs/go-ipfs/unixfs/io"
14 ufspb "github.com/ipfs/go-ipfs/unixfs/pb"
15 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
16
17 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
18 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
mfs/file.go
+1 -1
@@ -5,9 +5,9 @@ import (
5 "fmt"
6 "sync"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
8 ft "github.com/ipfs/go-ipfs/unixfs"
9 mod "github.com/ipfs/go-ipfs/unixfs/mod"
10 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11
12 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
13 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
mfs/mfs_test.go
+1 -1
@@ -15,11 +15,11 @@ import (
15 "time"
16
17 importer "github.com/ipfs/go-ipfs/importer"
18 - dag "github.com/ipfs/go-ipfs/merkledag"
18 "github.com/ipfs/go-ipfs/path"
19 ft "github.com/ipfs/go-ipfs/unixfs"
20 uio "github.com/ipfs/go-ipfs/unixfs/io"
21 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
22 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
23
24 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
25 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
mfs/system.go
+1 -1
@@ -16,8 +16,8 @@ import (
16 "sync"
17 "time"
18
19 - dag "github.com/ipfs/go-ipfs/merkledag"
19 ft "github.com/ipfs/go-ipfs/unixfs"
20 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
21
22 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
23 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
package.json
+6
@@ -557,6 +557,12 @@
557 "hash": "QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R",
558 "name": "go-blockservice",
559 "version": "1.0.1"
560 + },
561 + {
562 + "author": "why",
563 + "hash": "QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59",
564 + "name": "go-merkledag",
565 + "version": "1.0.0"
566 }
567 ],
568 "gxVersion": "0.10.0",
path/resolver/resolver.go
+1 -1
@@ -7,8 +7,8 @@ import (
7 "fmt"
8 "time"
9
10 - dag "github.com/ipfs/go-ipfs/merkledag"
10 path "github.com/ipfs/go-ipfs/path"
11 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
12
13 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
14 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
path/resolver/resolver_test.go
+2 -2
@@ -5,10 +5,10 @@ import (
5 "fmt"
6 "testing"
7
8 - merkledag "github.com/ipfs/go-ipfs/merkledag"
9 - dagmock "github.com/ipfs/go-ipfs/merkledag/test"
8 path "github.com/ipfs/go-ipfs/path"
9 "github.com/ipfs/go-ipfs/path/resolver"
10 + merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11 + dagmock "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
12
13 util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
14 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
pin/gc/gc.go
+1 -1
@@ -7,9 +7,9 @@ import (
7 "fmt"
8 "strings"
9
10 - dag "github.com/ipfs/go-ipfs/merkledag"
10 pin "github.com/ipfs/go-ipfs/pin"
11 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
12 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
13
14 "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
15 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
pin/pin.go
+1 -1
@@ -10,7 +10,7 @@ import (
10 "time"
11
12 "github.com/ipfs/go-ipfs/dagutils"
13 - mdag "github.com/ipfs/go-ipfs/merkledag"
13 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
14
15 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
16 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
pin/pin_test.go
+1 -1
@@ -5,8 +5,8 @@ import (
5 "testing"
6 "time"
7
8 - mdag "github.com/ipfs/go-ipfs/merkledag"
8 bs "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
9 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
10
11 util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
12 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
pin/set.go
+1 -1
@@ -9,8 +9,8 @@ import (
9 "hash/fnv"
10 "sort"
11
12 - "github.com/ipfs/go-ipfs/merkledag"
12 "github.com/ipfs/go-ipfs/pin/internal/pb"
13 + "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
14
15 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
16 "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
pin/set_test.go
+1 -1
@@ -5,8 +5,8 @@ import (
5 "encoding/binary"
6 "testing"
7
8 - dag "github.com/ipfs/go-ipfs/merkledag"
8 bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
9 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
10
11 offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
12 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
tar/format.go
+1 -1
@@ -10,9 +10,9 @@ import (
10
11 "github.com/ipfs/go-ipfs/dagutils"
12 importer "github.com/ipfs/go-ipfs/importer"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
13 path "github.com/ipfs/go-ipfs/path"
14 uio "github.com/ipfs/go-ipfs/unixfs/io"
15 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
16
17 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
18 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
unixfs/archive/tar/writer.go
+1 -1
@@ -10,10 +10,10 @@ import (
10 "path"
11 "time"
12
13 - mdag "github.com/ipfs/go-ipfs/merkledag"
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 uio "github.com/ipfs/go-ipfs/unixfs/io"
15 upb "github.com/ipfs/go-ipfs/unixfs/pb"
16 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
17
18 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
19 )
unixfs/hamt/hamt.go
+1 -1
@@ -25,9 +25,9 @@ import (
25 "fmt"
26 "os"
27
28 - dag "github.com/ipfs/go-ipfs/merkledag"
28 format "github.com/ipfs/go-ipfs/unixfs"
29 upb "github.com/ipfs/go-ipfs/unixfs/pb"
30 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
31
32 bitfield "gx/ipfs/QmTbBs3Y3u5F69XNJzdnnc6SP5GKgcXxCDzx6w8m6piVRT/go-bitfield"
33 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
unixfs/hamt/hamt_stress_test.go
+1 -1
@@ -8,8 +8,8 @@ import (
8 "testing"
9 "time"
10
11 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
11 ft "github.com/ipfs/go-ipfs/unixfs"
12 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
13
14 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
15 )
unixfs/hamt/hamt_test.go
+2 -2
@@ -10,9 +10,9 @@ import (
10 "time"
11
12 "github.com/ipfs/go-ipfs/dagutils"
13 - dag "github.com/ipfs/go-ipfs/merkledag"
14 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
15 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
16
17 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
18 )
unixfs/io/dagreader.go
+1 -1
@@ -5,9 +5,9 @@ import (
5 "errors"
6 "io"
7
8 - mdag "github.com/ipfs/go-ipfs/merkledag"
8 ft "github.com/ipfs/go-ipfs/unixfs"
9 ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
10 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11
12 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
13 )
unixfs/io/dagreader_test.go
+1 -1
@@ -8,8 +8,8 @@ import (
8 "strings"
9 "testing"
10
11 - mdag "github.com/ipfs/go-ipfs/merkledag"
11 "github.com/ipfs/go-ipfs/unixfs"
12 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
13
14 context "context"
15
unixfs/io/directory.go
+1 -1
@@ -5,9 +5,9 @@ import (
5 "fmt"
6 "os"
7
8 - mdag "github.com/ipfs/go-ipfs/merkledag"
8 format "github.com/ipfs/go-ipfs/unixfs"
9 hamt "github.com/ipfs/go-ipfs/unixfs/hamt"
10 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
11
12 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
13 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
unixfs/io/directory_test.go
+1 -1
@@ -5,8 +5,8 @@ import (
5 "fmt"
6 "testing"
7
8 - mdtest "github.com/ipfs/go-ipfs/merkledag/test"
8 ft "github.com/ipfs/go-ipfs/unixfs"
9 + mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
10 )
11
12 func TestEmptyNode(t *testing.T) {
unixfs/io/pbdagreader.go
+1 -1
@@ -6,9 +6,9 @@ import (
6 "fmt"
7 "io"
8
9 - mdag "github.com/ipfs/go-ipfs/merkledag"
9 ft "github.com/ipfs/go-ipfs/unixfs"
10 ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
11 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
12
13 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
14 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
unixfs/io/resolve.go
+1 -1
@@ -3,9 +3,9 @@ package io
3 import (
4 "context"
5
6 - dag "github.com/ipfs/go-ipfs/merkledag"
6 ft "github.com/ipfs/go-ipfs/unixfs"
7 hamt "github.com/ipfs/go-ipfs/unixfs/hamt"
8 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
9
10 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
11 )
unixfs/mod/dagmodifier.go
+1 -1
@@ -10,9 +10,9 @@ import (
10
11 help "github.com/ipfs/go-ipfs/importer/helpers"
12 trickle "github.com/ipfs/go-ipfs/importer/trickle"
13 - mdag "github.com/ipfs/go-ipfs/merkledag"
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 uio "github.com/ipfs/go-ipfs/unixfs/io"
15 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
16
17 chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
18 cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
unixfs/test/utils.go
+2 -2
@@ -10,9 +10,9 @@ import (
10
11 h "github.com/ipfs/go-ipfs/importer/helpers"
12 trickle "github.com/ipfs/go-ipfs/importer/trickle"
13 - mdag "github.com/ipfs/go-ipfs/merkledag"
14 - mdagmock "github.com/ipfs/go-ipfs/merkledag/test"
13 ft "github.com/ipfs/go-ipfs/unixfs"
14 + mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
15 + mdagmock "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
16
17 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
18 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
unixfs/unixfs.go
+1 -1
@@ -8,8 +8,8 @@ import (
8
9 proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
11 - dag "github.com/ipfs/go-ipfs/merkledag"
11 pb "github.com/ipfs/go-ipfs/unixfs/pb"
12 + dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
13 )
14
15 // Shorthands for protobuffer types