@cryptotaxi247 / kubo / commits / c8613b430

Add initial support for identity hashes.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Jun 21, 2018 at 22:45 UTC c8613b430070c9e3b2a737792db964bb168501f3
2 files changed +80 -4
core/builder.go
+6 -4
@@ -204,18 +204,20 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
204 opts.HasBloomFilterSize = 0
205 }
206
207 - cbs, err := bstore.CachedBlockstore(ctx, bs, opts)
207 + wbs, err := bstore.CachedBlockstore(ctx, bs, opts)
208 if err != nil {
209 return err
210 }
211
212 - n.BaseBlocks = cbs
212 + wbs = bstore.NewIdStore(wbs)
213 +
214 + n.BaseBlocks = wbs
215 n.GCLocker = bstore.NewGCLocker()
214 - n.Blockstore = bstore.NewGCBlockstore(cbs, n.GCLocker)
216 + n.Blockstore = bstore.NewGCBlockstore(wbs, n.GCLocker)
217
218 if conf.Experimental.FilestoreEnabled || conf.Experimental.UrlstoreEnabled {
219 // hash security
218 - n.Filestore = filestore.NewFilestore(cbs, n.Repo.FileManager())
220 + n.Filestore = filestore.NewFilestore(wbs, n.Repo.FileManager())
221 n.Blockstore = bstore.NewGCBlockstore(n.Filestore, n.GCLocker)
222 n.Blockstore = &verifbs.VerifBSGC{GCBlockstore: n.Blockstore}
223 }
test/sharness/t0046-id-hash.sh new
+74
@@ -0,0 +1,74 @@
1 +#!/usr/bin/env bash
2 +
3 +test_description="Test basic operations with identity hash"
4 +
5 +. lib/test-lib.sh
6 +
7 +test_init_ipfs
8 +
9 +ID_HASH0=z25RnHTQ7DveGAsV6YDSDR8EkWvD
10 +ID_HASH0_CONTENTS=jkD98jkD975hkD8
11 +
12 +test_expect_success "can fetch random id hash" '
13 + ipfs cat $ID_HASH0 > expected &&
14 + echo $ID_HASH0_CONTENTS > actual &&
15 + test_cmp expected actual
16 +'
17 +
18 +test_expect_success "can pin random id hash" '
19 + ipfs pin add $ID_HASH0
20 +'
21 +
22 +test_expect_success "ipfs add succeeds with id hash" '
23 + echo "djkd7jdkd7jkHHG" > junk.txt &&
24 + HASH=$(ipfs add -q --hash=id junk.txt)
25 +'
26 +
27 +test_expect_success "content not actually added" '
28 + ipfs refs local | fgrep -q -v $HASH
29 +'
30 +
31 +test_expect_success "but can fetch it anyway" '
32 + ipfs cat $HASH > actual &&
33 + test_cmp junk.txt actual
34 +'
35 +
36 +test_expect_success "block rm does nothing" '
37 + ipfs pin rm $HASH &&
38 + ipfs block rm $HASH
39 +'
40 +
41 +test_expect_success "can still fetch it" '
42 + ipfs cat $HASH > actual
43 + test_cmp junk.txt actual
44 +'
45 +
46 +test_expect_success "enable filestore" '
47 + ipfs config --json Experimental.FilestoreEnabled true
48 +'
49 +
50 +test_expect_success "can fetch random id hash (filestore enabled)" '
51 + ipfs cat $ID_HASH0 > expected &&
52 + echo $ID_HASH0_CONTENTS > actual &&
53 + test_cmp expected actual
54 +'
55 +
56 +test_expect_success "can pin random id hash (filestore enabled)" '
57 + ipfs pin add $ID_HASH0
58 +'
59 +
60 +test_expect_success "ipfs add succeeds with id hash and --nocopy" '
61 + echo "djkd7jdkd7jkHHG" > junk.txt &&
62 + HASH=$(ipfs add -q --hash=id --nocopy junk.txt)
63 +'
64 +
65 +test_expect_success "content not actually added (filestore enabled)" '
66 + ipfs refs local | fgrep -q -v $HASH
67 +'
68 +
69 +test_expect_success "but can fetch it anyway (filestore enabled)" '
70 + ipfs cat $HASH > actual &&
71 + test_cmp junk.txt actual
72 +'
73 +
74 +test_done