From 101c0920078d3dd8d86e8d8eadda895b45b37af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Levente=20T=C3=B3th?= Date: Thu, 30 Nov 2023 10:43:22 +0100 Subject: [PATCH] refactor: move newErasureHashTrieWriter to hashtrie test --- pkg/file/pipeline/hashtrie/hashtrie_test.go | 41 +++++++++++++++- pkg/file/pipeline/hashtrie/tools/tools.go | 54 --------------------- 2 files changed, 39 insertions(+), 56 deletions(-) delete mode 100644 pkg/file/pipeline/hashtrie/tools/tools.go diff --git a/pkg/file/pipeline/hashtrie/hashtrie_test.go b/pkg/file/pipeline/hashtrie/hashtrie_test.go index 61652d03253..ed1a6ef3fad 100644 --- a/pkg/file/pipeline/hashtrie/hashtrie_test.go +++ b/pkg/file/pipeline/hashtrie/hashtrie_test.go @@ -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" ) @@ -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() @@ -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 diff --git a/pkg/file/pipeline/hashtrie/tools/tools.go b/pkg/file/pipeline/hashtrie/tools/tools.go deleted file mode 100644 index a4d05f8e3ea..00000000000 --- a/pkg/file/pipeline/hashtrie/tools/tools.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2023 The Swarm Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package tools - -import ( - "context" - - "github.com/ethersphere/bee/pkg/encryption" - "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/store" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" -) - -// 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 -}