Skip to content

Commit 0752977

Browse files
authored
refactor: set level in ctx (#4981)
1 parent 14193f9 commit 0752977

35 files changed

+133
-154
lines changed

cmd/bee/cmd/split.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ func splitRefs(cmd *cobra.Command) {
110110
defer writer.Close()
111111

112112
p := requestPipelineFn(store, false, redundancy.Level(rLevel))
113-
ctx := redundancy.SetLevelInContext(cmd.Context(), redundancy.Level(rLevel))
114-
rootRef, err := p(ctx, reader)
113+
rootRef, err := p(cmd.Context(), reader)
115114
if err != nil {
116115
return fmt.Errorf("pipeline: %w", err)
117116
}
@@ -201,8 +200,7 @@ func splitChunks(cmd *cobra.Command) {
201200
})
202201

203202
p := requestPipelineFn(store, false, redundancy.Level(rLevel))
204-
ctx := redundancy.SetLevelInContext(cmd.Context(), redundancy.Level(rLevel))
205-
rootRef, err := p(ctx, reader)
203+
rootRef, err := p(cmd.Context(), reader)
206204
if err != nil {
207205
return fmt.Errorf("pipeline: %w", err)
208206
}

cmd/bee/cmd/split_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ func TestDBSplitChunks(t *testing.T) {
100100
// split the file manually and compare output with the split commands output.
101101
putter := &putter{chunks: make(map[string]swarm.Chunk)}
102102
p := requestPipelineFn(putter, false, redundancy.Level(3))
103-
ctx := redundancy.SetLevelInContext(context.Background(), redundancy.Level(3))
104-
_, err = p(ctx, bytes.NewReader(buf))
103+
_, err = p(context.Background(), bytes.NewReader(buf))
105104
if err != nil {
106105
t.Fatal(err)
107106
}

pkg/accesscontrol/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/ethersphere/bee/v2/pkg/accesscontrol"
1515
"github.com/ethersphere/bee/v2/pkg/accesscontrol/kvs"
16-
encryption "github.com/ethersphere/bee/v2/pkg/encryption"
16+
"github.com/ethersphere/bee/v2/pkg/encryption"
1717
"github.com/ethersphere/bee/v2/pkg/file"
1818
"github.com/ethersphere/bee/v2/pkg/file/loadsave"
1919
"github.com/ethersphere/bee/v2/pkg/file/redundancy"
@@ -182,7 +182,7 @@ func TestController_UpdateHandler(t *testing.T) {
182182
assertNoError(t, "Session key", err)
183183
refCipher := encryption.New(keys[0], 0, 0, sha3.NewLegacyKeccak256)
184184
ls := createLs()
185-
gls := loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), true, redundancy.NONE))
185+
gls := loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), true, redundancy.NONE), redundancy.DefaultLevel)
186186
c := accesscontrol.NewController(al)
187187
href, err := getHistoryFixture(t, ctx, ls, al, &publisher.PublicKey)
188188
assertNoError(t, "history fixture create", err)
@@ -307,7 +307,7 @@ func TestController_Get(t *testing.T) {
307307
al1 := accesscontrol.NewLogic(diffieHellman1)
308308
al2 := accesscontrol.NewLogic(diffieHellman2)
309309
ls := createLs()
310-
gls := loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), true, redundancy.NONE))
310+
gls := loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), true, redundancy.NONE), redundancy.DefaultLevel)
311311
c1 := accesscontrol.NewController(al1)
312312
c2 := accesscontrol.NewController(al2)
313313

pkg/accesscontrol/grantee_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool,
3232
}
3333

3434
func createLs() file.LoadSaver {
35-
return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE))
35+
return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE), redundancy.DefaultLevel)
3636
}
3737

3838
func generateKeyListFixture() ([]*ecdsa.PublicKey, error) {

pkg/accesscontrol/history_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/ethersphere/bee/v2/pkg/file/loadsave"
1515
"github.com/ethersphere/bee/v2/pkg/file/pipeline"
1616
"github.com/ethersphere/bee/v2/pkg/file/pipeline/builder"
17+
"github.com/ethersphere/bee/v2/pkg/file/redundancy"
1718
"github.com/ethersphere/bee/v2/pkg/storage"
1819
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
1920
"github.com/ethersphere/bee/v2/pkg/swarm"
@@ -37,7 +38,7 @@ func TestSingleNodeHistoryLookup(t *testing.T) {
3738
t.Parallel()
3839
storer := mockstorer.New()
3940
ctx := context.Background()
40-
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false))
41+
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false), redundancy.DefaultLevel)
4142

4243
h, err := accesscontrol.NewHistory(ls)
4344
assertNoError(t, "create history", err)
@@ -61,7 +62,7 @@ func TestMultiNodeHistoryLookup(t *testing.T) {
6162
t.Parallel()
6263
storer := mockstorer.New()
6364
ctx := context.Background()
64-
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false))
65+
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false), redundancy.DefaultLevel)
6566

