blocks: move block format to it's own repo
We need to reference it from outside of this repo. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jun 15, 2017 at 21:02 UTC
bccd4d4e8f19ecf255537eb00a59f277894b5ba5
35 files changed
+33
-213
blocks/blocks.go
deleted
-82
@@ -1,82 +0,0 @@
1
-// Package blocks contains the lowest level of IPFS data structures.
2
-// A block is raw data accompanied by a CID. The CID contains the multihash
3
-// corresponding to the block.
4
-package blocks
5
-
6
-import (
7
- "errors"
8
- "fmt"
9
-
10
- mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash"
11
- u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
12
- cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
13
-)
14
-
15
-// ErrWrongHash is returned when the Cid of a block is not the expected
16
-// according to the contents. It is currently used only when debugging.
17
-var ErrWrongHash = errors.New("data did not match given hash")
18
-
19
-// Block provides abstraction for blocks implementations.
20
-type Block interface {
21
- RawData() []byte
22
- Cid() *cid.Cid
23
- String() string
24
- Loggable() map[string]interface{}
25
-}
26
-
27
-// A BasicBlock is a singular block of data in ipfs. It implements the Block
28
-// interface.
29
-type BasicBlock struct {
30
- cid *cid.Cid
31
- data []byte
32
-}
33
-
34
-// NewBlock creates a Block object from opaque data. It will hash the data.
35
-func NewBlock(data []byte) *BasicBlock {
36
- // TODO: fix assumptions
37
- return &BasicBlock{data: data, cid: cid.NewCidV0(u.Hash(data))}
38
-}
39
-
40
-// NewBlockWithCid creates a new block when the hash of the data
41
-// is already known, this is used to save time in situations where
42
-// we are able to be confident that the data is correct.
43
-func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) {
44
- if u.Debug {
45
- chkc, err := c.Prefix().Sum(data)
46
- if err != nil {
47
- return nil, err
48
- }
49
-
50
- if !chkc.Equals(c) {
51
- return nil, ErrWrongHash
52
- }
53
- }
54
- return &BasicBlock{data: data, cid: c}, nil
55
-}
56
-
57
-// Multihash returns the hash contained in the block CID.
58
-func (b *BasicBlock) Multihash() mh.Multihash {
59
- return b.cid.Hash()
60
-}
61
-
62
-// RawData returns the block raw contents as a byte slice.
63
-func (b *BasicBlock) RawData() []byte {
64
- return b.data
65
-}
66
-
67
-// Cid returns the content identifier of the block.
68
-func (b *BasicBlock) Cid() *cid.Cid {
69
- return b.cid
70
-}
71
-
72
-// String provides a human-readable representation of the block CID.
73
-func (b *BasicBlock) String() string {
74
- return fmt.Sprintf("[Block %s]", b.Cid())
75
-}
76
-
77
-// Loggable returns a go-log loggable item.
78
-func (b *BasicBlock) Loggable() map[string]interface{} {
79
- return map[string]interface{}{
80
- "block": b.Cid().String(),
81
- }
82
-}
blocks/blocks_test.go
deleted
-98
@@ -1,98 +0,0 @@
1
-package blocks
2
-
3
-import (
4
- "bytes"
5
- "testing"
6
-
7
- mh "gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash"
8
- u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
9
- cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
10
-)
11
-
12
-func TestBlocksBasic(t *testing.T) {
13
-
14
- // Test empty data
15
- empty := []byte{}
16
- NewBlock(empty)
17
-
18
- // Test nil case
19
- NewBlock(nil)
20
-
21
- // Test some data
22
- NewBlock([]byte("Hello world!"))
23
-}
24
-
25
-func TestData(t *testing.T) {
26
- data := []byte("some data")
27
- block := NewBlock(data)
28
-
29
- if !bytes.Equal(block.RawData(), data) {
30
- t.Error("data is wrong")
31
- }
32
-}
33
-
34
-func TestHash(t *testing.T) {
35
- data := []byte("some other data")
36
- block := NewBlock(data)
37
-
38
- hash, err := mh.Sum(data, mh.SHA2_256, -1)
39
- if err != nil {
40
- t.Fatal(err)
41
- }
42
-
43
- if !bytes.Equal(block.Multihash(), hash) {
44
- t.Error("wrong multihash")
45
- }
46
-}
47
-
48
-func TestCid(t *testing.T) {
49
- data := []byte("yet another data")
50
- block := NewBlock(data)
51
- c := block.Cid()
52
-
53
- if !bytes.Equal(block.Multihash(), c.Hash()) {
54
- t.Error("key contains wrong data")
55
- }
56
-}
57
-
58
-func TestManualHash(t *testing.T) {
59
- oldDebugState := u.Debug
60
- defer (func() {
61
- u.Debug = oldDebugState
62
- })()
63
-
64
- data := []byte("I can't figure out more names .. data")
65
- hash, err := mh.Sum(data, mh.SHA2_256, -1)
66
- if err != nil {
67
- t.Fatal(err)
68
- }
69
-
70
- c := cid.NewCidV0(hash)
71
-
72
- u.Debug = false
73
- block, err := NewBlockWithCid(data, c)
74
- if err != nil {
75
- t.Fatal(err)
76
- }
77
-
78
- if !bytes.Equal(block.Multihash(), hash) {
79
- t.Error("wrong multihash")
80
- }
81
-
82
- data[5] = byte((uint32(data[5]) + 5) % 256) // Transfrom hash to be different
83
- block, err = NewBlockWithCid(data, c)
84
- if err != nil {
85
- t.Fatal(err)
86
- }
87
-
88
- if !bytes.Equal(block.Multihash(), hash) {
89
- t.Error("wrong multihash")
90
- }
91
-
92
- u.Debug = true
93
-
94
- _, err = NewBlockWithCid(data, c)
95
- if err != ErrWrongHash {
96
- t.Fatal(err)
97
- }
98
-}
blocks/blockstore/arc_cache.go
+1
-1
@@ -3,7 +3,7 @@ package blockstore
3
import (
4
"context"
5
6
- "github.com/ipfs/go-ipfs/blocks"
6
+ "github.com/ipfs/go-block-format"
7
8
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
9
"gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
blocks/blockstore/arc_cache_test.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"context"
5
"testing"
6
7
- "github.com/ipfs/go-ipfs/blocks"
7
+ "github.com/ipfs/go-block-format"
8
9
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
10
syncds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/sync"
blocks/blockstore/blockstore.go
+1
-1
@@ -8,7 +8,7 @@ import (
8
"sync"
9
"sync/atomic"
10
11
- blocks "github.com/ipfs/go-ipfs/blocks"
11
+ blocks "github.com/ipfs/go-block-format"
12
dshelp "github.com/ipfs/go-ipfs/thirdparty/ds-help"
13
14
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
blocks/blockstore/blockstore_test.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"fmt"
7
"testing"
8
9
- blocks "github.com/ipfs/go-ipfs/blocks"
9
+ blocks "github.com/ipfs/go-block-format"
10
dshelp "github.com/ipfs/go-ipfs/thirdparty/ds-help"
11
12
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
blocks/blockstore/bloom_cache.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"sync/atomic"
6
"time"
7
8
- "github.com/ipfs/go-ipfs/blocks"
8
+ "github.com/ipfs/go-block-format"
9
10
"gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
11
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
blocks/blockstore/bloom_cache_test.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"testing"
7
"time"
8
9
- "github.com/ipfs/go-ipfs/blocks"
9
+ "github.com/ipfs/go-block-format"
10
11
context "context"
12
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
blocks/blocksutil/block_generator.go
+1
-1
@@ -2,7 +2,7 @@
2
// with Blocks.
3
package blocksutil
4
5
-import "github.com/ipfs/go-ipfs/blocks"
5
+import "github.com/ipfs/go-block-format"
6
7
// NewBlockGenerator returns an object capable of
8
// producing blocks.
blockservice/blockservice.go
+1
-1
@@ -8,7 +8,7 @@ import (
8
"errors"
9
"fmt"
10
11
- blocks "github.com/ipfs/go-ipfs/blocks"
11
+ blocks "github.com/ipfs/go-block-format"
12
"github.com/ipfs/go-ipfs/blocks/blockstore"
13
exchange "github.com/ipfs/go-ipfs/exchange"
14
blockservice/blockservice_test.go
+1
-1
@@ -3,7 +3,7 @@ package blockservice
3
import (
4
"testing"
5
6
- "github.com/ipfs/go-ipfs/blocks"
6
+ "github.com/ipfs/go-block-format"
7
"github.com/ipfs/go-ipfs/blocks/blockstore"
8
butil "github.com/ipfs/go-ipfs/blocks/blocksutil"
9
offline "github.com/ipfs/go-ipfs/exchange/offline"
blockservice/test/blocks_test.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"testing"
8
"time"
9
10
- blocks "github.com/ipfs/go-ipfs/blocks"
10
+ blocks "github.com/ipfs/go-block-format"
11
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
12
. "github.com/ipfs/go-ipfs/blockservice"
13
offline "github.com/ipfs/go-ipfs/exchange/offline"
core/commands/block.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"io/ioutil"
8
"strings"
9
10
- "github.com/ipfs/go-ipfs/blocks"
10
+ "github.com/ipfs/go-block-format"
11
util "github.com/ipfs/go-ipfs/blocks/blockstore/util"
12
cmds "github.com/ipfs/go-ipfs/commands"
13
core/commands/pubsub.go
+1
-1
@@ -10,7 +10,7 @@ import (
10
"sync"
11
"time"
12
13
- blocks "github.com/ipfs/go-ipfs/blocks"
13
+ blocks "github.com/ipfs/go-block-format"
14
cmds "github.com/ipfs/go-ipfs/commands"
15
core "github.com/ipfs/go-ipfs/core"
16
core/coreunix/add_test.go
+1
-1
@@ -10,7 +10,7 @@ import (
10
"testing"
11
"time"
12
13
- "github.com/ipfs/go-ipfs/blocks"
13
+ "github.com/ipfs/go-block-format"
14
"github.com/ipfs/go-ipfs/blocks/blockstore"
15
"github.com/ipfs/go-ipfs/blockservice"
16
"github.com/ipfs/go-ipfs/commands/files"
exchange/bitswap/bitswap.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
"sync"
10
"time"
11
12
- blocks "github.com/ipfs/go-ipfs/blocks"
12
+ blocks "github.com/ipfs/go-block-format"
13
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
14
exchange "github.com/ipfs/go-ipfs/exchange"
15
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
exchange/bitswap/bitswap_test.go
+1
-1
@@ -8,7 +8,7 @@ import (
8
"testing"
9
"time"
10
11
- blocks "github.com/ipfs/go-ipfs/blocks"
11
+ blocks "github.com/ipfs/go-block-format"
12
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
13
blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
14
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
exchange/bitswap/decision/engine.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"time"
7
8
context "context"
9
- blocks "github.com/ipfs/go-ipfs/blocks"
9
+ blocks "github.com/ipfs/go-block-format"
10
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
11
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
12
wl "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
exchange/bitswap/decision/engine_test.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
"testing"
10
11
context "context"
12
- blocks "github.com/ipfs/go-ipfs/blocks"
12
+ blocks "github.com/ipfs/go-block-format"
13
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
14
message "github.com/ipfs/go-ipfs/exchange/bitswap/message"
15
testutil "github.com/ipfs/go-ipfs/thirdparty/testutil"
exchange/bitswap/message/message.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"fmt"
5
"io"
6
7
- blocks "github.com/ipfs/go-ipfs/blocks"
7
+ blocks "github.com/ipfs/go-block-format"
8
pb "github.com/ipfs/go-ipfs/exchange/bitswap/message/pb"
9
wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
10
exchange/bitswap/message/message_test.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
7
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
9
- blocks "github.com/ipfs/go-ipfs/blocks"
9
+ blocks "github.com/ipfs/go-block-format"
10
pb "github.com/ipfs/go-ipfs/exchange/bitswap/message/pb"
11
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
12
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
exchange/bitswap/notifications/notifications.go
+1
-1
@@ -3,7 +3,7 @@ package notifications
3
import (
4
"context"
5
6
- blocks "github.com/ipfs/go-ipfs/blocks"
6
+ blocks "github.com/ipfs/go-block-format"
7
8
pubsub "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/briantigerchow/pubsub"
9
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
exchange/bitswap/notifications/notifications_test.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"testing"
7
"time"
8
9
- blocks "github.com/ipfs/go-ipfs/blocks"
9
+ blocks "github.com/ipfs/go-block-format"
10
blocksutil "github.com/ipfs/go-ipfs/blocks/blocksutil"
11
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
12
)
exchange/bitswap/testnet/network_test.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"testing"
6
7
context "context"
8
- blocks "github.com/ipfs/go-ipfs/blocks"
8
+ blocks "github.com/ipfs/go-block-format"
9
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
10
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
11
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
exchange/interface.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"context"
6
"io"
7
8
- blocks "github.com/ipfs/go-ipfs/blocks"
8
+ blocks "github.com/ipfs/go-block-format"
9
10
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
11
)
exchange/offline/offline.go
+1
-1
@@ -5,7 +5,7 @@ package offline
5
import (
6
"context"
7
8
- blocks "github.com/ipfs/go-ipfs/blocks"
8
+ blocks "github.com/ipfs/go-block-format"
9
"github.com/ipfs/go-ipfs/blocks/blockstore"
10
exchange "github.com/ipfs/go-ipfs/exchange"
11
exchange/offline/offline_test.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"context"
5
"testing"
6
7
- blocks "github.com/ipfs/go-ipfs/blocks"
7
+ blocks "github.com/ipfs/go-block-format"
8
"github.com/ipfs/go-ipfs/blocks/blockstore"
9
"github.com/ipfs/go-ipfs/blocks/blocksutil"
10
exchange/reprovide/reprovide_test.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"testing"
5
6
context "context"
7
- blocks "github.com/ipfs/go-ipfs/blocks"
7
+ blocks "github.com/ipfs/go-block-format"
8
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
9
mock "github.com/ipfs/go-ipfs/routing/mock"
10
testutil "github.com/ipfs/go-ipfs/thirdparty/testutil"
filestore/filestore.go
+1
-1
@@ -10,7 +10,7 @@ package filestore
10
import (
11
"context"
12
13
- "github.com/ipfs/go-ipfs/blocks"
13
+ "github.com/ipfs/go-block-format"
14
"github.com/ipfs/go-ipfs/blocks/blockstore"
15
posinfo "github.com/ipfs/go-ipfs/thirdparty/posinfo"
16
filestore/fsrefstore.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"os"
8
"path/filepath"
9
10
- "github.com/ipfs/go-ipfs/blocks"
10
+ "github.com/ipfs/go-block-format"
11
"github.com/ipfs/go-ipfs/blocks/blockstore"
12
pb "github.com/ipfs/go-ipfs/filestore/pb"
13
dshelp "github.com/ipfs/go-ipfs/thirdparty/ds-help"
importer/chunk/rabin_test.go
+1
-1
@@ -3,7 +3,7 @@ package chunk
3
import (
4
"bytes"
5
"fmt"
6
- "github.com/ipfs/go-ipfs/blocks"
6
+ "github.com/ipfs/go-block-format"
7
"gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
8
"io"
9
"testing"
merkledag/merkledag.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"strings"
8
"sync"
9
10
- blocks "github.com/ipfs/go-ipfs/blocks"
10
+ blocks "github.com/ipfs/go-block-format"
11
bserv "github.com/ipfs/go-ipfs/blockservice"
12
offline "github.com/ipfs/go-ipfs/exchange/offline"
13
merkledag/merkledag_test.go
+1
-1
@@ -13,7 +13,7 @@ import (
13
"testing"
14
"time"
15
16
- blocks "github.com/ipfs/go-ipfs/blocks"
16
+ blocks "github.com/ipfs/go-block-format"
17
bserv "github.com/ipfs/go-ipfs/blockservice"
18
bstest "github.com/ipfs/go-ipfs/blockservice/test"
19
offline "github.com/ipfs/go-ipfs/exchange/offline"
merkledag/raw.go
+1
-1
@@ -1,7 +1,7 @@
1
package merkledag
2
3
import (
4
- "github.com/ipfs/go-ipfs/blocks"
4
+ "github.com/ipfs/go-block-format"
5
6
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
7
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
test/integration/bitswap_wo_routing_test.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"bytes"
5
"testing"
6
7
- "github.com/ipfs/go-ipfs/blocks"
7
+ "github.com/ipfs/go-block-format"
8
"github.com/ipfs/go-ipfs/core"
9
"github.com/ipfs/go-ipfs/core/mock"
10