Extract blockservice and verifcid
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 27, 2018 at 18:21 UTC
0a3a3c9ba717b3b1d33147fc80d9318c4e0c1bcb
26 files changed
+28
-650
blockservice/blockservice.go
deleted
-336
@@ -1,336 +0,0 @@
1
-// package blockservice implements a BlockService interface that provides
2
-// a single GetBlock/AddBlock interface that seamlessly retrieves data either
3
-// locally or from a remote peer through the exchange.
4
-package blockservice
5
-
6
-import (
7
- "context"
8
- "errors"
9
- "fmt"
10
- "io"
11
-
12
- "github.com/ipfs/go-ipfs/thirdparty/verifcid"
13
-
14
- blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
15
- cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
16
- blockstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
17
- exchange "gx/ipfs/Qmc2faLf7URkHpsbfYM4EMbr8iSAcGAe8VPgVi64HVnwji/go-ipfs-exchange-interface"
18
- logging "gx/ipfs/QmcVVHfdyv15GVPk7NrxdWjh2hLVccXnoD8j2tyQShiXJb/go-log"
19
-)
20
-
21
-var log = logging.Logger("blockservice")
22
-
23
-var ErrNotFound = errors.New("blockservice: key not found")
24
-
25
-// BlockGetter is the common interface shared between blockservice sessions and
26
-// the blockservice.
27
-type BlockGetter interface {
28
- // GetBlock gets the requested block.
29
- GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error)
30
-
31
- // GetBlocks does a batch request for the given cids, returning blocks as
32
- // they are found, in no particular order.
33
- //
34
- // It may not be able to find all requested blocks (or the context may
35
- // be canceled). In that case, it will close the channel early. It is up
36
- // to the consumer to detect this situation and keep track which blocks
37
- // it has received and which it hasn't.
38
- GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block
39
-}
40
-
41
-// BlockService is a hybrid block datastore. It stores data in a local
42
-// datastore and may retrieve data from a remote Exchange.
43
-// It uses an internal `datastore.Datastore` instance to store values.
44
-type BlockService interface {
45
- io.Closer
46
- BlockGetter
47
-
48
- // Blockstore returns a reference to the underlying blockstore
49
- Blockstore() blockstore.Blockstore
50
-
51
- // Exchange returns a reference to the underlying exchange (usually bitswap)
52
- Exchange() exchange.Interface
53
-
54
- // AddBlock puts a given block to the underlying datastore
55
- AddBlock(o blocks.Block) error
56
-
57
- // AddBlocks adds a slice of blocks at the same time using batching
58
- // capabilities of the underlying datastore whenever possible.
59
- AddBlocks(bs []blocks.Block) error
60
-
61
- // DeleteBlock deletes the given block from the blockservice.
62
- DeleteBlock(o *cid.Cid) error
63
-}
64
-
65
-type blockService struct {
66
- blockstore blockstore.Blockstore
67
- exchange exchange.Interface
68
- // If checkFirst is true then first check that a block doesn't
69
- // already exist to avoid republishing the block on the exchange.
70
- checkFirst bool
71
-}
72
-
73
-// NewBlockService creates a BlockService with given datastore instance.
74
-func New(bs blockstore.Blockstore, rem exchange.Interface) BlockService {
75
- if rem == nil {
76
- log.Warning("blockservice running in local (offline) mode.")
77
- }
78
-
79
- return &blockService{
80
- blockstore: bs,
81
- exchange: rem,
82
- checkFirst: true,
83
- }
84
-}
85
-
86
-// NewWriteThrough ceates a BlockService that guarantees writes will go
87
-// through to the blockstore and are not skipped by cache checks.
88
-func NewWriteThrough(bs blockstore.Blockstore, rem exchange.Interface) BlockService {
89
- if rem == nil {
90
- log.Warning("blockservice running in local (offline) mode.")
91
- }
92
-
93
- return &blockService{
94
- blockstore: bs,
95
- exchange: rem,
96
- checkFirst: false,
97
- }
98
-}
99
-
100
-// Blockstore returns the blockstore behind this blockservice.
101
-func (s *blockService) Blockstore() blockstore.Blockstore {
102
- return s.blockstore
103
-}
104
-
105
-// Exchange returns the exchange behind this blockservice.
106
-func (s *blockService) Exchange() exchange.Interface {
107
- return s.exchange
108
-}
109
-
110
-// NewSession creates a new session that allows for
111
-// controlled exchange of wantlists to decrease the bandwidth overhead.
112
-// If the current exchange is a SessionExchange, a new exchange
113
-// session will be created. Otherwise, the current exchange will be used
114
-// directly.
115
-func NewSession(ctx context.Context, bs BlockService) *Session {
116
- exch := bs.Exchange()
117
- if sessEx, ok := exch.(exchange.SessionExchange); ok {
118
- ses := sessEx.NewSession(ctx)
119
- return &Session{
120
- ses: ses,
121
- bs: bs.Blockstore(),
122
- }
123
- }
124
- return &Session{
125
- ses: exch,
126
- bs: bs.Blockstore(),
127
- }
128
-}
129
-
130
-// AddBlock adds a particular block to the service, Putting it into the datastore.
131
-// TODO pass a context into this if the remote.HasBlock is going to remain here.
132
-func (s *blockService) AddBlock(o blocks.Block) error {
133
- c := o.Cid()
134
- // hash security
135
- err := verifcid.ValidateCid(c)
136
- if err != nil {
137
- return err
138
- }
139
- if s.checkFirst {
140
- if has, err := s.blockstore.Has(c); has || err != nil {
141
- return err
142
- }
143
- }
144
-
145
- if err := s.blockstore.Put(o); err != nil {
146
- return err
147
- }
148
-
149
- log.Event(context.TODO(), "BlockService.BlockAdded", c)
150
-
151
- if err := s.exchange.HasBlock(o); err != nil {
152
- // TODO(#4623): really an error?
153
- return errors.New("blockservice is closed")
154
- }
155
-
156
- return nil
157
-}
158
-
159
-func (s *blockService) AddBlocks(bs []blocks.Block) error {
160
- // hash security
161
- for _, b := range bs {
162
- err := verifcid.ValidateCid(b.Cid())
163
- if err != nil {
164
- return err
165
- }
166
- }
167
- var toput []blocks.Block
168
- if s.checkFirst {
169
- toput = make([]blocks.Block, 0, len(bs))
170
- for _, b := range bs {
171
- has, err := s.blockstore.Has(b.Cid())
172
- if err != nil {
173
- return err
174
- }
175
- if !has {
176
- toput = append(toput, b)
177
- }
178
- }
179
- } else {
180
- toput = bs
181
- }
182
-
183
- err := s.blockstore.PutMany(toput)
184
- if err != nil {
185
- return err
186
- }
187
-
188
- for _, o := range toput {
189
- log.Event(context.TODO(), "BlockService.BlockAdded", o.Cid())
190
- if err := s.exchange.HasBlock(o); err != nil {
191
- // TODO(#4623): Should this really *return*?
192
- return fmt.Errorf("blockservice is closed (%s)", err)
193
- }
194
- }
195
- return nil
196
-}
197
-
198
-// GetBlock retrieves a particular block from the service,
199
-// Getting it from the datastore using the key (hash).
200
-func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error) {
201
- log.Debugf("BlockService GetBlock: '%s'", c)
202
-
203
- var f exchange.Fetcher
204
- if s.exchange != nil {
205
- f = s.exchange
206
- }
207
-
208
- return getBlock(ctx, c, s.blockstore, f) // hash security
209
-}
210
-
211
-func getBlock(ctx context.Context, c *cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) (blocks.Block, error) {
212
- err := verifcid.ValidateCid(c) // hash security
213
- if err != nil {
214
- return nil, err
215
- }
216
-
217
- block, err := bs.Get(c)
218
- if err == nil {
219
- return block, nil
220
- }
221
-
222
- if err == blockstore.ErrNotFound && f != nil {
223
- // TODO be careful checking ErrNotFound. If the underlying
224
- // implementation changes, this will break.
225
- log.Debug("Blockservice: Searching bitswap")
226
- blk, err := f.GetBlock(ctx, c)
227
- if err != nil {
228
- if err == blockstore.ErrNotFound {
229
- return nil, ErrNotFound
230
- }
231
- return nil, err
232
- }
233
- log.Event(ctx, "BlockService.BlockFetched", c)
234
- return blk, nil
235
- }
236
-
237
- log.Debug("Blockservice GetBlock: Not found")
238
- if err == blockstore.ErrNotFound {
239
- return nil, ErrNotFound
240
- }
241
-
242
- return nil, err
243
-}
244
-
245
-// GetBlocks gets a list of blocks asynchronously and returns through
246
-// the returned channel.
247
-// NB: No guarantees are made about order.
248
-func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block {
249
- return getBlocks(ctx, ks, s.blockstore, s.exchange) // hash security
250
-}
251
-
252
-func getBlocks(ctx context.Context, ks []*cid.Cid, bs blockstore.Blockstore, f exchange.Fetcher) <-chan blocks.Block {
253
- out := make(chan blocks.Block)
254
-
255
- go func() {
256
- defer close(out)
257
-
258
- k := 0
259
- for _, c := range ks {
260
- // hash security
261
- if err := verifcid.ValidateCid(c); err == nil {
262
- ks[k] = c
263
- k++
264
- } else {
265
- log.Errorf("unsafe CID (%s) passed to blockService.GetBlocks: %s", c, err)
266
- }
267
- }
268
- ks = ks[:k]
269
-
270
- var misses []*cid.Cid
271
- for _, c := range ks {
272
- hit, err := bs.Get(c)
273
- if err != nil {
274
- misses = append(misses, c)
275
- continue
276
- }
277
- select {
278
- case out <- hit:
279
- case <-ctx.Done():
280
- return
281
- }
282
- }
283
-
284
- if len(misses) == 0 {
285
- return
286
- }
287
-
288
- rblocks, err := f.GetBlocks(ctx, misses)
289
- if err != nil {
290
- log.Debugf("Error with GetBlocks: %s", err)
291
- return
292
- }
293
-
294
- for b := range rblocks {
295
- log.Event(ctx, "BlockService.BlockFetched", b.Cid())
296
- select {
297
- case out <- b:
298
- case <-ctx.Done():
299
- return
300
- }
301
- }
302
- }()
303
- return out
304
-}
305
-
306
-// DeleteBlock deletes a block in the blockservice from the datastore
307
-func (s *blockService) DeleteBlock(c *cid.Cid) error {
308
- err := s.blockstore.DeleteBlock(c)
309
- if err == nil {
310
- log.Event(context.TODO(), "BlockService.BlockDeleted", c)
311
- }
312
- return err
313
-}
314
-
315
-func (s *blockService) Close() error {
316
- log.Debug("blockservice is shutting down...")
317
- return s.exchange.Close()
318
-}
319
-
320
-// Session is a helper type to provide higher level access to bitswap sessions
321
-type Session struct {
322
- bs blockstore.Blockstore
323
- ses exchange.Fetcher
324
-}
325
-
326
-// GetBlock gets a block in the context of a request session
327
-func (s *Session) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error) {
328
- return getBlock(ctx, c, s.bs, s.ses) // hash security
329
-}
330
-
331
-// GetBlocks gets blocks in the context of a request session
332
-func (s *Session) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block {
333
- return getBlocks(ctx, ks, s.bs, s.ses) // hash security
334
-}
335
-
336
-var _ BlockGetter = (*Session)(nil)
blockservice/blockservice_test.go
deleted
-48
@@ -1,48 +0,0 @@
1
-package blockservice
2
-
3
-import (
4
- "testing"
5
-
6
- offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
7
- blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
8
- butil "gx/ipfs/QmYqPGpZ9Yemr55xus9DiEztkns6Jti5XJ7hC94JbvkdqZ/go-ipfs-blocksutil"
9
- blockstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
10
- ds "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore"
11
- dssync "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore/sync"
12
-)
13
-
14
-func TestWriteThroughWorks(t *testing.T) {
15
- bstore := &PutCountingBlockstore{
16
- blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())),
17
- 0,
18
- }
19
- bstore2 := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
20
- exch := offline.Exchange(bstore2)
21
- bserv := NewWriteThrough(bstore, exch)
22
- bgen := butil.NewBlockGenerator()
23
-
24
- block := bgen.Next()
25
-
26
- t.Logf("PutCounter: %d", bstore.PutCounter)
27
- bserv.AddBlock(block)
28
- if bstore.PutCounter != 1 {
29
- t.Fatalf("expected just one Put call, have: %d", bstore.PutCounter)
30
- }
31
-
32
- bserv.AddBlock(block)
33
- if bstore.PutCounter != 2 {
34
- t.Fatalf("Put should have called again, should be 2 is: %d", bstore.PutCounter)
35
- }
36
-}
37
-
38
-var _ blockstore.Blockstore = (*PutCountingBlockstore)(nil)
39
-
40
-type PutCountingBlockstore struct {
41
- blockstore.Blockstore
42
- PutCounter int
43
-}
44
-
45
-func (bs *PutCountingBlockstore) Put(block blocks.Block) error {
46
- bs.PutCounter++
47
- return bs.Blockstore.Put(block)
48
-}
blockservice/test/blocks_test.go
deleted
-97
@@ -1,97 +0,0 @@
1
-package bstest
2
-
3
-import (
4
- "bytes"
5
- "context"
6
- "fmt"
7
- "testing"
8
- "time"
9
-
10
- . "github.com/ipfs/go-ipfs/blockservice"
11
-
12
- u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
13
- offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
14
- blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
15
- cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
16
- blockstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
17
- ds "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore"
18
- dssync "gx/ipfs/QmeiCcJfDW1GJnWUArudsv5rQsihpi4oyddPhdqo3CfX6i/go-datastore/sync"
19
-)
20
-
21
-func newObject(data []byte) blocks.Block {
22
- return blocks.NewBlock(data)
23
-}
24
-
25
-func TestBlocks(t *testing.T) {
26
- bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
27
- bs := New(bstore, offline.Exchange(bstore))
28
- defer bs.Close()
29
-
30
- o := newObject([]byte("beep boop"))
31
- h := cid.NewCidV0(u.Hash([]byte("beep boop")))
32
- if !o.Cid().Equals(h) {
33
- t.Error("Block key and data multihash key not equal")
34
- }
35
-
36
- err := bs.AddBlock(o)
37
- if err != nil {
38
- t.Error("failed to add block to BlockService", err)
39
- return
40
- }
41
-
42
- ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
43
- defer cancel()
44
- b2, err := bs.GetBlock(ctx, o.Cid())
45
- if err != nil {
46
- t.Error("failed to retrieve block from BlockService", err)
47
- return
48
- }
49
-
50
- if !o.Cid().Equals(b2.Cid()) {
51
- t.Error("Block keys not equal.")
52
- }
53
-
54
- if !bytes.Equal(o.RawData(), b2.RawData()) {
55
- t.Error("Block data is not equal.")
56
- }
57
-}
58
-
59
-func makeObjects(n int) []blocks.Block {
60
- var out []blocks.Block
61
- for i := 0; i < n; i++ {
62
- out = append(out, newObject([]byte(fmt.Sprintf("object %d", i))))
63
- }
64
- return out
65
-}
66
-
67
-func TestGetBlocksSequential(t *testing.T) {
68
- var servs = Mocks(4)
69
- for _, s := range servs {
70
- defer s.Close()
71
- }
72
- objs := makeObjects(50)
73
-
74
- var cids []*cid.Cid
75
- for _, o := range objs {
76
- cids = append(cids, o.Cid())
77
- servs[0].AddBlock(o)
78
- }
79
-
80
- t.Log("one instance at a time, get blocks concurrently")
81
-
82
- for i := 1; i < len(servs); i++ {
83
- ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
84
- defer cancel()
85
- out := servs[i].GetBlocks(ctx, cids)
86
- gotten := make(map[string]blocks.Block)
87
- for blk := range out {
88
- if _, ok := gotten[blk.Cid().KeyString()]; ok {
89
- t.Fatal("Got duplicate block!")
90
- }
91
- gotten[blk.Cid().KeyString()] = blk
92
- }
93
- if len(gotten) != len(objs) {
94
- t.Fatalf("Didnt get enough blocks back: %d/%d", len(gotten), len(objs))
95
- }
96
- }
97
-}
blockservice/test/mock.go
deleted
-24
@@ -1,24 +0,0 @@
1
-package bstest
2
-
3
-import (
4
- . "github.com/ipfs/go-ipfs/blockservice"
5
- bitswap "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap"
6
- tn "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap/testnet"
7
-
8
- delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
9
- mockrouting "gx/ipfs/QmbFRJeEmEU16y3BmKKaD4a9fm5oHsEAMHe2vSB1UnfLMi/go-ipfs-routing/mock"
10
-)
11
-
12
-// Mocks returns |n| connected mock Blockservices
13
-func Mocks(n int) []BlockService {
14
- net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
15
- sg := bitswap.NewTestSessionGenerator(net)
16
-
17
- instances := sg.Instances(n)
18
-
19
- var servs []BlockService
20
- for _, i := range instances {
21
- servs = append(servs, New(i.Blockstore(), i.Exchange))
22
- }
23
- return servs
24
-}
core/builder.go
+1
-1
@@ -9,7 +9,6 @@ import (
9
"syscall"
10
"time"
11
12
- bserv "github.com/ipfs/go-ipfs/blockservice"
12
filestore "github.com/ipfs/go-ipfs/filestore"
13
dag "github.com/ipfs/go-ipfs/merkledag"
14
resolver "github.com/ipfs/go-ipfs/path/resolver"
@@ -18,6 +17,7 @@ import (
17
cfg "github.com/ipfs/go-ipfs/repo/config"
18
"github.com/ipfs/go-ipfs/thirdparty/verifbs"
19
uio "github.com/ipfs/go-ipfs/unixfs/io"
20
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
21
22
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
23
goprocessctx "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
core/commands/add.go
+1
-1
@@ -7,7 +7,6 @@ import (
7
"os"
8
"strings"
9
10
- blockservice "github.com/ipfs/go-ipfs/blockservice"
10
core "github.com/ipfs/go-ipfs/core"
11
"github.com/ipfs/go-ipfs/core/coreunix"
12
filestore "github.com/ipfs/go-ipfs/filestore"
@@ -15,6 +14,7 @@ import (
14
dagtest "github.com/ipfs/go-ipfs/merkledag/test"
15
mfs "github.com/ipfs/go-ipfs/mfs"
16
ft "github.com/ipfs/go-ipfs/unixfs"
17
+ blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
18
19
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
20
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
core/commands/files.go
+1
-1
@@ -11,7 +11,6 @@ import (
11
"sort"
12
"strings"
13
14
- bservice "github.com/ipfs/go-ipfs/blockservice"
14
oldcmds "github.com/ipfs/go-ipfs/commands"
15
lgc "github.com/ipfs/go-ipfs/commands/legacy"
16
core "github.com/ipfs/go-ipfs/core"
@@ -22,6 +21,7 @@ import (
21
resolver "github.com/ipfs/go-ipfs/path/resolver"
22
ft "github.com/ipfs/go-ipfs/unixfs"
23
uio "github.com/ipfs/go-ipfs/unixfs/io"
24
+ bservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
25
26
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
27
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
core/commands/ls.go
+1
-1
@@ -6,7 +6,6 @@ import (
6
"io"
7
"text/tabwriter"
8
9
- blockservice "github.com/ipfs/go-ipfs/blockservice"
9
cmds "github.com/ipfs/go-ipfs/commands"
10
core "github.com/ipfs/go-ipfs/core"
11
e "github.com/ipfs/go-ipfs/core/commands/e"
@@ -16,6 +15,7 @@ import (
15
unixfs "github.com/ipfs/go-ipfs/unixfs"
16
uio "github.com/ipfs/go-ipfs/unixfs/io"
17
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
18
+ blockservice "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
19
20
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
21
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/commands/pin.go
+2
-2
@@ -7,7 +7,6 @@ import (
7
"io"
8
"time"
9
10
- bserv "github.com/ipfs/go-ipfs/blockservice"
10
cmds "github.com/ipfs/go-ipfs/commands"
11
core "github.com/ipfs/go-ipfs/core"
12
e "github.com/ipfs/go-ipfs/core/commands/e"
@@ -16,10 +15,11 @@ import (
15
path "github.com/ipfs/go-ipfs/path"
16
resolver "github.com/ipfs/go-ipfs/path/resolver"
17
pin "github.com/ipfs/go-ipfs/pin"
19
- "github.com/ipfs/go-ipfs/thirdparty/verifcid"
18
uio "github.com/ipfs/go-ipfs/unixfs/io"
19
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
20
21
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
22
+ "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
23
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
24
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
25
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
core/core.go
+1
-1
@@ -20,7 +20,6 @@ import (
20
"strings"
21
"time"
22
23
- bserv "github.com/ipfs/go-ipfs/blockservice"
23
rp "github.com/ipfs/go-ipfs/exchange/reprovide"
24
filestore "github.com/ipfs/go-ipfs/filestore"
25
mount "github.com/ipfs/go-ipfs/fuse/mount"
@@ -34,6 +33,7 @@ import (
33
repo "github.com/ipfs/go-ipfs/repo"
34
config "github.com/ipfs/go-ipfs/repo/config"
35
ft "github.com/ipfs/go-ipfs/unixfs"
36
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
37
bitswap "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap"
38
bsnet "gx/ipfs/QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m/go-bitswap/network"
39
core/coreapi/pin.go
+1
-1
@@ -4,11 +4,11 @@ import (
4
"context"
5
"fmt"
6
7
- bserv "github.com/ipfs/go-ipfs/blockservice"
7
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
8
caopts "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
10
merkledag "github.com/ipfs/go-ipfs/merkledag"
11
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
12
13
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
14
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
core/coreunix/add_test.go
+1
-1
@@ -10,12 +10,12 @@ import (
10
"testing"
11
"time"
12
13
- "github.com/ipfs/go-ipfs/blockservice"
13
"github.com/ipfs/go-ipfs/core"
14
dag "github.com/ipfs/go-ipfs/merkledag"
15
"github.com/ipfs/go-ipfs/pin/gc"
16
"github.com/ipfs/go-ipfs/repo"
17
"github.com/ipfs/go-ipfs/repo/config"
18
+ "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
19
20
pi "gx/ipfs/QmSHjPDw8yNgLZ7cBfX7w3Smn7PHwYhNEpd4LHQQxUg35L/go-ipfs-posinfo"
21
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
core/coreunix/metadata_test.go
+1
-1
@@ -6,12 +6,12 @@ import (
6
"io/ioutil"
7
"testing"
8
9
- bserv "github.com/ipfs/go-ipfs/blockservice"
9
core "github.com/ipfs/go-ipfs/core"
10
importer "github.com/ipfs/go-ipfs/importer"
11
merkledag "github.com/ipfs/go-ipfs/merkledag"
12
ft "github.com/ipfs/go-ipfs/unixfs"
13
uio "github.com/ipfs/go-ipfs/unixfs/io"
14
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
15
16
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
17
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
exchange/reprovide/reprovide.go
+1
-2
@@ -5,9 +5,8 @@ import (
5
"fmt"
6
"time"
7
8
- "github.com/ipfs/go-ipfs/thirdparty/verifcid"
9
-
8
backoff "gx/ipfs/QmPJUtEJsm5YLUWhF6imvyCH8KZXRJa9Wup7FDMwTy5Ufz/backoff"
9
+ "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
10
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
11
routing "gx/ipfs/QmZ383TySJVeZWzGnWui6pRcKyYZk9VkKTuW7tmKRWk5au/go-libp2p-routing"
12
logging "gx/ipfs/QmcVVHfdyv15GVPk7NrxdWjh2hLVccXnoD8j2tyQShiXJb/go-log"
merkledag/merkledag.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"fmt"
7
"sync"
8
9
- bserv "github.com/ipfs/go-ipfs/blockservice"
9
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
10
11
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
12
ipldcbor "gx/ipfs/QmWrbExtUaQQHjJ8FVVDAWj5o1MRAELDUV3VmoQsZHHb6L/go-ipld-cbor"
merkledag/merkledag_test.go
+2
-2
@@ -13,11 +13,11 @@ import (
13
"testing"
14
"time"
15
16
- bserv "github.com/ipfs/go-ipfs/blockservice"
17
- bstest "github.com/ipfs/go-ipfs/blockservice/test"
16
. "github.com/ipfs/go-ipfs/merkledag"
17
mdpb "github.com/ipfs/go-ipfs/merkledag/pb"
18
dstest "github.com/ipfs/go-ipfs/merkledag/test"
19
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
20
+ bstest "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice/test"
21
22
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
23
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
merkledag/test/utils.go
+1
-1
@@ -1,8 +1,8 @@
1
package mdutils
2
3
import (
4
- bsrv "github.com/ipfs/go-ipfs/blockservice"
4
dag "github.com/ipfs/go-ipfs/merkledag"
5
+ bsrv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
6
7
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
8
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
merkledag/utils/utils.go
+1
-1
@@ -4,9 +4,9 @@ import (
4
"context"
5
"errors"
6
7
- bserv "github.com/ipfs/go-ipfs/blockservice"
7
dag "github.com/ipfs/go-ipfs/merkledag"
8
path "github.com/ipfs/go-ipfs/path"
9
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
10
11
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
12
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
mfs/mfs_test.go
+1
-1
@@ -14,12 +14,12 @@ import (
14
"testing"
15
"time"
16
17
- bserv "github.com/ipfs/go-ipfs/blockservice"
17
importer "github.com/ipfs/go-ipfs/importer"
18
dag "github.com/ipfs/go-ipfs/merkledag"
19
"github.com/ipfs/go-ipfs/path"
20
ft "github.com/ipfs/go-ipfs/unixfs"
21
uio "github.com/ipfs/go-ipfs/unixfs/io"
22
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
23
24
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
25
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
package.json
+6
@@ -551,6 +551,12 @@
551
"hash": "QmSLYFS88MpPsszqWdhGSxvHyoTnmaU4A74SD6KGib6Z3m",
552
"name": "go-bitswap",
553
"version": "1.0.0"
554
+ },
555
+ {
556
+ "author": "why",
557
+ "hash": "QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R",
558
+ "name": "go-blockservice",
559
+ "version": "1.0.1"
560
}
561
],
562
"gxVersion": "0.10.0",
pin/gc/gc.go
+2
-2
@@ -7,11 +7,11 @@ import (
7
"fmt"
8
"strings"
9
10
- bserv "github.com/ipfs/go-ipfs/blockservice"
10
dag "github.com/ipfs/go-ipfs/merkledag"
11
pin "github.com/ipfs/go-ipfs/pin"
13
- "github.com/ipfs/go-ipfs/thirdparty/verifcid"
12
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
13
14
+ "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
15
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
16
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
17
ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
pin/pin_test.go
+1
-1
@@ -5,8 +5,8 @@ import (
5
"testing"
6
"time"
7
8
- bs "github.com/ipfs/go-ipfs/blockservice"
8
mdag "github.com/ipfs/go-ipfs/merkledag"
9
+ bs "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
10
11
util "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
12
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
pin/set_test.go
+1
-1
@@ -5,8 +5,8 @@ import (
5
"encoding/binary"
6
"testing"
7
8
- bserv "github.com/ipfs/go-ipfs/blockservice"
8
dag "github.com/ipfs/go-ipfs/merkledag"
9
+ bserv "gx/ipfs/QmNqRBAhovtf4jVd5cF7YvHaFSsQHHZBaUFwGQWPM2CV7R/go-blockservice"
10
11
offline "gx/ipfs/QmS6mo1dPpHdYsVkm27BRZDLxpKBCiJKUH8fHX15XFfMez/go-ipfs-exchange-offline"
12
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
thirdparty/verifbs/verifbs.go
+1
-2
@@ -1,8 +1,7 @@
1
package verifbs
2
3
import (
4
- "github.com/ipfs/go-ipfs/thirdparty/verifcid"
5
-
4
+ "gx/ipfs/QmQwgv79RHrRnoXmhnpC1BPtY55HHeneGMpPwmmBU1fUAG/go-verifcid"
5
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
6
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
7
bstore "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
thirdparty/verifcid/validate.go
deleted
-62
@@ -1,62 +0,0 @@
1
-package verifcid
2
-
3
-import (
4
- "fmt"
5
-
6
- mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
7
- cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
8
-)
9
-
10
-var ErrPossiblyInsecureHashFunction = fmt.Errorf("potentially insecure hash functions not allowed")
11
-var ErrBelowMinimumHashLength = fmt.Errorf("hashes must be at %d least bytes long", minimumHashLength)
12
-
13
-const minimumHashLength = 20
14
-
15
-var goodset = map[uint64]bool{
16
- mh.SHA2_256: true,
17
- mh.SHA2_512: true,
18
- mh.SHA3_224: true,
19
- mh.SHA3_256: true,
20
- mh.SHA3_384: true,
21
- mh.SHA3_512: true,
22
- mh.SHAKE_256: true,
23
- mh.DBL_SHA2_256: true,
24
- mh.KECCAK_224: true,
25
- mh.KECCAK_256: true,
26
- mh.KECCAK_384: true,
27
- mh.KECCAK_512: true,
28
- mh.ID: true,
29
-
30
- mh.SHA1: true, // not really secure but still useful
31
-}
32
-
33
-func IsGoodHash(code uint64) bool {
34
- good, found := goodset[code]
35
- if good {
36
- return true
37
- }
38
-
39
- if !found {
40
- if code >= mh.BLAKE2B_MIN+19 && code <= mh.BLAKE2B_MAX {
41
- return true
42
- }
43
- if code >= mh.BLAKE2S_MIN+19 && code <= mh.BLAKE2S_MAX {
44
- return true
45
- }
46
- }
47
-
48
- return false
49
-}
50
-
51
-func ValidateCid(c *cid.Cid) error {
52
- pref := c.Prefix()
53
- if !IsGoodHash(pref.MhType) {
54
- return ErrPossiblyInsecureHashFunction
55
- }
56
-
57
- if pref.MhType != mh.ID && pref.MhLength < minimumHashLength {
58
- return ErrBelowMinimumHashLength
59
- }
60
-
61
- return nil
62
-}
thirdparty/verifcid/validate_test.go
deleted
-59
@@ -1,59 +0,0 @@
1
-package verifcid
2
-
3
-import (
4
- "testing"
5
-
6
- mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
7
-
8
- cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
9
-)
10
-
11
-func TestValidateCids(t *testing.T) {
12
- assertTrue := func(v bool) {
13
- t.Helper()
14
- if !v {
15
- t.Fatal("expected success")
16
- }
17
- }
18
- assertFalse := func(v bool) {
19
- t.Helper()
20
- if v {
21
- t.Fatal("expected failure")
22
- }
23
- }
24
-
25
- assertTrue(IsGoodHash(mh.SHA2_256))
26
- assertTrue(IsGoodHash(mh.BLAKE2B_MIN + 32))
27
- assertTrue(IsGoodHash(mh.DBL_SHA2_256))
28
- assertTrue(IsGoodHash(mh.KECCAK_256))
29
- assertTrue(IsGoodHash(mh.SHA3))
30
-
31
- assertTrue(IsGoodHash(mh.SHA1))
32
-
33
- assertFalse(IsGoodHash(mh.BLAKE2B_MIN + 5))
34
-
35
- mhcid := func(code uint64, length int) *cid.Cid {
36
- mhash, err := mh.Sum([]byte{}, code, length)
37
- if err != nil {
38
- t.Fatal(err)
39
- }
40
- return cid.NewCidV1(cid.DagCBOR, mhash)
41
- }
42
-
43
- cases := []struct {
44
- cid *cid.Cid
45
- err error
46
- }{
47
- {mhcid(mh.SHA2_256, 32), nil},
48
- {mhcid(mh.SHA2_256, 16), ErrBelowMinimumHashLength},
49
- {mhcid(mh.MURMUR3, 4), ErrPossiblyInsecureHashFunction},
50
- }
51
-
52
- for i, cas := range cases {
53
- if ValidateCid(cas.cid) != cas.err {
54
- t.Errorf("wrong result in case of %s (index %d). Expected: %s, got %s",
55
- cas.cid, i, cas.err, ValidateCid(cas.cid))
56
- }
57
- }
58
-
59
-}