6667
h, err := accesscontrol.NewHistory(ls)
6768
assertNoError(t, "create history", err)
@@ -133,7 +134,7 @@ func TestHistoryStore(t *testing.T) {
133134
t.Parallel()
134135
storer := mockstorer.New()
135136
ctx := context.Background()
136-
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false))
137+
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false), redundancy.DefaultLevel)
137138

138139
h1, err := accesscontrol.NewHistory(ls)
139140
assertNoError(t, "create history", err)

pkg/accesscontrol/kvs/kvs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool,
3131
}
3232

3333
func createLs() file.LoadSaver {
34-
return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE))
34+
return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE), redundancy.DefaultLevel)
3535
}
3636

3737
func keyValuePair(t *testing.T) ([]byte, []byte) {

pkg/accesscontrol/mock/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func New(o ...Option) accesscontrol.Controller {
5555
refMap: make(map[string]swarm.Address),
5656
publisher: "",
5757
encrypter: encryption.New(encryption.Key("b6ee086390c280eeb9824c331a4427596f0c8510d5564bc1b6168d0059a46e2b"), 0, 0, sha3.NewLegacyKeccak256),
58-
ls: loadsave.New(storer.ChunkStore(), storer.Cache(), requestPipelineFactory(context.Background(), storer.Cache(), false, redundancy.NONE)),
58+
ls: loadsave.New(storer.ChunkStore(), storer.Cache(), requestPipelineFactory(context.Background(), storer.Cache(), false, redundancy.NONE), redundancy.DefaultLevel),
5959
}
6060
for _, v := range o {
6161
v.apply(m)

pkg/api/accesscontrol.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (s *Service) actDecryptionHandler() func(h http.Handler) http.Handler {
126126
cache = *headers.Cache
127127
}
128128
ctx := r.Context()
129-
ls := loadsave.NewReadonly(s.storer.Download(cache))
129+
ls := loadsave.NewReadonly(s.storer.Download(cache), redundancy.DefaultLevel)
130130
reference, err := s.accesscontrol.DownloadHandler(ctx, ls, paths.Address, headers.Publisher, *headers.HistoryAddress, timestamp)
131131
if err != nil {
132132
logger.Debug("access control download failed", "error", err)
@@ -160,7 +160,7 @@ func (s *Service) actEncryptionHandler(
160160
historyRootHash swarm.Address,
161161
) (swarm.Address, error) {
162162
publisherPublicKey := &s.publicKey
163-
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
163+
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE), redundancy.DefaultLevel)
164164
storageReference, historyReference, encryptedReference, err := s.accesscontrol.UploadHandler(ctx, ls, reference, publisherPublicKey, historyRootHash)
165165
if err != nil {
166166
return swarm.ZeroAddress, err
@@ -206,7 +206,7 @@ func (s *Service) actListGranteesHandler(w http.ResponseWriter, r *http.Request)
206206
cache = *headers.Cache
207207
}
208208
publisher := &s.publicKey
209-
ls := loadsave.NewReadonly(s.storer.Download(cache))
209+
ls := loadsave.NewReadonly(s.storer.Download(cache), redundancy.DefaultLevel)
210210
grantees, err := s.accesscontrol.Get(r.Context(), ls, publisher, paths.GranteesAddress)
211211
if err != nil {
212212
logger.Debug("could not get grantees", "error", err)
@@ -346,8 +346,8 @@ func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request)
346346

347347
granteeref := paths.GranteesAddress
348348
publisher := &s.publicKey
349-
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
350-
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
349+
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE), redundancy.DefaultLevel)
350+
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE), redundancy.DefaultLevel)
351351
granteeref, encryptedglref, historyref, actref, err := s.accesscontrol.UpdateHandler(ctx, ls, gls, granteeref, historyAddress, publisher, grantees.Addlist, grantees.Revokelist)
352352
if err != nil {
353353
logger.Debug("failed to update grantee list", "error", err)
@@ -500,8 +500,8 @@ func (s *Service) actCreateGranteesHandler(w http.ResponseWriter, r *http.Reques
500500
}
501501

502502
publisher := &s.publicKey
503-
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
504-
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
503+
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE), redundancy.DefaultLevel)
504+
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE), redundancy.DefaultLevel)
505505
granteeref, encryptedglref, historyref, actref, err := s.accesscontrol.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, historyAddress, publisher, list, nil)
506506
if err != nil {
507507
logger.Debug("failed to create grantee list", "error", err)

pkg/api/accesscontrol_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
//nolint:ireturn
3636
func prepareHistoryFixture(storer api.Storer) (accesscontrol.History, swarm.Address) {
3737
ctx := context.Background()
38-
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false, redundancy.NONE))
38+
ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false, redundancy.NONE), redundancy.DefaultLevel)
3939

4040
h, _ := accesscontrol.NewHistory(ls)
4141

pkg/api/bytes.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
5454
deferred = defaultUploadMethod(headers.Deferred)
5555
)
5656

57-
ctx = redundancy.SetLevelInContext(ctx, headers.RLevel)
58-
5957
if deferred || headers.Pin {
6058
tag, err = s.getOrCreateSessionID(headers.SwarmTag)
6159
if err != nil {

0 commit comments

Comments
 (0)