Skip to content

Commit

Permalink
Add initial support for identity hashes.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Jul 19, 2018
1 parent 1dede1b commit c8613b4
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,20 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
opts.HasBloomFilterSize = 0
}

cbs, err := bstore.CachedBlockstore(ctx, bs, opts)
wbs, err := bstore.CachedBlockstore(ctx, bs, opts)
if err != nil {
return err
}

n.BaseBlocks = cbs
wbs = bstore.NewIdStore(wbs)

n.BaseBlocks = wbs
n.GCLocker = bstore.NewGCLocker()
n.Blockstore = bstore.NewGCBlockstore(cbs, n.GCLocker)
n.Blockstore = bstore.NewGCBlockstore(wbs, n.GCLocker)

if conf.Experimental.FilestoreEnabled || conf.Experimental.UrlstoreEnabled {
// hash security
n.Filestore = filestore.NewFilestore(cbs, n.Repo.FileManager())
n.Filestore = filestore.NewFilestore(wbs, n.Repo.FileManager())
n.Blockstore = bstore.NewGCBlockstore(n.Filestore, n.GCLocker)
n.Blockstore = &verifbs.VerifBSGC{GCBlockstore: n.Blockstore}
}
Expand Down
74 changes: 74 additions & 0 deletions test/sharness/t0046-id-hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

test_description="Test basic operations with identity hash"

. lib/test-lib.sh

test_init_ipfs

ID_HASH0=z25RnHTQ7DveGAsV6YDSDR8EkWvD
ID_HASH0_CONTENTS=jkD98jkD975hkD8

test_expect_success "can fetch random id hash" '
ipfs cat $ID_HASH0 > expected &&
echo $ID_HASH0_CONTENTS > actual &&
test_cmp expected actual
'

test_expect_success "can pin random id hash" '
ipfs pin add $ID_HASH0
'

test_expect_success "ipfs add succeeds with id hash" '
echo "djkd7jdkd7jkHHG" > junk.txt &&
HASH=$(ipfs add -q --hash=id junk.txt)
'

test_expect_success "content not actually added" '
ipfs refs local | fgrep -q -v $HASH
'

test_expect_success "but can fetch it anyway" '
ipfs cat $HASH > actual &&
test_cmp junk.txt actual
'

test_expect_success "block rm does nothing" '
ipfs pin rm $HASH &&
ipfs block rm $HASH
'

test_expect_success "can still fetch it" '
ipfs cat $HASH > actual
test_cmp junk.txt actual
'

test_expect_success "enable filestore" '
ipfs config --json Experimental.FilestoreEnabled true
'

test_expect_success "can fetch random id hash (filestore enabled)" '
ipfs cat $ID_HASH0 > expected &&
echo $ID_HASH0_CONTENTS > actual &&
test_cmp expected actual
'

test_expect_success "can pin random id hash (filestore enabled)" '
ipfs pin add $ID_HASH0
'

test_expect_success "ipfs add succeeds with id hash and --nocopy" '
echo "djkd7jdkd7jkHHG" > junk.txt &&
HASH=$(ipfs add -q --hash=id --nocopy junk.txt)
'

test_expect_success "content not actually added (filestore enabled)" '
ipfs refs local | fgrep -q -v $HASH
'

test_expect_success "but can fetch it anyway (filestore enabled)" '
ipfs cat $HASH > actual &&
test_cmp junk.txt actual
'

test_done

0 comments on commit c8613b4

Please sign in to comment.