Skip to content

Commit

Permalink
refactor: move newErasureHashTrieWriter to hashtrie test
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Nov 30, 2023
1 parent efba1cf commit 101c092
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 56 deletions.
41 changes: 39 additions & 2 deletions pkg/file/pipeline/hashtrie/hashtrie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import (

bmtUtils "github.com/ethersphere/bee/pkg/bmt"
"github.com/ethersphere/bee/pkg/cac"
"github.com/ethersphere/bee/pkg/encryption"
dec "github.com/ethersphere/bee/pkg/encryption/store"
"github.com/ethersphere/bee/pkg/file/pipeline"
"github.com/ethersphere/bee/pkg/file/pipeline/bmt"
enc "github.com/ethersphere/bee/pkg/file/pipeline/encryption"
"github.com/ethersphere/bee/pkg/file/pipeline/hashtrie"
"github.com/ethersphere/bee/pkg/file/pipeline/hashtrie/tools"
"github.com/ethersphere/bee/pkg/file/pipeline/mock"
"github.com/ethersphere/bee/pkg/file/pipeline/store"
"github.com/ethersphere/bee/pkg/file/redundancy"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/storage/inmemchunkstore"
"github.com/ethersphere/bee/pkg/swarm"
)
Expand All @@ -41,6 +43,41 @@ func init() {
binary.LittleEndian.PutUint64(span, 1)
}

// NewErasureHashTrieWriter returns back an redundancy param and a HastTrieWriter pipeline
// which are using simple BMT and StoreWriter pipelines for chunk writes
func newErasureHashTrieWriter(
ctx context.Context,
s storage.Putter,
rLevel redundancy.Level,
encryptChunks bool,
intermediateChunkPipeline, parityChunkPipeline pipeline.ChainWriter,
) (redundancy.IParams, pipeline.ChainWriter) {
pf := func() pipeline.ChainWriter {
lsw := store.NewStoreWriter(ctx, s, intermediateChunkPipeline)
return bmt.NewBmtWriter(lsw)
}
if encryptChunks {
pf = func() pipeline.ChainWriter {
lsw := store.NewStoreWriter(ctx, s, intermediateChunkPipeline)
b := bmt.NewBmtWriter(lsw)
return enc.NewEncryptionWriter(encryption.NewChunkEncrypter(), b)
}
}
ppf := func() pipeline.ChainWriter {
lsw := store.NewStoreWriter(ctx, s, parityChunkPipeline)
return bmt.NewBmtWriter(lsw)
}

hashSize := swarm.HashSize
if encryptChunks {
hashSize *= 2
}

r := redundancy.New(rLevel, encryptChunks, ppf)
ht := hashtrie.NewHashTrieWriter(hashSize, r, pf)
return r, ht
}

func TestLevels(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -270,7 +307,7 @@ func TestRedundancy(t *testing.T) {
intermediateChunkCounter := mock.NewChainWriter()
parityChunkCounter := mock.NewChainWriter()

r, ht := tools.NewErasureHashTrieWriter(ctx, s, tc.level, tc.encryption, intermediateChunkCounter, parityChunkCounter)
r, ht := newErasureHashTrieWriter(ctx, s, tc.level, tc.encryption, intermediateChunkCounter, parityChunkCounter)

// write data to the hashTrie
var key []byte
Expand Down
54 changes: 0 additions & 54 deletions pkg/file/pipeline/hashtrie/tools/tools.go

This file was deleted.

0 comments on commit 101c092

Please sign in to comment.