mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-22 21:21:43 +08:00
Merge pull request #5298 from ipfs/feat/extract-dagservice
Extract merkledag package, move dagutils to top level
This commit is contained in:
3
Rules.mk
3
Rules.mk
@ -50,9 +50,6 @@ endif
|
||||
dir := unixfs/pb
|
||||
include $(dir)/Rules.mk
|
||||
|
||||
dir := merkledag/pb
|
||||
include $(dir)/Rules.mk
|
||||
|
||||
dir := pin/internal/pb
|
||||
include $(dir)/Rules.mk
|
||||
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
filestore "github.com/ipfs/go-ipfs/filestore"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
@ -18,6 +17,7 @@ import (
|
||||
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
goprocessctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/core/coreunix"
|
||||
filestore "github.com/ipfs/go-ipfs/filestore"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
dagtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
b58 "gx/ipfs/QmWFAMPqsEyUX7gDUsRVmMWz59FxSpJ1b2v6bJ1yYzo7jY/go-base58-fast/base58"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -15,13 +15,13 @@ import (
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
bservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
uarchive "github.com/ipfs/go-ipfs/unixfs/archive"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
"gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
"gx/ipfs/QmPtj12fdwuAqj9sBSTNUxBNu8kCGNp8b3o8yUzMm5GHpq/pb"
|
||||
|
@ -9,13 +9,13 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
cmdkit "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
|
||||
)
|
||||
|
@ -17,10 +17,10 @@ import (
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
|
||||
logging "gx/ipfs/QmcVVHfdyv15GVPk7NrxdWjh2hLVccXnoD8j2tyQShiXJb/go-log"
|
||||
|
@ -11,12 +11,12 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
"gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
"github.com/ipfs/go-ipfs/core/coreunix"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
tar "github.com/ipfs/go-ipfs/tar"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
|
||||
)
|
||||
|
@ -12,12 +12,12 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
)
|
||||
|
||||
type LsLink struct {
|
||||
|
@ -23,7 +23,6 @@ import (
|
||||
rp "github.com/ipfs/go-ipfs/exchange/reprovide"
|
||||
filestore "github.com/ipfs/go-ipfs/filestore"
|
||||
mount "github.com/ipfs/go-ipfs/fuse/mount"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
ipnsrp "github.com/ipfs/go-ipfs/namesys/republisher"
|
||||
@ -34,6 +33,7 @@ import (
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
bitswap "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap"
|
||||
bsnet "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap/network"
|
||||
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -15,10 +15,10 @@ import (
|
||||
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
keystore "github.com/ipfs/go-ipfs/keystore"
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cbor "gx/ipfs/QmWrbExtUaQQHjJ8FVVDAWj5o1MRAELDUV3VmoQsZHHb6L/go-ipld-cbor"
|
||||
peer "gx/ipfs/QmdVrMn1LhB4ybb8hMVaMLXnA8XRSewMnK6YqXKXoTcRvN/go-libp2p-peer"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
|
||||
"github.com/ipfs/go-ipfs/merkledag"
|
||||
"gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
|
||||
"github.com/ipfs/go-ipfs/merkledag"
|
||||
"gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
block "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
|
@ -14,13 +14,13 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
"github.com/ipfs/go-ipfs/importer"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
resolver "github.com/ipfs/go-ipfs/path/resolver"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -13,12 +13,12 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
id "gx/ipfs/QmY51bqSM5XgxQZqsBrQcRkKTnCb8EKpJpR9K6Qax7Njco/go-libp2p/p2p/protocol/identify"
|
||||
ci "gx/ipfs/Qme1knMqwt1hKZbc1BmQFmnm9f36nyQGwXxPGVpVJ9rMK5/go-libp2p-crypto"
|
||||
|
@ -14,10 +14,10 @@ import (
|
||||
balanced "github.com/ipfs/go-ipfs/importer/balanced"
|
||||
ihelper "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
trickle "github.com/ipfs/go-ipfs/importer/trickle"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
"github.com/ipfs/go-ipfs/pin"
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
posinfo "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -11,11 +11,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
"github.com/ipfs/go-ipfs/pin/gc"
|
||||
"github.com/ipfs/go-ipfs/repo"
|
||||
"github.com/ipfs/go-ipfs/repo/config"
|
||||
"gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
|
||||
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
|
@ -2,8 +2,8 @@ package coreunix
|
||||
|
||||
import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
)
|
||||
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
@ -3,9 +3,9 @@ package reprovide
|
||||
import (
|
||||
"context"
|
||||
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
blocks "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
posinfo "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -12,11 +12,11 @@ import (
|
||||
"os"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
fuse "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse"
|
||||
fs "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs"
|
||||
|
@ -17,8 +17,8 @@ import (
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
fstest "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
|
||||
|
@ -11,10 +11,10 @@ import (
|
||||
"syscall"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
lgbl "gx/ipfs/QmRPkGkHLB72caXgdDYnoaWigXNWx95BcYDKV1n3KTEpaG/go-libp2p-loggables"
|
||||
fuse "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse"
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
"testing"
|
||||
|
||||
h "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
pb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
"testing"
|
||||
|
||||
h "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
h "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -1,137 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
|
||||
pb "github.com/ipfs/go-ipfs/merkledag/pb"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// for now, we use a PBNode intermediate thing.
|
||||
// because native go objects are nice.
|
||||
|
||||
// unmarshal decodes raw data into a *Node instance.
|
||||
// The conversion uses an intermediate PBNode.
|
||||
func (n *ProtoNode) unmarshal(encoded []byte) error {
|
||||
var pbn pb.PBNode
|
||||
if err := pbn.Unmarshal(encoded); err != nil {
|
||||
return fmt.Errorf("unmarshal failed. %v", err)
|
||||
}
|
||||
|
||||
pbnl := pbn.GetLinks()
|
||||
n.links = make([]*ipld.Link, len(pbnl))
|
||||
for i, l := range pbnl {
|
||||
n.links[i] = &ipld.Link{Name: l.GetName(), Size: l.GetTsize()}
|
||||
c, err := cid.Cast(l.GetHash())
|
||||
if err != nil {
|
||||
return fmt.Errorf("link hash #%d is not valid multihash. %v", i, err)
|
||||
}
|
||||
n.links[i].Cid = c
|
||||
}
|
||||
sort.Stable(LinkSlice(n.links)) // keep links sorted
|
||||
|
||||
n.data = pbn.GetData()
|
||||
n.encoded = encoded
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal encodes a *Node instance into a new byte slice.
|
||||
// The conversion uses an intermediate PBNode.
|
||||
func (n *ProtoNode) Marshal() ([]byte, error) {
|
||||
pbn := n.getPBNode()
|
||||
data, err := pbn.Marshal()
|
||||
if err != nil {
|
||||
return data, fmt.Errorf("marshal failed. %v", err)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (n *ProtoNode) getPBNode() *pb.PBNode {
|
||||
pbn := &pb.PBNode{}
|
||||
if len(n.links) > 0 {
|
||||
pbn.Links = make([]*pb.PBLink, len(n.links))
|
||||
}
|
||||
|
||||
sort.Stable(LinkSlice(n.links)) // keep links sorted
|
||||
for i, l := range n.links {
|
||||
pbn.Links[i] = &pb.PBLink{}
|
||||
pbn.Links[i].Name = &l.Name
|
||||
pbn.Links[i].Tsize = &l.Size
|
||||
if l.Cid != nil {
|
||||
pbn.Links[i].Hash = l.Cid.Bytes()
|
||||
}
|
||||
}
|
||||
|
||||
if len(n.data) > 0 {
|
||||
pbn.Data = n.data
|
||||
}
|
||||
return pbn
|
||||
}
|
||||
|
||||
// EncodeProtobuf returns the encoded raw data version of a Node instance.
|
||||
// It may use a cached encoded version, unless the force flag is given.
|
||||
func (n *ProtoNode) EncodeProtobuf(force bool) ([]byte, error) {
|
||||
sort.Stable(LinkSlice(n.links)) // keep links sorted
|
||||
if n.encoded == nil || force {
|
||||
n.cached = nil
|
||||
var err error
|
||||
n.encoded, err = n.Marshal()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if n.cached == nil {
|
||||
if n.Prefix.Codec == 0 { // unset
|
||||
n.Prefix = v0CidPrefix
|
||||
}
|
||||
c, err := n.Prefix.Sum(n.encoded)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
n.cached = c
|
||||
}
|
||||
|
||||
return n.encoded, nil
|
||||
}
|
||||
|
||||
// DecodeProtobuf decodes raw data and returns a new Node instance.
|
||||
func DecodeProtobuf(encoded []byte) (*ProtoNode, error) {
|
||||
n := new(ProtoNode)
|
||||
err := n.unmarshal(encoded)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("incorrectly formatted merkledag node: %s", err)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// DecodeProtobufBlock is a block decoder for protobuf IPLD nodes conforming to
|
||||
// node.DecodeBlockFunc
|
||||
func DecodeProtobufBlock(b blocks.Block) (ipld.Node, error) {
|
||||
c := b.Cid()
|
||||
if c.Type() != cid.DagProtobuf {
|
||||
return nil, fmt.Errorf("this function can only decode protobuf nodes")
|
||||
}
|
||||
|
||||
decnd, err := DecodeProtobuf(b.RawData())
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Unmarshal failed") {
|
||||
return nil, fmt.Errorf("the block referred to by '%s' was not a valid merkledag node", c)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to decode Protocol Buffers: %v", err)
|
||||
}
|
||||
|
||||
decnd.cached = c
|
||||
decnd.Prefix = c.Prefix()
|
||||
return decnd, nil
|
||||
}
|
||||
|
||||
// Type assertion
|
||||
var _ ipld.DecodeBlockFunc = DecodeProtobufBlock
|
@ -1,47 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// ErrorService implements ipld.DAGService, returning 'Err' for every call.
|
||||
type ErrorService struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
var _ ipld.DAGService = (*ErrorService)(nil)
|
||||
|
||||
// Add returns the cs.Err.
|
||||
func (cs *ErrorService) Add(ctx context.Context, nd ipld.Node) error {
|
||||
return cs.Err
|
||||
}
|
||||
|
||||
// AddMany returns the cs.Err.
|
||||
func (cs *ErrorService) AddMany(ctx context.Context, nds []ipld.Node) error {
|
||||
return cs.Err
|
||||
}
|
||||
|
||||
// Get returns the cs.Err.
|
||||
func (cs *ErrorService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
|
||||
return nil, cs.Err
|
||||
}
|
||||
|
||||
// GetMany many returns the cs.Err.
|
||||
func (cs *ErrorService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
|
||||
ch := make(chan *ipld.NodeOption)
|
||||
close(ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
// Remove returns the cs.Err.
|
||||
func (cs *ErrorService) Remove(ctx context.Context, c *cid.Cid) error {
|
||||
return cs.Err
|
||||
}
|
||||
|
||||
// RemoveMany returns the cs.Err.
|
||||
func (cs *ErrorService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
|
||||
return cs.Err
|
||||
}
|
@ -1,392 +0,0 @@
|
||||
// Package merkledag implements the IPFS Merkle DAG data structures.
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
|
||||
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
ipldcbor "gx/ipfs/QmWrbExtUaQQHjJ8FVVDAWj5o1MRAELDUV3VmoQsZHHb6L/go-ipld-cbor"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// TODO: We should move these registrations elsewhere. Really, most of the IPLD
|
||||
// functionality should go in a `go-ipld` repo but that will take a lot of work
|
||||
// and design.
|
||||
func init() {
|
||||
ipld.Register(cid.DagProtobuf, DecodeProtobufBlock)
|
||||
ipld.Register(cid.Raw, DecodeRawBlock)
|
||||
ipld.Register(cid.DagCBOR, ipldcbor.DecodeBlock)
|
||||
}
|
||||
|
||||
// contextKey is a type to use as value for the ProgressTracker contexts.
|
||||
type contextKey string
|
||||
|
||||
const progressContextKey contextKey = "progress"
|
||||
|
||||
// NewDAGService constructs a new DAGService (using the default implementation).
|
||||
// Note that the default implementation is also an ipld.LinkGetter.
|
||||
func NewDAGService(bs bserv.BlockService) *dagService {
|
||||
return &dagService{Blocks: bs}
|
||||
}
|
||||
|
||||
// dagService is an IPFS Merkle DAG service.
|
||||
// - the root is virtual (like a forest)
|
||||
// - stores nodes' data in a BlockService
|
||||
// TODO: should cache Nodes that are in memory, and be
|
||||
// able to free some of them when vm pressure is high
|
||||
type dagService struct {
|
||||
Blocks bserv.BlockService
|
||||
}
|
||||
|
||||
// Add adds a node to the dagService, storing the block in the BlockService
|
||||
func (n *dagService) Add(ctx context.Context, nd ipld.Node) error {
|
||||
if n == nil { // FIXME remove this assertion. protect with constructor invariant
|
||||
return fmt.Errorf("dagService is nil")
|
||||
}
|
||||
|
||||
return n.Blocks.AddBlock(nd)
|
||||
}
|
||||
|
||||
func (n *dagService) AddMany(ctx context.Context, nds []ipld.Node) error {
|
||||
blks := make([]blocks.Block, len(nds))
|
||||
for i, nd := range nds {
|
||||
blks[i] = nd
|
||||
}
|
||||
return n.Blocks.AddBlocks(blks)
|
||||
}
|
||||
|
||||
// Get retrieves a node from the dagService, fetching the block in the BlockService
|
||||
func (n *dagService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
|
||||
if n == nil {
|
||||
return nil, fmt.Errorf("dagService is nil")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
b, err := n.Blocks.GetBlock(ctx, c)
|
||||
if err != nil {
|
||||
if err == bserv.ErrNotFound {
|
||||
return nil, ipld.ErrNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get block for %s: %v", c, err)
|
||||
}
|
||||
|
||||
return ipld.Decode(b)
|
||||
}
|
||||
|
||||
// GetLinks return the links for the node, the node doesn't necessarily have
|
||||
// to exist locally.
|
||||
func (n *dagService) GetLinks(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
|
||||
if c.Type() == cid.Raw {
|
||||
return nil, nil
|
||||
}
|
||||
node, err := n.Get(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return node.Links(), nil
|
||||
}
|
||||
|
||||
func (n *dagService) Remove(ctx context.Context, c *cid.Cid) error {
|
||||
return n.Blocks.DeleteBlock(c)
|
||||
}
|
||||
|
||||
// RemoveMany removes multiple nodes from the DAG. It will likely be faster than
|
||||
// removing them individually.
|
||||
//
|
||||
// This operation is not atomic. If it returns an error, some nodes may or may
|
||||
// not have been removed.
|
||||
func (n *dagService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
|
||||
// TODO(#4608): make this batch all the way down.
|
||||
for _, c := range cids {
|
||||
if err := n.Blocks.DeleteBlock(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLinksDirect creates a function to get the links for a node, from
|
||||
// the node, bypassing the LinkService. If the node does not exist
|
||||
// locally (and can not be retrieved) an error will be returned.
|
||||
func GetLinksDirect(serv ipld.NodeGetter) GetLinks {
|
||||
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
|
||||
nd, err := serv.Get(ctx, c)
|
||||
if err != nil {
|
||||
if err == bserv.ErrNotFound {
|
||||
err = ipld.ErrNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nd.Links(), nil
|
||||
}
|
||||
}
|
||||
|
||||
type sesGetter struct {
|
||||
bs *bserv.Session
|
||||
}
|
||||
|
||||
// Get gets a single node from the DAG.
|
||||
func (sg *sesGetter) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
|
||||
blk, err := sg.bs.GetBlock(ctx, c)
|
||||
switch err {
|
||||
case bserv.ErrNotFound:
|
||||
return nil, ipld.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
case nil:
|
||||
// noop
|
||||
}
|
||||
|
||||
return ipld.Decode(blk)
|
||||
}
|
||||
|
||||
// GetMany gets many nodes at once, batching the request if possible.
|
||||
func (sg *sesGetter) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
|
||||
return getNodesFromBG(ctx, sg.bs, keys)
|
||||
}
|
||||
|
||||
// Session returns a NodeGetter using a new session for block fetches.
|
||||
func (n *dagService) Session(ctx context.Context) ipld.NodeGetter {
|
||||
return &sesGetter{bserv.NewSession(ctx, n.Blocks)}
|
||||
}
|
||||
|
||||
// FetchGraph fetches all nodes that are children of the given node
|
||||
func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error {
|
||||
var ng ipld.NodeGetter = serv
|
||||
ds, ok := serv.(*dagService)
|
||||
if ok {
|
||||
ng = &sesGetter{bserv.NewSession(ctx, ds.Blocks)}
|
||||
}
|
||||
|
||||
v, _ := ctx.Value(progressContextKey).(*ProgressTracker)
|
||||
if v == nil {
|
||||
return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, cid.NewSet().Visit)
|
||||
}
|
||||
set := cid.NewSet()
|
||||
visit := func(c *cid.Cid) bool {
|
||||
if set.Visit(c) {
|
||||
v.Increment()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, visit)
|
||||
}
|
||||
|
||||
// GetMany gets many nodes from the DAG at once.
|
||||
//
|
||||
// This method may not return all requested nodes (and may or may not return an
|
||||
// error indicating that it failed to do so. It is up to the caller to verify
|
||||
// that it received all nodes.
|
||||
func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.NodeOption {
|
||||
return getNodesFromBG(ctx, n.Blocks, keys)
|
||||
}
|
||||
|
||||
func dedupKeys(keys []*cid.Cid) []*cid.Cid {
|
||||
set := cid.NewSet()
|
||||
for _, c := range keys {
|
||||
set.Add(c)
|
||||
}
|
||||
if set.Len() == len(keys) {
|
||||
return keys
|
||||
}
|
||||
return set.Keys()
|
||||
}
|
||||
|
||||
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
|
||||
keys = dedupKeys(keys)
|
||||
|
||||
out := make(chan *ipld.NodeOption, len(keys))
|
||||
blocks := bs.GetBlocks(ctx, keys)
|
||||
var count int
|
||||
|
||||
go func() {
|
||||
defer close(out)
|
||||
for {
|
||||
select {
|
||||
case b, ok := <-blocks:
|
||||
if !ok {
|
||||
if count != len(keys) {
|
||||
out <- &ipld.NodeOption{Err: fmt.Errorf("failed to fetch all nodes")}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
nd, err := ipld.Decode(b)
|
||||
if err != nil {
|
||||
out <- &ipld.NodeOption{Err: err}
|
||||
return
|
||||
}
|
||||
|
||||
out <- &ipld.NodeOption{Node: nd}
|
||||
count++
|
||||
|
||||
case <-ctx.Done():
|
||||
out <- &ipld.NodeOption{Err: ctx.Err()}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return out
|
||||
}
|
||||
|
||||
// GetLinks is the type of function passed to the EnumerateChildren function(s)
|
||||
// for getting the children of an IPLD node.
|
||||
type GetLinks func(context.Context, *cid.Cid) ([]*ipld.Link, error)
|
||||
|
||||
// GetLinksWithDAG returns a GetLinks function that tries to use the given
|
||||
// NodeGetter as a LinkGetter to get the children of a given IPLD node. This may
|
||||
// allow us to traverse the DAG without actually loading and parsing the node in
|
||||
// question (if we already have the links cached).
|
||||
func GetLinksWithDAG(ng ipld.NodeGetter) GetLinks {
|
||||
return func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
|
||||
return ipld.GetLinks(ctx, ng, c)
|
||||
}
|
||||
}
|
||||
|
||||
// EnumerateChildren will walk the dag below the given root node and add all
|
||||
// unseen children to the passed in set.
|
||||
// TODO: parallelize to avoid disk latency perf hits?
|
||||
func EnumerateChildren(ctx context.Context, getLinks GetLinks, root *cid.Cid, visit func(*cid.Cid) bool) error {
|
||||
links, err := getLinks(ctx, root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, lnk := range links {
|
||||
c := lnk.Cid
|
||||
if visit(c) {
|
||||
err = EnumerateChildren(ctx, getLinks, c, visit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProgressTracker is used to show progress when fetching nodes.
|
||||
type ProgressTracker struct {
|
||||
Total int
|
||||
lk sync.Mutex
|
||||
}
|
||||
|
||||
// DeriveContext returns a new context with value "progress" derived from
|
||||
// the given one.
|
||||
func (p *ProgressTracker) DeriveContext(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, progressContextKey, p)
|
||||
}
|
||||
|
||||
// Increment adds one to the total progress.
|
||||
func (p *ProgressTracker) Increment() {
|
||||
p.lk.Lock()
|
||||
defer p.lk.Unlock()
|
||||
p.Total++
|
||||
}
|
||||
|
||||
// Value returns the current progress.
|
||||
func (p *ProgressTracker) Value() int {
|
||||
p.lk.Lock()
|
||||
defer p.lk.Unlock()
|
||||
return p.Total
|
||||
}
|
||||
|
||||
// FetchGraphConcurrency is total number of concurrent fetches that
|
||||
// 'fetchNodes' will start at a time
|
||||
var FetchGraphConcurrency = 8
|
||||
|
||||
// EnumerateChildrenAsync is equivalent to EnumerateChildren *except* that it
|
||||
// fetches children in parallel.
|
||||
//
|
||||
// NOTE: It *does not* make multiple concurrent calls to the passed `visit` function.
|
||||
func EnumerateChildrenAsync(ctx context.Context, getLinks GetLinks, c *cid.Cid, visit func(*cid.Cid) bool) error {
|
||||
feed := make(chan *cid.Cid)
|
||||
out := make(chan []*ipld.Link)
|
||||
done := make(chan struct{})
|
||||
|
||||
var setlk sync.Mutex
|
||||
|
||||
errChan := make(chan error)
|
||||
fetchersCtx, cancel := context.WithCancel(ctx)
|
||||
|
||||
defer cancel()
|
||||
|
||||
for i := 0; i < FetchGraphConcurrency; i++ {
|
||||
go func() {
|
||||
for ic := range feed {
|
||||
setlk.Lock()
|
||||
shouldVisit := visit(ic)
|
||||
setlk.Unlock()
|
||||
|
||||
if shouldVisit {
|
||||
links, err := getLinks(ctx, ic)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case out <- links:
|
||||
case <-fetchersCtx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
select {
|
||||
case done <- struct{}{}:
|
||||
case <-fetchersCtx.Done():
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
defer close(feed)
|
||||
|
||||
send := feed
|
||||
var todobuffer []*cid.Cid
|
||||
var inProgress int
|
||||
|
||||
next := c
|
||||
for {
|
||||
select {
|
||||
case send <- next:
|
||||
inProgress++
|
||||
if len(todobuffer) > 0 {
|
||||
next = todobuffer[0]
|
||||
todobuffer = todobuffer[1:]
|
||||
} else {
|
||||
next = nil
|
||||
send = nil
|
||||
}
|
||||
case <-done:
|
||||
inProgress--
|
||||
if inProgress == 0 && next == nil {
|
||||
return nil
|
||||
}
|
||||
case links := <-out:
|
||||
for _, lnk := range links {
|
||||
if next == nil {
|
||||
next = lnk.Cid
|
||||
send = feed
|
||||
} else {
|
||||
todobuffer = append(todobuffer, lnk.Cid)
|
||||
}
|
||||
}
|
||||
case err := <-errChan:
|
||||
return err
|
||||
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var _ ipld.LinkGetter = &dagService{}
|
||||
var _ ipld.NodeGetter = &dagService{}
|
||||
var _ ipld.NodeGetter = &sesGetter{}
|
||||
var _ ipld.DAGService = &dagService{}
|
@ -1,705 +0,0 @@
|
||||
package merkledag_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdpb "github.com/ipfs/go-ipfs/merkledag/pb"
|
||||
dstest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
bstest "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice/test"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
func TestNode(t *testing.T) {
|
||||
|
||||
n1 := NodeWithData([]byte("beep"))
|
||||
n2 := NodeWithData([]byte("boop"))
|
||||
n3 := NodeWithData([]byte("beep boop"))
|
||||
if err := n3.AddNodeLink("beep-link", n1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := n3.AddNodeLink("boop-link", n2); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
printn := func(name string, n *ProtoNode) {
|
||||
fmt.Println(">", name)
|
||||
fmt.Println("data:", string(n.Data()))
|
||||
|
||||
fmt.Println("links:")
|
||||
for _, l := range n.Links() {
|
||||
fmt.Println("-", l.Name, l.Size, l.Cid)
|
||||
}
|
||||
|
||||
e, err := n.EncodeProtobuf(false)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else {
|
||||
fmt.Println("encoded:", e)
|
||||
}
|
||||
|
||||
h := n.Multihash()
|
||||
k := n.Cid().Hash()
|
||||
if k.String() != h.String() {
|
||||
t.Error("Key is not equivalent to multihash")
|
||||
} else {
|
||||
fmt.Println("key: ", k)
|
||||
}
|
||||
|
||||
SubtestNodeStat(t, n)
|
||||
}
|
||||
|
||||
printn("beep", n1)
|
||||
printn("boop", n2)
|
||||
printn("beep boop", n3)
|
||||
}
|
||||
|
||||
func SubtestNodeStat(t *testing.T, n *ProtoNode) {
|
||||
enc, err := n.EncodeProtobuf(true)
|
||||
if err != nil {
|
||||
t.Error("n.EncodeProtobuf(true) failed")
|
||||
return
|
||||
}
|
||||
|
||||
cumSize, err := n.Size()
|
||||
if err != nil {
|
||||
t.Error("n.Size() failed")
|
||||
return
|
||||
}
|
||||
|
||||
k := n.Cid()
|
||||
|
||||
expected := ipld.NodeStat{
|
||||
NumLinks: len(n.Links()),
|
||||
BlockSize: len(enc),
|
||||
LinksSize: len(enc) - len(n.Data()), // includes framing.
|
||||
DataSize: len(n.Data()),
|
||||
CumulativeSize: int(cumSize),
|
||||
Hash: k.String(),
|
||||
}
|
||||
|
||||
actual, err := n.Stat()
|
||||
if err != nil {
|
||||
t.Error("n.Stat() failed")
|
||||
return
|
||||
}
|
||||
|
||||
if expected != *actual {
|
||||
t.Errorf("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
|
||||
} else {
|
||||
fmt.Printf("n.Stat correct: %s\n", actual)
|
||||
}
|
||||
}
|
||||
|
||||
type devZero struct{}
|
||||
|
||||
func (_ devZero) Read(b []byte) (int, error) {
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func TestBatchFetch(t *testing.T) {
|
||||
read := io.LimitReader(u.NewTimeSeededRand(), 1024*32)
|
||||
runBatchFetchTest(t, read)
|
||||
}
|
||||
|
||||
func TestBatchFetchDupBlock(t *testing.T) {
|
||||
read := io.LimitReader(devZero{}, 1024*32)
|
||||
runBatchFetchTest(t, read)
|
||||
}
|
||||
|
||||
// makeTestDAG creates a simple DAG from the data in a reader.
|
||||
// First, a node is created from each 512 bytes of data from the reader
|
||||
// (like a the Size chunker would do). Then all nodes are added as children
|
||||
// to a root node, which is returned.
|
||||
func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node {
|
||||
p := make([]byte, 512)
|
||||
nodes := []*ProtoNode{}
|
||||
|
||||
for {
|
||||
n, err := io.ReadFull(read, p)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if n != len(p) {
|
||||
t.Fatal("should have read 512 bytes from the reader")
|
||||
}
|
||||
|
||||
protoNode := NodeWithData(p)
|
||||
nodes = append(nodes, protoNode)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// Add a root referencing all created nodes
|
||||
root := NodeWithData(nil)
|
||||
for _, n := range nodes {
|
||||
root.AddNodeLink(n.Cid().String(), n)
|
||||
err := ds.Add(ctx, n)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
err := ds.Add(ctx, root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
// makeTestDAGReader takes the root node as returned by makeTestDAG and
|
||||
// provides a reader that reads all the RawData from that node and its children.
|
||||
func makeTestDAGReader(t *testing.T, root ipld.Node, ds ipld.DAGService) io.Reader {
|
||||
ctx := context.Background()
|
||||
buf := new(bytes.Buffer)
|
||||
buf.Write(root.RawData())
|
||||
for _, l := range root.Links() {
|
||||
n, err := ds.Get(ctx, l.Cid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = buf.Write(n.RawData())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
func runBatchFetchTest(t *testing.T, read io.Reader) {
|
||||
ctx := context.Background()
|
||||
var dagservs []ipld.DAGService
|
||||
for _, bsi := range bstest.Mocks(5) {
|
||||
dagservs = append(dagservs, NewDAGService(bsi))
|
||||
}
|
||||
|
||||
root := makeTestDAG(t, read, dagservs[0])
|
||||
|
||||
t.Log("finished setup.")
|
||||
|
||||
dagr := makeTestDAGReader(t, root, dagservs[0])
|
||||
|
||||
expected, err := ioutil.ReadAll(dagr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = dagservs[0].Add(ctx, root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log("Added file to first node.")
|
||||
|
||||
c := root.Cid()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
errs := make(chan error)
|
||||
|
||||
for i := 1; i < len(dagservs); i++ {
|
||||
wg.Add(1)
|
||||
go func(i int) {
|
||||
defer wg.Done()
|
||||
first, err := dagservs[i].Get(ctx, c)
|
||||
if err != nil {
|
||||
errs <- err
|
||||
}
|
||||
fmt.Println("Got first node back.")
|
||||
|
||||
firstpb, ok := first.(*ProtoNode)
|
||||
if !ok {
|
||||
errs <- ErrNotProtobuf
|
||||
}
|
||||
read := makeTestDAGReader(t, firstpb, dagservs[i])
|
||||
datagot, err := ioutil.ReadAll(read)
|
||||
if err != nil {
|
||||
errs <- err
|
||||
}
|
||||
|
||||
if !bytes.Equal(datagot, expected) {
|
||||
errs <- errors.New("got bad data back")
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(errs)
|
||||
}()
|
||||
|
||||
for err := range errs {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCantGet(t *testing.T) {
|
||||
ds := dstest.Mock()
|
||||
a := NodeWithData([]byte("A"))
|
||||
|
||||
c := a.Cid()
|
||||
_, err := ds.Get(context.Background(), c)
|
||||
if !strings.Contains(err.Error(), "not found") {
|
||||
t.Fatal("expected err not found, got: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchGraph(t *testing.T) {
|
||||
var dservs []ipld.DAGService
|
||||
bsis := bstest.Mocks(2)
|
||||
for _, bsi := range bsis {
|
||||
dservs = append(dservs, NewDAGService(bsi))
|
||||
}
|
||||
|
||||
read := io.LimitReader(u.NewTimeSeededRand(), 1024*32)
|
||||
root := makeTestDAG(t, read, dservs[0])
|
||||
|
||||
err := FetchGraph(context.TODO(), root.Cid(), dservs[1])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// create an offline dagstore and ensure all blocks were fetched
|
||||
bs := bserv.New(bsis[1].Blockstore(), offline.Exchange(bsis[1].Blockstore()))
|
||||
|
||||
offlineDS := NewDAGService(bs)
|
||||
|
||||
err = EnumerateChildren(context.Background(), offlineDS.GetLinks, root.Cid(), func(_ *cid.Cid) bool { return true })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnumerateChildren(t *testing.T) {
|
||||
bsi := bstest.Mocks(1)
|
||||
ds := NewDAGService(bsi[0])
|
||||
|
||||
read := io.LimitReader(u.NewTimeSeededRand(), 1024*1024)
|
||||
root := makeTestDAG(t, read, ds)
|
||||
|
||||
set := cid.NewSet()
|
||||
|
||||
err := EnumerateChildren(context.Background(), ds.GetLinks, root.Cid(), set.Visit)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var traverse func(n ipld.Node)
|
||||
traverse = func(n ipld.Node) {
|
||||
// traverse dag and check
|
||||
for _, lnk := range n.Links() {
|
||||
c := lnk.Cid
|
||||
if !set.Has(c) {
|
||||
t.Fatal("missing key in set! ", lnk.Cid.String())
|
||||
}
|
||||
child, err := ds.Get(context.Background(), c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
traverse(child)
|
||||
}
|
||||
}
|
||||
|
||||
traverse(root)
|
||||
}
|
||||
|
||||
func TestFetchFailure(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
ds := dstest.Mock()
|
||||
ds_bad := dstest.Mock()
|
||||
|
||||
top := new(ProtoNode)
|
||||
for i := 0; i < 10; i++ {
|
||||
nd := NodeWithData([]byte{byte('a' + i)})
|
||||
err := ds.Add(ctx, nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = top.AddNodeLink(fmt.Sprintf("AA%d", i), nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
nd := NodeWithData([]byte{'f', 'a' + byte(i)})
|
||||
err := ds_bad.Add(ctx, nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = top.AddNodeLink(fmt.Sprintf("BB%d", i), nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
getters := ipld.GetDAG(ctx, ds, top)
|
||||
for i, getter := range getters {
|
||||
_, err := getter.Get(ctx)
|
||||
if err != nil && i < 10 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err == nil && i >= 10 {
|
||||
t.Fatal("should have failed request")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalFailure(t *testing.T) {
|
||||
badData := []byte("hello world")
|
||||
|
||||
_, err := DecodeProtobuf(badData)
|
||||
if err == nil {
|
||||
t.Fatal("shouldnt succeed to parse this")
|
||||
}
|
||||
|
||||
// now with a bad link
|
||||
pbn := &mdpb.PBNode{Links: []*mdpb.PBLink{{Hash: []byte("not a multihash")}}}
|
||||
badlink, err := pbn.Marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = DecodeProtobuf(badlink)
|
||||
if err == nil {
|
||||
t.Fatal("should have failed to parse node with bad link")
|
||||
}
|
||||
|
||||
n := &ProtoNode{}
|
||||
n.Marshal()
|
||||
}
|
||||
|
||||
func TestBasicAddGet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
ds := dstest.Mock()
|
||||
nd := new(ProtoNode)
|
||||
|
||||
err := ds.Add(ctx, nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, err := ds.Get(ctx, nd.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !nd.Cid().Equals(out.Cid()) {
|
||||
t.Fatal("output didnt match input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRawNodes(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
rn := NewRawNode([]byte("test"))
|
||||
|
||||
ds := dstest.Mock()
|
||||
|
||||
err := ds.Add(ctx, rn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !rn.Cid().Equals(rn.Cid()) {
|
||||
t.Fatal("output cids didnt match")
|
||||
}
|
||||
|
||||
out, err := ds.Get(ctx, rn.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(out.RawData(), []byte("test")) {
|
||||
t.Fatal("raw block should match input data")
|
||||
}
|
||||
|
||||
if out.Links() != nil {
|
||||
t.Fatal("raw blocks shouldnt have links")
|
||||
}
|
||||
|
||||
if out.Tree("", -1) != nil {
|
||||
t.Fatal("tree should return no paths in a raw block")
|
||||
}
|
||||
|
||||
size, err := out.Size()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if size != 4 {
|
||||
t.Fatal("expected size to be 4")
|
||||
}
|
||||
|
||||
ns, err := out.Stat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ns.DataSize != 4 {
|
||||
t.Fatal("expected size to be 4, got: ", ns.DataSize)
|
||||
}
|
||||
|
||||
_, _, err = out.Resolve([]string{"foo"})
|
||||
if err != ErrLinkNotFound {
|
||||
t.Fatal("shouldnt find links under raw blocks")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtoNodeResolve(t *testing.T) {
|
||||
|
||||
nd := new(ProtoNode)
|
||||
nd.SetLinks([]*ipld.Link{{Name: "foo"}})
|
||||
|
||||
lnk, left, err := nd.ResolveLink([]string{"foo", "bar"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(left) != 1 || left[0] != "bar" {
|
||||
t.Fatal("expected the single path element 'bar' to remain")
|
||||
}
|
||||
|
||||
if lnk.Name != "foo" {
|
||||
t.Fatal("how did we get anything else?")
|
||||
}
|
||||
|
||||
tvals := nd.Tree("", -1)
|
||||
if len(tvals) != 1 || tvals[0] != "foo" {
|
||||
t.Fatal("expected tree to return []{\"foo\"}")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCidRetention(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
nd := new(ProtoNode)
|
||||
nd.SetData([]byte("fooooo"))
|
||||
|
||||
pref := nd.Cid().Prefix()
|
||||
pref.Version = 1
|
||||
|
||||
c2, err := pref.Sum(nd.RawData())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
blk, err := blocks.NewBlockWithCid(nd.RawData(), c2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bs := dstest.Bserv()
|
||||
err = bs.AddBlock(blk)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ds := NewDAGService(bs)
|
||||
out, err := ds.Get(ctx, c2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !out.Cid().Equals(c2) {
|
||||
t.Fatal("output cid didnt match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCidRawDoesnNeedData(t *testing.T) {
|
||||
srv := NewDAGService(dstest.Bserv())
|
||||
nd := NewRawNode([]byte("somedata"))
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// there is no data for this node in the blockservice
|
||||
// so dag service can't load it
|
||||
links, err := srv.GetLinks(ctx, nd.Cid())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(links) != 0 {
|
||||
t.Fatal("raw node shouldn't have any links")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetManyDuplicate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
srv := NewDAGService(dstest.Bserv())
|
||||
|
||||
nd := NodeWithData([]byte("foo"))
|
||||
if err := srv.Add(ctx, nd); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nds := srv.GetMany(ctx, []*cid.Cid{nd.Cid(), nd.Cid(), nd.Cid()})
|
||||
out, ok := <-nds
|
||||
if !ok {
|
||||
t.Fatal("expecting node foo")
|
||||
}
|
||||
if out.Err != nil {
|
||||
t.Fatal(out.Err)
|
||||
}
|
||||
if !out.Node.Cid().Equals(nd.Cid()) {
|
||||
t.Fatal("got wrong node")
|
||||
}
|
||||
out, ok = <-nds
|
||||
if ok {
|
||||
if out.Err != nil {
|
||||
t.Fatal(out.Err)
|
||||
} else {
|
||||
t.Fatal("expecting no more nodes")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnumerateAsyncFailsNotFound(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
a := NodeWithData([]byte("foo1"))
|
||||
b := NodeWithData([]byte("foo2"))
|
||||
c := NodeWithData([]byte("foo3"))
|
||||
d := NodeWithData([]byte("foo4"))
|
||||
|
||||
ds := dstest.Mock()
|
||||
for _, n := range []ipld.Node{a, b, c} {
|
||||
err := ds.Add(ctx, n)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
parent := new(ProtoNode)
|
||||
if err := parent.AddNodeLink("a", a); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := parent.AddNodeLink("b", b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := parent.AddNodeLink("c", c); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := parent.AddNodeLink("d", d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := ds.Add(ctx, parent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cset := cid.NewSet()
|
||||
err = EnumerateChildrenAsync(ctx, GetLinksDirect(ds), parent.Cid(), cset.Visit)
|
||||
if err == nil {
|
||||
t.Fatal("this should have failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressIndicator(t *testing.T) {
|
||||
testProgressIndicator(t, 5)
|
||||
}
|
||||
|
||||
func TestProgressIndicatorNoChildren(t *testing.T) {
|
||||
testProgressIndicator(t, 0)
|
||||
}
|
||||
|
||||
func testProgressIndicator(t *testing.T, depth int) {
|
||||
ds := dstest.Mock()
|
||||
|
||||
top, numChildren := mkDag(ds, depth)
|
||||
|
||||
v := new(ProgressTracker)
|
||||
ctx := v.DeriveContext(context.Background())
|
||||
|
||||
err := FetchGraph(ctx, top, ds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if v.Value() != numChildren+1 {
|
||||
t.Errorf("wrong number of children reported in progress indicator, expected %d, got %d",
|
||||
numChildren+1, v.Value())
|
||||
}
|
||||
}
|
||||
|
||||
func mkDag(ds ipld.DAGService, depth int) (*cid.Cid, int) {
|
||||
ctx := context.Background()
|
||||
|
||||
totalChildren := 0
|
||||
f := func() *ProtoNode {
|
||||
p := new(ProtoNode)
|
||||
buf := make([]byte, 16)
|
||||
rand.Read(buf)
|
||||
|
||||
p.SetData(buf)
|
||||
err := ds.Add(ctx, p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
for i := 0; i < depth; i++ {
|
||||
thisf := f
|
||||
f = func() *ProtoNode {
|
||||
pn := mkNodeWithChildren(thisf, 10)
|
||||
err := ds.Add(ctx, pn)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
totalChildren += 10
|
||||
return pn
|
||||
}
|
||||
}
|
||||
|
||||
nd := f()
|
||||
err := ds.Add(ctx, nd)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nd.Cid(), totalChildren
|
||||
}
|
||||
|
||||
func mkNodeWithChildren(getChild func() *ProtoNode, width int) *ProtoNode {
|
||||
cur := new(ProtoNode)
|
||||
|
||||
for i := 0; i < width; i++ {
|
||||
c := getChild()
|
||||
if err := cur.AddNodeLink(fmt.Sprint(i), c); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
return cur
|
||||
}
|
@ -1,380 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// Common errors
|
||||
var (
|
||||
ErrNotProtobuf = fmt.Errorf("expected protobuf dag node")
|
||||
ErrLinkNotFound = fmt.Errorf("no link by that name")
|
||||
)
|
||||
|
||||
// ProtoNode represents a node in the IPFS Merkle DAG.
|
||||
// nodes have opaque data and a set of navigable links.
|
||||
type ProtoNode struct {
|
||||
links []*ipld.Link
|
||||
data []byte
|
||||
|
||||
// cache encoded/marshaled value
|
||||
encoded []byte
|
||||
|
||||
cached *cid.Cid
|
||||
|
||||
// Prefix specifies cid version and hashing function
|
||||
Prefix cid.Prefix
|
||||
}
|
||||
|
||||
var v0CidPrefix = cid.Prefix{
|
||||
Codec: cid.DagProtobuf,
|
||||
MhLength: -1,
|
||||
MhType: mh.SHA2_256,
|
||||
Version: 0,
|
||||
}
|
||||
|
||||
var v1CidPrefix = cid.Prefix{
|
||||
Codec: cid.DagProtobuf,
|
||||
MhLength: -1,
|
||||
MhType: mh.SHA2_256,
|
||||
Version: 1,
|
||||
}
|
||||
|
||||
// V0CidPrefix returns a prefix for CIDv0
|
||||
func V0CidPrefix() cid.Prefix { return v0CidPrefix }
|
||||
|
||||
// V1CidPrefix returns a prefix for CIDv1 with the default settings
|
||||
func V1CidPrefix() cid.Prefix { return v1CidPrefix }
|
||||
|
||||
// PrefixForCidVersion returns the Protobuf prefix for a given CID version
|
||||
func PrefixForCidVersion(version int) (cid.Prefix, error) {
|
||||
switch version {
|
||||
case 0:
|
||||
return v0CidPrefix, nil
|
||||
case 1:
|
||||
return v1CidPrefix, nil
|
||||
default:
|
||||
return cid.Prefix{}, fmt.Errorf("unknown CID version: %d", version)
|
||||
}
|
||||
}
|
||||
|
||||
// SetPrefix sets the CID prefix if it is non nil, if prefix is nil then
|
||||
// it resets it the default value
|
||||
func (n *ProtoNode) SetPrefix(prefix *cid.Prefix) {
|
||||
if prefix == nil {
|
||||
n.Prefix = v0CidPrefix
|
||||
} else {
|
||||
n.Prefix = *prefix
|
||||
n.Prefix.Codec = cid.DagProtobuf
|
||||
n.encoded = nil
|
||||
n.cached = nil
|
||||
}
|
||||
}
|
||||
|
||||
// LinkSlice is a slice of ipld.Links
|
||||
type LinkSlice []*ipld.Link
|
||||
|
||||
func (ls LinkSlice) Len() int { return len(ls) }
|
||||
func (ls LinkSlice) Swap(a, b int) { ls[a], ls[b] = ls[b], ls[a] }
|
||||
func (ls LinkSlice) Less(a, b int) bool { return ls[a].Name < ls[b].Name }
|
||||
|
||||
// NodeWithData builds a new Protonode with the given data.
|
||||
func NodeWithData(d []byte) *ProtoNode {
|
||||
return &ProtoNode{data: d}
|
||||
}
|
||||
|
||||
// AddNodeLink adds a link to another node.
|
||||
func (n *ProtoNode) AddNodeLink(name string, that ipld.Node) error {
|
||||
n.encoded = nil
|
||||
|
||||
lnk, err := ipld.MakeLink(that)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lnk.Name = name
|
||||
|
||||
n.AddRawLink(name, lnk)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRawLink adds a copy of a link to this node
|
||||
func (n *ProtoNode) AddRawLink(name string, l *ipld.Link) error {
|
||||
n.encoded = nil
|
||||
n.links = append(n.links, &ipld.Link{
|
||||
Name: name,
|
||||
Size: l.Size,
|
||||
Cid: l.Cid,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveNodeLink removes a link on this node by the given name.
|
||||
func (n *ProtoNode) RemoveNodeLink(name string) error {
|
||||
n.encoded = nil
|
||||
good := make([]*ipld.Link, 0, len(n.links))
|
||||
var found bool
|
||||
|
||||
for _, l := range n.links {
|
||||
if l.Name != name {
|
||||
good = append(good, l)
|
||||
} else {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
n.links = good
|
||||
|
||||
if !found {
|
||||
return ipld.ErrNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetNodeLink returns a copy of the link with the given name.
|
||||
func (n *ProtoNode) GetNodeLink(name string) (*ipld.Link, error) {
|
||||
for _, l := range n.links {
|
||||
if l.Name == name {
|
||||
return &ipld.Link{
|
||||
Name: l.Name,
|
||||
Size: l.Size,
|
||||
Cid: l.Cid,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return nil, ErrLinkNotFound
|
||||
}
|
||||
|
||||
// GetLinkedProtoNode returns a copy of the ProtoNode with the given name.
|
||||
func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds ipld.DAGService, name string) (*ProtoNode, error) {
|
||||
nd, err := n.GetLinkedNode(ctx, ds, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pbnd, ok := nd.(*ProtoNode)
|
||||
if !ok {
|
||||
return nil, ErrNotProtobuf
|
||||
}
|
||||
|
||||
return pbnd, nil
|
||||
}
|
||||
|
||||
// GetLinkedNode returns a copy of the IPLD Node with the given name.
|
||||
func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds ipld.DAGService, name string) (ipld.Node, error) {
|
||||
lnk, err := n.GetNodeLink(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lnk.GetNode(ctx, ds)
|
||||
}
|
||||
|
||||
// Copy returns a copy of the node.
|
||||
// NOTE: Does not make copies of Node objects in the links.
|
||||
func (n *ProtoNode) Copy() ipld.Node {
|
||||
nnode := new(ProtoNode)
|
||||
if len(n.data) > 0 {
|
||||
nnode.data = make([]byte, len(n.data))
|
||||
copy(nnode.data, n.data)
|
||||
}
|
||||
|
||||
if len(n.links) > 0 {
|
||||
nnode.links = make([]*ipld.Link, len(n.links))
|
||||
copy(nnode.links, n.links)
|
||||
}
|
||||
|
||||
nnode.Prefix = n.Prefix
|
||||
|
||||
return nnode
|
||||
}
|
||||
|
||||
// RawData returns the protobuf-encoded version of the node.
|
||||
func (n *ProtoNode) RawData() []byte {
|
||||
out, _ := n.EncodeProtobuf(false)
|
||||
return out
|
||||
}
|
||||
|
||||
// Data returns the data stored by this node.
|
||||
func (n *ProtoNode) Data() []byte {
|
||||
return n.data
|
||||
}
|
||||
|
||||
// SetData stores data in this nodes.
|
||||
func (n *ProtoNode) SetData(d []byte) {
|
||||
n.encoded = nil
|
||||
n.cached = nil
|
||||
n.data = d
|
||||
}
|
||||
|
||||
// UpdateNodeLink return a copy of the node with the link name set to point to
|
||||
// that. If a link of the same name existed, it is removed.
|
||||
func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error) {
|
||||
newnode := n.Copy().(*ProtoNode)
|
||||
_ = newnode.RemoveNodeLink(name) // ignore error
|
||||
err := newnode.AddNodeLink(name, that)
|
||||
return newnode, err
|
||||
}
|
||||
|
||||
// Size returns the total size of the data addressed by node,
|
||||
// including the total sizes of references.
|
||||
func (n *ProtoNode) Size() (uint64, error) {
|
||||
b, err := n.EncodeProtobuf(false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
s := uint64(len(b))
|
||||
for _, l := range n.links {
|
||||
s += l.Size
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Stat returns statistics on the node.
|
||||
func (n *ProtoNode) Stat() (*ipld.NodeStat, error) {
|
||||
enc, err := n.EncodeProtobuf(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cumSize, err := n.Size()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ipld.NodeStat{
|
||||
Hash: n.Cid().String(),
|
||||
NumLinks: len(n.links),
|
||||
BlockSize: len(enc),
|
||||
LinksSize: len(enc) - len(n.data), // includes framing.
|
||||
DataSize: len(n.data),
|
||||
CumulativeSize: int(cumSize),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Loggable implements the ipfs/go-log.Loggable interface.
|
||||
func (n *ProtoNode) Loggable() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"node": n.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON reads the node fields from a JSON-encoded byte slice.
|
||||
func (n *ProtoNode) UnmarshalJSON(b []byte) error {
|
||||
s := struct {
|
||||
Data []byte `json:"data"`
|
||||
Links []*ipld.Link `json:"links"`
|
||||
}{}
|
||||
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n.data = s.Data
|
||||
n.links = s.Links
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON returns a JSON representation of the node.
|
||||
func (n *ProtoNode) MarshalJSON() ([]byte, error) {
|
||||
out := map[string]interface{}{
|
||||
"data": n.data,
|
||||
"links": n.links,
|
||||
}
|
||||
|
||||
return json.Marshal(out)
|
||||
}
|
||||
|
||||
// Cid returns the node's Cid, calculated according to its prefix
|
||||
// and raw data contents.
|
||||
func (n *ProtoNode) Cid() *cid.Cid {
|
||||
if n.encoded != nil && n.cached != nil {
|
||||
return n.cached
|
||||
}
|
||||
|
||||
if n.Prefix.Codec == 0 {
|
||||
n.SetPrefix(nil)
|
||||
}
|
||||
|
||||
c, err := n.Prefix.Sum(n.RawData())
|
||||
if err != nil {
|
||||
// programmer error
|
||||
err = fmt.Errorf("invalid CID of length %d: %x: %v", len(n.RawData()), n.RawData(), err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
n.cached = c
|
||||
return c
|
||||
}
|
||||
|
||||
// String prints the node's Cid.
|
||||
func (n *ProtoNode) String() string {
|
||||
return n.Cid().String()
|
||||
}
|
||||
|
||||
// Multihash hashes the encoded data of this node.
|
||||
func (n *ProtoNode) Multihash() mh.Multihash {
|
||||
// NOTE: EncodeProtobuf generates the hash and puts it in n.cached.
|
||||
_, err := n.EncodeProtobuf(false)
|
||||
if err != nil {
|
||||
// Note: no possibility exists for an error to be returned through here
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return n.cached.Hash()
|
||||
}
|
||||
|
||||
// Links returns the node links.
|
||||
func (n *ProtoNode) Links() []*ipld.Link {
|
||||
return n.links
|
||||
}
|
||||
|
||||
// SetLinks replaces the node links with the given ones.
|
||||
func (n *ProtoNode) SetLinks(links []*ipld.Link) {
|
||||
n.links = links
|
||||
}
|
||||
|
||||
// Resolve is an alias for ResolveLink.
|
||||
func (n *ProtoNode) Resolve(path []string) (interface{}, []string, error) {
|
||||
return n.ResolveLink(path)
|
||||
}
|
||||
|
||||
// ResolveLink consumes the first element of the path and obtains the link
|
||||
// corresponding to it from the node. It returns the link
|
||||
// and the path without the consumed element.
|
||||
func (n *ProtoNode) ResolveLink(path []string) (*ipld.Link, []string, error) {
|
||||
if len(path) == 0 {
|
||||
return nil, nil, fmt.Errorf("end of path, no more links to resolve")
|
||||
}
|
||||
|
||||
lnk, err := n.GetNodeLink(path[0])
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return lnk, path[1:], nil
|
||||
}
|
||||
|
||||
// Tree returns the link names of the ProtoNode.
|
||||
// ProtoNodes are only ever one path deep, so anything different than an empty
|
||||
// string for p results in nothing. The depth parameter is ignored.
|
||||
func (n *ProtoNode) Tree(p string, depth int) []string {
|
||||
if p != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make([]string, 0, len(n.links))
|
||||
for _, lnk := range n.links {
|
||||
out = append(out, lnk.Name)
|
||||
}
|
||||
return out
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package merkledag_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
func TestRemoveLink(t *testing.T) {
|
||||
nd := &ProtoNode{}
|
||||
nd.SetLinks([]*ipld.Link{
|
||||
{Name: "a"},
|
||||
{Name: "b"},
|
||||
{Name: "a"},
|
||||
{Name: "a"},
|
||||
{Name: "c"},
|
||||
{Name: "a"},
|
||||
})
|
||||
|
||||
err := nd.RemoveNodeLink("a")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(nd.Links()) != 2 {
|
||||
t.Fatal("number of links incorrect")
|
||||
}
|
||||
|
||||
if nd.Links()[0].Name != "b" {
|
||||
t.Fatal("link order wrong")
|
||||
}
|
||||
|
||||
if nd.Links()[1].Name != "c" {
|
||||
t.Fatal("link order wrong")
|
||||
}
|
||||
|
||||
// should fail
|
||||
err = nd.RemoveNodeLink("a")
|
||||
if err != ipld.ErrNotFound {
|
||||
t.Fatal("should have failed to remove link")
|
||||
}
|
||||
|
||||
// ensure nothing else got touched
|
||||
if len(nd.Links()) != 2 {
|
||||
t.Fatal("number of links incorrect")
|
||||
}
|
||||
|
||||
if nd.Links()[0].Name != "b" {
|
||||
t.Fatal("link order wrong")
|
||||
}
|
||||
|
||||
if nd.Links()[1].Name != "c" {
|
||||
t.Fatal("link order wrong")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindLink(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
ds := mdtest.Mock()
|
||||
ndEmpty := new(ProtoNode)
|
||||
err := ds.Add(ctx, ndEmpty)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
kEmpty := ndEmpty.Cid()
|
||||
|
||||
nd := &ProtoNode{}
|
||||
nd.SetLinks([]*ipld.Link{
|
||||
{Name: "a", Cid: kEmpty},
|
||||
{Name: "c", Cid: kEmpty},
|
||||
{Name: "b", Cid: kEmpty},
|
||||
})
|
||||
|
||||
err = ds.Add(ctx, nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lnk, err := nd.GetNodeLink("b")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if lnk.Name != "b" {
|
||||
t.Fatal("got wrong link back")
|
||||
}
|
||||
|
||||
_, err = nd.GetNodeLink("f")
|
||||
if err != ErrLinkNotFound {
|
||||
t.Fatal("shouldnt have found link")
|
||||
}
|
||||
|
||||
_, err = nd.GetLinkedNode(context.Background(), ds, "b")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
outnd, err := nd.UpdateNodeLink("b", nd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
olnk, err := outnd.GetNodeLink("b")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if olnk.Cid.String() == kEmpty.String() {
|
||||
t.Fatal("new link should have different hash")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeCopy(t *testing.T) {
|
||||
nd := &ProtoNode{}
|
||||
nd.SetLinks([]*ipld.Link{
|
||||
{Name: "a"},
|
||||
{Name: "c"},
|
||||
{Name: "b"},
|
||||
})
|
||||
|
||||
nd.SetData([]byte("testing"))
|
||||
|
||||
ond := nd.Copy().(*ProtoNode)
|
||||
ond.SetData(nil)
|
||||
|
||||
if nd.Data() == nil {
|
||||
t.Fatal("should be different objects")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJsonRoundtrip(t *testing.T) {
|
||||
nd := new(ProtoNode)
|
||||
nd.SetLinks([]*ipld.Link{
|
||||
{Name: "a"},
|
||||
{Name: "c"},
|
||||
{Name: "b"},
|
||||
})
|
||||
nd.SetData([]byte("testing"))
|
||||
|
||||
jb, err := nd.MarshalJSON()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
nn := new(ProtoNode)
|
||||
err = nn.UnmarshalJSON(jb)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(nn.Data(), nd.Data()) {
|
||||
t.Fatal("data wasnt the same")
|
||||
}
|
||||
|
||||
if !nn.Cid().Equals(nd.Cid()) {
|
||||
t.Fatal("objects differed after marshaling")
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
include mk/header.mk
|
||||
|
||||
PB_$(d) = $(wildcard $(d)/*.proto)
|
||||
TGTS_$(d) = $(PB_$(d):.proto=.pb.go)
|
||||
|
||||
#DEPS_GO += $(TGTS_$(d))
|
||||
|
||||
include mk/footer.mk
|
@ -1,801 +0,0 @@
|
||||
// Code generated by protoc-gen-gogo.
|
||||
// source: merkledag.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
/*
|
||||
Package merkledag_pb is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
merkledag.proto
|
||||
|
||||
It has these top-level messages:
|
||||
PBLink
|
||||
PBNode
|
||||
*/
|
||||
package merkledag_pb
|
||||
|
||||
import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
// discarding unused import gogoproto "code.google.com/p/gogoprotobuf/gogoproto/gogo.pb"
|
||||
|
||||
import io "io"
|
||||
import fmt "fmt"
|
||||
import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||
|
||||
import strings "strings"
|
||||
import reflect "reflect"
|
||||
|
||||
import sort "sort"
|
||||
import strconv "strconv"
|
||||
|
||||
import bytes "bytes"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = math.Inf
|
||||
|
||||
// An IPFS MerkleDAG Link
|
||||
type PBLink struct {
|
||||
// multihash of the target object
|
||||
Hash []byte `protobuf:"bytes,1,opt" json:"Hash,omitempty"`
|
||||
// utf string name. should be unique per object
|
||||
Name *string `protobuf:"bytes,2,opt" json:"Name,omitempty"`
|
||||
// cumulative size of target object
|
||||
Tsize *uint64 `protobuf:"varint,3,opt" json:"Tsize,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *PBLink) Reset() { *m = PBLink{} }
|
||||
func (*PBLink) ProtoMessage() {}
|
||||
|
||||
func (m *PBLink) GetHash() []byte {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PBLink) GetName() string {
|
||||
if m != nil && m.Name != nil {
|
||||
return *m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *PBLink) GetTsize() uint64 {
|
||||
if m != nil && m.Tsize != nil {
|
||||
return *m.Tsize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// An IPFS MerkleDAG Node
|
||||
type PBNode struct {
|
||||
// refs to other objects
|
||||
Links []*PBLink `protobuf:"bytes,2,rep" json:"Links,omitempty"`
|
||||
// opaque user data
|
||||
Data []byte `protobuf:"bytes,1,opt" json:"Data,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *PBNode) Reset() { *m = PBNode{} }
|
||||
func (*PBNode) ProtoMessage() {}
|
||||
|
||||
func (m *PBNode) GetLinks() []*PBLink {
|
||||
if m != nil {
|
||||
return m.Links
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PBNode) GetData() []byte {
|
||||
if m != nil {
|
||||
return m.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
}
|
||||
func (m *PBLink) Unmarshal(data []byte) error {
|
||||
l := len(data)
|
||||
index := 0
|
||||
for index < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
byteLen |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
postIndex := index + byteLen
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Hash = append([]byte{}, data[index:postIndex]...)
|
||||
index = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
stringLen |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
postIndex := index + int(stringLen)
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
s := string(data[index:postIndex])
|
||||
m.Name = &s
|
||||
index = postIndex
|
||||
case 3:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Tsize", wireType)
|
||||
}
|
||||
var v uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
v |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Tsize = &v
|
||||
default:
|
||||
var sizeOfWire int
|
||||
for {
|
||||
sizeOfWire++
|
||||
wire >>= 7
|
||||
if wire == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
index -= sizeOfWire
|
||||
skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (index + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...)
|
||||
index += skippy
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *PBNode) Unmarshal(data []byte) error {
|
||||
l := len(data)
|
||||
index := 0
|
||||
for index < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
switch fieldNum {
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Links", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
msglen |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
postIndex := index + msglen
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Links = append(m.Links, &PBLink{})
|
||||
m.Links[len(m.Links)-1].Unmarshal(data[index:postIndex])
|
||||
index = postIndex
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if index >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := data[index]
|
||||
index++
|
||||
byteLen |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
postIndex := index + byteLen
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Data = append([]byte{}, data[index:postIndex]...)
|
||||
index = postIndex
|
||||
default:
|
||||
var sizeOfWire int
|
||||
for {
|
||||
sizeOfWire++
|
||||
wire >>= 7
|
||||
if wire == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
index -= sizeOfWire
|
||||
skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (index + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, data[index:index+skippy]...)
|
||||
index += skippy
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *PBLink) String() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
s := strings.Join([]string{`&PBLink{`,
|
||||
`Hash:` + valueToStringMerkledag(this.Hash) + `,`,
|
||||
`Name:` + valueToStringMerkledag(this.Name) + `,`,
|
||||
`Tsize:` + valueToStringMerkledag(this.Tsize) + `,`,
|
||||
`XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
|
||||
`}`,
|
||||
}, "")
|
||||
return s
|
||||
}
|
||||
func (this *PBNode) String() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
s := strings.Join([]string{`&PBNode{`,
|
||||
`Links:` + strings.Replace(fmt.Sprintf("%v", this.Links), "PBLink", "PBLink", 1) + `,`,
|
||||
`Data:` + valueToStringMerkledag(this.Data) + `,`,
|
||||
`XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
|
||||
`}`,
|
||||
}, "")
|
||||
return s
|
||||
}
|
||||
func valueToStringMerkledag(v interface{}) string {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.IsNil() {
|
||||
return "nil"
|
||||
}
|
||||
pv := reflect.Indirect(rv).Interface()
|
||||
return fmt.Sprintf("*%v", pv)
|
||||
}
|
||||
func (m *PBLink) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
if m.Hash != nil {
|
||||
l = len(m.Hash)
|
||||
n += 1 + l + sovMerkledag(uint64(l))
|
||||
}
|
||||
if m.Name != nil {
|
||||
l = len(*m.Name)
|
||||
n += 1 + l + sovMerkledag(uint64(l))
|
||||
}
|
||||
if m.Tsize != nil {
|
||||
n += 1 + sovMerkledag(uint64(*m.Tsize))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *PBNode) Size() (n int) {
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Links) > 0 {
|
||||
for _, e := range m.Links {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovMerkledag(uint64(l))
|
||||
}
|
||||
}
|
||||
if m.Data != nil {
|
||||
l = len(m.Data)
|
||||
n += 1 + l + sovMerkledag(uint64(l))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovMerkledag(x uint64) (n int) {
|
||||
for {
|
||||
n++
|
||||
x >>= 7
|
||||
if x == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
func sozMerkledag(x uint64) (n int) {
|
||||
return sovMerkledag(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func NewPopulatedPBLink(r randyMerkledag, easy bool) *PBLink {
|
||||
this := &PBLink{}
|
||||
if r.Intn(10) != 0 {
|
||||
v1 := r.Intn(100)
|
||||
this.Hash = make([]byte, v1)
|
||||
for i := 0; i < v1; i++ {
|
||||
this.Hash[i] = byte(r.Intn(256))
|
||||
}
|
||||
}
|
||||
if r.Intn(10) != 0 {
|
||||
v2 := randStringMerkledag(r)
|
||||
this.Name = &v2
|
||||
}
|
||||
if r.Intn(10) != 0 {
|
||||
v3 := uint64(r.Uint32())
|
||||
this.Tsize = &v3
|
||||
}
|
||||
if !easy && r.Intn(10) != 0 {
|
||||
this.XXX_unrecognized = randUnrecognizedMerkledag(r, 4)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
func NewPopulatedPBNode(r randyMerkledag, easy bool) *PBNode {
|
||||
this := &PBNode{}
|
||||
if r.Intn(10) != 0 {
|
||||
v4 := r.Intn(10)
|
||||
this.Links = make([]*PBLink, v4)
|
||||
for i := 0; i < v4; i++ {
|
||||
this.Links[i] = NewPopulatedPBLink(r, easy)
|
||||
}
|
||||
}
|
||||
if r.Intn(10) != 0 {
|
||||
v5 := r.Intn(100)
|
||||
this.Data = make([]byte, v5)
|
||||
for i := 0; i < v5; i++ {
|
||||
this.Data[i] = byte(r.Intn(256))
|
||||
}
|
||||
}
|
||||
if !easy && r.Intn(10) != 0 {
|
||||
this.XXX_unrecognized = randUnrecognizedMerkledag(r, 3)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
type randyMerkledag interface {
|
||||
Float32() float32
|
||||
Float64() float64
|
||||
Int63() int64
|
||||
Int31() int32
|
||||
Uint32() uint32
|
||||
Intn(n int) int
|
||||
}
|
||||
|
||||
func randUTF8RuneMerkledag(r randyMerkledag) rune {
|
||||
return rune(r.Intn(126-43) + 43)
|
||||
}
|
||||
func randStringMerkledag(r randyMerkledag) string {
|
||||
v6 := r.Intn(100)
|
||||
tmps := make([]rune, v6)
|
||||
for i := 0; i < v6; i++ {
|
||||
tmps[i] = randUTF8RuneMerkledag(r)
|
||||
}
|
||||
return string(tmps)
|
||||
}
|
||||
func randUnrecognizedMerkledag(r randyMerkledag, maxFieldNumber int) (data []byte) {
|
||||
l := r.Intn(5)
|
||||
for i := 0; i < l; i++ {
|
||||
wire := r.Intn(4)
|
||||
if wire == 3 {
|
||||
wire = 5
|
||||
}
|
||||
fieldNumber := maxFieldNumber + r.Intn(100)
|
||||
data = randFieldMerkledag(data, r, fieldNumber, wire)
|
||||
}
|
||||
return data
|
||||
}
|
||||
func randFieldMerkledag(data []byte, r randyMerkledag, fieldNumber int, wire int) []byte {
|
||||
key := uint32(fieldNumber)<<3 | uint32(wire)
|
||||
switch wire {
|
||||
case 0:
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(key))
|
||||
v7 := r.Int63()
|
||||
if r.Intn(2) == 0 {
|
||||
v7 *= -1
|
||||
}
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(v7))
|
||||
case 1:
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(key))
|
||||
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)))
|
||||
case 2:
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(key))
|
||||
ll := r.Intn(100)
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(ll))
|
||||
for j := 0; j < ll; j++ {
|
||||
data = append(data, byte(r.Intn(256)))
|
||||
}
|
||||
default:
|
||||
data = encodeVarintPopulateMerkledag(data, uint64(key))
|
||||
data = append(data, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
|
||||
}
|
||||
return data
|
||||
}
|
||||
func encodeVarintPopulateMerkledag(data []byte, v uint64) []byte {
|
||||
for v >= 1<<7 {
|
||||
data = append(data, uint8(uint64(v)&0x7f|0x80))
|
||||
v >>= 7
|
||||
}
|
||||
data = append(data, uint8(v))
|
||||
return data
|
||||
}
|
||||
func (m *PBLink) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
n, err := m.MarshalTo(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
func (m *PBLink) MarshalTo(data []byte) (n int, err error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Hash != nil {
|
||||
data[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintMerkledag(data, i, uint64(len(m.Hash)))
|
||||
i += copy(data[i:], m.Hash)
|
||||
}
|
||||
if m.Name != nil {
|
||||
data[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintMerkledag(data, i, uint64(len(*m.Name)))
|
||||
i += copy(data[i:], *m.Name)
|
||||
}
|
||||
if m.Tsize != nil {
|
||||
data[i] = 0x18
|
||||
i++
|
||||
i = encodeVarintMerkledag(data, i, uint64(*m.Tsize))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (m *PBNode) Marshal() (data []byte, err error) {
|
||||
size := m.Size()
|
||||
data = make([]byte, size)
|
||||
n, err := m.MarshalTo(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data[:n], nil
|
||||
}
|
||||
|
||||
func (m *PBNode) MarshalTo(data []byte) (n int, err error) {
|
||||
var i int
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Links) > 0 {
|
||||
for _, msg := range m.Links {
|
||||
data[i] = 0x12
|
||||
i++
|
||||
i = encodeVarintMerkledag(data, i, uint64(msg.Size()))
|
||||
n, err := msg.MarshalTo(data[i:])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i += n
|
||||
}
|
||||
}
|
||||
if m.Data != nil {
|
||||
data[i] = 0xa
|
||||
i++
|
||||
i = encodeVarintMerkledag(data, i, uint64(len(m.Data)))
|
||||
i += copy(data[i:], m.Data)
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
i += copy(data[i:], m.XXX_unrecognized)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func encodeFixed64Merkledag(data []byte, offset int, v uint64) int {
|
||||
data[offset] = uint8(v)
|
||||
data[offset+1] = uint8(v >> 8)
|
||||
data[offset+2] = uint8(v >> 16)
|
||||
data[offset+3] = uint8(v >> 24)
|
||||
data[offset+4] = uint8(v >> 32)
|
||||
data[offset+5] = uint8(v >> 40)
|
||||
data[offset+6] = uint8(v >> 48)
|
||||
data[offset+7] = uint8(v >> 56)
|
||||
return offset + 8
|
||||
}
|
||||
func encodeFixed32Merkledag(data []byte, offset int, v uint32) int {
|
||||
data[offset] = uint8(v)
|
||||
data[offset+1] = uint8(v >> 8)
|
||||
data[offset+2] = uint8(v >> 16)
|
||||
data[offset+3] = uint8(v >> 24)
|
||||
return offset + 4
|
||||
}
|
||||
func encodeVarintMerkledag(data []byte, offset int, v uint64) int {
|
||||
for v >= 1<<7 {
|
||||
data[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
data[offset] = uint8(v)
|
||||
return offset + 1
|
||||
}
|
||||
func (this *PBLink) GoString() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
s := strings.Join([]string{`&merkledag_pb.PBLink{` +
|
||||
`Hash:` + valueToGoStringMerkledag(this.Hash, "byte"),
|
||||
`Name:` + valueToGoStringMerkledag(this.Name, "string"),
|
||||
`Tsize:` + valueToGoStringMerkledag(this.Tsize, "uint64"),
|
||||
`XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
|
||||
return s
|
||||
}
|
||||
func (this *PBNode) GoString() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
s := strings.Join([]string{`&merkledag_pb.PBNode{` +
|
||||
`Links:` + fmt.Sprintf("%#v", this.Links),
|
||||
`Data:` + valueToGoStringMerkledag(this.Data, "byte"),
|
||||
`XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
|
||||
return s
|
||||
}
|
||||
func valueToGoStringMerkledag(v interface{}, typ string) string {
|
||||
rv := reflect.ValueOf(v)
|
||||
if rv.IsNil() {
|
||||
return "nil"
|
||||
}
|
||||
pv := reflect.Indirect(rv).Interface()
|
||||
return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
|
||||
}
|
||||
func extensionToGoStringMerkledag(e map[int32]github_com_gogo_protobuf_proto.Extension) string {
|
||||
if e == nil {
|
||||
return "nil"
|
||||
}
|
||||
s := "map[int32]proto.Extension{"
|
||||
keys := make([]int, 0, len(e))
|
||||
for k := range e {
|
||||
keys = append(keys, int(k))
|
||||
}
|
||||
sort.Ints(keys)
|
||||
ss := []string{}
|
||||
for _, k := range keys {
|
||||
ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString())
|
||||
}
|
||||
s += strings.Join(ss, ",") + "}"
|
||||
return s
|
||||
}
|
||||
func (this *PBLink) VerboseEqual(that interface{}) error {
|
||||
if that == nil {
|
||||
if this == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("that == nil && this != nil")
|
||||
}
|
||||
|
||||
that1, ok := that.(*PBLink)
|
||||
if !ok {
|
||||
return fmt.Errorf("that is not of type *PBLink")
|
||||
}
|
||||
if that1 == nil {
|
||||
if this == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("that is type *PBLink but is nil && this != nil")
|
||||
} else if this == nil {
|
||||
return fmt.Errorf("that is type *PBLinkbut is not nil && this == nil")
|
||||
}
|
||||
if !bytes.Equal(this.Hash, that1.Hash) {
|
||||
return fmt.Errorf("Hash this(%v) Not Equal that(%v)", this.Hash, that1.Hash)
|
||||
}
|
||||
if this.Name != nil && that1.Name != nil {
|
||||
if *this.Name != *that1.Name {
|
||||
return fmt.Errorf("Name this(%v) Not Equal that(%v)", *this.Name, *that1.Name)
|
||||
}
|
||||
} else if this.Name != nil {
|
||||
return fmt.Errorf("this.Name == nil && that.Name != nil")
|
||||
} else if that1.Name != nil {
|
||||
return fmt.Errorf("Name this(%v) Not Equal that(%v)", this.Name, that1.Name)
|
||||
}
|
||||
if this.Tsize != nil && that1.Tsize != nil {
|
||||
if *this.Tsize != *that1.Tsize {
|
||||
return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", *this.Tsize, *that1.Tsize)
|
||||
}
|
||||
} else if this.Tsize != nil {
|
||||
return fmt.Errorf("this.Tsize == nil && that.Tsize != nil")
|
||||
} else if that1.Tsize != nil {
|
||||
return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", this.Tsize, that1.Tsize)
|
||||
}
|
||||
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
|
||||
return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *PBLink) Equal(that interface{}) bool {
|
||||
if that == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
that1, ok := that.(*PBLink)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if that1 == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} else if this == nil {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(this.Hash, that1.Hash) {
|
||||
return false
|
||||
}
|
||||
if this.Name != nil && that1.Name != nil {
|
||||
if *this.Name != *that1.Name {
|
||||
return false
|
||||
}
|
||||
} else if this.Name != nil {
|
||||
return false
|
||||
} else if that1.Name != nil {
|
||||
return false
|
||||
}
|
||||
if this.Tsize != nil && that1.Tsize != nil {
|
||||
if *this.Tsize != *that1.Tsize {
|
||||
return false
|
||||
}
|
||||
} else if this.Tsize != nil {
|
||||
return false
|
||||
} else if that1.Tsize != nil {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
func (this *PBNode) VerboseEqual(that interface{}) error {
|
||||
if that == nil {
|
||||
if this == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("that == nil && this != nil")
|
||||
}
|
||||
|
||||
that1, ok := that.(*PBNode)
|
||||
if !ok {
|
||||
return fmt.Errorf("that is not of type *PBNode")
|
||||
}
|
||||
if that1 == nil {
|
||||
if this == nil {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("that is type *PBNode but is nil && this != nil")
|
||||
} else if this == nil {
|
||||
return fmt.Errorf("that is type *PBNodebut is not nil && this == nil")
|
||||
}
|
||||
if len(this.Links) != len(that1.Links) {
|
||||
return fmt.Errorf("Links this(%v) Not Equal that(%v)", len(this.Links), len(that1.Links))
|
||||
}
|
||||
for i := range this.Links {
|
||||
if !this.Links[i].Equal(that1.Links[i]) {
|
||||
return fmt.Errorf("Links this[%v](%v) Not Equal that[%v](%v)", i, this.Links[i], i, that1.Links[i])
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(this.Data, that1.Data) {
|
||||
return fmt.Errorf("Data this(%v) Not Equal that(%v)", this.Data, that1.Data)
|
||||
}
|
||||
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
|
||||
return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *PBNode) Equal(that interface{}) bool {
|
||||
if that == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
that1, ok := that.(*PBNode)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if that1 == nil {
|
||||
if this == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
} else if this == nil {
|
||||
return false
|
||||
}
|
||||
if len(this.Links) != len(that1.Links) {
|
||||
return false
|
||||
}
|
||||
for i := range this.Links {
|
||||
if !this.Links[i].Equal(that1.Links[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(this.Data, that1.Data) {
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package merkledag.pb;
|
||||
|
||||
import "code.google.com/p/gogoprotobuf/gogoproto/gogo.proto";
|
||||
|
||||
option (gogoproto.gostring_all) = true;
|
||||
option (gogoproto.equal_all) = true;
|
||||
option (gogoproto.verbose_equal_all) = true;
|
||||
option (gogoproto.goproto_stringer_all) = false;
|
||||
option (gogoproto.stringer_all) = true;
|
||||
option (gogoproto.populate_all) = true;
|
||||
option (gogoproto.testgen_all) = true;
|
||||
option (gogoproto.benchgen_all) = true;
|
||||
option (gogoproto.marshaler_all) = true;
|
||||
option (gogoproto.sizer_all) = true;
|
||||
option (gogoproto.unmarshaler_all) = true;
|
||||
|
||||
|
||||
// An IPFS MerkleDAG Link
|
||||
message PBLink {
|
||||
|
||||
// multihash of the target object
|
||||
optional bytes Hash = 1;
|
||||
|
||||
// utf string name. should be unique per object
|
||||
optional string Name = 2;
|
||||
|
||||
// cumulative size of target object
|
||||
optional uint64 Tsize = 3;
|
||||
}
|
||||
|
||||
// An IPFS MerkleDAG Node
|
||||
message PBNode {
|
||||
|
||||
// refs to other objects
|
||||
repeated PBLink Links = 2;
|
||||
|
||||
// opaque user data
|
||||
optional bytes Data = 1;
|
||||
}
|
@ -1,450 +0,0 @@
|
||||
// Code generated by protoc-gen-gogo.
|
||||
// source: merkledag.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
/*
|
||||
Package merkledag_pb is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
merkledag.proto
|
||||
|
||||
It has these top-level messages:
|
||||
PBLink
|
||||
PBNode
|
||||
*/
|
||||
package merkledag_pb
|
||||
|
||||
import testing "testing"
|
||||
import math_rand "math/rand"
|
||||
import time "time"
|
||||
import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||
import encoding_json "encoding/json"
|
||||
import fmt "fmt"
|
||||
import go_parser "go/parser"
|
||||
|
||||
func TestPBLinkProto(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBLink{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBLinkMarshalTo(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, false)
|
||||
size := p.Size()
|
||||
data := make([]byte, size)
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBLink{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPBLinkProtoMarshal(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*PBLink, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedPBLink(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(data)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = data
|
||||
}
|
||||
msg := &PBLink{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestPBNodeProto(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBNode{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBNodeMarshalTo(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, false)
|
||||
size := p.Size()
|
||||
data := make([]byte, size)
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
_, err := p.MarshalTo(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBNode{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := range data {
|
||||
data[i] = byte(popr.Intn(256))
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPBNodeProtoMarshal(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*PBNode, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
pops[i] = NewPopulatedPBNode(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
total += len(data)
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
datas := make([][]byte, 10000)
|
||||
for i := 0; i < 10000; i++ {
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
datas[i] = data
|
||||
}
|
||||
msg := &PBNode{}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += len(datas[i%10000])
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestPBLinkJSON(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, true)
|
||||
jsondata, err := encoding_json.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBLink{}
|
||||
err = encoding_json.Unmarshal(jsondata, msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Json Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestPBNodeJSON(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, true)
|
||||
jsondata, err := encoding_json.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBNode{}
|
||||
err = encoding_json.Unmarshal(jsondata, msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Json Equal %#v", msg, p)
|
||||
}
|
||||
}
|
||||
func TestPBLinkProtoText(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, true)
|
||||
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
|
||||
msg := &PBLink{}
|
||||
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBLinkProtoCompactText(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, true)
|
||||
data := github_com_gogo_protobuf_proto.CompactTextString(p)
|
||||
msg := &PBLink{}
|
||||
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBNodeProtoText(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, true)
|
||||
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
|
||||
msg := &PBNode{}
|
||||
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBNodeProtoCompactText(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, true)
|
||||
data := github_com_gogo_protobuf_proto.CompactTextString(p)
|
||||
msg := &PBNode{}
|
||||
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
|
||||
}
|
||||
if !p.Equal(msg) {
|
||||
t.Fatalf("%#v !Proto %#v", msg, p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPBLinkStringer(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestPBNodeStringer(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, false)
|
||||
s1 := p.String()
|
||||
s2 := fmt.Sprintf("%v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("String want %v got %v", s1, s2)
|
||||
}
|
||||
}
|
||||
func TestPBLinkSize(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, true)
|
||||
size2 := github_com_gogo_protobuf_proto.Size(p)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(data) != size {
|
||||
t.Fatalf("size %v != marshalled size %v", size, len(data))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
|
||||
}
|
||||
size3 := github_com_gogo_protobuf_proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPBLinkSize(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*PBLink, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedPBLink(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestPBNodeSize(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, true)
|
||||
size2 := github_com_gogo_protobuf_proto.Size(p)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
size := p.Size()
|
||||
if len(data) != size {
|
||||
t.Fatalf("size %v != marshalled size %v", size, len(data))
|
||||
}
|
||||
if size2 != size {
|
||||
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
|
||||
}
|
||||
size3 := github_com_gogo_protobuf_proto.Size(p)
|
||||
if size3 != size {
|
||||
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPBNodeSize(b *testing.B) {
|
||||
popr := math_rand.New(math_rand.NewSource(616))
|
||||
total := 0
|
||||
pops := make([]*PBNode, 1000)
|
||||
for i := 0; i < 1000; i++ {
|
||||
pops[i] = NewPopulatedPBNode(popr, false)
|
||||
}
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
total += pops[i%1000].Size()
|
||||
}
|
||||
b.SetBytes(int64(total / b.N))
|
||||
}
|
||||
|
||||
func TestPBLinkGoString(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := go_parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
func TestPBNodeGoString(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, false)
|
||||
s1 := p.GoString()
|
||||
s2 := fmt.Sprintf("%#v", p)
|
||||
if s1 != s2 {
|
||||
t.Fatalf("GoString want %v got %v", s1, s2)
|
||||
}
|
||||
_, err := go_parser.ParseExpr(s1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
func TestPBLinkVerboseEqual(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBLink(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBLink{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
func TestPBNodeVerboseEqual(t *testing.T) {
|
||||
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
|
||||
p := NewPopulatedPBNode(popr, false)
|
||||
data, err := github_com_gogo_protobuf_proto.Marshal(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
msg := &PBNode{}
|
||||
if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := p.VerboseEqual(msg); err != nil {
|
||||
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
|
||||
}
|
||||
}
|
||||
|
||||
//These tests are generated by github.com/gogo/protobuf/plugin/testgen
|
101
merkledag/raw.go
101
merkledag/raw.go
@ -1,101 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// RawNode represents a node which only contains data.
|
||||
type RawNode struct {
|
||||
blocks.Block
|
||||
}
|
||||
|
||||
// NewRawNode creates a RawNode using the default sha2-256 hash function.
|
||||
func NewRawNode(data []byte) *RawNode {
|
||||
h := u.Hash(data)
|
||||
c := cid.NewCidV1(cid.Raw, h)
|
||||
blk, _ := blocks.NewBlockWithCid(data, c)
|
||||
|
||||
return &RawNode{blk}
|
||||
}
|
||||
|
||||
// DecodeRawBlock is a block decoder for raw IPLD nodes conforming to `node.DecodeBlockFunc`.
|
||||
func DecodeRawBlock(block blocks.Block) (ipld.Node, error) {
|
||||
if block.Cid().Type() != cid.Raw {
|
||||
return nil, fmt.Errorf("raw nodes cannot be decoded from non-raw blocks: %d", block.Cid().Type())
|
||||
}
|
||||
// Once you "share" a block, it should be immutable. Therefore, we can just use this block as-is.
|
||||
return &RawNode{block}, nil
|
||||
}
|
||||
|
||||
var _ ipld.DecodeBlockFunc = DecodeRawBlock
|
||||
|
||||
// NewRawNodeWPrefix creates a RawNode with the hash function
|
||||
// specified in prefix.
|
||||
func NewRawNodeWPrefix(data []byte, prefix cid.Prefix) (*RawNode, error) {
|
||||
prefix.Codec = cid.Raw
|
||||
if prefix.Version == 0 {
|
||||
prefix.Version = 1
|
||||
}
|
||||
c, err := prefix.Sum(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blk, err := blocks.NewBlockWithCid(data, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RawNode{blk}, nil
|
||||
}
|
||||
|
||||
// Links returns nil.
|
||||
func (rn *RawNode) Links() []*ipld.Link {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolveLink returns an error.
|
||||
func (rn *RawNode) ResolveLink(path []string) (*ipld.Link, []string, error) {
|
||||
return nil, nil, ErrLinkNotFound
|
||||
}
|
||||
|
||||
// Resolve returns an error.
|
||||
func (rn *RawNode) Resolve(path []string) (interface{}, []string, error) {
|
||||
return nil, nil, ErrLinkNotFound
|
||||
}
|
||||
|
||||
// Tree returns nil.
|
||||
func (rn *RawNode) Tree(p string, depth int) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Copy performs a deep copy of this node and returns it as an ipld.Node
|
||||
func (rn *RawNode) Copy() ipld.Node {
|
||||
copybuf := make([]byte, len(rn.RawData()))
|
||||
copy(copybuf, rn.RawData())
|
||||
nblk, err := blocks.NewBlockWithCid(rn.RawData(), rn.Cid())
|
||||
if err != nil {
|
||||
// programmer error
|
||||
panic("failure attempting to clone raw block: " + err.Error())
|
||||
}
|
||||
|
||||
return &RawNode{nblk}
|
||||
}
|
||||
|
||||
// Size returns the size of this node
|
||||
func (rn *RawNode) Size() (uint64, error) {
|
||||
return uint64(len(rn.RawData())), nil
|
||||
}
|
||||
|
||||
// Stat returns some Stats about this node.
|
||||
func (rn *RawNode) Stat() (*ipld.NodeStat, error) {
|
||||
return &ipld.NodeStat{
|
||||
CumulativeSize: len(rn.RawData()),
|
||||
DataSize: len(rn.RawData()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
var _ ipld.Node = (*RawNode)(nil)
|
@ -1,20 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// ErrReadOnly is used when a read-only datastructure is written to.
|
||||
var ErrReadOnly = fmt.Errorf("cannot write to readonly DAGService")
|
||||
|
||||
// NewReadOnlyDagService takes a NodeGetter, and returns a full DAGService
|
||||
// implementation that returns ErrReadOnly when its 'write' methods are
|
||||
// invoked.
|
||||
func NewReadOnlyDagService(ng ipld.NodeGetter) ipld.DAGService {
|
||||
return &ComboService{
|
||||
Read: ng,
|
||||
Write: &ErrorService{ErrReadOnly},
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package merkledag_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/ipfs/go-ipfs/merkledag"
|
||||
dstest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
func TestReadonlyProperties(t *testing.T) {
|
||||
ds := dstest.Mock()
|
||||
ro := NewReadOnlyDagService(ds)
|
||||
|
||||
ctx := context.Background()
|
||||
nds := []ipld.Node{
|
||||
NewRawNode([]byte("foo1")),
|
||||
NewRawNode([]byte("foo2")),
|
||||
NewRawNode([]byte("foo3")),
|
||||
NewRawNode([]byte("foo4")),
|
||||
}
|
||||
cids := []*cid.Cid{
|
||||
nds[0].Cid(),
|
||||
nds[1].Cid(),
|
||||
nds[2].Cid(),
|
||||
nds[3].Cid(),
|
||||
}
|
||||
|
||||
// add to the actual underlying datastore
|
||||
if err := ds.Add(ctx, nds[2]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ds.Add(ctx, nds[3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ro.Add(ctx, nds[0]); err != ErrReadOnly {
|
||||
t.Fatal("expected ErrReadOnly")
|
||||
}
|
||||
if err := ro.Add(ctx, nds[2]); err != ErrReadOnly {
|
||||
t.Fatal("expected ErrReadOnly")
|
||||
}
|
||||
|
||||
if err := ro.AddMany(ctx, nds[0:1]); err != ErrReadOnly {
|
||||
t.Fatal("expected ErrReadOnly")
|
||||
}
|
||||
|
||||
if err := ro.Remove(ctx, cids[3]); err != ErrReadOnly {
|
||||
t.Fatal("expected ErrReadOnly")
|
||||
}
|
||||
if err := ro.RemoveMany(ctx, cids[1:2]); err != ErrReadOnly {
|
||||
t.Fatal("expected ErrReadOnly")
|
||||
}
|
||||
|
||||
if _, err := ro.Get(ctx, cids[0]); err != ipld.ErrNotFound {
|
||||
t.Fatal("expected ErrNotFound")
|
||||
}
|
||||
if _, err := ro.Get(ctx, cids[3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// ComboService implements ipld.DAGService, using 'Read' for all fetch methods,
|
||||
// and 'Write' for all methods that add new objects.
|
||||
type ComboService struct {
|
||||
Read ipld.NodeGetter
|
||||
Write ipld.DAGService
|
||||
}
|
||||
|
||||
var _ ipld.DAGService = (*ComboService)(nil)
|
||||
|
||||
// Add writes a new node using the Write DAGService.
|
||||
func (cs *ComboService) Add(ctx context.Context, nd ipld.Node) error {
|
||||
return cs.Write.Add(ctx, nd)
|
||||
}
|
||||
|
||||
// AddMany adds nodes using the Write DAGService.
|
||||
func (cs *ComboService) AddMany(ctx context.Context, nds []ipld.Node) error {
|
||||
return cs.Write.AddMany(ctx, nds)
|
||||
}
|
||||
|
||||
// Get fetches a node using the Read DAGService.
|
||||
func (cs *ComboService) Get(ctx context.Context, c *cid.Cid) (ipld.Node, error) {
|
||||
return cs.Read.Get(ctx, c)
|
||||
}
|
||||
|
||||
// GetMany fetches nodes using the Read DAGService.
|
||||
func (cs *ComboService) GetMany(ctx context.Context, cids []*cid.Cid) <-chan *ipld.NodeOption {
|
||||
return cs.Read.GetMany(ctx, cids)
|
||||
}
|
||||
|
||||
// Remove deletes a node using the Write DAGService.
|
||||
func (cs *ComboService) Remove(ctx context.Context, c *cid.Cid) error {
|
||||
return cs.Write.Remove(ctx, c)
|
||||
}
|
||||
|
||||
// RemoveMany deletes nodes using the Write DAGService.
|
||||
func (cs *ComboService) RemoveMany(ctx context.Context, cids []*cid.Cid) error {
|
||||
return cs.Write.RemoveMany(ctx, cids)
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package merkledag
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// SessionMaker is an object that can generate a new fetching session.
|
||||
type SessionMaker interface {
|
||||
Session(context.Context) ipld.NodeGetter
|
||||
}
|
||||
|
||||
// NewSession returns a session backed NodeGetter if the given NodeGetter
|
||||
// implements SessionMaker.
|
||||
func NewSession(ctx context.Context, g ipld.NodeGetter) ipld.NodeGetter {
|
||||
if sm, ok := g.(SessionMaker); ok {
|
||||
return sm.Session(ctx)
|
||||
}
|
||||
return g
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package mdutils
|
||||
|
||||
import (
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
bsrv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
blockstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
|
||||
ds "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore"
|
||||
dssync "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore/sync"
|
||||
)
|
||||
|
||||
// Mock returns a new thread-safe, mock DAGService.
|
||||
func Mock() ipld.DAGService {
|
||||
return dag.NewDAGService(Bserv())
|
||||
}
|
||||
|
||||
// Bserv returns a new, thread-safe, mock BlockService.
|
||||
func Bserv() bsrv.BlockService {
|
||||
bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
|
||||
return bsrv.New(bstore, offline.Exchange(bstore))
|
||||
}
|
@ -1,223 +0,0 @@
|
||||
// Package traverse provides merkledag traversal functions
|
||||
package traverse
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
// Order is an identifier for traversal algorithm orders
|
||||
type Order int
|
||||
|
||||
// These constants define different traversing methods
|
||||
const (
|
||||
// DFSPre defines depth-first pre-order
|
||||
DFSPre Order = iota
|
||||
// DFSPost defines depth-first post-order
|
||||
DFSPost
|
||||
// BFS defines breadth-first order
|
||||
BFS
|
||||
)
|
||||
|
||||
// Options specifies a series of traversal options
|
||||
type Options struct {
|
||||
DAG ipld.NodeGetter // the dagservice to fetch nodes
|
||||
Order Order // what order to traverse in
|
||||
Func Func // the function to perform at each step
|
||||
ErrFunc ErrFunc // see ErrFunc. Optional
|
||||
|
||||
SkipDuplicates bool // whether to skip duplicate nodes
|
||||
}
|
||||
|
||||
// State is a current traversal state
|
||||
type State struct {
|
||||
Node ipld.Node
|
||||
Depth int
|
||||
}
|
||||
|
||||
type traversal struct {
|
||||
opts Options
|
||||
seen map[string]struct{}
|
||||
}
|
||||
|
||||
func (t *traversal) shouldSkip(n ipld.Node) (bool, error) {
|
||||
if t.opts.SkipDuplicates {
|
||||
k := n.Cid()
|
||||
if _, found := t.seen[k.KeyString()]; found {
|
||||
return true, nil
|
||||
}
|
||||
t.seen[k.KeyString()] = struct{}{}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (t *traversal) callFunc(next State) error {
|
||||
return t.opts.Func(next)
|
||||
}
|
||||
|
||||
// getNode returns the node for link. If it return an error,
|
||||
// stop processing. if it returns a nil node, just skip it.
|
||||
//
|
||||
// the error handling is a little complicated.
|
||||
func (t *traversal) getNode(link *ipld.Link) (ipld.Node, error) {
|
||||
|
||||
getNode := func(l *ipld.Link) (ipld.Node, error) {
|
||||
next, err := l.GetNode(context.TODO(), t.opts.DAG)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
skip, err := t.shouldSkip(next)
|
||||
if skip {
|
||||
next = nil
|
||||
}
|
||||
return next, err
|
||||
}
|
||||
|
||||
next, err := getNode(link)
|
||||
if err != nil && t.opts.ErrFunc != nil { // attempt recovery.
|
||||
err = t.opts.ErrFunc(err)
|
||||
next = nil // skip regardless
|
||||
}
|
||||
return next, err
|
||||
}
|
||||
|
||||
// Func is the type of the function called for each dag.Node visited by Traverse.
|
||||
// The traversal argument contains the current traversal state.
|
||||
// If an error is returned, processing stops.
|
||||
type Func func(current State) error
|
||||
|
||||
// ErrFunc is provided to handle problems when walking to the Node. Traverse
|
||||
// will call ErrFunc with the error encountered. ErrFunc can decide how to
|
||||
// handle that error, and return an error back to Traversal with how to proceed:
|
||||
// * nil - skip the Node and its children, but continue processing
|
||||
// * all other errors halt processing immediately.
|
||||
//
|
||||
// If ErrFunc is nil, Traversal will stop, as if:
|
||||
//
|
||||
// opts.ErrFunc = func(err error) { return err }
|
||||
//
|
||||
type ErrFunc func(err error) error
|
||||
|
||||
// Traverse initiates a DAG traversal with the given options starting at
|
||||
// the given root.
|
||||
func Traverse(root ipld.Node, o Options) error {
|
||||
t := traversal{
|
||||
opts: o,
|
||||
seen: map[string]struct{}{},
|
||||
}
|
||||
|
||||
state := State{
|
||||
Node: root,
|
||||
Depth: 0,
|
||||
}
|
||||
|
||||
switch o.Order {
|
||||
default:
|
||||
return dfsPreTraverse(state, &t)
|
||||
case DFSPre:
|
||||
return dfsPreTraverse(state, &t)
|
||||
case DFSPost:
|
||||
return dfsPostTraverse(state, &t)
|
||||
case BFS:
|
||||
return bfsTraverse(state, &t)
|
||||
}
|
||||
}
|
||||
|
||||
type dfsFunc func(state State, t *traversal) error
|
||||
|
||||
func dfsPreTraverse(state State, t *traversal) error {
|
||||
if err := t.callFunc(state); err != nil {
|
||||
return err
|
||||
}
|
||||
return dfsDescend(dfsPreTraverse, state, t)
|
||||
}
|
||||
|
||||
func dfsPostTraverse(state State, t *traversal) error {
|
||||
if err := dfsDescend(dfsPostTraverse, state, t); err != nil {
|
||||
return err
|
||||
}
|
||||
return t.callFunc(state)
|
||||
}
|
||||
|
||||
func dfsDescend(df dfsFunc, curr State, t *traversal) error {
|
||||
for _, l := range curr.Node.Links() {
|
||||
node, err := t.getNode(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if node == nil { // skip
|
||||
continue
|
||||
}
|
||||
|
||||
next := State{
|
||||
Node: node,
|
||||
Depth: curr.Depth + 1,
|
||||
}
|
||||
if err := df(next, t); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func bfsTraverse(root State, t *traversal) error {
|
||||
|
||||
if skip, err := t.shouldSkip(root.Node); skip || err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var q queue
|
||||
q.enq(root)
|
||||
for q.len() > 0 {
|
||||
curr := q.deq()
|
||||
if curr.Node == nil {
|
||||
return errors.New("failed to dequeue though queue not empty")
|
||||
}
|
||||
|
||||
// call user's func
|
||||
if err := t.callFunc(curr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, l := range curr.Node.Links() {
|
||||
node, err := t.getNode(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if node == nil { // skip
|
||||
continue
|
||||
}
|
||||
|
||||
q.enq(State{
|
||||
Node: node,
|
||||
Depth: curr.Depth + 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type queue struct {
|
||||
s []State
|
||||
}
|
||||
|
||||
func (q *queue) enq(n State) {
|
||||
q.s = append(q.s, n)
|
||||
}
|
||||
|
||||
func (q *queue) deq() State {
|
||||
if len(q.s) < 1 {
|
||||
return State{}
|
||||
}
|
||||
n := q.s[0]
|
||||
q.s = q.s[1:]
|
||||
return n
|
||||
}
|
||||
|
||||
func (q *queue) len() int {
|
||||
return len(q.s)
|
||||
}
|
@ -1,418 +0,0 @@
|
||||
package traverse
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdagtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
||||
func TestDFSPreNoSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: DFSPre, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
1 /a/ab
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
}
|
||||
|
||||
func TestDFSPreSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: DFSPre, SkipDuplicates: true, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
1 /a/ab
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
}
|
||||
|
||||
func TestDFSPostNoSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: DFSPost, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
1 /a/aa
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
1 /a/aa
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
1 /a/ab
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
1 /a/aa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
1 /a/aa
|
||||
0 /a
|
||||
`))
|
||||
}
|
||||
|
||||
func TestDFSPostSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: DFSPost, SkipDuplicates: true, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
1 /a/aa
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
1 /a/aa
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
1 /a/ab
|
||||
0 /a
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
2 /a/aa/aaa
|
||||
1 /a/aa
|
||||
0 /a
|
||||
`))
|
||||
}
|
||||
|
||||
func TestBFSNoSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: BFS, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
}
|
||||
|
||||
func TestBFSSkip(t *testing.T) {
|
||||
ds := mdagtest.Mock()
|
||||
opts := Options{Order: BFS, SkipDuplicates: true, DAG: ds}
|
||||
|
||||
testWalkOutputs(t, newFan(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
1 /a/ac
|
||||
1 /a/ad
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newLinkedList(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryTree(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
1 /a/ab
|
||||
2 /a/aa/aaa
|
||||
2 /a/aa/aab
|
||||
2 /a/ab/aba
|
||||
2 /a/ab/abb
|
||||
`))
|
||||
|
||||
testWalkOutputs(t, newBinaryDAG(t, ds), opts, []byte(`
|
||||
0 /a
|
||||
1 /a/aa
|
||||
2 /a/aa/aaa
|
||||
3 /a/aa/aaa/aaaa
|
||||
4 /a/aa/aaa/aaaa/aaaaa
|
||||
`))
|
||||
}
|
||||
|
||||
func testWalkOutputs(t *testing.T, root ipld.Node, opts Options, expect []byte) {
|
||||
expect = bytes.TrimLeft(expect, "\n")
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
walk := func(current State) error {
|
||||
s := fmt.Sprintf("%d %s\n", current.Depth, current.Node.(*mdag.ProtoNode).Data())
|
||||
t.Logf("walk: %s", s)
|
||||
buf.Write([]byte(s))
|
||||
return nil
|
||||
}
|
||||
|
||||
opts.Func = walk
|
||||
if err := Traverse(root, opts); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
actual := buf.Bytes()
|
||||
if !bytes.Equal(actual, expect) {
|
||||
t.Error("error: outputs differ")
|
||||
t.Logf("expect:\n%s", expect)
|
||||
t.Logf("actual:\n%s", actual)
|
||||
} else {
|
||||
t.Logf("expect matches actual:\n%s", expect)
|
||||
}
|
||||
}
|
||||
|
||||
func newFan(t *testing.T, ds ipld.DAGService) ipld.Node {
|
||||
a := mdag.NodeWithData([]byte("/a"))
|
||||
addLink(t, ds, a, child(t, ds, a, "aa"))
|
||||
addLink(t, ds, a, child(t, ds, a, "ab"))
|
||||
addLink(t, ds, a, child(t, ds, a, "ac"))
|
||||
addLink(t, ds, a, child(t, ds, a, "ad"))
|
||||
return a
|
||||
}
|
||||
|
||||
func newLinkedList(t *testing.T, ds ipld.DAGService) ipld.Node {
|
||||
a := mdag.NodeWithData([]byte("/a"))
|
||||
aa := child(t, ds, a, "aa")
|
||||
aaa := child(t, ds, aa, "aaa")
|
||||
aaaa := child(t, ds, aaa, "aaaa")
|
||||
aaaaa := child(t, ds, aaaa, "aaaaa")
|
||||
addLink(t, ds, aaaa, aaaaa)
|
||||
addLink(t, ds, aaa, aaaa)
|
||||
addLink(t, ds, aa, aaa)
|
||||
addLink(t, ds, a, aa)
|
||||
return a
|
||||
}
|
||||
|
||||
func newBinaryTree(t *testing.T, ds ipld.DAGService) ipld.Node {
|
||||
a := mdag.NodeWithData([]byte("/a"))
|
||||
aa := child(t, ds, a, "aa")
|
||||
ab := child(t, ds, a, "ab")
|
||||
addLink(t, ds, aa, child(t, ds, aa, "aaa"))
|
||||
addLink(t, ds, aa, child(t, ds, aa, "aab"))
|
||||
addLink(t, ds, ab, child(t, ds, ab, "aba"))
|
||||
addLink(t, ds, ab, child(t, ds, ab, "abb"))
|
||||
addLink(t, ds, a, aa)
|
||||
addLink(t, ds, a, ab)
|
||||
return a
|
||||
}
|
||||
|
||||
func newBinaryDAG(t *testing.T, ds ipld.DAGService) ipld.Node {
|
||||
a := mdag.NodeWithData([]byte("/a"))
|
||||
aa := child(t, ds, a, "aa")
|
||||
aaa := child(t, ds, aa, "aaa")
|
||||
aaaa := child(t, ds, aaa, "aaaa")
|
||||
aaaaa := child(t, ds, aaaa, "aaaaa")
|
||||
addLink(t, ds, aaaa, aaaaa)
|
||||
addLink(t, ds, aaaa, aaaaa)
|
||||
addLink(t, ds, aaa, aaaa)
|
||||
addLink(t, ds, aaa, aaaa)
|
||||
addLink(t, ds, aa, aaa)
|
||||
addLink(t, ds, aa, aaa)
|
||||
addLink(t, ds, a, aa)
|
||||
addLink(t, ds, a, aa)
|
||||
return a
|
||||
}
|
||||
|
||||
func addLink(t *testing.T, ds ipld.DAGService, a, b ipld.Node) {
|
||||
to := string(a.(*mdag.ProtoNode).Data()) + "2" + string(b.(*mdag.ProtoNode).Data())
|
||||
if err := ds.Add(context.Background(), b); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := a.(*mdag.ProtoNode).AddNodeLink(to, b.(*mdag.ProtoNode)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func child(t *testing.T, ds ipld.DAGService, a ipld.Node, name string) ipld.Node {
|
||||
return mdag.NodeWithData([]byte(string(a.(*mdag.ProtoNode).Data()) + "/" + name))
|
||||
}
|
@ -9,10 +9,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
ufspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
mod "github.com/ipfs/go-ipfs/unixfs/mod"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -15,11 +15,11 @@ import (
|
||||
"time"
|
||||
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
"github.com/ipfs/go-ipfs/path"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
|
@ -16,8 +16,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -557,6 +557,12 @@
|
||||
"hash": "QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R",
|
||||
"name": "go-blockservice",
|
||||
"version": "1.0.1"
|
||||
},
|
||||
{
|
||||
"author": "why",
|
||||
"hash": "QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59",
|
||||
"name": "go-merkledag",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
],
|
||||
"gxVersion": "0.10.0",
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagmock "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
"github.com/ipfs/go-ipfs/path/resolver"
|
||||
merkledag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
dagmock "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
"gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
@ -518,7 +518,7 @@ func (p *pinner) Update(ctx context.Context, from, to *cid.Cid, unpin bool) erro
|
||||
return fmt.Errorf("'from' cid was not recursively pinned already")
|
||||
}
|
||||
|
||||
err := dutils.DiffEnumerate(ctx, p.dserv, from, to)
|
||||
err := dagutils.DiffEnumerate(ctx, p.dserv, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
bs "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
"hash/fnv"
|
||||
"sort"
|
||||
|
||||
"github.com/ipfs/go-ipfs/merkledag"
|
||||
"github.com/ipfs/go-ipfs/pin/internal/pb"
|
||||
"gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -8,11 +8,11 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
importer "github.com/ipfs/go-ipfs/importer"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
dagutil "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
@ -42,7 +42,7 @@ func ImportTar(ctx context.Context, r io.Reader, ds ipld.DAGService) (*dag.Proto
|
||||
root := new(dag.ProtoNode)
|
||||
root.SetData([]byte("ipfs/tar"))
|
||||
|
||||
e := dagutil.NewDagEditor(root, ds)
|
||||
e := dagutils.NewDagEditor(root, ds)
|
||||
|
||||
for {
|
||||
h, err := tr.Next()
|
||||
|
@ -10,10 +10,10 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
upb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
@ -25,9 +25,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
format "github.com/ipfs/go-ipfs/unixfs"
|
||||
upb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
bitfield "gx/ipfs/QmTbBs3Y3u5F69XNJzdnnc6SP5GKgcXxCDzx6w8m6piVRT/go-bitfield"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
"github.com/ipfs/go-ipfs/unixfs"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
context "context"
|
||||
|
||||
|
@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
format "github.com/ipfs/go-ipfs/unixfs"
|
||||
hamt "github.com/ipfs/go-ipfs/unixfs/hamt"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
mdtest "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
mdtest "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
)
|
||||
|
||||
func TestEmptyNode(t *testing.T) {
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
|
@ -3,9 +3,9 @@ package io
|
||||
import (
|
||||
"context"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
hamt "github.com/ipfs/go-ipfs/unixfs/hamt"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
|
||||
)
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
|
||||
help "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
trickle "github.com/ipfs/go-ipfs/importer/trickle"
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
|
||||
chunker "gx/ipfs/QmVDjhUMtkRskBFAVNwyXuLSKbeAya7JKPnzAxMKDaK4x4/go-ipfs-chunker"
|
||||
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
|
||||
h "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
trickle "github.com/ipfs/go-ipfs/importer/trickle"
|
||||
mdag "github.com/ipfs/go-ipfs/merkledag"
|
||||
mdagmock "github.com/ipfs/go-ipfs/merkledag/test"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
mdag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
mdagmock "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag/test"
|
||||
|
||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
|
||||
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
|
||||
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
pb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
dag "gx/ipfs/QmRy4Qk9hbgFX9NGJRm8rBThrA8PZhNCitMgeRYyZ67s59/go-merkledag"
|
||||
)
|
||||
|
||||
// Shorthands for protobuffer types
|
||||
|
Reference in New Issue
Block a user