From 01f000faa69984a21f1200505df778a55a92e223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Mon, 19 Feb 2024 01:13:55 +0100 Subject: [PATCH 01/22] feat: add act.go with TODOs feat: Add Act interface feat: Add Marshal, Unmarshal skeleton feat: Refactor AccessType to iota feat: Add upload feat: Rename GenerateAccessControlManifest -> create feat: Add saltLengthIs32 feat: Add Mrshal, Unmarshal impl feat: Add Marshal Unmarshal feat: Remove ManifestEntry json annotations feat: Modify to public finc/method feat: Add ErrSaltLength Add pkg/dynamicaccess Refactor interfaces and implement default structs Refactor typo Refactor History package to use NewHistory() function Add Act interface and default implementation Add ACT use cases to act_ucs.md Add new files and implement interfaces, refactor packeges Update act_ucs.md base usecases Refactor access logic and add mock implementations*** Add DiffieHellman implementation and remove Keystore*** Refactor NewAccessLogic function Replace encryption.go to pkg/encryption Refactor packages Update act_ucs.md Update act_ucs.md Update act_ucs.md Update act_ucs.md Update act_ucs.md --- act_ucs.md | 46 +++++++++++++++++++++++++ pkg/dynamicaccess/accesslogic.go | 41 ++++++++++++++++++++++ pkg/dynamicaccess/accesslogic_test.go | 11 ++++++ pkg/dynamicaccess/act.go | 18 ++++++++++ pkg/dynamicaccess/act_test.go | 19 ++++++++++ pkg/dynamicaccess/container.go | 7 ++++ pkg/dynamicaccess/controller.go | 18 ++++++++++ pkg/dynamicaccess/diffieHellman.go | 31 +++++++++++++++++ pkg/dynamicaccess/diffieHellman_test.go | 10 ++++++ pkg/dynamicaccess/feed.go | 36 +++++++++++++++++++ pkg/dynamicaccess/feed_test.go | 40 +++++++++++++++++++++ pkg/dynamicaccess/grantee.go | 26 ++++++++++++++ pkg/dynamicaccess/grantee_test.go | 24 +++++++++++++ pkg/dynamicaccess/history.go | 22 ++++++++++++ pkg/dynamicaccess/history_test.go | 19 ++++++++++ pkg/dynamicaccess/mock/accesslogic.go | 12 +++++++ pkg/dynamicaccess/mock/container.go | 20 +++++++++++ pkg/dynamicaccess/mock/diffieHellman.go | 12 +++++++ pkg/dynamicaccess/publish.go | 12 +++++++ pkg/dynamicaccess/publish_test.go | 11 ++++++ pkg/dynamicaccess/timestamp.go | 10 ++++++ pkg/dynamicaccess/timestamp_test.go | 1 + 22 files changed, 446 insertions(+) create mode 100644 act_ucs.md create mode 100644 pkg/dynamicaccess/accesslogic.go create mode 100644 pkg/dynamicaccess/accesslogic_test.go create mode 100644 pkg/dynamicaccess/act.go create mode 100644 pkg/dynamicaccess/act_test.go create mode 100644 pkg/dynamicaccess/container.go create mode 100644 pkg/dynamicaccess/controller.go create mode 100644 pkg/dynamicaccess/diffieHellman.go create mode 100644 pkg/dynamicaccess/diffieHellman_test.go create mode 100644 pkg/dynamicaccess/feed.go create mode 100644 pkg/dynamicaccess/feed_test.go create mode 100644 pkg/dynamicaccess/grantee.go create mode 100644 pkg/dynamicaccess/grantee_test.go create mode 100644 pkg/dynamicaccess/history.go create mode 100644 pkg/dynamicaccess/history_test.go create mode 100644 pkg/dynamicaccess/mock/accesslogic.go create mode 100644 pkg/dynamicaccess/mock/container.go create mode 100644 pkg/dynamicaccess/mock/diffieHellman.go create mode 100644 pkg/dynamicaccess/publish.go create mode 100644 pkg/dynamicaccess/publish_test.go create mode 100644 pkg/dynamicaccess/timestamp.go create mode 100644 pkg/dynamicaccess/timestamp_test.go diff --git a/act_ucs.md b/act_ucs.md new file mode 100644 index 00000000000..82067211bfd --- /dev/null +++ b/act_ucs.md @@ -0,0 +1,46 @@ +# ACT user stories + +This file contains the SWARM ACT user stories. + +ZenHub Link: [SpDevTeam](https://app.zenhub.com/workspaces/spdevteam-6544d91246b817002d853e69/board) + +- [ ] **1** +- I'm a publisher +- I upload a content +- I grant access to content +- Viewer try to access to the content +___ + +- [ ] **2** +- I'm a publisher +- I granteed access for viewers to my channel +___ + +- [ ] **2/a** +- I'm a publisher +- I granteed access for additional viewers to my channel +___ + +- [ ] **2/b** +- I'm a publisher +- I remove viewers from the access list to my channel +___ + +- [ ] **3** +- I'm a viewer +- I requested access to the content +- If I got, I can access it +- If I didn't get, I can't +___ + +- [ ] **4** +- I'm a viewer +- I lost access to the content +- I can't access new ones +___ + +- [ ] **5** +- I'm a viewer +- I lost access to the content +- I can not access new ones, but the old ones I can +___ diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go new file mode 100644 index 00000000000..269fe4c4638 --- /dev/null +++ b/pkg/dynamicaccess/accesslogic.go @@ -0,0 +1,41 @@ +package dynamicaccess + +import ( + "hash" + + "github.com/ethersphere/bee/pkg/dynamicaccess/mock" + encryption "github.com/ethersphere/bee/pkg/encryption" +) + +type AccessLogic interface { + Get(encryped_ref string, publisher string, tag string) (string, error) +} + +type DefaultAccessLogic struct { + diffieHellman DiffieHellman + encryption encryption.Interface + act Act +} + +func (al *DefaultAccessLogic) Get(encryped_ref string, publisher string, tag string) (string, error) { + return "", nil +} + +func NewAccessLogic(key encryption.Key, padding int, initCtr uint32, hashFunc func() hash.Hash) AccessLogic { + return &DefaultAccessLogic{ + diffieHellman: &mock.DiffieHellmanMock{ + SharedSecretFunc: func(publicKey string, tag string, moment []byte) (string, error) { + return publicKey, nil + }, + }, + encryption: encryption.New(key, padding, initCtr, hashFunc), + act: &mock.ContainerMock{ + AddFunc: func(ref string, publisher string, tag string) error { + return nil + }, + GetFunc: func(ref string, publisher string, tag string) (string, error) { + return "", nil + }, + }, + } +} diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go new file mode 100644 index 00000000000..4f3ad6c44bc --- /dev/null +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -0,0 +1,11 @@ +package dynamicaccess + +import "testing" + +func TestXxx(t *testing.T) { + //key encryption.Key, padding int, initCtr uint32, hashFunc func() hash.Hash + al := NewAccessLogic(nil, 0, 0, nil) + if al == nil { + t.Errorf("Error creating access logic") + } +} diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go new file mode 100644 index 00000000000..b3448260312 --- /dev/null +++ b/pkg/dynamicaccess/act.go @@ -0,0 +1,18 @@ +package dynamicaccess + +type Act interface{} + +type defaultAct struct { +} + +func (a *defaultAct) Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) { + return "", nil +} + +func (a *defaultAct) Get(rootKey string) (value string, err error) { + return "", nil +} + +func NewAct() Container { + return &defaultAct{} +} diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go new file mode 100644 index 00000000000..e1d316d2841 --- /dev/null +++ b/pkg/dynamicaccess/act_test.go @@ -0,0 +1,19 @@ +package dynamicaccess + +import "testing" + +func TestAdd(t *testing.T) { + a := NewAct() + _, err := a.Add("", "") + if err != nil { + t.Error("Add() should not return an error") + } +} + +func TestGet(t *testing.T) { + a := NewAct() + _, err := a.Get("") + if err != nil { + t.Error("Get() should not return an error") + } +} diff --git a/pkg/dynamicaccess/container.go b/pkg/dynamicaccess/container.go new file mode 100644 index 00000000000..ae683aa0fcd --- /dev/null +++ b/pkg/dynamicaccess/container.go @@ -0,0 +1,7 @@ +package dynamicaccess + +// iterator +type Container interface { + Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) + Get(rootKey string) (value string, err error) +} diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go new file mode 100644 index 00000000000..3dfee5bff73 --- /dev/null +++ b/pkg/dynamicaccess/controller.go @@ -0,0 +1,18 @@ +package dynamicaccess + +type Controller interface { +} + +type defaultController struct { + histrory History + uploader Publish + grantee Grantee +} + +func NewController(histrory History, uploader Publish, grantee Grantee) Controller { + return &defaultController{ + histrory: histrory, + uploader: uploader, + grantee: grantee, + } +} diff --git a/pkg/dynamicaccess/diffieHellman.go b/pkg/dynamicaccess/diffieHellman.go new file mode 100644 index 00000000000..8ee9bb1bcce --- /dev/null +++ b/pkg/dynamicaccess/diffieHellman.go @@ -0,0 +1,31 @@ +package dynamicaccess + +import ( + "crypto/ecdsa" + + Crypto "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/keystore" + KeyStoreMem "github.com/ethersphere/bee/pkg/keystore/mem" +) + +type DiffieHellman interface { + SharedSecret(pubKey, tag string, moment []byte) (string, error) +} + +type defaultDiffieHellman struct { + key *ecdsa.PrivateKey + keyStoreService keystore.Service + keyStoreEdg keystore.EDG +} + +func (d *defaultDiffieHellman) SharedSecret(pubKey string, tag string, moment []byte) (string, error) { + return "", nil +} + +func NewDiffieHellman(key *ecdsa.PrivateKey) DiffieHellman { + return &defaultDiffieHellman{ + key: key, + keyStoreService: KeyStoreMem.New(), + keyStoreEdg: Crypto.EDGSecp256_K1, + } +} diff --git a/pkg/dynamicaccess/diffieHellman_test.go b/pkg/dynamicaccess/diffieHellman_test.go new file mode 100644 index 00000000000..2e1c870a178 --- /dev/null +++ b/pkg/dynamicaccess/diffieHellman_test.go @@ -0,0 +1,10 @@ +package dynamicaccess + +import "testing" + +func TestSharedSecret(t *testing.T) { + _, err := NewDiffieHellman(nil).SharedSecret("", "", nil) + if err != nil { + t.Errorf("Error generating shared secret: %v", err) + } +} diff --git a/pkg/dynamicaccess/feed.go b/pkg/dynamicaccess/feed.go new file mode 100644 index 00000000000..2576c2733a5 --- /dev/null +++ b/pkg/dynamicaccess/feed.go @@ -0,0 +1,36 @@ +package dynamicaccess + +// referencia: history.go +type Feed interface { + Update(itemKey string, content string) error + Get(itemKey string) (content string, err error) + AddNewGrantee(itemKey string, grantee string) error + RemoveGrantee(itemKey string, grantee string) error + GetAccess(encryptedRef string, publisher string, tag string) (access string, err error) +} + +type defaultFeed struct{} + +func (f *defaultFeed) Update(itemKey string, content string) error { + return nil +} + +func (f *defaultFeed) Get(itemKey string) (content string, err error) { + return "", nil +} + +func (f *defaultFeed) AddNewGrantee(itemKey string, grantee string) error { + return nil +} + +func (f *defaultFeed) RemoveGrantee(itemKey string, grantee string) error { + return nil +} + +func (f *defaultFeed) GetAccess(encryptedRef string, publisher string, tag string) (access string, err error) { + return "", nil +} + +func NewFeed() Feed { + return &defaultFeed{} +} diff --git a/pkg/dynamicaccess/feed_test.go b/pkg/dynamicaccess/feed_test.go new file mode 100644 index 00000000000..1839e6230b9 --- /dev/null +++ b/pkg/dynamicaccess/feed_test.go @@ -0,0 +1,40 @@ +package dynamicaccess + +import "testing" + +func TestFeedUpdate(t *testing.T) { + err := NewFeed().Update("", "") + if err != nil { + t.Errorf("Error updating feed: %v", err) + } +} + +func TestFeedGet(t *testing.T) { + content, err := NewFeed().Get("") + if err != nil { + t.Errorf("Error getting feed: %v", err) + } + _ = content // Ignore the content if not needed +} + +func TestFeedAddNewGrantee(t *testing.T) { + err := NewFeed().AddNewGrantee("", "") + if err != nil { + t.Errorf("Error adding new grantee to feed: %v", err) + } +} + +func TestFeedRemoveGrantee(t *testing.T) { + err := NewFeed().RemoveGrantee("", "") + if err != nil { + t.Errorf("Error removing grantee from feed: %v", err) + } +} + +func TestFeedGetAccess(t *testing.T) { + access, err := NewFeed().GetAccess("", "", "") + if err != nil { + t.Errorf("Error getting access to feed: %v", err) + } + _ = access // Ignore the access if not needed +} diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go new file mode 100644 index 00000000000..27eb1636a09 --- /dev/null +++ b/pkg/dynamicaccess/grantee.go @@ -0,0 +1,26 @@ +package dynamicaccess + +type Grantee interface { + Revoke(topic string) error + RevokeList(topic string, removeList []string, addList []string) (string, error) + Publish(topic string) error +} + +type defaultGrantee struct { +} + +func (g *defaultGrantee) Revoke(topic string) error { + return nil +} + +func (g *defaultGrantee) RevokeList(topic string, removeList []string, addList []string) (string, error) { + return "", nil +} + +func (g *defaultGrantee) Publish(topic string) error { + return nil +} + +func NewGrantee() Grantee { + return &defaultGrantee{} +} diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go new file mode 100644 index 00000000000..38b2d10b347 --- /dev/null +++ b/pkg/dynamicaccess/grantee_test.go @@ -0,0 +1,24 @@ +package dynamicaccess + +import "testing" + +func TestGranteeRevoke(t *testing.T) { + err := NewGrantee().Revoke("") + if err != nil { + t.Errorf("Error revoking grantee: %v", err) + } +} + +func TestGranteeRevokeList(t *testing.T) { + _, err := NewGrantee().RevokeList("", nil, nil) + if err != nil { + t.Errorf("Error revoking list of grantees: %v", err) + } +} + +func TestGranteePublish(t *testing.T) { + err := NewGrantee().Publish("") + if err != nil { + t.Errorf("Error publishing grantee: %v", err) + } +} diff --git a/pkg/dynamicaccess/history.go b/pkg/dynamicaccess/history.go new file mode 100644 index 00000000000..b9a9438b331 --- /dev/null +++ b/pkg/dynamicaccess/history.go @@ -0,0 +1,22 @@ +package dynamicaccess + +// TODO FROM BEE!!!! +// timestamp alapú history +type History interface { + Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) + Get(rootKey string) (value string, err error) +} + +type defaultHistory struct{} + +func (h *defaultHistory) Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) { + return "", nil +} + +func (h *defaultHistory) Get(rootKey string) (value string, err error) { + return "", nil +} + +func NewHistory() History { + return &defaultHistory{} +} diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go new file mode 100644 index 00000000000..9116e41f548 --- /dev/null +++ b/pkg/dynamicaccess/history_test.go @@ -0,0 +1,19 @@ +package dynamicaccess + +import "testing" + +func TestHistoryAdd(t *testing.T) { + newRootHash, err := NewHistory().Add("", "") + if err != nil { + t.Errorf("Error adding history: %v", err) + } + _ = newRootHash // Ignore the newRootHash if not needed +} + +func TestHistoryGet(t *testing.T) { + value, err := NewHistory().Get("") + if err != nil { + t.Errorf("Error getting history: %v", err) + } + _ = value // Ignore the value if not needed +} diff --git a/pkg/dynamicaccess/mock/accesslogic.go b/pkg/dynamicaccess/mock/accesslogic.go new file mode 100644 index 00000000000..8be8e3a07fd --- /dev/null +++ b/pkg/dynamicaccess/mock/accesslogic.go @@ -0,0 +1,12 @@ +package mock + +type AccessLogicMock struct { + GetFunc func(string, string, string) (string, error) +} + +func (ma *AccessLogicMock) Get(encryped_ref string, publisher string, tag string) (string, error) { + if ma.GetFunc == nil { + return "", nil + } + return ma.GetFunc(encryped_ref, publisher, tag) +} diff --git a/pkg/dynamicaccess/mock/container.go b/pkg/dynamicaccess/mock/container.go new file mode 100644 index 00000000000..3cad9badd39 --- /dev/null +++ b/pkg/dynamicaccess/mock/container.go @@ -0,0 +1,20 @@ +package mock + +type ContainerMock struct { + AddFunc func(string, string, string) error + GetFunc func(string, string, string) (string, error) +} + +func (ma *ContainerMock) Add(ref string, publisher string, tag string) error { + if ma.AddFunc == nil { + return nil + } + return ma.AddFunc(ref, publisher, tag) +} + +func (ma *ContainerMock) Get(ref string, publisher string, tag string) (string, error) { + if ma.GetFunc == nil { + return "", nil + } + return ma.GetFunc(ref, publisher, tag) +} diff --git a/pkg/dynamicaccess/mock/diffieHellman.go b/pkg/dynamicaccess/mock/diffieHellman.go new file mode 100644 index 00000000000..f71131b11ff --- /dev/null +++ b/pkg/dynamicaccess/mock/diffieHellman.go @@ -0,0 +1,12 @@ +package mock + +type DiffieHellmanMock struct { + SharedSecretFunc func(string, string, []byte) (string, error) +} + +func (ma *DiffieHellmanMock) SharedSecret(publicKey string, tag string, moment []byte) (string, error) { + if ma.SharedSecretFunc == nil { + return "", nil + } + return ma.SharedSecretFunc(publicKey, tag, moment) +} diff --git a/pkg/dynamicaccess/publish.go b/pkg/dynamicaccess/publish.go new file mode 100644 index 00000000000..f913288e4d5 --- /dev/null +++ b/pkg/dynamicaccess/publish.go @@ -0,0 +1,12 @@ +package dynamicaccess + +type Publish interface { + upload(ref string) (string, error) +} + +type DefaultPublish struct { +} + +func (d *DefaultPublish) upload(ref string) (string, error) { + return "default", nil +} diff --git a/pkg/dynamicaccess/publish_test.go b/pkg/dynamicaccess/publish_test.go new file mode 100644 index 00000000000..d31069da4a3 --- /dev/null +++ b/pkg/dynamicaccess/publish_test.go @@ -0,0 +1,11 @@ +package dynamicaccess + +import "testing" + +func TestUpload(t *testing.T) { + p := &DefaultPublish{} + _, err := p.upload("test") + if err != nil { + t.Errorf("Error uploading file: %v", err) + } +} diff --git a/pkg/dynamicaccess/timestamp.go b/pkg/dynamicaccess/timestamp.go new file mode 100644 index 00000000000..48347d33a7c --- /dev/null +++ b/pkg/dynamicaccess/timestamp.go @@ -0,0 +1,10 @@ +package dynamicaccess + +// container interface bee-ből a manifest +type Timestamp interface{} + +type defaultTimeStamp struct{} + +func NewTimestamp() Timestamp { + return &defaultTimeStamp{} +} diff --git a/pkg/dynamicaccess/timestamp_test.go b/pkg/dynamicaccess/timestamp_test.go new file mode 100644 index 00000000000..e39ccbcf0c5 --- /dev/null +++ b/pkg/dynamicaccess/timestamp_test.go @@ -0,0 +1 @@ +package dynamicaccess From 9f4551e37f62a60d26c56f9ee49e5c23965af683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Wed, 13 Mar 2024 15:43:35 +0100 Subject: [PATCH 02/22] Diffie-Hellman (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use DiffieHellmanMock * Adds a comment about Get * Add support for ECDSA public key in DiffieHellman.SharedSecret function * Update defaultAct implementation * Adds pseudo code for Access Logic * Update default Act creation; Fix basic Act tests * Refactor access logic to use new ActMock implementation * feat(history): test mockups wip * Refactor DiffieHellman implementation * changes pseudocode for Diffie-Hellmann read * Co-authored-by: Bálint Ujvári * DiffieHellman mock generates a real sherd secret * Refactor Act * Adds manifest lookup * Extend act_test * Adds unit tests, some values are mocked * Refactor act mock impl with map[string]map[string]string * Add check mock implementation for DiffieHellman interface * Add Load, Store to Act interface. Refactor Act interface * refactor act, diffieHellman mocks, tests * Add TestLoadStore function to act_test.go * Remove unnecessary code in Load function * Add history mock and History lookup test * Act refactor Co-authored-by: Bálint Ujvári * Refactor Add method to return Act interface * Change Get method return type to []byte --------- Co-authored-by: Ferenc Sárai Co-authored-by: Peter Ott Co-authored-by: Bálint Ujvári Co-authored-by: Levente Kiss Co-authored-by: Roland Seres Co-authored-by: Kexort Co-authored-by: Bálint Ujvári --- pkg/dynamicaccess/accesslogic.go | 146 ++++++++++++++++--- pkg/dynamicaccess/accesslogic_test.go | 177 +++++++++++++++++++++++- pkg/dynamicaccess/act.go | 51 ++++++- pkg/dynamicaccess/act_test.go | 122 ++++++++++++++-- pkg/dynamicaccess/diffieHellman.go | 28 ++-- pkg/dynamicaccess/diffieHellman_test.go | 50 ++++++- pkg/dynamicaccess/feed.go | 36 ----- pkg/dynamicaccess/feed_test.go | 40 ------ pkg/dynamicaccess/history.go | 35 +++-- pkg/dynamicaccess/history_test.go | 65 +++++++-- pkg/dynamicaccess/mock/act.go | 47 +++++++ pkg/dynamicaccess/mock/diffieHellman.go | 20 ++- pkg/dynamicaccess/mock/history.go | 90 ++++++++++++ 13 files changed, 739 insertions(+), 168 deletions(-) delete mode 100644 pkg/dynamicaccess/feed.go delete mode 100644 pkg/dynamicaccess/feed_test.go create mode 100644 pkg/dynamicaccess/mock/act.go create mode 100644 pkg/dynamicaccess/mock/history.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 269fe4c4638..ee141d7b69f 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -1,41 +1,143 @@ package dynamicaccess import ( - "hash" + "context" + "crypto/ecdsa" + "errors" - "github.com/ethersphere/bee/pkg/dynamicaccess/mock" encryption "github.com/ethersphere/bee/pkg/encryption" + file "github.com/ethersphere/bee/pkg/file" + manifest "github.com/ethersphere/bee/pkg/manifest" + "golang.org/x/crypto/sha3" ) +var hashFunc = sha3.NewLegacyKeccak256 + type AccessLogic interface { - Get(encryped_ref string, publisher string, tag string) (string, error) + Get(act_root_hash string, encryped_ref string, publisher string, tag string) (string, error) + GetLookUpKey(publisher string, tag string) (string, error) + GetAccessKeyDecriptionKey(publisher string, tag string) (string, error) + GetEncryptedAccessKey(act_root_hash string, lookup_key string) (manifest.Entry, error) } type DefaultAccessLogic struct { diffieHellman DiffieHellman - encryption encryption.Interface - act Act + //encryption encryption.Interface + act defaultAct +} + +// Will give back Swarm reference with symmertic encryption key (128 byte) +// @publisher: public key +func (al *DefaultAccessLogic) GetLookUpKey(publisher string, tag string) (string, error) { + zeroByteArray := []byte{0} + // Generate lookup key using Diffie Hellman + lookup_key, err := al.diffieHellman.SharedSecret(publisher, tag, zeroByteArray) + if err != nil { + return "", err + } + return lookup_key, nil + +} + +func (al *DefaultAccessLogic) GetAccessKeyDecriptionKey(publisher string, tag string) (string, error) { + oneByteArray := []byte{1} + // Generate access key decryption key using Diffie Hellman + access_key_decryption_key, err := al.diffieHellman.SharedSecret(publisher, tag, oneByteArray) + if err != nil { + return "", err + } + return access_key_decryption_key, nil } -func (al *DefaultAccessLogic) Get(encryped_ref string, publisher string, tag string) (string, error) { - return "", nil +func (al *DefaultAccessLogic) GetEncryptedAccessKey(act_root_hash string, lookup_key string) (manifest.Entry, error) { + if act_root_hash == "" { + return nil, errors.New("no ACT root hash was provided") + } + if lookup_key == "" { + return nil, errors.New("no lookup key") + } + + manifest_raw, err := al.act.Get(act_root_hash) + if err != nil { + return nil, err + } + al.act.Get(act_root_hash) + + // Lookup encrypted access key from the ACT manifest + var loadSaver file.LoadSaver + var ctx context.Context + loadSaver.Load(ctx, []byte(manifest_raw)) // Load the manifest file into loadSaver + //y, err := x.Load(ctx, []byte(manifest_obj)) + manifestObj, err := manifest.NewDefaultManifest(loadSaver, false) + if err != nil { + return nil, err + } + encrypted_access_key, err := manifestObj.Lookup(ctx, lookup_key) + if err != nil { + return nil, err + } + + return encrypted_access_key, nil } -func NewAccessLogic(key encryption.Key, padding int, initCtr uint32, hashFunc func() hash.Hash) AccessLogic { +func (al *DefaultAccessLogic) Get(act_root_hash string, encryped_ref string, publisher string, tag string) (string, error) { + + lookup_key, err := al.GetLookUpKey(publisher, tag) + if err != nil { + return "", err + } + access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(publisher, tag) + if err != nil { + return "", err + } + + // Lookup encrypted access key from the ACT manifest + + encrypted_access_key, err := al.GetEncryptedAccessKey(act_root_hash, lookup_key) + if err != nil { + return "", err + } + + // Decrypt access key + access_key_cipher := encryption.New(encryption.Key(access_key_decryption_key), 4096, uint32(0), hashFunc) + access_key, err := access_key_cipher.Decrypt(encrypted_access_key.Reference().Bytes()) + if err != nil { + return "", err + } + + // Decrypt reference + ref_cipher := encryption.New(access_key, 4096, uint32(0), hashFunc) + ref, err := ref_cipher.Decrypt([]byte(encryped_ref)) + if err != nil { + return "", err + } + + return string(ref), nil +} + +func NewAccessLogic(diffieHellmanPrivateKey *ecdsa.PrivateKey) AccessLogic { return &DefaultAccessLogic{ - diffieHellman: &mock.DiffieHellmanMock{ - SharedSecretFunc: func(publicKey string, tag string, moment []byte) (string, error) { - return publicKey, nil - }, - }, - encryption: encryption.New(key, padding, initCtr, hashFunc), - act: &mock.ContainerMock{ - AddFunc: func(ref string, publisher string, tag string) error { - return nil - }, - GetFunc: func(ref string, publisher string, tag string) (string, error) { - return "", nil - }, - }, + diffieHellman: NewDiffieHellman(diffieHellmanPrivateKey), + //encryption: encryption.New(key, padding, initCtr, hashFunc), + act: defaultAct{}, + + // { + // AddFunc: func(ref string, publisher string, tag string) error { + // return nil + // }, + // GetFunc: func(ref string, publisher string, tag string) (string, error) { + // return "", nil + // }, + // }, } } + +// ------- +// act: &mock.ContainerMock{ +// AddFunc: func(ref string, publisher string, tag string) error { +// return nil +// }, +// GetFunc: func(ref string, publisher string, tag string) (string, error) { +// return "", nil +// }, +// }, diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index 4f3ad6c44bc..cc4ad28ebce 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -1,11 +1,176 @@ package dynamicaccess -import "testing" +import ( + "errors" + "testing" -func TestXxx(t *testing.T) { - //key encryption.Key, padding int, initCtr uint32, hashFunc func() hash.Hash - al := NewAccessLogic(nil, 0, 0, nil) - if al == nil { - t.Errorf("Error creating access logic") + "github.com/ethersphere/bee/pkg/crypto" +) + +func setupAccessLogic() AccessLogic { + privateKey, err := crypto.GenerateSecp256k1Key() + if err != nil { + errors.New("error creating private key") + } + al := NewAccessLogic(privateKey) + + return al +} + +func TestGetLookupKey_Success(t *testing.T) { + al := setupAccessLogic() + + publisher := "examplePublisher" + tag := "exampleTag" + + lookupKey, err := al.GetLookUpKey(publisher, tag) + if err != nil { + t.Errorf("Could not fetch lookup key from publisher and tag") + } + + expectedLookupKey := "expectedLookupKey" + if lookupKey != expectedLookupKey { + t.Errorf("The lookup key that was returned is not correct!") + } +} + +func TestGetLookupKey_Error(t *testing.T) { + al := setupAccessLogic() + + invalidPublisher := "" + tag := "exampleTag" + + lookupKey, err := al.GetLookUpKey(invalidPublisher, tag) + if err != nil { + t.Errorf("There was an error while fetching lookup key") + } + + if lookupKey != "" { + t.Errorf("Expected lookup key to be empty for invalid input") + } +} + +func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { + al := setupAccessLogic() + + publisher := "examplePublisher" + tag := "exampleTag" + + access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(publisher, tag) + if err != nil { + t.Errorf("GetAccessKeyDecriptionKey gave back error") + } + + expectedResult := "we-dont-know" + if access_key_decryption_key != expectedResult { + t.Errorf("The access key decryption key is not correct!") + } +} + +func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { + al := setupAccessLogic() + + invalidPublisher := "" + tag := "exampleTag" + + access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(invalidPublisher, tag) + if err != nil { + t.Errorf("GetAccessKeyDecriptionKey gave back error") + } + + if access_key_decryption_key != "" { + t.Errorf("GetAccessKeyDecriptionKey should give back empty string for invalid input!") + } +} + +func TestGetEncryptedAccessKey_Success(t *testing.T) { + al := setupAccessLogic() + + actRootHash := "0xabcexample" + lookupKey := "exampleLookupKey" + + encrypted_access_key, err := al.GetEncryptedAccessKey(actRootHash, lookupKey) + if err != nil { + t.Errorf("There was an error while executing GetEncryptedAccessKey") + } + + expectedEncryptedKey := "abc013encryptedkey" + if encrypted_access_key != expectedEncryptedKey { + t.Errorf("GetEncryptedAccessKey didn't give back the expected value!") + } +} + +func TestGetEncryptedAccessKey_Error(t *testing.T) { + al := setupAccessLogic() + + actRootHash := "0xabcexample" + lookupKey := "exampleLookupKey" + + empty_act_result, _ := al.GetEncryptedAccessKey("", lookupKey) + if empty_act_result != nil { + t.Errorf("GetEncryptedAccessKey should give back nil for empty act root hash!") + } + + empty_lookup_result, _ := al.GetEncryptedAccessKey(actRootHash, "") + + if empty_lookup_result != nil { + t.Errorf("GetEncryptedAccessKey should give back nil for empty lookup key!") + } +} + +func TestGet_Success(t *testing.T) { + al := setupAccessLogic() + + actRootHash := "0xabcexample" + encryptedRef := "bzzabcasab" + publisher := "examplePublisher" + tag := "exampleTag" + + ref, err := al.Get(actRootHash, encryptedRef, publisher, tag) + if err != nil { + t.Errorf("There was an error while calling Get") + } + + expectedRef := "bzzNotEncrypted128long" + if ref != expectedRef { + t.Errorf("Get gave back wrong Swarm reference!") + } +} + +func TestGet_Error(t *testing.T) { + al := setupAccessLogic() + + actRootHash := "0xabcexample" + encryptedRef := "bzzabcasab" + publisher := "examplePublisher" + tag := "exampleTag" + + refOne, _ := al.Get("", encryptedRef, publisher, tag) + if refOne != "" { + t.Errorf("Get should give back empty string if ACT root hash not provided!") + } + + refTwo, _ := al.Get(actRootHash, "", publisher, tag) + if refTwo != "" { + t.Errorf("Get should give back empty string if encrypted ref not provided!") + } + + refThree, _ := al.Get(actRootHash, encryptedRef, "", tag) + if refThree != "" { + t.Errorf("Get should give back empty string if publisher not provided!") + } + + refFour, _ := al.Get(actRootHash, encryptedRef, publisher, "") + if refFour != "" { + t.Errorf("Get should give back empty string if tag was not provided!") + } +} + +func TestNewAccessLogic(t *testing.T) { + logic := setupAccessLogic() + + _, ok := logic.(*DefaultAccessLogic) + if !ok { + t.Errorf("NewAccessLogic: expected type *DefaultAccessLogic, got %T", logic) } } diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index b3448260312..b63b1dafc6b 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -1,18 +1,55 @@ package dynamicaccess -type Act interface{} +import ( + "encoding/hex" + + "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/swarm" +) + +type Act interface { + Add(lookupKey []byte, encryptedAccessKey []byte) Act + Get(lookupKey []byte) []byte + Load(lookupKey []byte) manifest.Entry + Store(me manifest.Entry) +} + +var _ Act = (*defaultAct)(nil) type defaultAct struct { + container map[string]string +} + +func (act *defaultAct) Add(lookupKey []byte, encryptedAccessKey []byte) Act { + act.container[hex.EncodeToString(lookupKey)] = hex.EncodeToString(encryptedAccessKey) + return act +} + +func (act *defaultAct) Get(lookupKey []byte) []byte { + if key, ok := act.container[hex.EncodeToString(lookupKey)]; ok { + bytes, err := hex.DecodeString(key) + if err == nil { + return bytes + } + } + return make([]byte, 0) } -func (a *defaultAct) Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) { - return "", nil +// to manifestEntry +func (act *defaultAct) Load(lookupKey []byte) manifest.Entry { + return manifest.NewEntry(swarm.NewAddress(lookupKey), act.container) } -func (a *defaultAct) Get(rootKey string) (value string, err error) { - return "", nil +// from manifestEntry +func (act *defaultAct) Store(me manifest.Entry) { + if act.container == nil { + act.container = make(map[string]string) + } + act.container = me.Metadata() } -func NewAct() Container { - return &defaultAct{} +func NewDefaultAct() Act { + return &defaultAct{ + container: make(map[string]string), + } } diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index e1d316d2841..0e5ca853f0b 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -1,19 +1,119 @@ -package dynamicaccess +package dynamicaccess_test -import "testing" +import ( + "bytes" + "context" + "encoding/hex" + "testing" -func TestAdd(t *testing.T) { - a := NewAct() - _, err := a.Add("", "") - if err != nil { - t.Error("Add() should not return an error") + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/file/loadsave" + "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/pkg/file/redundancy" + "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/storage" + mockstorer "github.com/ethersphere/bee/pkg/storer/mock" + "github.com/ethersphere/bee/pkg/swarm" +) + +func TestActAddGet(t *testing.T) { + act := dynamicaccess.NewDefaultAct() + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + act2 := act.Add(lookupKey, encryptedAccesskey) + if act2 == nil { + t.Error("Add() should return an act") + } + + key := act.Get(lookupKey) + if !bytes.Equal(key, encryptedAccesskey) { + t.Errorf("Get() value is not the expected %s != %s", key, encryptedAccesskey) } } -func TestGet(t *testing.T) { - a := NewAct() - _, err := a.Get("") +func TestActWithManifest(t *testing.T) { + + storer := mockstorer.New() + encrypt := false + ctx := context.Background() + ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false, 0)) + rootManifest, err := manifest.NewDefaultManifest(ls, encrypt) + if err != nil { + t.Error("DefaultManifest should not return an error") + } + + act := dynamicaccess.NewDefaultAct() + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + act2 := act.Add(lookupKey, encryptedAccesskey) + if act2 == nil { + t.Error("Add() should return an act") + } + + actManifEntry := act.Load(lookupKey) + if actManifEntry == nil { + t.Error("Load() should return a manifest.Entry") + } + + err = rootManifest.Add(ctx, hex.EncodeToString(lookupKey), actManifEntry) + if err != nil { + t.Error("rootManifest.Add() should not return an error") + } + + _, err = rootManifest.Store(ctx) + if err != nil { + t.Error("rootManifest.Store() should not return an error") + } + + actualMe, err := rootManifest.Lookup(ctx, hex.EncodeToString(lookupKey)) if err != nil { - t.Error("Get() should not return an error") + t.Error("rootManifest.Lookup() should not return an error") + } + + actualAct := dynamicaccess.NewDefaultAct() + actualAct.Store(actualMe) + actualEak := actualAct.Get(lookupKey) + if !bytes.Equal(actualEak, encryptedAccesskey) { + t.Errorf("actualAct.Store() value is not the expected %s != %s", actualEak, encryptedAccesskey) + } +} + +func TestActStore(t *testing.T) { + mp := make(map[string]string) + + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + mp[hex.EncodeToString(lookupKey)] = hex.EncodeToString(encryptedAccesskey) + + me := manifest.NewEntry(swarm.NewAddress(lookupKey), mp) + act := dynamicaccess.NewDefaultAct() + act.Store(me) + eak := act.Get(lookupKey) + + if !bytes.Equal(eak, encryptedAccesskey) { + t.Errorf("Store() value is not the expected %s != %s", eak, encryptedAccesskey) + } + +} + +func TestActLoad(t *testing.T) { + act := dynamicaccess.NewDefaultAct() + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + act.Add(lookupKey, encryptedAccesskey) + me := act.Load(lookupKey) + + eak := me.Metadata()[hex.EncodeToString(lookupKey)] + + if eak != hex.EncodeToString(encryptedAccesskey) { + t.Errorf("Load() value is not the expected %s != %s", eak, encryptedAccesskey) + } + +} + +func pipelineFactory(s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { + return func() pipeline.Interface { + return builder.NewPipelineBuilder(context.Background(), s, encrypt, rLevel) } } diff --git a/pkg/dynamicaccess/diffieHellman.go b/pkg/dynamicaccess/diffieHellman.go index 8ee9bb1bcce..a9ff7f7f8cd 100644 --- a/pkg/dynamicaccess/diffieHellman.go +++ b/pkg/dynamicaccess/diffieHellman.go @@ -2,30 +2,30 @@ package dynamicaccess import ( "crypto/ecdsa" + "errors" - Crypto "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/keystore" - KeyStoreMem "github.com/ethersphere/bee/pkg/keystore/mem" + "github.com/ethersphere/bee/pkg/crypto" ) type DiffieHellman interface { - SharedSecret(pubKey, tag string, moment []byte) (string, error) + SharedSecret(publicKey *ecdsa.PublicKey, tag string, moment []byte) ([]byte, error) // tag- topic? } +var _ DiffieHellman = (*defaultDiffieHellman)(nil) + type defaultDiffieHellman struct { - key *ecdsa.PrivateKey - keyStoreService keystore.Service - keyStoreEdg keystore.EDG + key *ecdsa.PrivateKey } -func (d *defaultDiffieHellman) SharedSecret(pubKey string, tag string, moment []byte) (string, error) { - return "", nil +func (dh *defaultDiffieHellman) SharedSecret(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) { + x, _ := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, dh.key.D.Bytes()) + if x == nil { + return nil, errors.New("shared secret is point at infinity") + } + return crypto.LegacyKeccak256(append(x.Bytes(), salt...)) } func NewDiffieHellman(key *ecdsa.PrivateKey) DiffieHellman { - return &defaultDiffieHellman{ - key: key, - keyStoreService: KeyStoreMem.New(), - keyStoreEdg: Crypto.EDGSecp256_K1, - } + return &defaultDiffieHellman{key: key} + } diff --git a/pkg/dynamicaccess/diffieHellman_test.go b/pkg/dynamicaccess/diffieHellman_test.go index 2e1c870a178..5c80592b3ec 100644 --- a/pkg/dynamicaccess/diffieHellman_test.go +++ b/pkg/dynamicaccess/diffieHellman_test.go @@ -1,10 +1,54 @@ -package dynamicaccess +package dynamicaccess_test -import "testing" +import ( + "bytes" + "crypto/rand" + "encoding/hex" + "io" + "testing" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/dynamicaccess" +) func TestSharedSecret(t *testing.T) { - _, err := NewDiffieHellman(nil).SharedSecret("", "", nil) + pk, _ := crypto.GenerateSecp256k1Key() + _, err := dynamicaccess.NewDiffieHellman(pk).SharedSecret(&pk.PublicKey, "", nil) if err != nil { t.Errorf("Error generating shared secret: %v", err) } } + +func TestECDHCorrect(t *testing.T) { + t.Parallel() + + key1, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + dh1 := dynamicaccess.NewDiffieHellman(key1) + + key2, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + dh2 := dynamicaccess.NewDiffieHellman(key2) + + moment := make([]byte, 1) + if _, err := io.ReadFull(rand.Reader, moment); err != nil { + t.Fatal(err) + } + + shared1, err := dh1.SharedSecret(&key2.PublicKey, "", moment) + if err != nil { + t.Fatal(err) + } + shared2, err := dh2.SharedSecret(&key1.PublicKey, "", moment) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(shared1, shared2) { + t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(shared1), hex.EncodeToString(shared2)) + } +} diff --git a/pkg/dynamicaccess/feed.go b/pkg/dynamicaccess/feed.go deleted file mode 100644 index 2576c2733a5..00000000000 --- a/pkg/dynamicaccess/feed.go +++ /dev/null @@ -1,36 +0,0 @@ -package dynamicaccess - -// referencia: history.go -type Feed interface { - Update(itemKey string, content string) error - Get(itemKey string) (content string, err error) - AddNewGrantee(itemKey string, grantee string) error - RemoveGrantee(itemKey string, grantee string) error - GetAccess(encryptedRef string, publisher string, tag string) (access string, err error) -} - -type defaultFeed struct{} - -func (f *defaultFeed) Update(itemKey string, content string) error { - return nil -} - -func (f *defaultFeed) Get(itemKey string) (content string, err error) { - return "", nil -} - -func (f *defaultFeed) AddNewGrantee(itemKey string, grantee string) error { - return nil -} - -func (f *defaultFeed) RemoveGrantee(itemKey string, grantee string) error { - return nil -} - -func (f *defaultFeed) GetAccess(encryptedRef string, publisher string, tag string) (access string, err error) { - return "", nil -} - -func NewFeed() Feed { - return &defaultFeed{} -} diff --git a/pkg/dynamicaccess/feed_test.go b/pkg/dynamicaccess/feed_test.go deleted file mode 100644 index 1839e6230b9..00000000000 --- a/pkg/dynamicaccess/feed_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package dynamicaccess - -import "testing" - -func TestFeedUpdate(t *testing.T) { - err := NewFeed().Update("", "") - if err != nil { - t.Errorf("Error updating feed: %v", err) - } -} - -func TestFeedGet(t *testing.T) { - content, err := NewFeed().Get("") - if err != nil { - t.Errorf("Error getting feed: %v", err) - } - _ = content // Ignore the content if not needed -} - -func TestFeedAddNewGrantee(t *testing.T) { - err := NewFeed().AddNewGrantee("", "") - if err != nil { - t.Errorf("Error adding new grantee to feed: %v", err) - } -} - -func TestFeedRemoveGrantee(t *testing.T) { - err := NewFeed().RemoveGrantee("", "") - if err != nil { - t.Errorf("Error removing grantee from feed: %v", err) - } -} - -func TestFeedGetAccess(t *testing.T) { - access, err := NewFeed().GetAccess("", "", "") - if err != nil { - t.Errorf("Error getting access to feed: %v", err) - } - _ = access // Ignore the access if not needed -} diff --git a/pkg/dynamicaccess/history.go b/pkg/dynamicaccess/history.go index b9a9438b331..e2705fffeac 100644 --- a/pkg/dynamicaccess/history.go +++ b/pkg/dynamicaccess/history.go @@ -1,22 +1,35 @@ package dynamicaccess -// TODO FROM BEE!!!! -// timestamp alapú history +import ( + "github.com/ethereum/go-ethereum/common" +) + type History interface { - Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) - Get(rootKey string) (value string, err error) + Add(timestamp int64, act Act) error + Get(timestamp int64) (Act, error) + Lookup(at int64) (Act, error) +} + +var _ History = (*history)(nil) + +type history struct { + history map[int64]*Act +} + +func NewHistory(topic []byte, owner common.Address) *history { + return &history{history: make(map[int64]*Act)} } -type defaultHistory struct{} +func (h *history) Add(timestamp int64, act Act) error { -func (h *defaultHistory) Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) { - return "", nil + return nil } -func (h *defaultHistory) Get(rootKey string) (value string, err error) { - return "", nil +func (h *history) Lookup(at int64) (Act, error) { + return nil, nil } -func NewHistory() History { - return &defaultHistory{} +func (h *history) Get(timestamp int64) (Act, error) { + // get the feed + return nil, nil } diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index 9116e41f548..2a24e65d862 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -1,19 +1,58 @@ -package dynamicaccess +package dynamicaccess_test -import "testing" +import ( + "encoding/hex" + "testing" + "time" -func TestHistoryAdd(t *testing.T) { - newRootHash, err := NewHistory().Add("", "") - if err != nil { - t.Errorf("Error adding history: %v", err) + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/dynamicaccess/mock" + "github.com/stretchr/testify/assert" +) + +func TestHistoryLookup(t *testing.T) { + h := pretareTestHistory() + now := time.Now() + + tests := []struct { + input int64 + expected string + }{ + {input: 0, expected: "value3"}, + {input: now.Unix(), expected: "value3"}, + {input: now.AddDate(0, -5, 0).Unix(), expected: "value3"}, + {input: now.AddDate(0, -6, 0).Unix(), expected: "value3"}, + {input: now.AddDate(-1, 0, 0).Unix(), expected: "value3"}, + {input: now.AddDate(-1, -6, 0).Unix(), expected: "value2"}, + {input: now.AddDate(-2, -0, 0).Unix(), expected: "value2"}, + {input: now.AddDate(-2, -6, 0).Unix(), expected: "value1"}, + {input: now.AddDate(-3, -0, 0).Unix(), expected: "value1"}, } - _ = newRootHash // Ignore the newRootHash if not needed -} -func TestHistoryGet(t *testing.T) { - value, err := NewHistory().Get("") - if err != nil { - t.Errorf("Error getting history: %v", err) + for _, tt := range tests { + t.Run("", func(t *testing.T) { + actAt, _ := h.Lookup(tt.input) + output := actAt.Get([]byte("key1")) + assert.Equal(t, output, hex.EncodeToString([]byte(tt.expected))) + }) } - _ = value // Ignore the value if not needed +} + +func pretareTestHistory() dynamicaccess.History { + var ( + h = mock.NewHistory() + now = time.Now() + act1 = dynamicaccess.NewDefaultAct() + act2 = dynamicaccess.NewDefaultAct() + act3 = dynamicaccess.NewDefaultAct() + ) + act1.Add([]byte("key1"), []byte("value1")) + act2.Add([]byte("key1"), []byte("value2")) + act3.Add([]byte("key1"), []byte("value3")) + + h.Insert(now.AddDate(-3, 0, 0).Unix(), act1) + h.Insert(now.AddDate(-2, 0, 0).Unix(), act2) + h.Insert(now.AddDate(-1, 0, 0).Unix(), act3) + + return h } diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go new file mode 100644 index 00000000000..1fd68caa399 --- /dev/null +++ b/pkg/dynamicaccess/mock/act.go @@ -0,0 +1,47 @@ +package mock + +import ( + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/manifest" +) + +type ActMock struct { + AddFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act + GetFunc func(lookupKey []byte) []byte + LoadFunc func(lookupKey []byte) manifest.Entry + StoreFunc func(me manifest.Entry) +} + +var _ dynamicaccess.Act = (*ActMock)(nil) + +func (act *ActMock) Add(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act { + if act.AddFunc == nil { + return act + } + return act.AddFunc(lookupKey, encryptedAccessKey) +} + +func (act *ActMock) Get(lookupKey []byte) []byte { + if act.GetFunc == nil { + return make([]byte, 0) + } + return act.GetFunc(lookupKey) +} + +func (act *ActMock) Load(lookupKey []byte) manifest.Entry { + if act.LoadFunc == nil { + return nil + } + return act.LoadFunc(lookupKey) +} + +func (act *ActMock) Store(me manifest.Entry) { + if act.StoreFunc == nil { + return + } + act.StoreFunc(me) +} + +func NewActMock() dynamicaccess.Act { + return &ActMock{} +} diff --git a/pkg/dynamicaccess/mock/diffieHellman.go b/pkg/dynamicaccess/mock/diffieHellman.go index f71131b11ff..91601026893 100644 --- a/pkg/dynamicaccess/mock/diffieHellman.go +++ b/pkg/dynamicaccess/mock/diffieHellman.go @@ -1,12 +1,22 @@ package mock +import ( + "crypto/ecdsa" +) + type DiffieHellmanMock struct { - SharedSecretFunc func(string, string, []byte) (string, error) + SharedSecretFunc func(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) + key *ecdsa.PrivateKey } -func (ma *DiffieHellmanMock) SharedSecret(publicKey string, tag string, moment []byte) (string, error) { - if ma.SharedSecretFunc == nil { - return "", nil +func (dhm *DiffieHellmanMock) SharedSecret(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) { + if dhm.SharedSecretFunc == nil { + return nil, nil } - return ma.SharedSecretFunc(publicKey, tag, moment) + return dhm.SharedSecretFunc(publicKey, tag, salt) + +} + +func NewDiffieHellmanMock(key *ecdsa.PrivateKey) *DiffieHellmanMock { + return &DiffieHellmanMock{key: key} } diff --git a/pkg/dynamicaccess/mock/history.go b/pkg/dynamicaccess/mock/history.go new file mode 100644 index 00000000000..68559c2277a --- /dev/null +++ b/pkg/dynamicaccess/mock/history.go @@ -0,0 +1,90 @@ +package mock + +import ( + "context" + "sort" + "time" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/feeds" + "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/pkg/swarm" +) + +type historyMock struct { + history map[int64]dynamicaccess.Act +} + +func NewHistory() *historyMock { + return &historyMock{history: make(map[int64]dynamicaccess.Act)} +} + +func (h *historyMock) Add(timestamp int64, act dynamicaccess.Act) error { + h.history[timestamp] = act + return nil +} + +func (h *historyMock) Insert(timestamp int64, act dynamicaccess.Act) *historyMock { + h.Add(timestamp, act) + return h +} + +func (h *historyMock) Lookup(at int64) (dynamicaccess.Act, error) { + keys := []int64{} + for k := range h.history { + keys = append(keys, k) + } + + sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] }) + + timestamp := time.Now() + if at != 0 { + timestamp = time.Unix(at, 0) + } + + for i := len(keys) - 1; i >= 0; i-- { + update := time.Unix(keys[i], 0) + if update.Before(timestamp) || update.Equal(timestamp) { + return h.history[keys[i]], nil + } + } + return nil, nil +} + +func (h *historyMock) Get(timestamp int64) (dynamicaccess.Act, error) { + return h.history[timestamp], nil +} + +type finder struct { + getter *feeds.Getter +} + +type updater struct { + *feeds.Putter + next uint64 +} + +func (f *finder) At(ctx context.Context, at int64, after uint64) (chunk swarm.Chunk, currentIndex, nextIndex feeds.Index, err error) { + return nil, nil, nil, nil +} + +func HistoryFinder(getter storage.Getter, feed *feeds.Feed) feeds.Lookup { + return &finder{feeds.NewGetter(getter, feed)} +} + +func (u *updater) Update(ctx context.Context, at int64, payload []byte) error { + return nil +} + +func (u *updater) Feed() *feeds.Feed { + return nil +} + +func HistoryUpdater(putter storage.Putter, signer crypto.Signer, topic []byte) (feeds.Updater, error) { + p, err := feeds.NewPutter(putter, signer, topic) + if err != nil { + return nil, err + } + return &updater{Putter: p}, nil +} From b1a8a15e1c189fdddf3ce8e932c179bfa8798b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Ar=C3=A1nyi?= Date: Wed, 13 Mar 2024 19:07:06 +0400 Subject: [PATCH 03/22] Acces Logic (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use DiffieHellmanMock * Adds a comment about Get * Add support for ECDSA public key in DiffieHellman.SharedSecret function * Update defaultAct implementation * Adds pseudo code for Access Logic * Update default Act creation; Fix basic Act tests * Refactor access logic to use new ActMock implementation * feat(history): test mockups wip * Refactor DiffieHellman implementation * changes pseudocode for Diffie-Hellmann read * Co-authored-by: Bálint Ujvári * DiffieHellman mock generates a real sherd secret * Refactor Act * Adds manifest lookup * Extend act_test * Adds unit tests, some values are mocked * Refactor act mock impl with map[string]map[string]string * Add check mock implementation for DiffieHellman interface * started Add * changed some sig * save * new grantee addition handling * mod * changed helper function visibilities * some mod with grantee * test mod * save * no error in actInit * Add_New_Grantee_To_Content * comment * copied act_test.go * no compiler errors on our side * Adds Add_New_Grantee_To_Content and ActInit * almost complete grantee container * maybe complete grantee container * Solves merge conflict * access-logic-merge * fix merge issues --- pkg/dynamicaccess/accesslogic.go | 123 ++++++++++++++++++-------- pkg/dynamicaccess/accesslogic_test.go | 115 ++++++++++++++++++------ pkg/dynamicaccess/grantee.go | 48 ++++++++-- pkg/dynamicaccess/grantee_test.go | 102 ++++++++++++++++++--- 4 files changed, 304 insertions(+), 84 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index ee141d7b69f..803c1110517 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -8,16 +8,22 @@ import ( encryption "github.com/ethersphere/bee/pkg/encryption" file "github.com/ethersphere/bee/pkg/file" manifest "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/swarm" "golang.org/x/crypto/sha3" ) var hashFunc = sha3.NewLegacyKeccak256 type AccessLogic interface { - Get(act_root_hash string, encryped_ref string, publisher string, tag string) (string, error) - GetLookUpKey(publisher string, tag string) (string, error) - GetAccessKeyDecriptionKey(publisher string, tag string) (string, error) - GetEncryptedAccessKey(act_root_hash string, lookup_key string) (manifest.Entry, error) + Get(act *Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (string, error) + //Add(act *Act, ref string, publisher ecdsa.PublicKey, tag string) (string, error) + getLookUpKey(publisher ecdsa.PublicKey, tag string) (string, error) + getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) (string, error) + getEncryptedAccessKey(act Act, lookup_key string) (manifest.Entry, error) + //createEncryptedAccessKey(ref string) + Add_New_Grantee_To_Content(act *Act, encryptedRef swarm.Address, publisherPubKey ecdsa.PublicKey, granteePubKey ecdsa.PublicKey) (*Act, error) + ActInit(ref swarm.Address, publisher ecdsa.PublicKey, tag string) (*Act, swarm.Address, error) + // CreateAccessKey() } type DefaultAccessLogic struct { @@ -26,42 +32,95 @@ type DefaultAccessLogic struct { act defaultAct } -// Will give back Swarm reference with symmertic encryption key (128 byte) -// @publisher: public key -func (al *DefaultAccessLogic) GetLookUpKey(publisher string, tag string) (string, error) { +// Will create a new Act list with only one element (the creator), and will also create encrypted_ref +func (al *DefaultAccessLogic) ActInit(ref swarm.Address, publisher ecdsa.PublicKey, tag string) (*Act, swarm.Address, error) { + act := NewDefaultAct() + + lookup_key, _ := al.getLookUpKey(publisher, "") + access_key_encryption_key, _ := al.getAccessKeyDecriptionKey(publisher, "") + + access_key_cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) + access_key := encryption.GenerateRandomKey(encryption.KeyLength) + encrypted_access_key, _ := access_key_cipher.Encrypt([]byte(access_key)) + + ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) + encrypted_ref, _ := ref_cipher.Encrypt(ref.Bytes()) + + act.Add([]byte(lookup_key), encrypted_access_key) + + return &act, swarm.NewAddress(encrypted_ref), nil +} + +// publisher is public key +func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act *Act, encryptedRef swarm.Address, publisherPubKey ecdsa.PublicKey, granteePubKey ecdsa.PublicKey) (*Act, error) { + + // error handling no encrypted_ref + + // 2 Diffie-Hellman for the publisher (the Creator) + publisher_lookup_key, _ := al.getLookUpKey(publisherPubKey, "") + publisher_ak_decryption_key, _ := al.getAccessKeyDecriptionKey(publisherPubKey, "") + + // Get previously generated access key + access_key_decryption_cipher := encryption.New(encryption.Key(publisher_ak_decryption_key), 0, uint32(0), hashFunc) + encrypted_ak, _ := al.getEncryptedAccessKey(*act, publisher_lookup_key) + access_key, _ := access_key_decryption_cipher.Decrypt(encrypted_ak.Reference().Bytes()) + + // --Encrypt access key for new Grantee-- + + // 2 Diffie-Hellman for the Grantee + lookup_key, _ := al.getLookUpKey(granteePubKey, "") + access_key_encryption_key, _ := al.getAccessKeyDecriptionKey(granteePubKey, "") + + // Encrypt the access key for the new Grantee + cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) + granteeEncryptedAccessKey, _ := cipher.Encrypt(access_key) + // Add the new encrypted access key for the Act + actObj := *act + actObj.Add([]byte(lookup_key), granteeEncryptedAccessKey) + + return &actObj, nil + +} + +// +// act[lookupKey] := valamilyen_cipher.Encrypt(access_key) + +// end of pseudo code like code + +// func (al *DefaultAccessLogic) CreateAccessKey(reference string) { +// } + +func (al *DefaultAccessLogic) getLookUpKey(publisher ecdsa.PublicKey, tag string) (string, error) { zeroByteArray := []byte{0} // Generate lookup key using Diffie Hellman - lookup_key, err := al.diffieHellman.SharedSecret(publisher, tag, zeroByteArray) + lookup_key, err := al.diffieHellman.SharedSecret(&publisher, tag, zeroByteArray) if err != nil { return "", err } - return lookup_key, nil + return string(lookup_key), nil } -func (al *DefaultAccessLogic) GetAccessKeyDecriptionKey(publisher string, tag string) (string, error) { +func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) (string, error) { oneByteArray := []byte{1} // Generate access key decryption key using Diffie Hellman - access_key_decryption_key, err := al.diffieHellman.SharedSecret(publisher, tag, oneByteArray) + access_key_decryption_key, err := al.diffieHellman.SharedSecret(&publisher, tag, oneByteArray) if err != nil { return "", err } - return access_key_decryption_key, nil + return string(access_key_decryption_key), nil } -func (al *DefaultAccessLogic) GetEncryptedAccessKey(act_root_hash string, lookup_key string) (manifest.Entry, error) { - if act_root_hash == "" { +func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key string) (manifest.Entry, error) { + if act == nil { return nil, errors.New("no ACT root hash was provided") } if lookup_key == "" { return nil, errors.New("no lookup key") } - manifest_raw, err := al.act.Get(act_root_hash) - if err != nil { - return nil, err - } - al.act.Get(act_root_hash) + manifest_raw := act.Get([]byte(lookup_key)) + //al.act.Get(act_root_hash) // Lookup encrypted access key from the ACT manifest var loadSaver file.LoadSaver @@ -80,20 +139,20 @@ func (al *DefaultAccessLogic) GetEncryptedAccessKey(act_root_hash string, lookup return encrypted_access_key, nil } -func (al *DefaultAccessLogic) Get(act_root_hash string, encryped_ref string, publisher string, tag string) (string, error) { +func (al *DefaultAccessLogic) Get(act *Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (string, error) { - lookup_key, err := al.GetLookUpKey(publisher, tag) + lookup_key, err := al.getLookUpKey(publisher, tag) if err != nil { return "", err } - access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(publisher, tag) + access_key_decryption_key, err := al.getAccessKeyDecriptionKey(publisher, tag) if err != nil { return "", err } // Lookup encrypted access key from the ACT manifest - encrypted_access_key, err := al.GetEncryptedAccessKey(act_root_hash, lookup_key) + encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookup_key) if err != nil { return "", err } @@ -107,7 +166,7 @@ func (al *DefaultAccessLogic) Get(act_root_hash string, encryped_ref string, pub // Decrypt reference ref_cipher := encryption.New(access_key, 4096, uint32(0), hashFunc) - ref, err := ref_cipher.Decrypt([]byte(encryped_ref)) + ref, err := ref_cipher.Decrypt(encryped_ref.Bytes()) if err != nil { return "", err } @@ -115,20 +174,10 @@ func (al *DefaultAccessLogic) Get(act_root_hash string, encryped_ref string, pub return string(ref), nil } -func NewAccessLogic(diffieHellmanPrivateKey *ecdsa.PrivateKey) AccessLogic { +func NewAccessLogic(diffieHellman DiffieHellman) AccessLogic { return &DefaultAccessLogic{ - diffieHellman: NewDiffieHellman(diffieHellmanPrivateKey), - //encryption: encryption.New(key, padding, initCtr, hashFunc), - act: defaultAct{}, - - // { - // AddFunc: func(ref string, publisher string, tag string) error { - // return nil - // }, - // GetFunc: func(ref string, publisher string, tag string) (string, error) { - // return "", nil - // }, - // }, + diffieHellman: diffieHellman, + act: defaultAct{}, } } diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index cc4ad28ebce..ee7c16c43e0 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -1,10 +1,15 @@ package dynamicaccess import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" "errors" + "fmt" "testing" "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/swarm" ) func setupAccessLogic() AccessLogic { @@ -12,7 +17,8 @@ func setupAccessLogic() AccessLogic { if err != nil { errors.New("error creating private key") } - al := NewAccessLogic(privateKey) + diffieHellman := NewDiffieHellman(privateKey) + al := NewAccessLogic(diffieHellman) return al } @@ -20,27 +26,33 @@ func setupAccessLogic() AccessLogic { func TestGetLookupKey_Success(t *testing.T) { al := setupAccessLogic() - publisher := "examplePublisher" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + // ! this will be random, we can not know the lookup key for a randomly generated key + act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") + fmt.Println(act, encryptedRef) + tag := "exampleTag" - lookupKey, err := al.GetLookUpKey(publisher, tag) + lookupKey, err := al.getLookUpKey(id0.PublicKey, tag) if err != nil { t.Errorf("Could not fetch lookup key from publisher and tag") } expectedLookupKey := "expectedLookupKey" if lookupKey != expectedLookupKey { + fmt.Println(string(lookupKey)) t.Errorf("The lookup key that was returned is not correct!") } } -func TestGetLookupKey_Error(t *testing.T) { +func TestGetLookUpKey_Error(t *testing.T) { al := setupAccessLogic() - invalidPublisher := "" + invalidPublisher := ecdsa.PublicKey{} tag := "exampleTag" - lookupKey, err := al.GetLookUpKey(invalidPublisher, tag) + lookupKey, err := al.getLookUpKey(invalidPublisher, tag) + if err != nil { t.Errorf("There was an error while fetching lookup key") } @@ -53,10 +65,10 @@ func TestGetLookupKey_Error(t *testing.T) { func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { al := setupAccessLogic() - publisher := "examplePublisher" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) tag := "exampleTag" - access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(publisher, tag) + access_key_decryption_key, err := al.getAccessKeyDecriptionKey(id0.PublicKey, tag) if err != nil { t.Errorf("GetAccessKeyDecriptionKey gave back error") } @@ -70,10 +82,10 @@ func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { al := setupAccessLogic() - invalidPublisher := "" + invalidPublisher := ecdsa.PublicKey{} tag := "exampleTag" - access_key_decryption_key, err := al.GetAccessKeyDecriptionKey(invalidPublisher, tag) + access_key_decryption_key, err := al.getAccessKeyDecriptionKey(invalidPublisher, tag) if err != nil { t.Errorf("GetAccessKeyDecriptionKey gave back error") } @@ -86,16 +98,18 @@ func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { func TestGetEncryptedAccessKey_Success(t *testing.T) { al := setupAccessLogic() - actRootHash := "0xabcexample" lookupKey := "exampleLookupKey" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - encrypted_access_key, err := al.GetEncryptedAccessKey(actRootHash, lookupKey) + act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") + + encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookupKey) if err != nil { t.Errorf("There was an error while executing GetEncryptedAccessKey") } expectedEncryptedKey := "abc013encryptedkey" - if encrypted_access_key != expectedEncryptedKey { + if encrypted_access_key.Reference().String() != expectedEncryptedKey { t.Errorf("GetEncryptedAccessKey didn't give back the expected value!") } } @@ -103,15 +117,16 @@ func TestGetEncryptedAccessKey_Success(t *testing.T) { func TestGetEncryptedAccessKey_Error(t *testing.T) { al := setupAccessLogic() - actRootHash := "0xabcexample" lookupKey := "exampleLookupKey" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - empty_act_result, _ := al.GetEncryptedAccessKey("", lookupKey) + act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") + empty_act_result, _ := al.getEncryptedAccessKey(*act, lookupKey) if empty_act_result != nil { t.Errorf("GetEncryptedAccessKey should give back nil for empty act root hash!") } - empty_lookup_result, _ := al.GetEncryptedAccessKey(actRootHash, "") + empty_lookup_result, _ := al.getEncryptedAccessKey(*act, "") if empty_lookup_result != nil { t.Errorf("GetEncryptedAccessKey should give back nil for empty lookup key!") @@ -121,12 +136,11 @@ func TestGetEncryptedAccessKey_Error(t *testing.T) { func TestGet_Success(t *testing.T) { al := setupAccessLogic() - actRootHash := "0xabcexample" - encryptedRef := "bzzabcasab" - publisher := "examplePublisher" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") tag := "exampleTag" - ref, err := al.Get(actRootHash, encryptedRef, publisher, tag) + ref, err := al.Get(act, encryptedRef, id0.PublicKey, tag) if err != nil { t.Errorf("There was an error while calling Get") } @@ -140,27 +154,35 @@ func TestGet_Success(t *testing.T) { func TestGet_Error(t *testing.T) { al := setupAccessLogic() - actRootHash := "0xabcexample" - encryptedRef := "bzzabcasab" - publisher := "examplePublisher" + //actRootHash := "0xabcexample" + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + act, encrypredRef, err := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") + if err != nil { + t.Errorf("Error initializing Act") + t.Errorf(err.Error()) + } + //encryptedRef := "bzzabcasab" tag := "exampleTag" - refOne, _ := al.Get("", encryptedRef, publisher, tag) + refOne, err := al.Get(act, encrypredRef, id0.PublicKey, tag) + if err != nil { + t.Errorf(err.Error()) + } if refOne != "" { t.Errorf("Get should give back empty string if ACT root hash not provided!") } - refTwo, _ := al.Get(actRootHash, "", publisher, tag) + refTwo, _ := al.Get(act, swarm.EmptyAddress, id0.PublicKey, tag) if refTwo != "" { t.Errorf("Get should give back empty string if encrypted ref not provided!") } - refThree, _ := al.Get(actRootHash, encryptedRef, "", tag) + refThree, _ := al.Get(act, encrypredRef, ecdsa.PublicKey{}, tag) if refThree != "" { t.Errorf("Get should give back empty string if publisher not provided!") } - refFour, _ := al.Get(actRootHash, encryptedRef, publisher, "") + refFour, _ := al.Get(act, encrypredRef, id0.PublicKey, "") if refFour != "" { t.Errorf("Get should give back empty string if tag was not provided!") } @@ -174,3 +196,42 @@ func TestNewAccessLogic(t *testing.T) { t.Errorf("NewAccessLogic: expected type *DefaultAccessLogic, got %T", logic) } } + +// func TestAddGrantee(t *testing.T) { +// al := setupAccessLogic() +// // ref := "example_ref" +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// testGranteeList := NewGrantee() + +// // Add grantee keys to the testGranteeList +// id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// id3, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// testGranteeList.AddGrantees([]ecdsa.PublicKey{id1.PublicKey, id2.PublicKey, id3.PublicKey}) + +// // Initialize empty ACT +// actMock := MockAct.NewActMock() +// actMockRootHash := "exampleRootHash" + +// // Add each grantee to content using ActMock and validate the resulting ACT +// for i := 0; i < len(testGranteeList.GetGrantees()); i++ { +// lookupKey, _ := al.getLookUpKey(testGranteeList.GetGrantees()[i], "") +// encryptedAccessKey := "exampleEncryptedAccessKey" +// _, err := actMock.Add(actMockRootHash, []byte(lookupKey), []byte(encryptedAccessKey)) +// if err != nil { +// t.Fatalf("Failed to add grantee to content using ActMock: %v", err) +// } + +// // Validate the resulting ACT +// encryptedAccessKeyFromMock, err := actMock.Get(actMockRootHash, []byte(lookupKey)) +// if err != nil { +// t.Fatalf("Failed to retrieve encrypted access key from ActMock: %v", err) +// } +// encryptedAccessKeyFromMockBytes, _ := hex.DecodeString(encryptedAccessKeyFromMock) +// if string(encryptedAccessKeyFromMockBytes) != encryptedAccessKey { +// t.Errorf("Encrypted access key retrieved from ActMock doesn't match expected value") +// } +// } + +// al.Add_New_Grantee_To_Content(actMock, encryptedRef, id0.PublicKey, testGranteeList.GetGrantees()[i]) +// } diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index 27eb1636a09..bb39899e012 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -1,24 +1,54 @@ package dynamicaccess +import "crypto/ecdsa" + type Grantee interface { - Revoke(topic string) error - RevokeList(topic string, removeList []string, addList []string) (string, error) - Publish(topic string) error + //? ÁTBESZÉLNI + // Revoke(topic string) error + // Publish(topic string) error + + // RevokeList(topic string, removeList []string, addList []string) (string, error) + // RevokeGrantees(topic string, removeList []string) (string, error) + AddGrantees(addList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) + RemoveGrantees(removeList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) + GetGrantees() []ecdsa.PublicKey } type defaultGrantee struct { + topic string //lint:ignore U1000 Ignore unused struct field + grantees []ecdsa.PublicKey // Modified field name to start with an uppercase letter } -func (g *defaultGrantee) Revoke(topic string) error { - return nil +func (g *defaultGrantee) GetGrantees() []ecdsa.PublicKey { + return g.grantees } -func (g *defaultGrantee) RevokeList(topic string, removeList []string, addList []string) (string, error) { - return "", nil +// func (g *defaultGrantee) Revoke(topic string) error { +// return nil +// } + +// func (g *defaultGrantee) RevokeList(topic string, removeList []string, addList []string) (string, error) { +// return "", nil +// } + +// func (g *defaultGrantee) Publish(topic string) error { +// return nil +// } + +func (g *defaultGrantee) AddGrantees(addList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) { + g.grantees = append(g.grantees, addList...) + return g.grantees, nil } -func (g *defaultGrantee) Publish(topic string) error { - return nil +func (g *defaultGrantee) RemoveGrantees(removeList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) { + for _, remove := range removeList { + for i, grantee := range g.grantees { + if grantee == remove { + g.grantees = append(g.grantees[:i], g.grantees[i+1:]...) + } + } + } + return g.grantees, nil } func NewGrantee() Grantee { diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 38b2d10b347..5140216d2a2 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -1,24 +1,104 @@ package dynamicaccess -import "testing" +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "reflect" + "testing" +) -func TestGranteeRevoke(t *testing.T) { - err := NewGrantee().Revoke("") - if err != nil { - t.Errorf("Error revoking grantee: %v", err) - } -} +// func TestGranteeRevoke(t *testing.T) { +// err := NewGrantee().Revoke("") +// if err != nil { +// t.Errorf("Error revoking grantee: %v", err) +// } +// } -func TestGranteeRevokeList(t *testing.T) { +/*func TestGranteeRevokeList(t *testing.T) { _, err := NewGrantee().RevokeList("", nil, nil) if err != nil { t.Errorf("Error revoking list of grantees: %v", err) } +}*/ + +// func TestGranteePublish(t *testing.T) { +// err := NewGrantee().Publish("") +// if err != nil { +// t.Errorf("Error publishing grantee: %v", err) +// } +// } + +func TestGranteeAddGrantees(t *testing.T) { + // Create a new Grantee + grantee := NewGrantee() + + // Generate some dummy ecdsa.PublicKey values + key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + + // Add the keys to the grantee + addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} + grantees, err := grantee.AddGrantees(addList) + + // Check for errors + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + + // Check if the keys were added correctly + if !reflect.DeepEqual(grantees, addList) { + t.Errorf("Expected grantees %v, got %v", addList, grantees) + } } -func TestGranteePublish(t *testing.T) { - err := NewGrantee().Publish("") +func TestRemoveGrantees(t *testing.T) { + // Create a new Grantee + grantee := NewGrantee() + + // Generate some dummy ecdsa.PublicKey values + key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + + // Add the keys to the grantee + addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} + grantee.AddGrantees(addList) + + // Remove one of the keys + removeList := []ecdsa.PublicKey{key1.PublicKey} + grantees, err := grantee.RemoveGrantees(removeList) + + // Check for errors if err != nil { - t.Errorf("Error publishing grantee: %v", err) + t.Fatalf("Expected no error, got %v", err) + } + + // Check if the key was removed correctly + expectedGrantees := []ecdsa.PublicKey{key2.PublicKey} + if !reflect.DeepEqual(grantees, expectedGrantees) { + t.Errorf("Expected grantees %v, got %v", expectedGrantees, grantees) } } + +func TestGetGrantees(t *testing.T) { + // Create a new Grantee + grantee := NewGrantee() + + // Generate some dummy ecdsa.PublicKey values + key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + + // Add the keys to the grantee + addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} + grantee.AddGrantees(addList) + + // Get the grantees + grantees := grantee.GetGrantees() + + // Check if the grantees were returned correctly + if !reflect.DeepEqual(grantees, addList) { + t.Errorf("Expected grantees %v, got %v", addList, grantees) + } +} + + From 7bed79783e0fad62952560d083ff25a5dbe89fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Ar=C3=A1nyi?= Date: Wed, 13 Mar 2024 19:27:36 +0400 Subject: [PATCH 04/22] Added context & details to use cases (#6) ZH #106 Added context & details to use cases --- act_ucs.md | 66 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/act_ucs.md b/act_ucs.md index 82067211bfd..14f93f346e4 100644 --- a/act_ucs.md +++ b/act_ucs.md @@ -4,43 +4,83 @@ This file contains the SWARM ACT user stories. ZenHub Link: [SpDevTeam](https://app.zenhub.com/workspaces/spdevteam-6544d91246b817002d853e69/board) +### Context & definitions +- Content is created as a 'channel', i.e. as a feed with a specific topic. +- The content is uploaded to the feed, and new version of the content could be uploaded any time. +- The content can be accessed by the publisher and any viewers if it does not have ACT defined. +- The content can be accessed by the publisher and any viewers if it has ACT defined and the viewer is in the grantees list. +- A publisher is a user who is uploading new content. +- A viewer is a user who is accessing content. +- When a viewer is losing access it means that in the newly generated ACT the viewer will no longer be present in the grantee list. +- The publisher should be able to modify the ACT, using the same private key, but on multiple nodes in parallel. +- The publisher should be able to modify the grantee list, using the same private key, but on multiple nodes in parallel (this would potentially require the grantee list to be encrypted as well). + +### Use cases + - [ ] **1** - I'm a publisher -- I upload a content -- I grant access to content -- Viewer try to access to the content +- I upload some new content +- I create an ACT for the content, but without additional grantees +- I can access the content +___ + +- [ ] **1/a** +- I'm a publisher +- I have an existing ACT for some content +- I can read and edit the ACT ___ - [ ] **2** - I'm a publisher -- I granteed access for viewers to my channel +- I have an existing ACT for some content, but without additional grantees +- I grant access to the content for some new viewers +- Those viewers can access the content ___ - [ ] **2/a** - I'm a publisher -- I granteed access for additional viewers to my channel +- I have an existing ACT for some content with some existing grantees +- I grant access to the content to additional viewers +- The existing viewers can access the content still +- The additional viewers can access the content ___ - [ ] **2/b** - I'm a publisher -- I remove viewers from the access list to my channel +- I remove viewers from the grantee list of the ACT content +- The content is unchanged +- The removed viewers can access the content still +- The existing viewers can access the content still +___ + +- [ ] **2/c** +- I'm a publisher +- I remove viewers from the grantee list of the ACT content +- The content is updated +- The removed viewers can't access the latest version of content anymore +- The removed viewers can access an older version of the content, the version up until the moment they were removed +- The existing viewers can access the content still, including the latest version ___ - [ ] **3** - I'm a viewer - I requested access to the content -- If I got, I can access it -- If I didn't get, I can't +- If I was granted access, I can access the content +- If I was not granted access, I can't access the content still ___ - [ ] **4** - I'm a viewer -- I lost access to the content -- I can't access new ones +- I had access to the content until now +- My access to the content got revoked +- The content is unchanged +- I can access the content still ___ -- [ ] **5** +- [ ] **4/a** - I'm a viewer -- I lost access to the content -- I can not access new ones, but the old ones I can +- I had access to the content until now +- My access to the content got revoked +- The content is updated +- I can't access versions of the content that were uploaded after I lost access ___ From d11600187c146ded2c01b193d3c398f8f32d6db2 Mon Sep 17 00:00:00 2001 From: Kexort Date: Thu, 14 Mar 2024 16:31:37 +0100 Subject: [PATCH 05/22] Add grantee management (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add grantee management * Added controller test * Fix test fixture, refactor accesslogic * Add UploadHandler --------- Co-authored-by: Bálint Ujvári --- pkg/dynamicaccess/accesslogic.go | 124 +++--- pkg/dynamicaccess/accesslogic_test.go | 460 +++++++++++----------- pkg/dynamicaccess/controller.go | 42 +- pkg/dynamicaccess/controller_test.go | 99 +++++ pkg/dynamicaccess/grantee.go | 33 +- pkg/dynamicaccess/grantee_manager.go | 41 ++ pkg/dynamicaccess/grantee_manager_test.go | 41 ++ pkg/dynamicaccess/grantee_test.go | 35 +- pkg/dynamicaccess/history_test.go | 4 +- pkg/dynamicaccess/mock/act.go | 7 +- 10 files changed, 539 insertions(+), 347 deletions(-) create mode 100644 pkg/dynamicaccess/controller_test.go create mode 100644 pkg/dynamicaccess/grantee_manager.go create mode 100644 pkg/dynamicaccess/grantee_manager_test.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 803c1110517..b3c01974f24 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -1,13 +1,9 @@ package dynamicaccess import ( - "context" "crypto/ecdsa" - "errors" encryption "github.com/ethersphere/bee/pkg/encryption" - file "github.com/ethersphere/bee/pkg/file" - manifest "github.com/ethersphere/bee/pkg/manifest" "github.com/ethersphere/bee/pkg/swarm" "golang.org/x/crypto/sha3" ) @@ -15,55 +11,53 @@ import ( var hashFunc = sha3.NewLegacyKeccak256 type AccessLogic interface { - Get(act *Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (string, error) + Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) + EncryptRef(act Act, publisherPubKey ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) //Add(act *Act, ref string, publisher ecdsa.PublicKey, tag string) (string, error) - getLookUpKey(publisher ecdsa.PublicKey, tag string) (string, error) - getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) (string, error) - getEncryptedAccessKey(act Act, lookup_key string) (manifest.Entry, error) + getLookUpKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) + getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) + getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) //createEncryptedAccessKey(ref string) - Add_New_Grantee_To_Content(act *Act, encryptedRef swarm.Address, publisherPubKey ecdsa.PublicKey, granteePubKey ecdsa.PublicKey) (*Act, error) - ActInit(ref swarm.Address, publisher ecdsa.PublicKey, tag string) (*Act, swarm.Address, error) + Add_New_Grantee_To_Content(act Act, publisherPubKey, granteePubKey ecdsa.PublicKey) (Act, error) + AddPublisher(act Act, publisher ecdsa.PublicKey, tag string) (Act, error) // CreateAccessKey() } type DefaultAccessLogic struct { diffieHellman DiffieHellman //encryption encryption.Interface - act defaultAct } // Will create a new Act list with only one element (the creator), and will also create encrypted_ref -func (al *DefaultAccessLogic) ActInit(ref swarm.Address, publisher ecdsa.PublicKey, tag string) (*Act, swarm.Address, error) { - act := NewDefaultAct() +func (al *DefaultAccessLogic) AddPublisher(act Act, publisher ecdsa.PublicKey, tag string) (Act, error) { + access_key := encryption.GenerateRandomKey(encryption.KeyLength) lookup_key, _ := al.getLookUpKey(publisher, "") access_key_encryption_key, _ := al.getAccessKeyDecriptionKey(publisher, "") access_key_cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) - access_key := encryption.GenerateRandomKey(encryption.KeyLength) - encrypted_access_key, _ := access_key_cipher.Encrypt([]byte(access_key)) + encrypted_access_key, _ := access_key_cipher.Encrypt(access_key) - ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) - encrypted_ref, _ := ref_cipher.Encrypt(ref.Bytes()) + act.Add(lookup_key, encrypted_access_key) - act.Add([]byte(lookup_key), encrypted_access_key) + return act, nil +} - return &act, swarm.NewAddress(encrypted_ref), nil +func (al *DefaultAccessLogic) EncryptRef(act Act, publisherPubKey ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { + access_key := al.getAccessKey(act, publisherPubKey) + ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) + encrypted_ref, _ := ref_cipher.Encrypt(ref.Bytes()) + return swarm.NewAddress(encrypted_ref), nil } // publisher is public key -func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act *Act, encryptedRef swarm.Address, publisherPubKey ecdsa.PublicKey, granteePubKey ecdsa.PublicKey) (*Act, error) { +func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act Act, publisherPubKey, granteePubKey ecdsa.PublicKey) (Act, error) { // error handling no encrypted_ref // 2 Diffie-Hellman for the publisher (the Creator) - publisher_lookup_key, _ := al.getLookUpKey(publisherPubKey, "") - publisher_ak_decryption_key, _ := al.getAccessKeyDecriptionKey(publisherPubKey, "") - // Get previously generated access key - access_key_decryption_cipher := encryption.New(encryption.Key(publisher_ak_decryption_key), 0, uint32(0), hashFunc) - encrypted_ak, _ := al.getEncryptedAccessKey(*act, publisher_lookup_key) - access_key, _ := access_key_decryption_cipher.Decrypt(encrypted_ak.Reference().Bytes()) + access_key := al.getAccessKey(act, publisherPubKey) // --Encrypt access key for new Grantee-- @@ -75,11 +69,20 @@ func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act *Act, encryptedRef cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) granteeEncryptedAccessKey, _ := cipher.Encrypt(access_key) // Add the new encrypted access key for the Act - actObj := *act - actObj.Add([]byte(lookup_key), granteeEncryptedAccessKey) + act.Add(lookup_key, granteeEncryptedAccessKey) + + return act, nil + +} - return &actObj, nil +func (al *DefaultAccessLogic) getAccessKey(act Act, publisherPubKey ecdsa.PublicKey) []byte { + publisher_lookup_key, _ := al.getLookUpKey(publisherPubKey, "") + publisher_ak_decryption_key, _ := al.getAccessKeyDecriptionKey(publisherPubKey, "") + access_key_decryption_cipher := encryption.New(encryption.Key(publisher_ak_decryption_key), 0, uint32(0), hashFunc) + encrypted_ak, _ := al.getEncryptedAccessKey(act, publisher_lookup_key) + access_key, _ := access_key_decryption_cipher.Decrypt(encrypted_ak) + return access_key } // @@ -90,94 +93,69 @@ func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act *Act, encryptedRef // func (al *DefaultAccessLogic) CreateAccessKey(reference string) { // } -func (al *DefaultAccessLogic) getLookUpKey(publisher ecdsa.PublicKey, tag string) (string, error) { +func (al *DefaultAccessLogic) getLookUpKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) { zeroByteArray := []byte{0} // Generate lookup key using Diffie Hellman lookup_key, err := al.diffieHellman.SharedSecret(&publisher, tag, zeroByteArray) if err != nil { - return "", err + return []byte{}, err } - return string(lookup_key), nil + return lookup_key, nil } -func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) (string, error) { +func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) { oneByteArray := []byte{1} // Generate access key decryption key using Diffie Hellman access_key_decryption_key, err := al.diffieHellman.SharedSecret(&publisher, tag, oneByteArray) if err != nil { - return "", err + return []byte{}, err } - return string(access_key_decryption_key), nil + return access_key_decryption_key, nil } -func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key string) (manifest.Entry, error) { - if act == nil { - return nil, errors.New("no ACT root hash was provided") - } - if lookup_key == "" { - return nil, errors.New("no lookup key") - } - - manifest_raw := act.Get([]byte(lookup_key)) - //al.act.Get(act_root_hash) - - // Lookup encrypted access key from the ACT manifest - var loadSaver file.LoadSaver - var ctx context.Context - loadSaver.Load(ctx, []byte(manifest_raw)) // Load the manifest file into loadSaver - //y, err := x.Load(ctx, []byte(manifest_obj)) - manifestObj, err := manifest.NewDefaultManifest(loadSaver, false) - if err != nil { - return nil, err - } - encrypted_access_key, err := manifestObj.Lookup(ctx, lookup_key) - if err != nil { - return nil, err - } - - return encrypted_access_key, nil +func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { + return act.Get(lookup_key), nil } -func (al *DefaultAccessLogic) Get(act *Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (string, error) { +func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) { lookup_key, err := al.getLookUpKey(publisher, tag) if err != nil { - return "", err + return swarm.EmptyAddress, err } access_key_decryption_key, err := al.getAccessKeyDecriptionKey(publisher, tag) if err != nil { - return "", err + return swarm.EmptyAddress, err } // Lookup encrypted access key from the ACT manifest - encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookup_key) + encrypted_access_key, err := al.getEncryptedAccessKey(act, lookup_key) if err != nil { - return "", err + return swarm.EmptyAddress, err } // Decrypt access key - access_key_cipher := encryption.New(encryption.Key(access_key_decryption_key), 4096, uint32(0), hashFunc) - access_key, err := access_key_cipher.Decrypt(encrypted_access_key.Reference().Bytes()) + access_key_cipher := encryption.New(encryption.Key(access_key_decryption_key), 0, uint32(0), hashFunc) + access_key, err := access_key_cipher.Decrypt(encrypted_access_key) if err != nil { - return "", err + return swarm.EmptyAddress, err } // Decrypt reference - ref_cipher := encryption.New(access_key, 4096, uint32(0), hashFunc) + ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) ref, err := ref_cipher.Decrypt(encryped_ref.Bytes()) if err != nil { - return "", err + return swarm.EmptyAddress, err } - return string(ref), nil + return swarm.NewAddress(ref), nil } func NewAccessLogic(diffieHellman DiffieHellman) AccessLogic { return &DefaultAccessLogic{ diffieHellman: diffieHellman, - act: defaultAct{}, } } diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index ee7c16c43e0..c3125b65cd6 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -1,237 +1,237 @@ -package dynamicaccess - -import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "errors" - "fmt" - "testing" +package dynamicaccess_test + +// import ( +// "crypto/ecdsa" +// "crypto/elliptic" +// "crypto/rand" +// "errors" +// "fmt" +// "testing" + +// "github.com/ethersphere/bee/pkg/crypto" +// "github.com/ethersphere/bee/pkg/swarm" +// ) + +// func setupAccessLogic() AccessLogic { +// privateKey, err := crypto.GenerateSecp256k1Key() +// if err != nil { +// errors.New("error creating private key") +// } +// diffieHellman := NewDiffieHellman(privateKey) +// al := NewAccessLogic(diffieHellman) + +// return al +// } - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" -) - -func setupAccessLogic() AccessLogic { - privateKey, err := crypto.GenerateSecp256k1Key() - if err != nil { - errors.New("error creating private key") - } - diffieHellman := NewDiffieHellman(privateKey) - al := NewAccessLogic(diffieHellman) +// func TestGetLookupKey_Success(t *testing.T) { +// al := setupAccessLogic() - return al -} - -func TestGetLookupKey_Success(t *testing.T) { - al := setupAccessLogic() - - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - // ! this will be random, we can not know the lookup key for a randomly generated key - act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - fmt.Println(act, encryptedRef) - - tag := "exampleTag" +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// // ! this will be random, we can not know the lookup key for a randomly generated key +// act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") +// fmt.Println(act, encryptedRef) - lookupKey, err := al.getLookUpKey(id0.PublicKey, tag) - if err != nil { - t.Errorf("Could not fetch lookup key from publisher and tag") - } - - expectedLookupKey := "expectedLookupKey" - if lookupKey != expectedLookupKey { - fmt.Println(string(lookupKey)) - t.Errorf("The lookup key that was returned is not correct!") - } -} +// tag := "exampleTag" -func TestGetLookUpKey_Error(t *testing.T) { - al := setupAccessLogic() - - invalidPublisher := ecdsa.PublicKey{} - tag := "exampleTag" - - lookupKey, err := al.getLookUpKey(invalidPublisher, tag) - - if err != nil { - t.Errorf("There was an error while fetching lookup key") - } - - if lookupKey != "" { - t.Errorf("Expected lookup key to be empty for invalid input") - } -} - -func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { - al := setupAccessLogic() - - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - tag := "exampleTag" - - access_key_decryption_key, err := al.getAccessKeyDecriptionKey(id0.PublicKey, tag) - if err != nil { - t.Errorf("GetAccessKeyDecriptionKey gave back error") - } - - expectedResult := "we-dont-know" - if access_key_decryption_key != expectedResult { - t.Errorf("The access key decryption key is not correct!") - } -} - -func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { - al := setupAccessLogic() - - invalidPublisher := ecdsa.PublicKey{} - tag := "exampleTag" - - access_key_decryption_key, err := al.getAccessKeyDecriptionKey(invalidPublisher, tag) - if err != nil { - t.Errorf("GetAccessKeyDecriptionKey gave back error") - } - - if access_key_decryption_key != "" { - t.Errorf("GetAccessKeyDecriptionKey should give back empty string for invalid input!") - } -} - -func TestGetEncryptedAccessKey_Success(t *testing.T) { - al := setupAccessLogic() - - lookupKey := "exampleLookupKey" - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - - act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - - encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookupKey) - if err != nil { - t.Errorf("There was an error while executing GetEncryptedAccessKey") - } - - expectedEncryptedKey := "abc013encryptedkey" - if encrypted_access_key.Reference().String() != expectedEncryptedKey { - t.Errorf("GetEncryptedAccessKey didn't give back the expected value!") - } -} - -func TestGetEncryptedAccessKey_Error(t *testing.T) { - al := setupAccessLogic() - - lookupKey := "exampleLookupKey" - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - - act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - empty_act_result, _ := al.getEncryptedAccessKey(*act, lookupKey) - if empty_act_result != nil { - t.Errorf("GetEncryptedAccessKey should give back nil for empty act root hash!") - } - - empty_lookup_result, _ := al.getEncryptedAccessKey(*act, "") - - if empty_lookup_result != nil { - t.Errorf("GetEncryptedAccessKey should give back nil for empty lookup key!") - } -} - -func TestGet_Success(t *testing.T) { - al := setupAccessLogic() - - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - tag := "exampleTag" - - ref, err := al.Get(act, encryptedRef, id0.PublicKey, tag) - if err != nil { - t.Errorf("There was an error while calling Get") - } - - expectedRef := "bzzNotEncrypted128long" - if ref != expectedRef { - t.Errorf("Get gave back wrong Swarm reference!") - } -} - -func TestGet_Error(t *testing.T) { - al := setupAccessLogic() - - //actRootHash := "0xabcexample" - id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - act, encrypredRef, err := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - if err != nil { - t.Errorf("Error initializing Act") - t.Errorf(err.Error()) - } - //encryptedRef := "bzzabcasab" - tag := "exampleTag" - - refOne, err := al.Get(act, encrypredRef, id0.PublicKey, tag) - if err != nil { - t.Errorf(err.Error()) - } - if refOne != "" { - t.Errorf("Get should give back empty string if ACT root hash not provided!") - } - - refTwo, _ := al.Get(act, swarm.EmptyAddress, id0.PublicKey, tag) - if refTwo != "" { - t.Errorf("Get should give back empty string if encrypted ref not provided!") - } - - refThree, _ := al.Get(act, encrypredRef, ecdsa.PublicKey{}, tag) - if refThree != "" { - t.Errorf("Get should give back empty string if publisher not provided!") - } - - refFour, _ := al.Get(act, encrypredRef, id0.PublicKey, "") - if refFour != "" { - t.Errorf("Get should give back empty string if tag was not provided!") - } -} - -func TestNewAccessLogic(t *testing.T) { - logic := setupAccessLogic() - - _, ok := logic.(*DefaultAccessLogic) - if !ok { - t.Errorf("NewAccessLogic: expected type *DefaultAccessLogic, got %T", logic) - } -} - -// func TestAddGrantee(t *testing.T) { +// lookupKey, err := al.getLookUpKey(id0.PublicKey, tag) +// if err != nil { +// t.Errorf("Could not fetch lookup key from publisher and tag") +// } + +// expectedLookupKey := "expectedLookupKey" +// if lookupKey != expectedLookupKey { +// fmt.Println(string(lookupKey)) +// t.Errorf("The lookup key that was returned is not correct!") +// } +// } + +// func TestGetLookUpKey_Error(t *testing.T) { // al := setupAccessLogic() -// // ref := "example_ref" + +// invalidPublisher := ecdsa.PublicKey{} +// tag := "exampleTag" + +// lookupKey, err := al.getLookUpKey(invalidPublisher, tag) + +// if err != nil { +// t.Errorf("There was an error while fetching lookup key") +// } + +// if lookupKey != "" { +// t.Errorf("Expected lookup key to be empty for invalid input") +// } +// } + +// func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { +// al := setupAccessLogic() + // id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// testGranteeList := NewGrantee() - -// // Add grantee keys to the testGranteeList -// id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// id3, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// testGranteeList.AddGrantees([]ecdsa.PublicKey{id1.PublicKey, id2.PublicKey, id3.PublicKey}) - -// // Initialize empty ACT -// actMock := MockAct.NewActMock() -// actMockRootHash := "exampleRootHash" - -// // Add each grantee to content using ActMock and validate the resulting ACT -// for i := 0; i < len(testGranteeList.GetGrantees()); i++ { -// lookupKey, _ := al.getLookUpKey(testGranteeList.GetGrantees()[i], "") -// encryptedAccessKey := "exampleEncryptedAccessKey" -// _, err := actMock.Add(actMockRootHash, []byte(lookupKey), []byte(encryptedAccessKey)) -// if err != nil { -// t.Fatalf("Failed to add grantee to content using ActMock: %v", err) -// } - -// // Validate the resulting ACT -// encryptedAccessKeyFromMock, err := actMock.Get(actMockRootHash, []byte(lookupKey)) -// if err != nil { -// t.Fatalf("Failed to retrieve encrypted access key from ActMock: %v", err) -// } -// encryptedAccessKeyFromMockBytes, _ := hex.DecodeString(encryptedAccessKeyFromMock) -// if string(encryptedAccessKeyFromMockBytes) != encryptedAccessKey { -// t.Errorf("Encrypted access key retrieved from ActMock doesn't match expected value") -// } -// } - -// al.Add_New_Grantee_To_Content(actMock, encryptedRef, id0.PublicKey, testGranteeList.GetGrantees()[i]) +// tag := "exampleTag" + +// access_key_decryption_key, err := al.getAccessKeyDecriptionKey(id0.PublicKey, tag) +// if err != nil { +// t.Errorf("GetAccessKeyDecriptionKey gave back error") +// } + +// expectedResult := "we-dont-know" +// if access_key_decryption_key != expectedResult { +// t.Errorf("The access key decryption key is not correct!") +// } +// } + +// func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { +// al := setupAccessLogic() + +// invalidPublisher := ecdsa.PublicKey{} +// tag := "exampleTag" + +// access_key_decryption_key, err := al.getAccessKeyDecriptionKey(invalidPublisher, tag) +// if err != nil { +// t.Errorf("GetAccessKeyDecriptionKey gave back error") +// } + +// if access_key_decryption_key != "" { +// t.Errorf("GetAccessKeyDecriptionKey should give back empty string for invalid input!") +// } // } + +// func TestGetEncryptedAccessKey_Success(t *testing.T) { +// al := setupAccessLogic() + +// lookupKey := "exampleLookupKey" +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + +// act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") + +// encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookupKey) +// if err != nil { +// t.Errorf("There was an error while executing GetEncryptedAccessKey") +// } + +// expectedEncryptedKey := "abc013encryptedkey" +// if encrypted_access_key.Reference().String() != expectedEncryptedKey { +// t.Errorf("GetEncryptedAccessKey didn't give back the expected value!") +// } +// } + +// func TestGetEncryptedAccessKey_Error(t *testing.T) { +// al := setupAccessLogic() + +// lookupKey := "exampleLookupKey" +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + +// act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") +// empty_act_result, _ := al.getEncryptedAccessKey(*act, lookupKey) +// if empty_act_result != nil { +// t.Errorf("GetEncryptedAccessKey should give back nil for empty act root hash!") +// } + +// empty_lookup_result, _ := al.getEncryptedAccessKey(*act, "") + +// if empty_lookup_result != nil { +// t.Errorf("GetEncryptedAccessKey should give back nil for empty lookup key!") +// } +// } + +// func TestGet_Success(t *testing.T) { +// al := setupAccessLogic() + +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") +// tag := "exampleTag" + +// ref, err := al.Get(act, encryptedRef, id0.PublicKey, tag) +// if err != nil { +// t.Errorf("There was an error while calling Get") +// } + +// expectedRef := "bzzNotEncrypted128long" +// if ref != expectedRef { +// t.Errorf("Get gave back wrong Swarm reference!") +// } +// } + +// func TestGet_Error(t *testing.T) { +// al := setupAccessLogic() + +// //actRootHash := "0xabcexample" +// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// act, encrypredRef, err := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") +// if err != nil { +// t.Errorf("Error initializing Act") +// t.Errorf(err.Error()) +// } +// //encryptedRef := "bzzabcasab" +// tag := "exampleTag" + +// refOne, err := al.Get(act, encrypredRef, id0.PublicKey, tag) +// if err != nil { +// t.Errorf(err.Error()) +// } +// if refOne != "" { +// t.Errorf("Get should give back empty string if ACT root hash not provided!") +// } + +// refTwo, _ := al.Get(act, swarm.EmptyAddress, id0.PublicKey, tag) +// if refTwo != "" { +// t.Errorf("Get should give back empty string if encrypted ref not provided!") +// } + +// refThree, _ := al.Get(act, encrypredRef, ecdsa.PublicKey{}, tag) +// if refThree != "" { +// t.Errorf("Get should give back empty string if publisher not provided!") +// } + +// refFour, _ := al.Get(act, encrypredRef, id0.PublicKey, "") +// if refFour != "" { +// t.Errorf("Get should give back empty string if tag was not provided!") +// } +// } + +// func TestNewAccessLogic(t *testing.T) { +// logic := setupAccessLogic() + +// _, ok := logic.(*DefaultAccessLogic) +// if !ok { +// t.Errorf("NewAccessLogic: expected type *DefaultAccessLogic, got %T", logic) +// } +// } + +// // func TestAddGrantee(t *testing.T) { +// // al := setupAccessLogic() +// // // ref := "example_ref" +// // id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// // testGranteeList := NewGrantee() + +// // // Add grantee keys to the testGranteeList +// // id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// // id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// // id3, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +// // testGranteeList.AddGrantees([]ecdsa.PublicKey{id1.PublicKey, id2.PublicKey, id3.PublicKey}) + +// // // Initialize empty ACT +// // actMock := MockAct.NewActMock() +// // actMockRootHash := "exampleRootHash" + +// // // Add each grantee to content using ActMock and validate the resulting ACT +// // for i := 0; i < len(testGranteeList.GetGrantees()); i++ { +// // lookupKey, _ := al.getLookUpKey(testGranteeList.GetGrantees()[i], "") +// // encryptedAccessKey := "exampleEncryptedAccessKey" +// // _, err := actMock.Add(actMockRootHash, []byte(lookupKey), []byte(encryptedAccessKey)) +// // if err != nil { +// // t.Fatalf("Failed to add grantee to content using ActMock: %v", err) +// // } + +// // // Validate the resulting ACT +// // encryptedAccessKeyFromMock, err := actMock.Get(actMockRootHash, []byte(lookupKey)) +// // if err != nil { +// // t.Fatalf("Failed to retrieve encrypted access key from ActMock: %v", err) +// // } +// // encryptedAccessKeyFromMockBytes, _ := hex.DecodeString(encryptedAccessKeyFromMock) +// // if string(encryptedAccessKeyFromMockBytes) != encryptedAccessKey { +// // t.Errorf("Encrypted access key retrieved from ActMock doesn't match expected value") +// // } +// // } + +// // al.Add_New_Grantee_To_Content(actMock, encryptedRef, id0.PublicKey, testGranteeList.GetGrantees()[i]) +// // } diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index 3dfee5bff73..1637234d9c2 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -1,18 +1,46 @@ package dynamicaccess +import ( + "crypto/ecdsa" + + "github.com/ethersphere/bee/pkg/swarm" +) + type Controller interface { + DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) + UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) } type defaultController struct { - histrory History - uploader Publish - grantee Grantee + history History + granteeManager GranteeManager + accessLogic AccessLogic +} + +func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) { + act, err := c.history.Lookup(timestamp) + if err != nil { + return swarm.EmptyAddress, err + } + addr, err := c.accessLogic.Get(act, enryptedRef, *publisher, tag) + return addr, err +} + +func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { + act, _ := c.history.Lookup(0) + if act == nil { + // new feed + act = NewDefaultAct() + act = c.granteeManager.Publish(act, *publisher, topic) + } + //FIXME: check if ACT is consistent with the grantee list + return c.accessLogic.EncryptRef(act, *publisher, ref) } -func NewController(histrory History, uploader Publish, grantee Grantee) Controller { +func NewController(history History, granteeManager GranteeManager, accessLogic AccessLogic) Controller { return &defaultController{ - histrory: histrory, - uploader: uploader, - grantee: grantee, + history: history, + granteeManager: granteeManager, + accessLogic: accessLogic, } } diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go new file mode 100644 index 00000000000..d043a18532c --- /dev/null +++ b/pkg/dynamicaccess/controller_test.go @@ -0,0 +1,99 @@ +package dynamicaccess_test + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "encoding/hex" + "testing" + "time" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/dynamicaccess/mock" + "github.com/ethersphere/bee/pkg/encryption" + "github.com/ethersphere/bee/pkg/swarm" + "golang.org/x/crypto/sha3" +) + +var hashFunc = sha3.NewLegacyKeccak256 + +func mockTestHistory(key, val []byte) dynamicaccess.History { + var ( + h = mock.NewHistory() + now = time.Now() + act = mock.NewActMock(nil, func(lookupKey []byte) []byte { + return val + }) + ) + // act.Add(key, val) + h.Insert(now.AddDate(-3, 0, 0).Unix(), act) + return h +} + +func TestDecrypt(t *testing.T) { + pk := getPrivateKey() + ak := encryption.Key([]byte("cica")) + + dh := dynamicaccess.NewDiffieHellman(pk) + aek, _ := dh.SharedSecret(&pk.PublicKey, "", []byte{1}) + e2 := encryption.New(aek, 0, uint32(0), hashFunc) + peak, _ := e2.Encrypt(ak) + + h := mockTestHistory(nil, peak) + al := setupAccessLogic(pk) + gm := dynamicaccess.NewGranteeManager(al) + c := dynamicaccess.NewController(h, gm, al) + eref, ref := prepareEncryptedChunkReference(ak) + // ech := al.EncryptRef(ch, "tag") + + ts := int64(0) + addr, err := c.DownloadHandler(ts, eref, &pk.PublicKey, "tag") + if err != nil { + t.Fatalf("DownloadHandler() returned an error: %v", err) + } + if !addr.Equal(ref) { + t.Fatalf("Decrypted chunk address: %s is not the expected: %s", addr, ref) + } +} + +func TestEncrypt(t *testing.T) { + pk := getPrivateKey() + ak := encryption.Key([]byte("cica")) + + dh := dynamicaccess.NewDiffieHellman(pk) + aek, _ := dh.SharedSecret(&pk.PublicKey, "", []byte{1}) + e2 := encryption.New(aek, 0, uint32(0), hashFunc) + peak, _ := e2.Encrypt(ak) + + h := mockTestHistory(nil, peak) + al := setupAccessLogic(pk) + gm := dynamicaccess.NewGranteeManager(al) + c := dynamicaccess.NewController(h, gm, al) + eref, ref := prepareEncryptedChunkReference(ak) + + key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + gm.Add("topic", []*ecdsa.PublicKey{&key1.PublicKey}) + + addr, _ := c.UploadHandler(ref, &pk.PublicKey, "topic") + if !addr.Equal(eref) { + t.Fatalf("Decrypted chunk address: %s is not the expected: %s", addr, eref) + } +} + +func prepareEncryptedChunkReference(ak []byte) (swarm.Address, swarm.Address) { + addr, _ := hex.DecodeString("f7b1a45b70ee91d3dbfd98a2a692387f24db7279a9c96c447409e9205cf265baef29bf6aa294264762e33f6a18318562c86383dd8bfea2cec14fae08a8039bf3") + e1 := encryption.New(ak, 0, uint32(0), hashFunc) + ech, err := e1.Encrypt(addr) + if err != nil { + return swarm.EmptyAddress, swarm.NewAddress(addr) + } + return swarm.NewAddress(ech), swarm.NewAddress(addr) +} + +func getPrivateKey() *ecdsa.PrivateKey { + data, _ := hex.DecodeString("c786dd84b61485de12146fd9c4c02d87e8fd95f0542765cb7fc3d2e428c0bcfa") + + privKey, _ := crypto.DecodeSecp256k1PrivateKey(data) + return privKey +} diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index bb39899e012..2a07d84b3ed 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -1,6 +1,8 @@ package dynamicaccess -import "crypto/ecdsa" +import ( + "crypto/ecdsa" +) type Grantee interface { //? ÁTBESZÉLNI @@ -9,18 +11,17 @@ type Grantee interface { // RevokeList(topic string, removeList []string, addList []string) (string, error) // RevokeGrantees(topic string, removeList []string) (string, error) - AddGrantees(addList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) - RemoveGrantees(removeList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) - GetGrantees() []ecdsa.PublicKey + AddGrantees(topic string, addList []*ecdsa.PublicKey) error + RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error + GetGrantees(topic string) []*ecdsa.PublicKey } type defaultGrantee struct { - topic string //lint:ignore U1000 Ignore unused struct field - grantees []ecdsa.PublicKey // Modified field name to start with an uppercase letter + grantees map[string][]*ecdsa.PublicKey // Modified field name to start with an uppercase letter } -func (g *defaultGrantee) GetGrantees() []ecdsa.PublicKey { - return g.grantees +func (g *defaultGrantee) GetGrantees(topic string) []*ecdsa.PublicKey { + return g.grantees[topic] } // func (g *defaultGrantee) Revoke(topic string) error { @@ -35,22 +36,22 @@ func (g *defaultGrantee) GetGrantees() []ecdsa.PublicKey { // return nil // } -func (g *defaultGrantee) AddGrantees(addList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) { - g.grantees = append(g.grantees, addList...) - return g.grantees, nil +func (g *defaultGrantee) AddGrantees(topic string, addList []*ecdsa.PublicKey) error { + g.grantees[topic] = append(g.grantees[topic], addList...) + return nil } -func (g *defaultGrantee) RemoveGrantees(removeList []ecdsa.PublicKey) ([]ecdsa.PublicKey, error) { +func (g *defaultGrantee) RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error { for _, remove := range removeList { - for i, grantee := range g.grantees { + for i, grantee := range g.grantees[topic] { if grantee == remove { - g.grantees = append(g.grantees[:i], g.grantees[i+1:]...) + g.grantees[topic] = append(g.grantees[topic][:i], g.grantees[topic][i+1:]...) } } } - return g.grantees, nil + return nil } func NewGrantee() Grantee { - return &defaultGrantee{} + return &defaultGrantee{grantees: make(map[string][]*ecdsa.PublicKey)} } diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go new file mode 100644 index 00000000000..9172a05db03 --- /dev/null +++ b/pkg/dynamicaccess/grantee_manager.go @@ -0,0 +1,41 @@ +package dynamicaccess + +import "crypto/ecdsa" + +type GranteeManager interface { + Get(topic string) []*ecdsa.PublicKey + Add(topic string, addList []*ecdsa.PublicKey) error + Publish(act Act, publisher ecdsa.PublicKey, topic string) Act + + // HandleGrantees(topic string, addList, removeList []*ecdsa.PublicKey) *Act + + // Load(grantee Grantee) + // Save() +} + +var _ GranteeManager = (*granteeManager)(nil) + +type granteeManager struct { + accessLogic AccessLogic + granteeList Grantee +} + +func NewGranteeManager(al AccessLogic) *granteeManager { + return &granteeManager{accessLogic: al, granteeList: NewGrantee()} +} + +func (gm *granteeManager) Get(topic string) []*ecdsa.PublicKey { + return gm.granteeList.GetGrantees(topic) +} + +func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { + return gm.granteeList.AddGrantees(topic, addList) +} + +func (gm *granteeManager) Publish(act Act, publisher ecdsa.PublicKey, topic string) Act { + gm.accessLogic.AddPublisher(act, publisher, "") + for _, grantee := range gm.granteeList.GetGrantees(topic) { + gm.accessLogic.Add_New_Grantee_To_Content(act, publisher, *grantee) + } + return act +} diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go new file mode 100644 index 00000000000..d8e806498e0 --- /dev/null +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -0,0 +1,41 @@ +package dynamicaccess_test + +import ( + "crypto/ecdsa" + "crypto/elliptic" + "crypto/rand" + "fmt" + "testing" + + "github.com/ethersphere/bee/pkg/dynamicaccess" +) + +func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.AccessLogic { + // privateKey, err := crypto.GenerateSecp256k1Key() + // if err != nil { + // errors.New("error creating private key") + // } + diffieHellman := dynamicaccess.NewDiffieHellman(privateKey) + al := dynamicaccess.NewAccessLogic(diffieHellman) + + return al +} + +func TestAdd(t *testing.T) { + act := dynamicaccess.NewDefaultAct() + m := dynamicaccess.NewGranteeManager(setupAccessLogic(getPrivateKey())) + pub, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + + id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + err := m.Add("topic", []*ecdsa.PublicKey{&id1.PublicKey}) + if err != nil { + t.Errorf("Add() returned an error") + } + err = m.Add("topic", []*ecdsa.PublicKey{&id2.PublicKey}) + if err != nil { + t.Errorf("Add() returned an error") + } + m.Publish(act, pub.PublicKey, "topic") + fmt.Println("") +} diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 5140216d2a2..2d795ab2eef 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -1,4 +1,4 @@ -package dynamicaccess +package dynamicaccess_test import ( "crypto/ecdsa" @@ -6,6 +6,8 @@ import ( "crypto/rand" "reflect" "testing" + + "github.com/ethersphere/bee/pkg/dynamicaccess" ) // func TestGranteeRevoke(t *testing.T) { @@ -31,16 +33,16 @@ import ( func TestGranteeAddGrantees(t *testing.T) { // Create a new Grantee - grantee := NewGrantee() + grantee := dynamicaccess.NewGrantee() // Generate some dummy ecdsa.PublicKey values key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) // Add the keys to the grantee - addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} - grantees, err := grantee.AddGrantees(addList) - + addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} + err := grantee.AddGrantees("topicName", addList) + grantees := grantee.GetGrantees("topicName") // Check for errors if err != nil { t.Fatalf("Expected no error, got %v", err) @@ -54,19 +56,20 @@ func TestGranteeAddGrantees(t *testing.T) { func TestRemoveGrantees(t *testing.T) { // Create a new Grantee - grantee := NewGrantee() + grantee := dynamicaccess.NewGrantee() // Generate some dummy ecdsa.PublicKey values key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) // Add the keys to the grantee - addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} - grantee.AddGrantees(addList) + addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} + grantee.AddGrantees("topicName", addList) // Remove one of the keys - removeList := []ecdsa.PublicKey{key1.PublicKey} - grantees, err := grantee.RemoveGrantees(removeList) + removeList := []*ecdsa.PublicKey{&key1.PublicKey} + err := grantee.RemoveGrantees("topicName", removeList) + grantees := grantee.GetGrantees("topicName") // Check for errors if err != nil { @@ -74,7 +77,7 @@ func TestRemoveGrantees(t *testing.T) { } // Check if the key was removed correctly - expectedGrantees := []ecdsa.PublicKey{key2.PublicKey} + expectedGrantees := []*ecdsa.PublicKey{&key2.PublicKey} if !reflect.DeepEqual(grantees, expectedGrantees) { t.Errorf("Expected grantees %v, got %v", expectedGrantees, grantees) } @@ -82,23 +85,21 @@ func TestRemoveGrantees(t *testing.T) { func TestGetGrantees(t *testing.T) { // Create a new Grantee - grantee := NewGrantee() + grantee := dynamicaccess.NewGrantee() // Generate some dummy ecdsa.PublicKey values key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) // Add the keys to the grantee - addList := []ecdsa.PublicKey{key1.PublicKey, key2.PublicKey} - grantee.AddGrantees(addList) + addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} + grantee.AddGrantees("topicName", addList) // Get the grantees - grantees := grantee.GetGrantees() + grantees := grantee.GetGrantees("topicName") // Check if the grantees were returned correctly if !reflect.DeepEqual(grantees, addList) { t.Errorf("Expected grantees %v, got %v", addList, grantees) } } - - diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index 2a24e65d862..ac333edc919 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -11,7 +11,7 @@ import ( ) func TestHistoryLookup(t *testing.T) { - h := pretareTestHistory() + h := prepareTestHistory() now := time.Now() tests := []struct { @@ -38,7 +38,7 @@ func TestHistoryLookup(t *testing.T) { } } -func pretareTestHistory() dynamicaccess.History { +func prepareTestHistory() dynamicaccess.History { var ( h = mock.NewHistory() now = time.Now() diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go index 1fd68caa399..a83fad36f8c 100644 --- a/pkg/dynamicaccess/mock/act.go +++ b/pkg/dynamicaccess/mock/act.go @@ -42,6 +42,9 @@ func (act *ActMock) Store(me manifest.Entry) { act.StoreFunc(me) } -func NewActMock() dynamicaccess.Act { - return &ActMock{} +func NewActMock(addFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act, getFunc func(lookupKey []byte) []byte) dynamicaccess.Act { + return &ActMock{ + AddFunc: addFunc, + GetFunc: getFunc, + } } From 0875a6db357910cbe7736a3a0649db3059578eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Tue, 19 Mar 2024 11:06:08 +0100 Subject: [PATCH 06/22] (refactor): from `Get` to `Lookup` to improve clarity and consistency. The changes have been made in the `accesslogic.go`, `act.go`, `act_test.go`, `history_test.go`, and `mock/act.go` files. (#13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/accesslogic.go | 2 +- pkg/dynamicaccess/act.go | 4 ++-- pkg/dynamicaccess/act_test.go | 8 ++++---- pkg/dynamicaccess/history_test.go | 2 +- pkg/dynamicaccess/mock/act.go | 18 +++++++++--------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index b3c01974f24..c4c6e7438a8 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -115,7 +115,7 @@ func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKe } func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { - return act.Get(lookup_key), nil + return act.Lookup(lookup_key), nil } func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) { diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index b63b1dafc6b..2c1765d1d54 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -9,7 +9,7 @@ import ( type Act interface { Add(lookupKey []byte, encryptedAccessKey []byte) Act - Get(lookupKey []byte) []byte + Lookup(lookupKey []byte) []byte Load(lookupKey []byte) manifest.Entry Store(me manifest.Entry) } @@ -25,7 +25,7 @@ func (act *defaultAct) Add(lookupKey []byte, encryptedAccessKey []byte) Act { return act } -func (act *defaultAct) Get(lookupKey []byte) []byte { +func (act *defaultAct) Lookup(lookupKey []byte) []byte { if key, ok := act.container[hex.EncodeToString(lookupKey)]; ok { bytes, err := hex.DecodeString(key) if err == nil { diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index 0e5ca853f0b..a46cc3b228c 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -17,7 +17,7 @@ import ( "github.com/ethersphere/bee/pkg/swarm" ) -func TestActAddGet(t *testing.T) { +func TestActAddLookup(t *testing.T) { act := dynamicaccess.NewDefaultAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() @@ -26,7 +26,7 @@ func TestActAddGet(t *testing.T) { t.Error("Add() should return an act") } - key := act.Get(lookupKey) + key := act.Lookup(lookupKey) if !bytes.Equal(key, encryptedAccesskey) { t.Errorf("Get() value is not the expected %s != %s", key, encryptedAccesskey) } @@ -73,7 +73,7 @@ func TestActWithManifest(t *testing.T) { actualAct := dynamicaccess.NewDefaultAct() actualAct.Store(actualMe) - actualEak := actualAct.Get(lookupKey) + actualEak := actualAct.Lookup(lookupKey) if !bytes.Equal(actualEak, encryptedAccesskey) { t.Errorf("actualAct.Store() value is not the expected %s != %s", actualEak, encryptedAccesskey) } @@ -89,7 +89,7 @@ func TestActStore(t *testing.T) { me := manifest.NewEntry(swarm.NewAddress(lookupKey), mp) act := dynamicaccess.NewDefaultAct() act.Store(me) - eak := act.Get(lookupKey) + eak := act.Lookup(lookupKey) if !bytes.Equal(eak, encryptedAccesskey) { t.Errorf("Store() value is not the expected %s != %s", eak, encryptedAccesskey) diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index ac333edc919..340b2adcb35 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -32,7 +32,7 @@ func TestHistoryLookup(t *testing.T) { for _, tt := range tests { t.Run("", func(t *testing.T) { actAt, _ := h.Lookup(tt.input) - output := actAt.Get([]byte("key1")) + output := actAt.Lookup([]byte("key1")) assert.Equal(t, output, hex.EncodeToString([]byte(tt.expected))) }) } diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go index a83fad36f8c..8bcfb8ff0b9 100644 --- a/pkg/dynamicaccess/mock/act.go +++ b/pkg/dynamicaccess/mock/act.go @@ -6,10 +6,10 @@ import ( ) type ActMock struct { - AddFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act - GetFunc func(lookupKey []byte) []byte - LoadFunc func(lookupKey []byte) manifest.Entry - StoreFunc func(me manifest.Entry) + AddFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act + LookupFunc func(lookupKey []byte) []byte + LoadFunc func(lookupKey []byte) manifest.Entry + StoreFunc func(me manifest.Entry) } var _ dynamicaccess.Act = (*ActMock)(nil) @@ -21,11 +21,11 @@ func (act *ActMock) Add(lookupKey []byte, encryptedAccessKey []byte) dynamicacce return act.AddFunc(lookupKey, encryptedAccessKey) } -func (act *ActMock) Get(lookupKey []byte) []byte { - if act.GetFunc == nil { +func (act *ActMock) Lookup(lookupKey []byte) []byte { + if act.LookupFunc == nil { return make([]byte, 0) } - return act.GetFunc(lookupKey) + return act.LookupFunc(lookupKey) } func (act *ActMock) Load(lookupKey []byte) manifest.Entry { @@ -44,7 +44,7 @@ func (act *ActMock) Store(me manifest.Entry) { func NewActMock(addFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act, getFunc func(lookupKey []byte) []byte) dynamicaccess.Act { return &ActMock{ - AddFunc: addFunc, - GetFunc: getFunc, + AddFunc: addFunc, + LookupFunc: getFunc, } } From aaf62536e2a23a31d498c286af9c0fca3c72270e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Tue, 19 Mar 2024 14:09:42 +0100 Subject: [PATCH 07/22] Act params rename doc (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (refactor): ACT interface params + add doc comments * Revert "(refactor): ACT interface params + add doc comments" This reverts commit ee8da04fe7468a4fa65bd390fa17f72f2e93d301. * (refactor): ACT interface params + add doc comments * (refactor): Add error to ACT interface methods --------- Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/accesslogic.go | 6 +++- pkg/dynamicaccess/act.go | 44 ++++++++++++++++++---------- pkg/dynamicaccess/act_test.go | 26 +++++++++------- pkg/dynamicaccess/controller_test.go | 4 +-- pkg/dynamicaccess/history_test.go | 2 +- pkg/dynamicaccess/mock/act.go | 37 +++++++++++++---------- 6 files changed, 73 insertions(+), 46 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index c4c6e7438a8..256dbd9f5ef 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -115,7 +115,11 @@ func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKe } func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { - return act.Lookup(lookup_key), nil + val, err := act.Lookup(lookup_key) + if err != nil { + return []byte{}, err + } + return val, nil } func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) { diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index 2c1765d1d54..07728ebca67 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -1,3 +1,7 @@ +// Copyright 2024 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 dynamicaccess import ( @@ -7,11 +11,19 @@ import ( "github.com/ethersphere/bee/pkg/swarm" ) +// Act represents an interface for accessing and manipulating data. type Act interface { - Add(lookupKey []byte, encryptedAccessKey []byte) Act - Lookup(lookupKey []byte) []byte - Load(lookupKey []byte) manifest.Entry - Store(me manifest.Entry) + // Add adds a key-value pair to the data store. + Add(key []byte, val []byte) error + + // Lookup retrieves the value associated with the given key from the data store. + Lookup(key []byte) ([]byte, error) + + // Load retrieves the manifest entry associated with the given key from the data store. + Load(key []byte) (manifest.Entry, error) + + // Store stores the given manifest entry in the data store. + Store(me manifest.Entry) error } var _ Act = (*defaultAct)(nil) @@ -20,32 +32,34 @@ type defaultAct struct { container map[string]string } -func (act *defaultAct) Add(lookupKey []byte, encryptedAccessKey []byte) Act { - act.container[hex.EncodeToString(lookupKey)] = hex.EncodeToString(encryptedAccessKey) - return act +func (act *defaultAct) Add(key []byte, val []byte) error { + act.container[hex.EncodeToString(key)] = hex.EncodeToString(val) + return nil } -func (act *defaultAct) Lookup(lookupKey []byte) []byte { - if key, ok := act.container[hex.EncodeToString(lookupKey)]; ok { +func (act *defaultAct) Lookup(key []byte) ([]byte, error) { + if key, ok := act.container[hex.EncodeToString(key)]; ok { bytes, err := hex.DecodeString(key) - if err == nil { - return bytes + if err != nil { + return nil, err } + return bytes, nil } - return make([]byte, 0) + return make([]byte, 0), nil } // to manifestEntry -func (act *defaultAct) Load(lookupKey []byte) manifest.Entry { - return manifest.NewEntry(swarm.NewAddress(lookupKey), act.container) +func (act *defaultAct) Load(key []byte) (manifest.Entry, error) { + return manifest.NewEntry(swarm.NewAddress(key), act.container), nil } // from manifestEntry -func (act *defaultAct) Store(me manifest.Entry) { +func (act *defaultAct) Store(me manifest.Entry) error { if act.container == nil { act.container = make(map[string]string) } act.container = me.Metadata() + return nil } func NewDefaultAct() Act { diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index a46cc3b228c..0bd807cbcc2 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -1,3 +1,7 @@ +// Copyright 2024 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 dynamicaccess_test import ( @@ -21,12 +25,12 @@ func TestActAddLookup(t *testing.T) { act := dynamicaccess.NewDefaultAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() - act2 := act.Add(lookupKey, encryptedAccesskey) - if act2 == nil { - t.Error("Add() should return an act") + err := act.Add(lookupKey, encryptedAccesskey) + if err != nil { + t.Error("Add() should not return an error") } - key := act.Lookup(lookupKey) + key, _ := act.Lookup(lookupKey) if !bytes.Equal(key, encryptedAccesskey) { t.Errorf("Get() value is not the expected %s != %s", key, encryptedAccesskey) } @@ -46,12 +50,12 @@ func TestActWithManifest(t *testing.T) { act := dynamicaccess.NewDefaultAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() - act2 := act.Add(lookupKey, encryptedAccesskey) - if act2 == nil { - t.Error("Add() should return an act") + err = act.Add(lookupKey, encryptedAccesskey) + if err != nil { + t.Error("Add() should not return an error") } - actManifEntry := act.Load(lookupKey) + actManifEntry, _ := act.Load(lookupKey) if actManifEntry == nil { t.Error("Load() should return a manifest.Entry") } @@ -73,7 +77,7 @@ func TestActWithManifest(t *testing.T) { actualAct := dynamicaccess.NewDefaultAct() actualAct.Store(actualMe) - actualEak := actualAct.Lookup(lookupKey) + actualEak, _ := actualAct.Lookup(lookupKey) if !bytes.Equal(actualEak, encryptedAccesskey) { t.Errorf("actualAct.Store() value is not the expected %s != %s", actualEak, encryptedAccesskey) } @@ -89,7 +93,7 @@ func TestActStore(t *testing.T) { me := manifest.NewEntry(swarm.NewAddress(lookupKey), mp) act := dynamicaccess.NewDefaultAct() act.Store(me) - eak := act.Lookup(lookupKey) + eak, _ := act.Lookup(lookupKey) if !bytes.Equal(eak, encryptedAccesskey) { t.Errorf("Store() value is not the expected %s != %s", eak, encryptedAccesskey) @@ -102,7 +106,7 @@ func TestActLoad(t *testing.T) { lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() act.Add(lookupKey, encryptedAccesskey) - me := act.Load(lookupKey) + me, _ := act.Load(lookupKey) eak := me.Metadata()[hex.EncodeToString(lookupKey)] diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index d043a18532c..d42df211fc9 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -22,8 +22,8 @@ func mockTestHistory(key, val []byte) dynamicaccess.History { var ( h = mock.NewHistory() now = time.Now() - act = mock.NewActMock(nil, func(lookupKey []byte) []byte { - return val + act = mock.NewActMock(nil, func(lookupKey []byte) ([]byte, error) { + return val, nil }) ) // act.Add(key, val) diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index 340b2adcb35..f7997d55fcd 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -32,7 +32,7 @@ func TestHistoryLookup(t *testing.T) { for _, tt := range tests { t.Run("", func(t *testing.T) { actAt, _ := h.Lookup(tt.input) - output := actAt.Lookup([]byte("key1")) + output, _ := actAt.Lookup([]byte("key1")) assert.Equal(t, output, hex.EncodeToString([]byte(tt.expected))) }) } diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go index 8bcfb8ff0b9..4f320c13dce 100644 --- a/pkg/dynamicaccess/mock/act.go +++ b/pkg/dynamicaccess/mock/act.go @@ -1,3 +1,7 @@ +// Copyright 2024 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 mock import ( @@ -6,43 +10,44 @@ import ( ) type ActMock struct { - AddFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act - LookupFunc func(lookupKey []byte) []byte - LoadFunc func(lookupKey []byte) manifest.Entry - StoreFunc func(me manifest.Entry) + AddFunc func(key []byte, val []byte) error + LookupFunc func(key []byte) ([]byte, error) + LoadFunc func(key []byte) (manifest.Entry, error) + StoreFunc func(me manifest.Entry) error } var _ dynamicaccess.Act = (*ActMock)(nil) -func (act *ActMock) Add(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act { +func (act *ActMock) Add(key []byte, val []byte) error { if act.AddFunc == nil { - return act + return nil } - return act.AddFunc(lookupKey, encryptedAccessKey) + return act.AddFunc(key, val) } -func (act *ActMock) Lookup(lookupKey []byte) []byte { +func (act *ActMock) Lookup(key []byte) ([]byte, error) { if act.LookupFunc == nil { - return make([]byte, 0) + return make([]byte, 0), nil } - return act.LookupFunc(lookupKey) + return act.LookupFunc(key) } -func (act *ActMock) Load(lookupKey []byte) manifest.Entry { +func (act *ActMock) Load(key []byte) (manifest.Entry, error) { if act.LoadFunc == nil { - return nil + return nil, nil } - return act.LoadFunc(lookupKey) + return act.LoadFunc(key) } -func (act *ActMock) Store(me manifest.Entry) { +func (act *ActMock) Store(me manifest.Entry) error { if act.StoreFunc == nil { - return + return nil } act.StoreFunc(me) + return nil } -func NewActMock(addFunc func(lookupKey []byte, encryptedAccessKey []byte) dynamicaccess.Act, getFunc func(lookupKey []byte) []byte) dynamicaccess.Act { +func NewActMock(addFunc func(key []byte, val []byte) error, getFunc func(key []byte) ([]byte, error)) dynamicaccess.Act { return &ActMock{ AddFunc: addFunc, LookupFunc: getFunc, From 240ec98a3f31ceb5b8692eadf98e64e457d76d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Ujv=C3=A1ri?= <58116288+bosi95@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:48:54 +0100 Subject: [PATCH 08/22] Move and refactor ACT diffieHellman to Session. Add Key and NewFromKeystore functions. (#16) --- pkg/dynamicaccess/accesslogic.go | 72 +++++------- pkg/dynamicaccess/controller_test.go | 12 +- pkg/dynamicaccess/diffieHellman.go | 31 ----- pkg/dynamicaccess/diffieHellman_test.go | 54 --------- pkg/dynamicaccess/grantee_manager_test.go | 4 +- pkg/dynamicaccess/mock/diffieHellman.go | 22 ---- pkg/dynamicaccess/mock/session.go | 41 +++++++ pkg/dynamicaccess/session.go | 49 ++++++++ pkg/dynamicaccess/session_test.go | 132 ++++++++++++++++++++++ 9 files changed, 261 insertions(+), 156 deletions(-) delete mode 100644 pkg/dynamicaccess/diffieHellman.go delete mode 100644 pkg/dynamicaccess/diffieHellman_test.go delete mode 100644 pkg/dynamicaccess/mock/diffieHellman.go create mode 100644 pkg/dynamicaccess/mock/session.go create mode 100644 pkg/dynamicaccess/session.go create mode 100644 pkg/dynamicaccess/session_test.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 256dbd9f5ef..8f46256cd85 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -14,8 +14,7 @@ type AccessLogic interface { Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) EncryptRef(act Act, publisherPubKey ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) //Add(act *Act, ref string, publisher ecdsa.PublicKey, tag string) (string, error) - getLookUpKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) - getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) + getKeys(publicKey ecdsa.PublicKey) ([][]byte, error) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) //createEncryptedAccessKey(ref string) Add_New_Grantee_To_Content(act Act, publisherPubKey, granteePubKey ecdsa.PublicKey) (Act, error) @@ -24,7 +23,7 @@ type AccessLogic interface { } type DefaultAccessLogic struct { - diffieHellman DiffieHellman + session Session //encryption encryption.Interface } @@ -32,8 +31,12 @@ type DefaultAccessLogic struct { func (al *DefaultAccessLogic) AddPublisher(act Act, publisher ecdsa.PublicKey, tag string) (Act, error) { access_key := encryption.GenerateRandomKey(encryption.KeyLength) - lookup_key, _ := al.getLookUpKey(publisher, "") - access_key_encryption_key, _ := al.getAccessKeyDecriptionKey(publisher, "") + keys, err := al.getKeys(publisher) + if err != nil { + return nil, err + } + lookup_key := keys[0] + access_key_encryption_key := keys[1] access_key_cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) encrypted_access_key, _ := access_key_cipher.Encrypt(access_key) @@ -62,8 +65,12 @@ func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act Act, publisherPubKe // --Encrypt access key for new Grantee-- // 2 Diffie-Hellman for the Grantee - lookup_key, _ := al.getLookUpKey(granteePubKey, "") - access_key_encryption_key, _ := al.getAccessKeyDecriptionKey(granteePubKey, "") + keys, err := al.getKeys(granteePubKey) + if err != nil { + return nil, err + } + lookup_key := keys[0] + access_key_encryption_key := keys[1] // Encrypt the access key for the new Grantee cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) @@ -76,8 +83,12 @@ func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act Act, publisherPubKe } func (al *DefaultAccessLogic) getAccessKey(act Act, publisherPubKey ecdsa.PublicKey) []byte { - publisher_lookup_key, _ := al.getLookUpKey(publisherPubKey, "") - publisher_ak_decryption_key, _ := al.getAccessKeyDecriptionKey(publisherPubKey, "") + keys, err := al.getKeys(publisherPubKey) + if err != nil { + return nil + } + publisher_lookup_key := keys[0] + publisher_ak_decryption_key := keys[1] access_key_decryption_cipher := encryption.New(encryption.Key(publisher_ak_decryption_key), 0, uint32(0), hashFunc) encrypted_ak, _ := al.getEncryptedAccessKey(act, publisher_lookup_key) @@ -93,25 +104,16 @@ func (al *DefaultAccessLogic) getAccessKey(act Act, publisherPubKey ecdsa.Public // func (al *DefaultAccessLogic) CreateAccessKey(reference string) { // } -func (al *DefaultAccessLogic) getLookUpKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) { +func (al *DefaultAccessLogic) getKeys(publicKey ecdsa.PublicKey) ([][]byte, error) { + // Generate lookup key and access key decryption + oneByteArray := []byte{1} zeroByteArray := []byte{0} - // Generate lookup key using Diffie Hellman - lookup_key, err := al.diffieHellman.SharedSecret(&publisher, tag, zeroByteArray) - if err != nil { - return []byte{}, err - } - return lookup_key, nil - -} -func (al *DefaultAccessLogic) getAccessKeyDecriptionKey(publisher ecdsa.PublicKey, tag string) ([]byte, error) { - oneByteArray := []byte{1} - // Generate access key decryption key using Diffie Hellman - access_key_decryption_key, err := al.diffieHellman.SharedSecret(&publisher, tag, oneByteArray) + keys, err := al.session.Key(&publicKey, [][]byte{zeroByteArray, oneByteArray}) if err != nil { - return []byte{}, err + return [][]byte{}, err } - return access_key_decryption_key, nil + return keys, nil } func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { @@ -124,14 +126,12 @@ func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) { - lookup_key, err := al.getLookUpKey(publisher, tag) - if err != nil { - return swarm.EmptyAddress, err - } - access_key_decryption_key, err := al.getAccessKeyDecriptionKey(publisher, tag) + keys, err := al.getKeys(publisher) if err != nil { return swarm.EmptyAddress, err } + lookup_key := keys[0] + access_key_decryption_key := keys[1] // Lookup encrypted access key from the ACT manifest @@ -157,18 +157,8 @@ func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher return swarm.NewAddress(ref), nil } -func NewAccessLogic(diffieHellman DiffieHellman) AccessLogic { +func NewAccessLogic(s Session) AccessLogic { return &DefaultAccessLogic{ - diffieHellman: diffieHellman, + session: s, } } - -// ------- -// act: &mock.ContainerMock{ -// AddFunc: func(ref string, publisher string, tag string) error { -// return nil -// }, -// GetFunc: func(ref string, publisher string, tag string) (string, error) { -// return "", nil -// }, -// }, diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index d42df211fc9..30e17cde542 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -35,9 +35,9 @@ func TestDecrypt(t *testing.T) { pk := getPrivateKey() ak := encryption.Key([]byte("cica")) - dh := dynamicaccess.NewDiffieHellman(pk) - aek, _ := dh.SharedSecret(&pk.PublicKey, "", []byte{1}) - e2 := encryption.New(aek, 0, uint32(0), hashFunc) + si := dynamicaccess.NewDefaultSession(pk) + aek, _ := si.Key(&pk.PublicKey, [][]byte{{1}}) + e2 := encryption.New(aek[0], 0, uint32(0), hashFunc) peak, _ := e2.Encrypt(ak) h := mockTestHistory(nil, peak) @@ -61,9 +61,9 @@ func TestEncrypt(t *testing.T) { pk := getPrivateKey() ak := encryption.Key([]byte("cica")) - dh := dynamicaccess.NewDiffieHellman(pk) - aek, _ := dh.SharedSecret(&pk.PublicKey, "", []byte{1}) - e2 := encryption.New(aek, 0, uint32(0), hashFunc) + si := dynamicaccess.NewDefaultSession(pk) + aek, _ := si.Key(&pk.PublicKey, [][]byte{{1}}) + e2 := encryption.New(aek[0], 0, uint32(0), hashFunc) peak, _ := e2.Encrypt(ak) h := mockTestHistory(nil, peak) diff --git a/pkg/dynamicaccess/diffieHellman.go b/pkg/dynamicaccess/diffieHellman.go deleted file mode 100644 index a9ff7f7f8cd..00000000000 --- a/pkg/dynamicaccess/diffieHellman.go +++ /dev/null @@ -1,31 +0,0 @@ -package dynamicaccess - -import ( - "crypto/ecdsa" - "errors" - - "github.com/ethersphere/bee/pkg/crypto" -) - -type DiffieHellman interface { - SharedSecret(publicKey *ecdsa.PublicKey, tag string, moment []byte) ([]byte, error) // tag- topic? -} - -var _ DiffieHellman = (*defaultDiffieHellman)(nil) - -type defaultDiffieHellman struct { - key *ecdsa.PrivateKey -} - -func (dh *defaultDiffieHellman) SharedSecret(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) { - x, _ := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, dh.key.D.Bytes()) - if x == nil { - return nil, errors.New("shared secret is point at infinity") - } - return crypto.LegacyKeccak256(append(x.Bytes(), salt...)) -} - -func NewDiffieHellman(key *ecdsa.PrivateKey) DiffieHellman { - return &defaultDiffieHellman{key: key} - -} diff --git a/pkg/dynamicaccess/diffieHellman_test.go b/pkg/dynamicaccess/diffieHellman_test.go deleted file mode 100644 index 5c80592b3ec..00000000000 --- a/pkg/dynamicaccess/diffieHellman_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package dynamicaccess_test - -import ( - "bytes" - "crypto/rand" - "encoding/hex" - "io" - "testing" - - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/dynamicaccess" -) - -func TestSharedSecret(t *testing.T) { - pk, _ := crypto.GenerateSecp256k1Key() - _, err := dynamicaccess.NewDiffieHellman(pk).SharedSecret(&pk.PublicKey, "", nil) - if err != nil { - t.Errorf("Error generating shared secret: %v", err) - } -} - -func TestECDHCorrect(t *testing.T) { - t.Parallel() - - key1, err := crypto.GenerateSecp256k1Key() - if err != nil { - t.Fatal(err) - } - dh1 := dynamicaccess.NewDiffieHellman(key1) - - key2, err := crypto.GenerateSecp256k1Key() - if err != nil { - t.Fatal(err) - } - dh2 := dynamicaccess.NewDiffieHellman(key2) - - moment := make([]byte, 1) - if _, err := io.ReadFull(rand.Reader, moment); err != nil { - t.Fatal(err) - } - - shared1, err := dh1.SharedSecret(&key2.PublicKey, "", moment) - if err != nil { - t.Fatal(err) - } - shared2, err := dh2.SharedSecret(&key1.PublicKey, "", moment) - if err != nil { - t.Fatal(err) - } - - if !bytes.Equal(shared1, shared2) { - t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(shared1), hex.EncodeToString(shared2)) - } -} diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index d8e806498e0..4b55400f465 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -15,8 +15,8 @@ func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.AccessLogic { // if err != nil { // errors.New("error creating private key") // } - diffieHellman := dynamicaccess.NewDiffieHellman(privateKey) - al := dynamicaccess.NewAccessLogic(diffieHellman) + si := dynamicaccess.NewDefaultSession(privateKey) + al := dynamicaccess.NewAccessLogic(si) return al } diff --git a/pkg/dynamicaccess/mock/diffieHellman.go b/pkg/dynamicaccess/mock/diffieHellman.go deleted file mode 100644 index 91601026893..00000000000 --- a/pkg/dynamicaccess/mock/diffieHellman.go +++ /dev/null @@ -1,22 +0,0 @@ -package mock - -import ( - "crypto/ecdsa" -) - -type DiffieHellmanMock struct { - SharedSecretFunc func(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) - key *ecdsa.PrivateKey -} - -func (dhm *DiffieHellmanMock) SharedSecret(publicKey *ecdsa.PublicKey, tag string, salt []byte) ([]byte, error) { - if dhm.SharedSecretFunc == nil { - return nil, nil - } - return dhm.SharedSecretFunc(publicKey, tag, salt) - -} - -func NewDiffieHellmanMock(key *ecdsa.PrivateKey) *DiffieHellmanMock { - return &DiffieHellmanMock{key: key} -} diff --git a/pkg/dynamicaccess/mock/session.go b/pkg/dynamicaccess/mock/session.go new file mode 100644 index 00000000000..ba3e3f8c8f2 --- /dev/null +++ b/pkg/dynamicaccess/mock/session.go @@ -0,0 +1,41 @@ +package mock + +import ( + "crypto/ecdsa" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/keystore" +) + +type SessionMock struct { + KeyFunc func(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) + key *ecdsa.PrivateKey +} + +func (s *SessionMock) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { + if s.KeyFunc == nil { + return nil, nil + } + return s.KeyFunc(publicKey, nonces) + +} + +func NewSessionMock(key *ecdsa.PrivateKey) *SessionMock { + return &SessionMock{key: key} +} + +func NewFromKeystore( + ks keystore.Service, + tag, + password string, + keyFunc func(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error), +) *SessionMock { + key, created, err := ks.Key(tag, password, crypto.EDGSecp256_K1) + if !created || err != nil { + return nil + } + return &SessionMock{ + key: key, + KeyFunc: keyFunc, + } +} diff --git a/pkg/dynamicaccess/session.go b/pkg/dynamicaccess/session.go new file mode 100644 index 00000000000..95a3c07e87b --- /dev/null +++ b/pkg/dynamicaccess/session.go @@ -0,0 +1,49 @@ +package dynamicaccess + +import ( + "crypto/ecdsa" + "errors" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/keystore" +) + +// Session represents an interface for a Diffie-Helmann key derivation +type Session interface { + // Key returns a derived key for each nonce + Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) +} + +var _ Session = (*session)(nil) + +type session struct { + key *ecdsa.PrivateKey +} + +func (s *session) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { + x, _ := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes()) + if x == nil { + return nil, errors.New("shared secret is point at infinity") + } + + keys := make([][]byte, len(nonces)) + for _, nonce := range nonces { + key, err := crypto.LegacyKeccak256(append(x.Bytes(), nonce...)) + if err != nil { + return nil, err + } + keys = append(keys, key) + } + + return keys, nil +} + +func NewDefaultSession(key *ecdsa.PrivateKey) Session { + return &session{ + key: key, + } +} + +func NewFromKeystore(ks keystore.Service, tag, password string) Session { + return nil +} diff --git a/pkg/dynamicaccess/session_test.go b/pkg/dynamicaccess/session_test.go new file mode 100644 index 00000000000..0cfee7691da --- /dev/null +++ b/pkg/dynamicaccess/session_test.go @@ -0,0 +1,132 @@ +package dynamicaccess_test + +import ( + "bytes" + "crypto/ecdsa" + "crypto/rand" + "encoding/hex" + "io" + "testing" + + "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/dynamicaccess/mock" + memkeystore "github.com/ethersphere/bee/pkg/keystore/mem" +) + +func mockKeyFunc(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { + return [][]byte{{1}}, nil +} + +func TestSessionNewDefaultSession(t *testing.T) { + pk, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatalf("Error generating private key: %v", err) + } + si := dynamicaccess.NewDefaultSession(pk) + if si == nil { + t.Fatal("Session instance is nil") + } +} + +func TestSessionNewFromKeystore(t *testing.T) { + ks := memkeystore.New() + si := mock.NewFromKeystore(ks, "tag", "password", mockKeyFunc) + if si == nil { + t.Fatal("Session instance is nil") + } +} + +func TestSessionKey(t *testing.T) { + t.Parallel() + + key1, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + si1 := dynamicaccess.NewDefaultSession(key1) + + key2, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + si2 := dynamicaccess.NewDefaultSession(key2) + + nonces := make([][]byte, 1) + if _, err := io.ReadFull(rand.Reader, nonces[0]); err != nil { + t.Fatal(err) + } + + keys1, err := si1.Key(&key2.PublicKey, nonces) + if err != nil { + t.Fatal(err) + } + keys2, err := si2.Key(&key1.PublicKey, nonces) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(keys1[0], keys2[0]) { + t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) + } +} + +func TestSessionKeyFromKeystore(t *testing.T) { + t.Parallel() + + ks := memkeystore.New() + tag1 := "tag1" + tag2 := "tag2" + password1 := "password1" + password2 := "password2" + + si1 := mock.NewFromKeystore(ks, tag1, password1, mockKeyFunc) + exists, err := ks.Exists(tag1) + if err != nil { + t.Fatal(err) + } + if !exists { + t.Fatal("Key1 should exist") + } + key1, created, err := ks.Key(tag1, password1, crypto.EDGSecp256_K1) + if err != nil { + t.Fatal(err) + } + if created { + t.Fatal("Key1 should not be created") + } + + si2 := mock.NewFromKeystore(ks, tag2, password2, mockKeyFunc) + exists, err = ks.Exists(tag2) + if err != nil { + t.Fatal(err) + } + if !exists { + t.Fatal("Key2 should exist") + } + key2, created, err := ks.Key(tag2, password2, crypto.EDGSecp256_K1) + if err != nil { + t.Fatal(err) + } + if created { + t.Fatal("Key2 should not be created") + } + + nonces := make([][]byte, 1) + if _, err := io.ReadFull(rand.Reader, nonces[0]); err != nil { + t.Fatal(err) + } + + keys1, err := si1.Key(&key2.PublicKey, nonces) + if err != nil { + t.Fatal(err) + } + keys2, err := si2.Key(&key1.PublicKey, nonces) + if err != nil { + t.Fatal(err) + } + + if !bytes.Equal(keys1[0], keys2[0]) { + t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) + } +} From 021458979382b827e2004cad18ad25508581793a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Tue, 19 Mar 2024 15:50:12 +0100 Subject: [PATCH 09/22] Act swarm address (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (refactor): ACT interface params + add doc comments * Revert "(refactor): ACT interface params + add doc comments" This reverts commit ee8da04fe7468a4fa65bd390fa17f72f2e93d301. * (refactor): ACT interface params + add doc comments * (refactor): Add error to ACT interface methods * Add in-memory storage and implement Store and Load methods * Move and refactor ACT diffieHellman to Session. Add Key and NewFromKeystore functions. --------- Co-authored-by: Ferenc Sárai Co-authored-by: Bálint Ujvári --- pkg/dynamicaccess/act.go | 68 ++++++++++++++++++++++------ pkg/dynamicaccess/act_test.go | 83 +++-------------------------------- pkg/dynamicaccess/mock/act.go | 19 ++++---- 3 files changed, 70 insertions(+), 100 deletions(-) diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index 07728ebca67..c8cbd9fa663 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -5,12 +5,44 @@ package dynamicaccess import ( + "crypto/rand" "encoding/hex" + "fmt" + "sync" "github.com/ethersphere/bee/pkg/manifest" "github.com/ethersphere/bee/pkg/swarm" ) +var lock = &sync.Mutex{} + +type single struct { + memoryMock map[string]manifest.Entry +} + +var singleInMemorySwarm *single + +func getInMemorySwarm() *single { + if singleInMemorySwarm == nil { + lock.Lock() + defer lock.Unlock() + if singleInMemorySwarm == nil { + singleInMemorySwarm = &single{ + memoryMock: make(map[string]manifest.Entry)} + } + } + return singleInMemorySwarm +} + +func getMemory() map[string]manifest.Entry { + ch := make(chan *single) + go func() { + ch <- getInMemorySwarm() + }() + mem := <-ch + return mem.memoryMock +} + // Act represents an interface for accessing and manipulating data. type Act interface { // Add adds a key-value pair to the data store. @@ -19,15 +51,16 @@ type Act interface { // Lookup retrieves the value associated with the given key from the data store. Lookup(key []byte) ([]byte, error) - // Load retrieves the manifest entry associated with the given key from the data store. - Load(key []byte) (manifest.Entry, error) + // Load loads the data store from the given address. + Load(addr swarm.Address) error - // Store stores the given manifest entry in the data store. - Store(me manifest.Entry) error + // Store stores the current state of the data store and returns the address of the ACT. + Store() (swarm.Address, error) } var _ Act = (*defaultAct)(nil) +// defaultAct is a simple implementation of the Act interface, with in memory storage. type defaultAct struct { container map[string]string } @@ -48,20 +81,29 @@ func (act *defaultAct) Lookup(key []byte) ([]byte, error) { return make([]byte, 0), nil } -// to manifestEntry -func (act *defaultAct) Load(key []byte) (manifest.Entry, error) { - return manifest.NewEntry(swarm.NewAddress(key), act.container), nil -} - -// from manifestEntry -func (act *defaultAct) Store(me manifest.Entry) error { - if act.container == nil { - act.container = make(map[string]string) +func (act *defaultAct) Load(addr swarm.Address) error { + memory := getMemory() + me := memory[addr.String()] + if me == nil { + return fmt.Errorf("ACT not found at address: %s", addr.String()) } act.container = me.Metadata() return nil } +func (act *defaultAct) Store() (swarm.Address, error) { + // Generate a random swarm.Address + b := make([]byte, 32) + if _, err := rand.Read(b); err != nil { + return swarm.EmptyAddress, fmt.Errorf("failed to generate random address: %w", err) + } + swarm_ref := swarm.NewAddress(b) + mem := getMemory() + mem[swarm_ref.String()] = manifest.NewEntry(swarm_ref, act.container) + + return swarm_ref, nil +} + func NewDefaultAct() Act { return &defaultAct{ container: make(map[string]string), diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index 0bd807cbcc2..5a980977f9b 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -6,18 +6,10 @@ package dynamicaccess_test import ( "bytes" - "context" "encoding/hex" "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/storage" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" "github.com/ethersphere/bee/pkg/swarm" ) @@ -36,88 +28,25 @@ func TestActAddLookup(t *testing.T) { } } -func TestActWithManifest(t *testing.T) { - - storer := mockstorer.New() - encrypt := false - ctx := context.Background() - ls := loadsave.New(storer.ChunkStore(), storer.Cache(), pipelineFactory(storer.Cache(), false, 0)) - rootManifest, err := manifest.NewDefaultManifest(ls, encrypt) - if err != nil { - t.Error("DefaultManifest should not return an error") - } +func TestActStoreLoad(t *testing.T) { act := dynamicaccess.NewDefaultAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() - err = act.Add(lookupKey, encryptedAccesskey) + err := act.Add(lookupKey, encryptedAccesskey) if err != nil { t.Error("Add() should not return an error") } - actManifEntry, _ := act.Load(lookupKey) - if actManifEntry == nil { - t.Error("Load() should return a manifest.Entry") - } - - err = rootManifest.Add(ctx, hex.EncodeToString(lookupKey), actManifEntry) - if err != nil { - t.Error("rootManifest.Add() should not return an error") - } - - _, err = rootManifest.Store(ctx) + swarm_ref, err := act.Store() if err != nil { - t.Error("rootManifest.Store() should not return an error") - } - - actualMe, err := rootManifest.Lookup(ctx, hex.EncodeToString(lookupKey)) - if err != nil { - t.Error("rootManifest.Lookup() should not return an error") + t.Error("Store() should not return an error") } actualAct := dynamicaccess.NewDefaultAct() - actualAct.Store(actualMe) + actualAct.Load(swarm_ref) actualEak, _ := actualAct.Lookup(lookupKey) if !bytes.Equal(actualEak, encryptedAccesskey) { - t.Errorf("actualAct.Store() value is not the expected %s != %s", actualEak, encryptedAccesskey) - } -} - -func TestActStore(t *testing.T) { - mp := make(map[string]string) - - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - mp[hex.EncodeToString(lookupKey)] = hex.EncodeToString(encryptedAccesskey) - - me := manifest.NewEntry(swarm.NewAddress(lookupKey), mp) - act := dynamicaccess.NewDefaultAct() - act.Store(me) - eak, _ := act.Lookup(lookupKey) - - if !bytes.Equal(eak, encryptedAccesskey) { - t.Errorf("Store() value is not the expected %s != %s", eak, encryptedAccesskey) - } - -} - -func TestActLoad(t *testing.T) { - act := dynamicaccess.NewDefaultAct() - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - act.Add(lookupKey, encryptedAccesskey) - me, _ := act.Load(lookupKey) - - eak := me.Metadata()[hex.EncodeToString(lookupKey)] - - if eak != hex.EncodeToString(encryptedAccesskey) { - t.Errorf("Load() value is not the expected %s != %s", eak, encryptedAccesskey) - } - -} - -func pipelineFactory(s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { - return func() pipeline.Interface { - return builder.NewPipelineBuilder(context.Background(), s, encrypt, rLevel) + t.Errorf("actualAct.Load() value is not the expected %s != %s", hex.EncodeToString(actualEak), hex.EncodeToString(encryptedAccesskey)) } } diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go index 4f320c13dce..a915f38f123 100644 --- a/pkg/dynamicaccess/mock/act.go +++ b/pkg/dynamicaccess/mock/act.go @@ -6,14 +6,14 @@ package mock import ( "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/swarm" ) type ActMock struct { AddFunc func(key []byte, val []byte) error LookupFunc func(key []byte) ([]byte, error) - LoadFunc func(key []byte) (manifest.Entry, error) - StoreFunc func(me manifest.Entry) error + LoadFunc func(addr swarm.Address) error + StoreFunc func() (swarm.Address, error) } var _ dynamicaccess.Act = (*ActMock)(nil) @@ -32,19 +32,18 @@ func (act *ActMock) Lookup(key []byte) ([]byte, error) { return act.LookupFunc(key) } -func (act *ActMock) Load(key []byte) (manifest.Entry, error) { +func (act *ActMock) Load(addr swarm.Address) error { if act.LoadFunc == nil { - return nil, nil + return nil } - return act.LoadFunc(key) + return act.LoadFunc(addr) } -func (act *ActMock) Store(me manifest.Entry) error { +func (act *ActMock) Store() (swarm.Address, error) { if act.StoreFunc == nil { - return nil + return swarm.EmptyAddress, nil } - act.StoreFunc(me) - return nil + return act.StoreFunc() } func NewActMock(addFunc func(key []byte, val []byte) error, getFunc func(key []byte) ([]byte, error)) dynamicaccess.Act { From 5c7d25458e5597433c902924e96aa2f3f1556932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Tue, 19 Mar 2024 17:00:52 +0100 Subject: [PATCH 10/22] (rename): defaultAct to inMemoryAct (#17) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (refactor): ACT interface params + add doc comments * Revert "(refactor): ACT interface params + add doc comments" This reverts commit ee8da04fe7468a4fa65bd390fa17f72f2e93d301. * (refactor): ACT interface params + add doc comments * (refactor): Add error to ACT interface methods * Add in-memory storage and implement Store and Load methods * *refactor) Rename defaultAct to inMemroryAct --------- Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/act.go | 18 +++++++++--------- pkg/dynamicaccess/act_test.go | 6 +++--- pkg/dynamicaccess/controller.go | 2 +- pkg/dynamicaccess/grantee_manager_test.go | 2 +- pkg/dynamicaccess/history_test.go | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index c8cbd9fa663..1153f2fc868 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -58,19 +58,19 @@ type Act interface { Store() (swarm.Address, error) } -var _ Act = (*defaultAct)(nil) +var _ Act = (*inMemoryAct)(nil) -// defaultAct is a simple implementation of the Act interface, with in memory storage. -type defaultAct struct { +// inMemoryAct is a simple implementation of the Act interface, with in memory storage. +type inMemoryAct struct { container map[string]string } -func (act *defaultAct) Add(key []byte, val []byte) error { +func (act *inMemoryAct) Add(key []byte, val []byte) error { act.container[hex.EncodeToString(key)] = hex.EncodeToString(val) return nil } -func (act *defaultAct) Lookup(key []byte) ([]byte, error) { +func (act *inMemoryAct) Lookup(key []byte) ([]byte, error) { if key, ok := act.container[hex.EncodeToString(key)]; ok { bytes, err := hex.DecodeString(key) if err != nil { @@ -81,7 +81,7 @@ func (act *defaultAct) Lookup(key []byte) ([]byte, error) { return make([]byte, 0), nil } -func (act *defaultAct) Load(addr swarm.Address) error { +func (act *inMemoryAct) Load(addr swarm.Address) error { memory := getMemory() me := memory[addr.String()] if me == nil { @@ -91,7 +91,7 @@ func (act *defaultAct) Load(addr swarm.Address) error { return nil } -func (act *defaultAct) Store() (swarm.Address, error) { +func (act *inMemoryAct) Store() (swarm.Address, error) { // Generate a random swarm.Address b := make([]byte, 32) if _, err := rand.Read(b); err != nil { @@ -104,8 +104,8 @@ func (act *defaultAct) Store() (swarm.Address, error) { return swarm_ref, nil } -func NewDefaultAct() Act { - return &defaultAct{ +func NewInMemoryAct() Act { + return &inMemoryAct{ container: make(map[string]string), } } diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index 5a980977f9b..3480077102a 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -14,7 +14,7 @@ import ( ) func TestActAddLookup(t *testing.T) { - act := dynamicaccess.NewDefaultAct() + act := dynamicaccess.NewInMemoryAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() err := act.Add(lookupKey, encryptedAccesskey) @@ -30,7 +30,7 @@ func TestActAddLookup(t *testing.T) { func TestActStoreLoad(t *testing.T) { - act := dynamicaccess.NewDefaultAct() + act := dynamicaccess.NewInMemoryAct() lookupKey := swarm.RandAddress(t).Bytes() encryptedAccesskey := swarm.RandAddress(t).Bytes() err := act.Add(lookupKey, encryptedAccesskey) @@ -43,7 +43,7 @@ func TestActStoreLoad(t *testing.T) { t.Error("Store() should not return an error") } - actualAct := dynamicaccess.NewDefaultAct() + actualAct := dynamicaccess.NewInMemoryAct() actualAct.Load(swarm_ref) actualEak, _ := actualAct.Lookup(lookupKey) if !bytes.Equal(actualEak, encryptedAccesskey) { diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index 1637234d9c2..6267a878279 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -30,7 +30,7 @@ func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.Pu act, _ := c.history.Lookup(0) if act == nil { // new feed - act = NewDefaultAct() + act = NewInMemoryAct() act = c.granteeManager.Publish(act, *publisher, topic) } //FIXME: check if ACT is consistent with the grantee list diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index 4b55400f465..bc90ef504ae 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -22,7 +22,7 @@ func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.AccessLogic { } func TestAdd(t *testing.T) { - act := dynamicaccess.NewDefaultAct() + act := dynamicaccess.NewInMemoryAct() m := dynamicaccess.NewGranteeManager(setupAccessLogic(getPrivateKey())) pub, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index f7997d55fcd..a58aa44ecaa 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -42,9 +42,9 @@ func prepareTestHistory() dynamicaccess.History { var ( h = mock.NewHistory() now = time.Now() - act1 = dynamicaccess.NewDefaultAct() - act2 = dynamicaccess.NewDefaultAct() - act3 = dynamicaccess.NewDefaultAct() + act1 = dynamicaccess.NewInMemoryAct() + act2 = dynamicaccess.NewInMemoryAct() + act3 = dynamicaccess.NewInMemoryAct() ) act1.Add([]byte("key1"), []byte("value1")) act2.Add([]byte("key1"), []byte("value2")) From 2c1b7bbbbc56acf85ed50bd1b094014832077c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Wed, 20 Mar 2024 10:12:43 +0100 Subject: [PATCH 11/22] (refactor): Update controller_test.go to use NewInMemoryAct, modify Session.Key to return correct dimensional byte slice (#18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (refactor): Update controller_test.go to use NewInMemoryAct, modify Session.Key to return two-dimensional byte slice * (refactor:) Refactor session Key function to use append instead of index-based assignment --------- Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/controller_test.go | 18 ++++++++---------- pkg/dynamicaccess/session.go | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index 30e17cde542..531470eceee 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -22,11 +22,9 @@ func mockTestHistory(key, val []byte) dynamicaccess.History { var ( h = mock.NewHistory() now = time.Now() - act = mock.NewActMock(nil, func(lookupKey []byte) ([]byte, error) { - return val, nil - }) + act = dynamicaccess.NewInMemoryAct() ) - // act.Add(key, val) + act.Add(key, val) h.Insert(now.AddDate(-3, 0, 0).Unix(), act) return h } @@ -36,11 +34,11 @@ func TestDecrypt(t *testing.T) { ak := encryption.Key([]byte("cica")) si := dynamicaccess.NewDefaultSession(pk) - aek, _ := si.Key(&pk.PublicKey, [][]byte{{1}}) - e2 := encryption.New(aek[0], 0, uint32(0), hashFunc) + aek, _ := si.Key(&pk.PublicKey, [][]byte{{0}, {1}}) + e2 := encryption.New(aek[1], 0, uint32(0), hashFunc) peak, _ := e2.Encrypt(ak) - h := mockTestHistory(nil, peak) + h := mockTestHistory(aek[0], peak) al := setupAccessLogic(pk) gm := dynamicaccess.NewGranteeManager(al) c := dynamicaccess.NewController(h, gm, al) @@ -62,11 +60,11 @@ func TestEncrypt(t *testing.T) { ak := encryption.Key([]byte("cica")) si := dynamicaccess.NewDefaultSession(pk) - aek, _ := si.Key(&pk.PublicKey, [][]byte{{1}}) - e2 := encryption.New(aek[0], 0, uint32(0), hashFunc) + aek, _ := si.Key(&pk.PublicKey, [][]byte{{0}, {1}}) + e2 := encryption.New(aek[1], 0, uint32(0), hashFunc) peak, _ := e2.Encrypt(ak) - h := mockTestHistory(nil, peak) + h := mockTestHistory(aek[0], peak) al := setupAccessLogic(pk) gm := dynamicaccess.NewGranteeManager(al) c := dynamicaccess.NewController(h, gm, al) diff --git a/pkg/dynamicaccess/session.go b/pkg/dynamicaccess/session.go index 95a3c07e87b..9d7634ffd01 100644 --- a/pkg/dynamicaccess/session.go +++ b/pkg/dynamicaccess/session.go @@ -26,7 +26,7 @@ func (s *session) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, er return nil, errors.New("shared secret is point at infinity") } - keys := make([][]byte, len(nonces)) + keys := make([][]byte, 0, len(nonces)) for _, nonce := range nonces { key, err := crypto.LegacyKeccak256(append(x.Bytes(), nonce...)) if err != nil { From 2f6a9e2cfaf476aa57d674b2ea164fc0206bfdf0 Mon Sep 17 00:00:00 2001 From: rolandlor <33499567+rolandlor@users.noreply.github.com> Date: Thu, 21 Mar 2024 13:58:43 +0100 Subject: [PATCH 12/22] Act access logic merge (#19) * grantee container and access logc tests are passed * refactored access logic and grantee container * PR 19 comments resolving * Refactor * Refactor --- pkg/dynamicaccess/accesslogic.go | 153 ++++---- pkg/dynamicaccess/accesslogic_test.go | 447 ++++++++++------------ pkg/dynamicaccess/act.go | 2 +- pkg/dynamicaccess/controller.go | 10 +- pkg/dynamicaccess/grantee.go | 34 +- pkg/dynamicaccess/grantee_manager.go | 12 +- pkg/dynamicaccess/grantee_manager_test.go | 6 +- pkg/dynamicaccess/grantee_test.go | 115 +++--- 8 files changed, 375 insertions(+), 404 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 8f46256cd85..417a4a40878 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -2,6 +2,7 @@ package dynamicaccess import ( "crypto/ecdsa" + "fmt" encryption "github.com/ethersphere/bee/pkg/encryption" "github.com/ethersphere/bee/pkg/swarm" @@ -10,146 +11,154 @@ import ( var hashFunc = sha3.NewLegacyKeccak256 -type AccessLogic interface { - Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) - EncryptRef(act Act, publisherPubKey ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) - //Add(act *Act, ref string, publisher ecdsa.PublicKey, tag string) (string, error) - getKeys(publicKey ecdsa.PublicKey) ([][]byte, error) - getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) - //createEncryptedAccessKey(ref string) - Add_New_Grantee_To_Content(act Act, publisherPubKey, granteePubKey ecdsa.PublicKey) (Act, error) - AddPublisher(act Act, publisher ecdsa.PublicKey, tag string) (Act, error) - // CreateAccessKey() +// Logic has the responsibility to return a ref for a given grantee and create new encrypted reference for a grantee +type Logic interface { + // Adds a new grantee to the ACT + AddNewGranteeToContent(act Act, publisherPubKey, granteePubKey *ecdsa.PublicKey) (Act, error) + // Get will return a decrypted reference, for given encrypted reference and grantee !!!!!!!!!!!!!!!!!!!!! + Get(act Act, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) } -type DefaultAccessLogic struct { +type ActLogic struct { session Session - //encryption encryption.Interface } -// Will create a new Act list with only one element (the creator), and will also create encrypted_ref -func (al *DefaultAccessLogic) AddPublisher(act Act, publisher ecdsa.PublicKey, tag string) (Act, error) { - access_key := encryption.GenerateRandomKey(encryption.KeyLength) +var _ Logic = (*ActLogic)(nil) + +// Adds a new publisher to an empty act +func (al ActLogic) AddPublisher(act Act, publisher *ecdsa.PublicKey) (Act, error) { + accessKey := encryption.GenerateRandomKey(encryption.KeyLength) keys, err := al.getKeys(publisher) if err != nil { return nil, err } - lookup_key := keys[0] - access_key_encryption_key := keys[1] + lookupKey := keys[0] + accessKeyEncryptionKey := keys[1] - access_key_cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) - encrypted_access_key, _ := access_key_cipher.Encrypt(access_key) + accessKeyCipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) + encryptedAccessKey, err := accessKeyCipher.Encrypt([]byte(accessKey)) + if err != nil { + return nil, err + } - act.Add(lookup_key, encrypted_access_key) + act.Add(lookupKey, encryptedAccessKey) return act, nil } -func (al *DefaultAccessLogic) EncryptRef(act Act, publisherPubKey ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { - access_key := al.getAccessKey(act, publisherPubKey) - ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) - encrypted_ref, _ := ref_cipher.Encrypt(ref.Bytes()) - return swarm.NewAddress(encrypted_ref), nil -} - -// publisher is public key -func (al *DefaultAccessLogic) Add_New_Grantee_To_Content(act Act, publisherPubKey, granteePubKey ecdsa.PublicKey) (Act, error) { +// Encrypts a SWARM reference for a publisher +func (al ActLogic) EncryptRef(act Act, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { + accessKey := al.getAccessKey(act, publisherPubKey) + refCipher := encryption.New(accessKey, 0, uint32(0), hashFunc) + encryptedRef, _ := refCipher.Encrypt(ref.Bytes()) - // error handling no encrypted_ref + return swarm.NewAddress(encryptedRef), nil +} - // 2 Diffie-Hellman for the publisher (the Creator) +// Adds a new grantee to the ACT +func (al ActLogic) AddNewGranteeToContent(act Act, publisherPubKey, granteePubKey *ecdsa.PublicKey) (Act, error) { // Get previously generated access key - access_key := al.getAccessKey(act, publisherPubKey) - - // --Encrypt access key for new Grantee-- + accessKey := al.getAccessKey(act, publisherPubKey) - // 2 Diffie-Hellman for the Grantee + // Encrypt the access key for the new Grantee keys, err := al.getKeys(granteePubKey) if err != nil { return nil, err } - lookup_key := keys[0] - access_key_encryption_key := keys[1] + lookupKey := keys[0] + accessKeyEncryptionKey := keys[1] // Encrypt the access key for the new Grantee - cipher := encryption.New(encryption.Key(access_key_encryption_key), 0, uint32(0), hashFunc) - granteeEncryptedAccessKey, _ := cipher.Encrypt(access_key) + cipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) + granteeEncryptedAccessKey, err := cipher.Encrypt(accessKey) + if err != nil { + return nil, err + } + // Add the new encrypted access key for the Act - act.Add(lookup_key, granteeEncryptedAccessKey) + act.Add(lookupKey, granteeEncryptedAccessKey) return act, nil } -func (al *DefaultAccessLogic) getAccessKey(act Act, publisherPubKey ecdsa.PublicKey) []byte { +// Will return the access key for a publisher (public key) +func (al *ActLogic) getAccessKey(act Act, publisherPubKey *ecdsa.PublicKey) []byte { keys, err := al.getKeys(publisherPubKey) if err != nil { return nil } - publisher_lookup_key := keys[0] - publisher_ak_decryption_key := keys[1] - - access_key_decryption_cipher := encryption.New(encryption.Key(publisher_ak_decryption_key), 0, uint32(0), hashFunc) - encrypted_ak, _ := al.getEncryptedAccessKey(act, publisher_lookup_key) - access_key, _ := access_key_decryption_cipher.Decrypt(encrypted_ak) - return access_key -} + publisherLookupKey := keys[0] + publisherAKDecryptionKey := keys[1] -// -// act[lookupKey] := valamilyen_cipher.Encrypt(access_key) + accessKeyDecryptionCipher := encryption.New(encryption.Key(publisherAKDecryptionKey), 0, uint32(0), hashFunc) + encryptedAK, err := al.getEncryptedAccessKey(act, publisherLookupKey) + if err != nil { + return nil + } -// end of pseudo code like code + accessKey, err := accessKeyDecryptionCipher.Decrypt(encryptedAK) + if err != nil { + return nil + } -// func (al *DefaultAccessLogic) CreateAccessKey(reference string) { -// } + return accessKey +} -func (al *DefaultAccessLogic) getKeys(publicKey ecdsa.PublicKey) ([][]byte, error) { +func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { // Generate lookup key and access key decryption oneByteArray := []byte{1} zeroByteArray := []byte{0} - keys, err := al.session.Key(&publicKey, [][]byte{zeroByteArray, oneByteArray}) + keys, err := al.session.Key(publicKey, [][]byte{zeroByteArray, oneByteArray}) if err != nil { - return [][]byte{}, err + return nil, err } return keys, nil } -func (al *DefaultAccessLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { +// Gets the encrypted access key for a given grantee +func (al *ActLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { val, err := act.Lookup(lookup_key) if err != nil { - return []byte{}, err + return nil, err } return val, nil } -func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher ecdsa.PublicKey, tag string) (swarm.Address, error) { +// Get will return a decrypted reference, for given encrypted reference and grantee +func (al ActLogic) Get(act Act, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { + if encryped_ref.Compare(swarm.EmptyAddress) == 0 { + return swarm.EmptyAddress, fmt.Errorf("encrypted ref not provided") + } + if grantee == nil { + return swarm.EmptyAddress, fmt.Errorf("grantee not provided") + } - keys, err := al.getKeys(publisher) + keys, err := al.getKeys(grantee) if err != nil { return swarm.EmptyAddress, err } - lookup_key := keys[0] - access_key_decryption_key := keys[1] + lookupKey := keys[0] + accessKeyDecryptionKey := keys[1] // Lookup encrypted access key from the ACT manifest - - encrypted_access_key, err := al.getEncryptedAccessKey(act, lookup_key) + encryptedAccessKey, err := al.getEncryptedAccessKey(act, lookupKey) if err != nil { return swarm.EmptyAddress, err } // Decrypt access key - access_key_cipher := encryption.New(encryption.Key(access_key_decryption_key), 0, uint32(0), hashFunc) - access_key, err := access_key_cipher.Decrypt(encrypted_access_key) + accessKeyCipher := encryption.New(encryption.Key(accessKeyDecryptionKey), 0, uint32(0), hashFunc) + accessKey, err := accessKeyCipher.Decrypt(encryptedAccessKey) if err != nil { return swarm.EmptyAddress, err } // Decrypt reference - ref_cipher := encryption.New(access_key, 0, uint32(0), hashFunc) - ref, err := ref_cipher.Decrypt(encryped_ref.Bytes()) + refCipher := encryption.New(accessKey, 0, uint32(0), hashFunc) + ref, err := refCipher.Decrypt(encryped_ref.Bytes()) if err != nil { return swarm.EmptyAddress, err } @@ -157,8 +166,8 @@ func (al *DefaultAccessLogic) Get(act Act, encryped_ref swarm.Address, publisher return swarm.NewAddress(ref), nil } -func NewAccessLogic(s Session) AccessLogic { - return &DefaultAccessLogic{ +func NewLogic(s Session) ActLogic { + return ActLogic{ session: s, } -} +} \ No newline at end of file diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index c3125b65cd6..46a4cc39ec6 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -1,237 +1,214 @@ package dynamicaccess_test -// import ( -// "crypto/ecdsa" -// "crypto/elliptic" -// "crypto/rand" -// "errors" -// "fmt" -// "testing" - -// "github.com/ethersphere/bee/pkg/crypto" -// "github.com/ethersphere/bee/pkg/swarm" -// ) - -// func setupAccessLogic() AccessLogic { -// privateKey, err := crypto.GenerateSecp256k1Key() -// if err != nil { -// errors.New("error creating private key") -// } -// diffieHellman := NewDiffieHellman(privateKey) -// al := NewAccessLogic(diffieHellman) - -// return al -// } - -// func TestGetLookupKey_Success(t *testing.T) { -// al := setupAccessLogic() - -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// // ! this will be random, we can not know the lookup key for a randomly generated key -// act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") -// fmt.Println(act, encryptedRef) - -// tag := "exampleTag" - -// lookupKey, err := al.getLookUpKey(id0.PublicKey, tag) -// if err != nil { -// t.Errorf("Could not fetch lookup key from publisher and tag") -// } - -// expectedLookupKey := "expectedLookupKey" -// if lookupKey != expectedLookupKey { -// fmt.Println(string(lookupKey)) -// t.Errorf("The lookup key that was returned is not correct!") -// } -// } - -// func TestGetLookUpKey_Error(t *testing.T) { -// al := setupAccessLogic() - -// invalidPublisher := ecdsa.PublicKey{} -// tag := "exampleTag" - -// lookupKey, err := al.getLookUpKey(invalidPublisher, tag) - -// if err != nil { -// t.Errorf("There was an error while fetching lookup key") -// } - -// if lookupKey != "" { -// t.Errorf("Expected lookup key to be empty for invalid input") -// } -// } - -// func TestGetAccessKeyDecriptionKey_Success(t *testing.T) { -// al := setupAccessLogic() - -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// tag := "exampleTag" - -// access_key_decryption_key, err := al.getAccessKeyDecriptionKey(id0.PublicKey, tag) -// if err != nil { -// t.Errorf("GetAccessKeyDecriptionKey gave back error") -// } - -// expectedResult := "we-dont-know" -// if access_key_decryption_key != expectedResult { -// t.Errorf("The access key decryption key is not correct!") -// } -// } - -// func TestGetAccessKeyDecriptionKey_Error(t *testing.T) { -// al := setupAccessLogic() - -// invalidPublisher := ecdsa.PublicKey{} -// tag := "exampleTag" - -// access_key_decryption_key, err := al.getAccessKeyDecriptionKey(invalidPublisher, tag) -// if err != nil { -// t.Errorf("GetAccessKeyDecriptionKey gave back error") -// } - -// if access_key_decryption_key != "" { -// t.Errorf("GetAccessKeyDecriptionKey should give back empty string for invalid input!") -// } -// } - -// func TestGetEncryptedAccessKey_Success(t *testing.T) { -// al := setupAccessLogic() - -// lookupKey := "exampleLookupKey" -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - -// act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") - -// encrypted_access_key, err := al.getEncryptedAccessKey(*act, lookupKey) -// if err != nil { -// t.Errorf("There was an error while executing GetEncryptedAccessKey") -// } - -// expectedEncryptedKey := "abc013encryptedkey" -// if encrypted_access_key.Reference().String() != expectedEncryptedKey { -// t.Errorf("GetEncryptedAccessKey didn't give back the expected value!") -// } -// } - -// func TestGetEncryptedAccessKey_Error(t *testing.T) { -// al := setupAccessLogic() - -// lookupKey := "exampleLookupKey" -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - -// act, _, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") -// empty_act_result, _ := al.getEncryptedAccessKey(*act, lookupKey) -// if empty_act_result != nil { -// t.Errorf("GetEncryptedAccessKey should give back nil for empty act root hash!") -// } - -// empty_lookup_result, _ := al.getEncryptedAccessKey(*act, "") - -// if empty_lookup_result != nil { -// t.Errorf("GetEncryptedAccessKey should give back nil for empty lookup key!") -// } -// } - -// func TestGet_Success(t *testing.T) { -// al := setupAccessLogic() - -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// act, encryptedRef, _ := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") -// tag := "exampleTag" - -// ref, err := al.Get(act, encryptedRef, id0.PublicKey, tag) -// if err != nil { -// t.Errorf("There was an error while calling Get") -// } - -// expectedRef := "bzzNotEncrypted128long" -// if ref != expectedRef { -// t.Errorf("Get gave back wrong Swarm reference!") -// } -// } - -// func TestGet_Error(t *testing.T) { -// al := setupAccessLogic() - -// //actRootHash := "0xabcexample" -// id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// act, encrypredRef, err := al.ActInit(swarm.NewAddress([]byte("42")), id0.PublicKey, "") -// if err != nil { -// t.Errorf("Error initializing Act") -// t.Errorf(err.Error()) -// } -// //encryptedRef := "bzzabcasab" -// tag := "exampleTag" - -// refOne, err := al.Get(act, encrypredRef, id0.PublicKey, tag) -// if err != nil { -// t.Errorf(err.Error()) -// } -// if refOne != "" { -// t.Errorf("Get should give back empty string if ACT root hash not provided!") -// } - -// refTwo, _ := al.Get(act, swarm.EmptyAddress, id0.PublicKey, tag) -// if refTwo != "" { -// t.Errorf("Get should give back empty string if encrypted ref not provided!") -// } - -// refThree, _ := al.Get(act, encrypredRef, ecdsa.PublicKey{}, tag) -// if refThree != "" { -// t.Errorf("Get should give back empty string if publisher not provided!") -// } - -// refFour, _ := al.Get(act, encrypredRef, id0.PublicKey, "") -// if refFour != "" { -// t.Errorf("Get should give back empty string if tag was not provided!") -// } -// } - -// func TestNewAccessLogic(t *testing.T) { -// logic := setupAccessLogic() - -// _, ok := logic.(*DefaultAccessLogic) -// if !ok { -// t.Errorf("NewAccessLogic: expected type *DefaultAccessLogic, got %T", logic) -// } -// } - -// // func TestAddGrantee(t *testing.T) { -// // al := setupAccessLogic() -// // // ref := "example_ref" -// // id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// // testGranteeList := NewGrantee() - -// // // Add grantee keys to the testGranteeList -// // id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// // id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// // id3, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) -// // testGranteeList.AddGrantees([]ecdsa.PublicKey{id1.PublicKey, id2.PublicKey, id3.PublicKey}) - -// // // Initialize empty ACT -// // actMock := MockAct.NewActMock() -// // actMockRootHash := "exampleRootHash" - -// // // Add each grantee to content using ActMock and validate the resulting ACT -// // for i := 0; i < len(testGranteeList.GetGrantees()); i++ { -// // lookupKey, _ := al.getLookUpKey(testGranteeList.GetGrantees()[i], "") -// // encryptedAccessKey := "exampleEncryptedAccessKey" -// // _, err := actMock.Add(actMockRootHash, []byte(lookupKey), []byte(encryptedAccessKey)) -// // if err != nil { -// // t.Fatalf("Failed to add grantee to content using ActMock: %v", err) -// // } - -// // // Validate the resulting ACT -// // encryptedAccessKeyFromMock, err := actMock.Get(actMockRootHash, []byte(lookupKey)) -// // if err != nil { -// // t.Fatalf("Failed to retrieve encrypted access key from ActMock: %v", err) -// // } -// // encryptedAccessKeyFromMockBytes, _ := hex.DecodeString(encryptedAccessKeyFromMock) -// // if string(encryptedAccessKeyFromMockBytes) != encryptedAccessKey { -// // t.Errorf("Encrypted access key retrieved from ActMock doesn't match expected value") -// // } -// // } - -// // al.Add_New_Grantee_To_Content(actMock, encryptedRef, id0.PublicKey, testGranteeList.GetGrantees()[i]) -// // } +import ( + "crypto/ecdsa" + "crypto/elliptic" + "encoding/hex" + "math/big" + "testing" + + "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/swarm" +) + +// Generates a new test environment with a fix private key +func setupAccessLogic2() dynamicaccess.ActLogic { + privateKey := generateFixPrivateKey(1000) + diffieHellman := dynamicaccess.NewDefaultSession(&privateKey) + al := dynamicaccess.NewLogic(diffieHellman) + + return al +} + +// Generates a fixed identity with private and public key. The private key is generated from the input +func generateFixPrivateKey(input int64) ecdsa.PrivateKey { + fixedD := big.NewInt(input) + curve := elliptic.P256() + x, y := curve.ScalarBaseMult(fixedD.Bytes()) + + privateKey := ecdsa.PrivateKey{ + PublicKey: ecdsa.PublicKey{ + Curve: curve, + X: x, + Y: y, + }, + D: fixedD, + } + + return privateKey +} + +func TestGet_Success(t *testing.T) { + al := setupAccessLogic2() + id0 := generateFixPrivateKey(0) + + act := dynamicaccess.NewInMemoryAct() + act, err := al.AddPublisher(act, &id0.PublicKey) + if err != nil { + t.Errorf("AddPublisher: expected no error, got %v", err) + } + + byteRef, _ := hex.DecodeString("39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559") + + expectedRef := swarm.NewAddress(byteRef) + t.Logf("encryptedRef: %s", expectedRef.String()) + + encryptedRef, err := al.EncryptRef(act, &id0.PublicKey, expectedRef) + t.Logf("encryptedRef: %s", encryptedRef.String()) + if err != nil { + t.Errorf("There was an error while calling EncryptRef: ") + t.Error(err) + } + + ref, err := al.Get(act, encryptedRef, &id0.PublicKey) + if err != nil { + t.Errorf("There was an error while calling Get: ") + t.Error(err) + } + + if expectedRef.Compare(ref) != 0 { + + t.Errorf("Get gave back wrong Swarm reference!") + } +} + +// This test function tests those cases where different parameters are missing +func TestGet_Error(t *testing.T) { + al := setupAccessLogic2() + id0 := generateFixPrivateKey(0) + + act := dynamicaccess.NewInMemoryAct() + act, err := al.AddPublisher(act, &id0.PublicKey) + if err != nil { + t.Errorf("AddPublisher: expected no error, got %v", err) + } + + expectedRef := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" + + encryptedRef, _ := al.EncryptRef(act, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) + + _, err = al.Get(dynamicaccess.NewInMemoryAct(), encryptedRef, &id0.PublicKey) + if err == nil { + t.Errorf("Get should give back encrypted access key not found error!") + } + + refTwo, _ := al.Get(act, swarm.EmptyAddress, &id0.PublicKey) + if swarm.EmptyAddress.Compare(refTwo) != 0 { + t.Errorf("Get should give back empty string if encrypted ref not provided!") + } + + _, err = al.Get(act, encryptedRef, nil) + if err == nil { + t.Errorf("Get should give back error if grantee not provided!") + } +} + +func TestAddPublisher(t *testing.T) { + al := setupAccessLogic2() + id0 := generateFixPrivateKey(0) + savedLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" + act := dynamicaccess.NewInMemoryAct() + act, err := al.AddPublisher(act, &id0.PublicKey) + if err != nil { + t.Errorf("AddPublisher: expected no error, got %v", err) + } + + decodedSavedLookupKey, err := hex.DecodeString(savedLookupKey) + if err != nil { + t.Errorf("AddPublisher: expected no error, got %v", err) + } + + encryptedAccessKey, _ := act.Lookup(decodedSavedLookupKey) + decodedEncryptedAccessKey := hex.EncodeToString(encryptedAccessKey) + + // A random value is returned so it is only possibly to check the length of the returned value + // We know the lookup key because the generated private key is fixed + if len(decodedEncryptedAccessKey) != 64 { + t.Errorf("AddPublisher: expected encrypted access key length 64, got %d", len(decodedEncryptedAccessKey)) + } + if act == nil { + t.Errorf("AddPublisher: expected act, got nil") + } +} + +func TestAdd_New_Grantee_To_Content(t *testing.T) { + al := setupAccessLogic2() + + id0 := generateFixPrivateKey(0) + id1 := generateFixPrivateKey(1) + id2 := generateFixPrivateKey(2) + + publisherLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" + firstAddedGranteeLookupKey := "e221a2abf64357260e8f2c937ee938aed98dce097e537c1a3fd4caf73510dbe4" + secondAddedGranteeLookupKey := "8fe8dff7cd15a6a0095c1b25071a5691e7c901fd0b95857a96c0e4659b48716a" + + act := dynamicaccess.NewInMemoryAct() + act, err := al.AddPublisher(act, &id0.PublicKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + + act, err = al.AddNewGranteeToContent(act, &id0.PublicKey, &id1.PublicKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + + act, err = al.AddNewGranteeToContent(act, &id0.PublicKey, &id2.PublicKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + + lookupKeyAsByte, err := hex.DecodeString(publisherLookupKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + result, _ := act.Lookup(lookupKeyAsByte) + hexEncodedEncryptedAK := hex.EncodeToString(result) + if len(hexEncodedEncryptedAK) != 64 { + t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) + } + + lookupKeyAsByte, err = hex.DecodeString(firstAddedGranteeLookupKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + result, _ = act.Lookup(lookupKeyAsByte) + hexEncodedEncryptedAK = hex.EncodeToString(result) + if len(hexEncodedEncryptedAK) != 64 { + t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) + } + + lookupKeyAsByte, err = hex.DecodeString(secondAddedGranteeLookupKey) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + result, _ = act.Lookup(lookupKeyAsByte) + hexEncodedEncryptedAK = hex.EncodeToString(result) + if len(hexEncodedEncryptedAK) != 64 { + t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) + } +} + +func TestEncryptRef(t *testing.T) { + ref := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" + savedEncryptedRef := "230cdcfb2e67adddb2822b38f70105213ab3e4f97d03560bfbfbb218f487c5303e9aa9a97e62aa1a8003f162679e7c65e1c8e3aacaec2043fd5d2a4a7d69285e" + + al := setupAccessLogic2() + id0 := generateFixPrivateKey(0) + act := dynamicaccess.NewInMemoryAct() + decodedLookupKey, err := hex.DecodeString("bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a") + if err != nil { + t.Errorf("EncryptRef: expected no error, got %v", err) + } + + act.Add(decodedLookupKey, []byte("42")) + + encryptedRefValue, err := al.EncryptRef(act, &id0.PublicKey, swarm.NewAddress([]byte(ref))) + if err != nil { + t.Errorf("EncryptRef: expected no error, got %v", err) + } + + if encryptedRefValue.String() != savedEncryptedRef { + t.Errorf("EncryptRef: expected encrypted ref, got empty address") + } +} \ No newline at end of file diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index 1153f2fc868..1f1dbb85897 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -78,7 +78,7 @@ func (act *inMemoryAct) Lookup(key []byte) ([]byte, error) { } return bytes, nil } - return make([]byte, 0), nil + return nil, fmt.Errorf("key not found") } func (act *inMemoryAct) Load(addr swarm.Address) error { diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index 6267a878279..92363014c9b 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -14,7 +14,7 @@ type Controller interface { type defaultController struct { history History granteeManager GranteeManager - accessLogic AccessLogic + accessLogic ActLogic } func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) { @@ -22,7 +22,7 @@ func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.A if err != nil { return swarm.EmptyAddress, err } - addr, err := c.accessLogic.Get(act, enryptedRef, *publisher, tag) + addr, err := c.accessLogic.Get(act, enryptedRef, publisher) return addr, err } @@ -31,13 +31,13 @@ func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.Pu if act == nil { // new feed act = NewInMemoryAct() - act = c.granteeManager.Publish(act, *publisher, topic) + act = c.granteeManager.Publish(act, publisher, topic) } //FIXME: check if ACT is consistent with the grantee list - return c.accessLogic.EncryptRef(act, *publisher, ref) + return c.accessLogic.EncryptRef(act, publisher, ref) } -func NewController(history History, granteeManager GranteeManager, accessLogic AccessLogic) Controller { +func NewController(history History, granteeManager GranteeManager, accessLogic ActLogic) Controller { return &defaultController{ history: history, granteeManager: granteeManager, diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index 2a07d84b3ed..dfd7015e49f 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -5,37 +5,22 @@ import ( ) type Grantee interface { - //? ÁTBESZÉLNI - // Revoke(topic string) error - // Publish(topic string) error - - // RevokeList(topic string, removeList []string, addList []string) (string, error) - // RevokeGrantees(topic string, removeList []string) (string, error) AddGrantees(topic string, addList []*ecdsa.PublicKey) error RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error GetGrantees(topic string) []*ecdsa.PublicKey } type defaultGrantee struct { - grantees map[string][]*ecdsa.PublicKey // Modified field name to start with an uppercase letter + grantees map[string][]*ecdsa.PublicKey } func (g *defaultGrantee) GetGrantees(topic string) []*ecdsa.PublicKey { - return g.grantees[topic] + grantees := g.grantees[topic] + keys := make([]*ecdsa.PublicKey, len(grantees)) + copy(keys, grantees) + return keys } -// func (g *defaultGrantee) Revoke(topic string) error { -// return nil -// } - -// func (g *defaultGrantee) RevokeList(topic string, removeList []string, addList []string) (string, error) { -// return "", nil -// } - -// func (g *defaultGrantee) Publish(topic string) error { -// return nil -// } - func (g *defaultGrantee) AddGrantees(topic string, addList []*ecdsa.PublicKey) error { g.grantees[topic] = append(g.grantees[topic], addList...) return nil @@ -44,14 +29,17 @@ func (g *defaultGrantee) AddGrantees(topic string, addList []*ecdsa.PublicKey) e func (g *defaultGrantee) RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error { for _, remove := range removeList { for i, grantee := range g.grantees[topic] { - if grantee == remove { - g.grantees[topic] = append(g.grantees[topic][:i], g.grantees[topic][i+1:]...) + if *grantee == *remove { + g.grantees[topic][i] = g.grantees[topic][len(g.grantees[topic])-1] + g.grantees[topic] = g.grantees[topic][:len(g.grantees[topic])-1] } } } + + return nil } func NewGrantee() Grantee { return &defaultGrantee{grantees: make(map[string][]*ecdsa.PublicKey)} -} +} \ No newline at end of file diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index 9172a05db03..6b287af6941 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -5,7 +5,7 @@ import "crypto/ecdsa" type GranteeManager interface { Get(topic string) []*ecdsa.PublicKey Add(topic string, addList []*ecdsa.PublicKey) error - Publish(act Act, publisher ecdsa.PublicKey, topic string) Act + Publish(act Act, publisher *ecdsa.PublicKey, topic string) Act // HandleGrantees(topic string, addList, removeList []*ecdsa.PublicKey) *Act @@ -16,11 +16,11 @@ type GranteeManager interface { var _ GranteeManager = (*granteeManager)(nil) type granteeManager struct { - accessLogic AccessLogic + accessLogic ActLogic granteeList Grantee } -func NewGranteeManager(al AccessLogic) *granteeManager { +func NewGranteeManager(al ActLogic) *granteeManager { return &granteeManager{accessLogic: al, granteeList: NewGrantee()} } @@ -32,10 +32,10 @@ func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { return gm.granteeList.AddGrantees(topic, addList) } -func (gm *granteeManager) Publish(act Act, publisher ecdsa.PublicKey, topic string) Act { - gm.accessLogic.AddPublisher(act, publisher, "") +func (gm *granteeManager) Publish(act Act, publisher *ecdsa.PublicKey, topic string) Act { + gm.accessLogic.AddPublisher(act, publisher) for _, grantee := range gm.granteeList.GetGrantees(topic) { - gm.accessLogic.Add_New_Grantee_To_Content(act, publisher, *grantee) + gm.accessLogic.AddNewGranteeToContent(act, publisher, grantee) } return act } diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index bc90ef504ae..fc5969f4492 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -10,13 +10,13 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" ) -func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.AccessLogic { +func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.ActLogic { // privateKey, err := crypto.GenerateSecp256k1Key() // if err != nil { // errors.New("error creating private key") // } si := dynamicaccess.NewDefaultSession(privateKey) - al := dynamicaccess.NewAccessLogic(si) + al := dynamicaccess.NewLogic(si) return al } @@ -36,6 +36,6 @@ func TestAdd(t *testing.T) { if err != nil { t.Errorf("Add() returned an error") } - m.Publish(act, pub.PublicKey, "topic") + m.Publish(act, &pub.PublicKey, "topic") fmt.Println("") } diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 2d795ab2eef..7418a741d77 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -10,96 +10,93 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" ) -// func TestGranteeRevoke(t *testing.T) { -// err := NewGrantee().Revoke("") -// if err != nil { -// t.Errorf("Error revoking grantee: %v", err) -// } -// } - -/*func TestGranteeRevokeList(t *testing.T) { - _, err := NewGrantee().RevokeList("", nil, nil) - if err != nil { - t.Errorf("Error revoking list of grantees: %v", err) - } -}*/ - -// func TestGranteePublish(t *testing.T) { -// err := NewGrantee().Publish("") -// if err != nil { -// t.Errorf("Error publishing grantee: %v", err) -// } -// } - func TestGranteeAddGrantees(t *testing.T) { - // Create a new Grantee grantee := dynamicaccess.NewGrantee() - // Generate some dummy ecdsa.PublicKey values - key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Add the keys to the grantee addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - err := grantee.AddGrantees("topicName", addList) - grantees := grantee.GetGrantees("topicName") - // Check for errors + exampleTopic := "topic" + err = grantee.AddGrantees(exampleTopic, addList) + if err != nil { - t.Fatalf("Expected no error, got %v", err) + t.Errorf("Expected no error, got %v", err) } - // Check if the keys were added correctly + grantees := grantee.GetGrantees(exampleTopic) if !reflect.DeepEqual(grantees, addList) { t.Errorf("Expected grantees %v, got %v", addList, grantees) } } func TestRemoveGrantees(t *testing.T) { - // Create a new Grantee grantee := dynamicaccess.NewGrantee() - // Generate some dummy ecdsa.PublicKey values - key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } + + key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Add the keys to the grantee addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - grantee.AddGrantees("topicName", addList) + exampleTopic := "topic" + err = grantee.AddGrantees(exampleTopic, addList) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Remove one of the keys removeList := []*ecdsa.PublicKey{&key1.PublicKey} - err := grantee.RemoveGrantees("topicName", removeList) - grantees := grantee.GetGrantees("topicName") - - // Check for errors + err = grantee.RemoveGrantees(exampleTopic, removeList) if err != nil { - t.Fatalf("Expected no error, got %v", err) + t.Errorf("Expected no error, got %v", err) } - // Check if the key was removed correctly + grantees := grantee.GetGrantees(exampleTopic) expectedGrantees := []*ecdsa.PublicKey{&key2.PublicKey} - if !reflect.DeepEqual(grantees, expectedGrantees) { - t.Errorf("Expected grantees %v, got %v", expectedGrantees, grantees) + + for i, grantee := range grantees { + if grantee != expectedGrantees[i] { + t.Errorf("Expected grantee %v, got %v", expectedGrantees[i], grantee) + } } } func TestGetGrantees(t *testing.T) { - // Create a new Grantee grantee := dynamicaccess.NewGrantee() - // Generate some dummy ecdsa.PublicKey values - key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - key2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Add the keys to the grantee - addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - grantee.AddGrantees("topicName", addList) + key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Get the grantees - grantees := grantee.GetGrantees("topicName") + addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} + exampleTopic := "topic" + err = grantee.AddGrantees(exampleTopic, addList) + if err != nil { + t.Errorf("Expected no error, got %v", err) + } - // Check if the grantees were returned correctly - if !reflect.DeepEqual(grantees, addList) { - t.Errorf("Expected grantees %v, got %v", addList, grantees) + grantees := grantee.GetGrantees(exampleTopic) + for i, grantee := range grantees { + if grantee != addList[i] { + t.Errorf("Expected grantee %v, got %v", addList[i], grantee) + } } -} +} \ No newline at end of file From a03787c5179971a875f4f4a09ba4589eb6258109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Fri, 22 Mar 2024 13:09:37 +0100 Subject: [PATCH 13/22] Act kvs merge (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * grantee container and access logc tests are passed * refactored access logic and grantee container * PR 19 comments resolving * Refactor * Refactor * working manifest ACT with basic tests * (refactor:) Refactor act_test * (refactor:) Refactor kvs -> kvs.manifest, kvs.memory * (refactror:) kvs * refactor kvs contsructors --------- Co-authored-by: Roland Seres Co-authored-by: Bálint Ujvári Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/accesslogic.go | 50 +++++----- pkg/dynamicaccess/accesslogic_test.go | 72 +++++++------- pkg/dynamicaccess/act.go | 110 +++++++--------------- pkg/dynamicaccess/act_test.go | 72 ++++++++++++-- pkg/dynamicaccess/container.go | 7 -- pkg/dynamicaccess/controller.go | 18 ++-- pkg/dynamicaccess/controller_test.go | 2 +- pkg/dynamicaccess/grantee_manager.go | 16 ++-- pkg/dynamicaccess/grantee_manager_test.go | 11 +-- pkg/dynamicaccess/history_test.go | 9 +- pkg/dynamicaccess/mock/act.go | 18 ++-- pkg/kvs/kvs.go | 34 +++++++ pkg/kvs/manifest/kvs.go | 86 +++++++++++++++++ pkg/kvs/memory/kvs.go | 67 +++++++++++++ 14 files changed, 388 insertions(+), 184 deletions(-) delete mode 100644 pkg/dynamicaccess/container.go create mode 100644 pkg/kvs/kvs.go create mode 100644 pkg/kvs/manifest/kvs.go create mode 100644 pkg/kvs/memory/kvs.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 417a4a40878..4b5abcd739e 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -14,24 +14,25 @@ var hashFunc = sha3.NewLegacyKeccak256 // Logic has the responsibility to return a ref for a given grantee and create new encrypted reference for a grantee type Logic interface { // Adds a new grantee to the ACT - AddNewGranteeToContent(act Act, publisherPubKey, granteePubKey *ecdsa.PublicKey) (Act, error) - // Get will return a decrypted reference, for given encrypted reference and grantee !!!!!!!!!!!!!!!!!!!!! - Get(act Act, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) + AddNewGranteeToContent(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey) (swarm.Address, error) + // Get will return a decrypted reference, for given encrypted reference and grantee + Get(rootHash swarm.Address, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) } type ActLogic struct { session Session + act Act } var _ Logic = (*ActLogic)(nil) // Adds a new publisher to an empty act -func (al ActLogic) AddPublisher(act Act, publisher *ecdsa.PublicKey) (Act, error) { +func (al ActLogic) AddPublisher(rootHash swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) { accessKey := encryption.GenerateRandomKey(encryption.KeyLength) keys, err := al.getKeys(publisher) if err != nil { - return nil, err + return swarm.EmptyAddress, err } lookupKey := keys[0] accessKeyEncryptionKey := keys[1] @@ -39,17 +40,15 @@ func (al ActLogic) AddPublisher(act Act, publisher *ecdsa.PublicKey) (Act, error accessKeyCipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) encryptedAccessKey, err := accessKeyCipher.Encrypt([]byte(accessKey)) if err != nil { - return nil, err + return swarm.EmptyAddress, err } - act.Add(lookupKey, encryptedAccessKey) - - return act, nil + return al.act.Add(rootHash, lookupKey, encryptedAccessKey) } // Encrypts a SWARM reference for a publisher -func (al ActLogic) EncryptRef(act Act, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { - accessKey := al.getAccessKey(act, publisherPubKey) +func (al ActLogic) EncryptRef(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { + accessKey := al.getAccessKey(rootHash, publisherPubKey) refCipher := encryption.New(accessKey, 0, uint32(0), hashFunc) encryptedRef, _ := refCipher.Encrypt(ref.Bytes()) @@ -57,14 +56,14 @@ func (al ActLogic) EncryptRef(act Act, publisherPubKey *ecdsa.PublicKey, ref swa } // Adds a new grantee to the ACT -func (al ActLogic) AddNewGranteeToContent(act Act, publisherPubKey, granteePubKey *ecdsa.PublicKey) (Act, error) { +func (al ActLogic) AddNewGranteeToContent(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey) (swarm.Address, error) { // Get previously generated access key - accessKey := al.getAccessKey(act, publisherPubKey) + accessKey := al.getAccessKey(rootHash, publisherPubKey) // Encrypt the access key for the new Grantee keys, err := al.getKeys(granteePubKey) if err != nil { - return nil, err + return swarm.EmptyAddress, err } lookupKey := keys[0] accessKeyEncryptionKey := keys[1] @@ -73,18 +72,16 @@ func (al ActLogic) AddNewGranteeToContent(act Act, publisherPubKey, granteePubKe cipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) granteeEncryptedAccessKey, err := cipher.Encrypt(accessKey) if err != nil { - return nil, err + return swarm.EmptyAddress, err } // Add the new encrypted access key for the Act - act.Add(lookupKey, granteeEncryptedAccessKey) - - return act, nil + return al.act.Add(rootHash, lookupKey, granteeEncryptedAccessKey) } // Will return the access key for a publisher (public key) -func (al *ActLogic) getAccessKey(act Act, publisherPubKey *ecdsa.PublicKey) []byte { +func (al *ActLogic) getAccessKey(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey) []byte { keys, err := al.getKeys(publisherPubKey) if err != nil { return nil @@ -93,7 +90,7 @@ func (al *ActLogic) getAccessKey(act Act, publisherPubKey *ecdsa.PublicKey) []by publisherAKDecryptionKey := keys[1] accessKeyDecryptionCipher := encryption.New(encryption.Key(publisherAKDecryptionKey), 0, uint32(0), hashFunc) - encryptedAK, err := al.getEncryptedAccessKey(act, publisherLookupKey) + encryptedAK, err := al.getEncryptedAccessKey(rootHash, publisherLookupKey) if err != nil { return nil } @@ -119,8 +116,8 @@ func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { } // Gets the encrypted access key for a given grantee -func (al *ActLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, error) { - val, err := act.Lookup(lookup_key) +func (al *ActLogic) getEncryptedAccessKey(rootHash swarm.Address, lookup_key []byte) ([]byte, error) { + val, err := al.act.Lookup(rootHash, lookup_key) if err != nil { return nil, err } @@ -128,7 +125,7 @@ func (al *ActLogic) getEncryptedAccessKey(act Act, lookup_key []byte) ([]byte, e } // Get will return a decrypted reference, for given encrypted reference and grantee -func (al ActLogic) Get(act Act, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { +func (al ActLogic) Get(rootHash swarm.Address, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { if encryped_ref.Compare(swarm.EmptyAddress) == 0 { return swarm.EmptyAddress, fmt.Errorf("encrypted ref not provided") } @@ -144,7 +141,7 @@ func (al ActLogic) Get(act Act, encryped_ref swarm.Address, grantee *ecdsa.Publi accessKeyDecryptionKey := keys[1] // Lookup encrypted access key from the ACT manifest - encryptedAccessKey, err := al.getEncryptedAccessKey(act, lookupKey) + encryptedAccessKey, err := al.getEncryptedAccessKey(rootHash, lookupKey) if err != nil { return swarm.EmptyAddress, err } @@ -166,8 +163,9 @@ func (al ActLogic) Get(act Act, encryped_ref swarm.Address, grantee *ecdsa.Publi return swarm.NewAddress(ref), nil } -func NewLogic(s Session) ActLogic { +func NewLogic(s Session, act Act) ActLogic { return ActLogic{ session: s, + act: act, } -} \ No newline at end of file +} diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index 46a4cc39ec6..b87bac84ffd 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -8,14 +8,15 @@ import ( "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" + mockstorer "github.com/ethersphere/bee/pkg/storer/mock" "github.com/ethersphere/bee/pkg/swarm" ) // Generates a new test environment with a fix private key -func setupAccessLogic2() dynamicaccess.ActLogic { +func setupAccessLogic2(act dynamicaccess.Act) dynamicaccess.ActLogic { privateKey := generateFixPrivateKey(1000) diffieHellman := dynamicaccess.NewDefaultSession(&privateKey) - al := dynamicaccess.NewLogic(diffieHellman) + al := dynamicaccess.NewLogic(diffieHellman, act) return al } @@ -39,11 +40,11 @@ func generateFixPrivateKey(input int64) ecdsa.PrivateKey { } func TestGet_Success(t *testing.T) { - al := setupAccessLogic2() id0 := generateFixPrivateKey(0) - - act := dynamicaccess.NewInMemoryAct() - act, err := al.AddPublisher(act, &id0.PublicKey) + var mockStorer = mockstorer.New() + act := dynamicaccess.NewInManifestAct(mockStorer) + al := setupAccessLogic2(act) + ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } @@ -53,20 +54,20 @@ func TestGet_Success(t *testing.T) { expectedRef := swarm.NewAddress(byteRef) t.Logf("encryptedRef: %s", expectedRef.String()) - encryptedRef, err := al.EncryptRef(act, &id0.PublicKey, expectedRef) + encryptedRef, err := al.EncryptRef(ref, &id0.PublicKey, expectedRef) t.Logf("encryptedRef: %s", encryptedRef.String()) if err != nil { t.Errorf("There was an error while calling EncryptRef: ") t.Error(err) } - ref, err := al.Get(act, encryptedRef, &id0.PublicKey) + acutalRef, err := al.Get(ref, encryptedRef, &id0.PublicKey) if err != nil { t.Errorf("There was an error while calling Get: ") t.Error(err) } - if expectedRef.Compare(ref) != 0 { + if expectedRef.Compare(acutalRef) != 0 { t.Errorf("Get gave back wrong Swarm reference!") } @@ -74,51 +75,55 @@ func TestGet_Success(t *testing.T) { // This test function tests those cases where different parameters are missing func TestGet_Error(t *testing.T) { - al := setupAccessLogic2() id0 := generateFixPrivateKey(0) act := dynamicaccess.NewInMemoryAct() - act, err := al.AddPublisher(act, &id0.PublicKey) + al := setupAccessLogic2(act) + ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } expectedRef := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" - encryptedRef, _ := al.EncryptRef(act, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) + encryptedRef, _ := al.EncryptRef(ref, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) - _, err = al.Get(dynamicaccess.NewInMemoryAct(), encryptedRef, &id0.PublicKey) + r, err := al.Get(swarm.RandAddress(t), encryptedRef, &id0.PublicKey) if err == nil { + t.Logf("r: %s", r.String()) t.Errorf("Get should give back encrypted access key not found error!") } - refTwo, _ := al.Get(act, swarm.EmptyAddress, &id0.PublicKey) + refTwo, _ := al.Get(swarm.RandAddress(t), swarm.EmptyAddress, &id0.PublicKey) if swarm.EmptyAddress.Compare(refTwo) != 0 { t.Errorf("Get should give back empty string if encrypted ref not provided!") } - _, err = al.Get(act, encryptedRef, nil) + _, err = al.Get(swarm.RandAddress(t), encryptedRef, nil) if err == nil { t.Errorf("Get should give back error if grantee not provided!") } } func TestAddPublisher(t *testing.T) { - al := setupAccessLogic2() id0 := generateFixPrivateKey(0) savedLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" act := dynamicaccess.NewInMemoryAct() - act, err := al.AddPublisher(act, &id0.PublicKey) + al := setupAccessLogic2(act) + ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } decodedSavedLookupKey, err := hex.DecodeString(savedLookupKey) if err != nil { - t.Errorf("AddPublisher: expected no error, got %v", err) + t.Errorf("DecodeString: expected no error, got %v", err) } - encryptedAccessKey, _ := act.Lookup(decodedSavedLookupKey) + encryptedAccessKey, err := act.Lookup(ref, decodedSavedLookupKey) + if err != nil { + t.Errorf("Lookup: expected no error, got %v", err) + } decodedEncryptedAccessKey := hex.EncodeToString(encryptedAccessKey) // A random value is returned so it is only possibly to check the length of the returned value @@ -132,7 +137,6 @@ func TestAddPublisher(t *testing.T) { } func TestAdd_New_Grantee_To_Content(t *testing.T) { - al := setupAccessLogic2() id0 := generateFixPrivateKey(0) id1 := generateFixPrivateKey(1) @@ -143,17 +147,18 @@ func TestAdd_New_Grantee_To_Content(t *testing.T) { secondAddedGranteeLookupKey := "8fe8dff7cd15a6a0095c1b25071a5691e7c901fd0b95857a96c0e4659b48716a" act := dynamicaccess.NewInMemoryAct() - act, err := al.AddPublisher(act, &id0.PublicKey) - if err != nil { + al := setupAccessLogic2(act) + ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) + if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - act, err = al.AddNewGranteeToContent(act, &id0.PublicKey, &id1.PublicKey) + ref, err = al.AddNewGranteeToContent(ref, &id0.PublicKey, &id1.PublicKey) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - act, err = al.AddNewGranteeToContent(act, &id0.PublicKey, &id2.PublicKey) + ref, err = al.AddNewGranteeToContent(ref, &id0.PublicKey, &id2.PublicKey) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } @@ -162,7 +167,7 @@ func TestAdd_New_Grantee_To_Content(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ := act.Lookup(lookupKeyAsByte) + result, _ := act.Lookup(ref, lookupKeyAsByte) hexEncodedEncryptedAK := hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) @@ -172,7 +177,7 @@ func TestAdd_New_Grantee_To_Content(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ = act.Lookup(lookupKeyAsByte) + result, _ = act.Lookup(ref, lookupKeyAsByte) hexEncodedEncryptedAK = hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) @@ -182,7 +187,7 @@ func TestAdd_New_Grantee_To_Content(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ = act.Lookup(lookupKeyAsByte) + result, _ = act.Lookup(ref, lookupKeyAsByte) hexEncodedEncryptedAK = hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) @@ -193,17 +198,20 @@ func TestEncryptRef(t *testing.T) { ref := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" savedEncryptedRef := "230cdcfb2e67adddb2822b38f70105213ab3e4f97d03560bfbfbb218f487c5303e9aa9a97e62aa1a8003f162679e7c65e1c8e3aacaec2043fd5d2a4a7d69285e" - al := setupAccessLogic2() id0 := generateFixPrivateKey(0) act := dynamicaccess.NewInMemoryAct() + al := setupAccessLogic2(act) decodedLookupKey, err := hex.DecodeString("bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a") if err != nil { t.Errorf("EncryptRef: expected no error, got %v", err) } - act.Add(decodedLookupKey, []byte("42")) - - encryptedRefValue, err := al.EncryptRef(act, &id0.PublicKey, swarm.NewAddress([]byte(ref))) + addRef, err := act.Add(swarm.EmptyAddress, decodedLookupKey, []byte("42")) + if err != nil { + t.Errorf("Add: expected no error, got %v", err) + } + + encryptedRefValue, err := al.EncryptRef(addRef, &id0.PublicKey, swarm.NewAddress([]byte(ref))) if err != nil { t.Errorf("EncryptRef: expected no error, got %v", err) } @@ -211,4 +219,4 @@ func TestEncryptRef(t *testing.T) { if encryptedRefValue.String() != savedEncryptedRef { t.Errorf("EncryptRef: expected encrypted ref, got empty address") } -} \ No newline at end of file +} diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go index 1f1dbb85897..f7595b5b1ec 100644 --- a/pkg/dynamicaccess/act.go +++ b/pkg/dynamicaccess/act.go @@ -5,107 +5,61 @@ package dynamicaccess import ( - "crypto/rand" - "encoding/hex" - "fmt" - "sync" - - "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/pkg/kvs" + kvsmanifest "github.com/ethersphere/bee/pkg/kvs/manifest" + kvsmemory "github.com/ethersphere/bee/pkg/kvs/memory" "github.com/ethersphere/bee/pkg/swarm" ) -var lock = &sync.Mutex{} - -type single struct { - memoryMock map[string]manifest.Entry -} - -var singleInMemorySwarm *single - -func getInMemorySwarm() *single { - if singleInMemorySwarm == nil { - lock.Lock() - defer lock.Unlock() - if singleInMemorySwarm == nil { - singleInMemorySwarm = &single{ - memoryMock: make(map[string]manifest.Entry)} - } - } - return singleInMemorySwarm -} - -func getMemory() map[string]manifest.Entry { - ch := make(chan *single) - go func() { - ch <- getInMemorySwarm() - }() - mem := <-ch - return mem.memoryMock -} - // Act represents an interface for accessing and manipulating data. type Act interface { // Add adds a key-value pair to the data store. - Add(key []byte, val []byte) error + Add(rootHash swarm.Address, key []byte, val []byte) (swarm.Address, error) // Lookup retrieves the value associated with the given key from the data store. - Lookup(key []byte) ([]byte, error) + Lookup(rootHash swarm.Address, key []byte) ([]byte, error) // Load loads the data store from the given address. - Load(addr swarm.Address) error + //Load(addr swarm.Address) error // Store stores the current state of the data store and returns the address of the ACT. - Store() (swarm.Address, error) + //Store() (swarm.Address, error) } -var _ Act = (*inMemoryAct)(nil) - -// inMemoryAct is a simple implementation of the Act interface, with in memory storage. -type inMemoryAct struct { - container map[string]string +// inKvsAct is an implementation of the Act interface that uses kvs storage. +type inKvsAct struct { + storage kvs.KeyValueStore } -func (act *inMemoryAct) Add(key []byte, val []byte) error { - act.container[hex.EncodeToString(key)] = hex.EncodeToString(val) - return nil +// Add adds a key-value pair to the in-memory data store. +func (act *inKvsAct) Add(rootHash swarm.Address, key []byte, val []byte) (swarm.Address, error) { + return act.storage.Put(rootHash, key, val) } -func (act *inMemoryAct) Lookup(key []byte) ([]byte, error) { - if key, ok := act.container[hex.EncodeToString(key)]; ok { - bytes, err := hex.DecodeString(key) - if err != nil { - return nil, err - } - return bytes, nil - } - return nil, fmt.Errorf("key not found") +// Lookup retrieves the value associated with the given key from the in-memory data store. +func (act *inKvsAct) Lookup(rootHash swarm.Address, key []byte) ([]byte, error) { + return act.storage.Get(rootHash, key) } -func (act *inMemoryAct) Load(addr swarm.Address) error { - memory := getMemory() - me := memory[addr.String()] - if me == nil { - return fmt.Errorf("ACT not found at address: %s", addr.String()) +// NewInMemoryAct creates a new instance of the Act interface with in-memory storage. +func NewInMemoryAct() Act { + s, err := kvs.NewKeyValueStore(nil, kvsmemory.KvsTypeMemory) + if err != nil { + return nil } - act.container = me.Metadata() - return nil -} - -func (act *inMemoryAct) Store() (swarm.Address, error) { - // Generate a random swarm.Address - b := make([]byte, 32) - if _, err := rand.Read(b); err != nil { - return swarm.EmptyAddress, fmt.Errorf("failed to generate random address: %w", err) + return &inKvsAct{ + storage: s, } - swarm_ref := swarm.NewAddress(b) - mem := getMemory() - mem[swarm_ref.String()] = manifest.NewEntry(swarm_ref, act.container) - - return swarm_ref, nil } -func NewInMemoryAct() Act { - return &inMemoryAct{ - container: make(map[string]string), +// NewInManifestAct creates a new instance of the Act interface with manifest storage. +func NewInManifestAct(storer api.Storer) Act { + s, err := kvs.NewKeyValueStore(storer, kvsmanifest.KvsTypeManifest) + if err != nil { + return nil + } + return &inKvsAct{ + storage: s, } } diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go index 3480077102a..6522a76b9ed 100644 --- a/pkg/dynamicaccess/act_test.go +++ b/pkg/dynamicaccess/act_test.go @@ -10,24 +10,77 @@ import ( "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" + mockstorer "github.com/ethersphere/bee/pkg/storer/mock" "github.com/ethersphere/bee/pkg/swarm" ) +type ActType int + +const ( + Memory ActType = iota + Manifest +) + +func (a ActType) String() string { + return [...]string{"Memory", "Manifest"}[a] +} + +var mockStorer = mockstorer.New() + +var acts = map[ActType]func() dynamicaccess.Act{ + Memory: dynamicaccess.NewInMemoryAct, + Manifest: func() dynamicaccess.Act { return dynamicaccess.NewInManifestAct(mockStorer) }, +} + func TestActAddLookup(t *testing.T) { - act := dynamicaccess.NewInMemoryAct() - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - err := act.Add(lookupKey, encryptedAccesskey) - if err != nil { - t.Error("Add() should not return an error") + for actType, actCreate := range acts { + t.Logf("Running test for ActType: %s", actType) + act := actCreate() + + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + + ref, err := act.Add(swarm.EmptyAddress, lookupKey, encryptedAccesskey) + if err != nil { + t.Errorf("Add() should not return an error: %v", err) + } + + key, err := act.Lookup(ref, lookupKey) + if err != nil { + t.Errorf("Lookup() should not return an error: %v", err) + } + + if !bytes.Equal(key, encryptedAccesskey) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) + } } +} + +func TestActAddLookupWithNew(t *testing.T) { + for actType, actCreate := range acts { + t.Logf("Running test for ActType: %s", actType) + act1 := actCreate() + lookupKey := swarm.RandAddress(t).Bytes() + encryptedAccesskey := swarm.RandAddress(t).Bytes() + + ref, err := act1.Add(swarm.EmptyAddress, lookupKey, encryptedAccesskey) + if err != nil { + t.Fatalf("Add() should not return an error: %v", err) + } + + act2 := actCreate() + key, err := act2.Lookup(ref, lookupKey) + if err != nil { + t.Fatalf("Lookup() should not return an error: %v", err) + } - key, _ := act.Lookup(lookupKey) - if !bytes.Equal(key, encryptedAccesskey) { - t.Errorf("Get() value is not the expected %s != %s", key, encryptedAccesskey) + if !bytes.Equal(key, encryptedAccesskey) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) + } } } +/* func TestActStoreLoad(t *testing.T) { act := dynamicaccess.NewInMemoryAct() @@ -50,3 +103,4 @@ func TestActStoreLoad(t *testing.T) { t.Errorf("actualAct.Load() value is not the expected %s != %s", hex.EncodeToString(actualEak), hex.EncodeToString(encryptedAccesskey)) } } +*/ diff --git a/pkg/dynamicaccess/container.go b/pkg/dynamicaccess/container.go deleted file mode 100644 index ae683aa0fcd..00000000000 --- a/pkg/dynamicaccess/container.go +++ /dev/null @@ -1,7 +0,0 @@ -package dynamicaccess - -// iterator -type Container interface { - Add(oldItemKey string, oldRootHash string) (newRootHash string, err error) - Get(rootKey string) (value string, err error) -} diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index 92363014c9b..9ced8a4d873 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -18,23 +18,29 @@ type defaultController struct { } func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) { - act, err := c.history.Lookup(timestamp) + _, err := c.history.Lookup(timestamp) if err != nil { return swarm.EmptyAddress, err } - addr, err := c.accessLogic.Get(act, enryptedRef, publisher) + addr, err := c.accessLogic.Get(swarm.EmptyAddress, enryptedRef, publisher) return addr, err } func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { - act, _ := c.history.Lookup(0) + act, err := c.history.Lookup(0) + if err != nil { + return swarm.EmptyAddress, err + } + var actRef swarm.Address if act == nil { // new feed - act = NewInMemoryAct() - act = c.granteeManager.Publish(act, publisher, topic) + actRef, err = c.granteeManager.Publish(swarm.EmptyAddress, publisher, topic) + if err != nil { + return swarm.EmptyAddress, err + } } //FIXME: check if ACT is consistent with the grantee list - return c.accessLogic.EncryptRef(act, publisher, ref) + return c.accessLogic.EncryptRef(actRef, publisher, ref) } func NewController(history History, granteeManager GranteeManager, accessLogic ActLogic) Controller { diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index 531470eceee..8f876232b05 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -24,7 +24,7 @@ func mockTestHistory(key, val []byte) dynamicaccess.History { now = time.Now() act = dynamicaccess.NewInMemoryAct() ) - act.Add(key, val) + act.Add(swarm.EmptyAddress, key, val) h.Insert(now.AddDate(-3, 0, 0).Unix(), act) return h } diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index 6b287af6941..e6884f77bea 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -1,11 +1,15 @@ package dynamicaccess -import "crypto/ecdsa" +import ( + "crypto/ecdsa" + + "github.com/ethersphere/bee/pkg/swarm" +) type GranteeManager interface { Get(topic string) []*ecdsa.PublicKey Add(topic string, addList []*ecdsa.PublicKey) error - Publish(act Act, publisher *ecdsa.PublicKey, topic string) Act + Publish(rootHash swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) // HandleGrantees(topic string, addList, removeList []*ecdsa.PublicKey) *Act @@ -32,10 +36,10 @@ func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { return gm.granteeList.AddGrantees(topic, addList) } -func (gm *granteeManager) Publish(act Act, publisher *ecdsa.PublicKey, topic string) Act { - gm.accessLogic.AddPublisher(act, publisher) +func (gm *granteeManager) Publish(rootHash swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { + ref, err := gm.accessLogic.AddPublisher(rootHash, publisher) for _, grantee := range gm.granteeList.GetGrantees(topic) { - gm.accessLogic.AddNewGranteeToContent(act, publisher, grantee) + ref, err = gm.accessLogic.AddNewGranteeToContent(ref, publisher, grantee) } - return act + return ref, err } diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index fc5969f4492..2144fd1410a 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -8,21 +8,18 @@ import ( "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/swarm" ) func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.ActLogic { - // privateKey, err := crypto.GenerateSecp256k1Key() - // if err != nil { - // errors.New("error creating private key") - // } + act := dynamicaccess.NewInMemoryAct() si := dynamicaccess.NewDefaultSession(privateKey) - al := dynamicaccess.NewLogic(si) + al := dynamicaccess.NewLogic(si, act) return al } func TestAdd(t *testing.T) { - act := dynamicaccess.NewInMemoryAct() m := dynamicaccess.NewGranteeManager(setupAccessLogic(getPrivateKey())) pub, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) @@ -36,6 +33,6 @@ func TestAdd(t *testing.T) { if err != nil { t.Errorf("Add() returned an error") } - m.Publish(act, &pub.PublicKey, "topic") + m.Publish(swarm.EmptyAddress, &pub.PublicKey, "topic") fmt.Println("") } diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index a58aa44ecaa..e501e075697 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -7,6 +7,7 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" "github.com/ethersphere/bee/pkg/dynamicaccess/mock" + "github.com/ethersphere/bee/pkg/swarm" "github.com/stretchr/testify/assert" ) @@ -32,7 +33,7 @@ func TestHistoryLookup(t *testing.T) { for _, tt := range tests { t.Run("", func(t *testing.T) { actAt, _ := h.Lookup(tt.input) - output, _ := actAt.Lookup([]byte("key1")) + output, _ := actAt.Lookup(swarm.EmptyAddress, []byte("key1")) assert.Equal(t, output, hex.EncodeToString([]byte(tt.expected))) }) } @@ -46,9 +47,9 @@ func prepareTestHistory() dynamicaccess.History { act2 = dynamicaccess.NewInMemoryAct() act3 = dynamicaccess.NewInMemoryAct() ) - act1.Add([]byte("key1"), []byte("value1")) - act2.Add([]byte("key1"), []byte("value2")) - act3.Add([]byte("key1"), []byte("value3")) + act1.Add(swarm.EmptyAddress, []byte("key1"), []byte("value1")) + act2.Add(swarm.EmptyAddress, []byte("key1"), []byte("value2")) + act3.Add(swarm.EmptyAddress, []byte("key1"), []byte("value3")) h.Insert(now.AddDate(-3, 0, 0).Unix(), act1) h.Insert(now.AddDate(-2, 0, 0).Unix(), act2) diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go index a915f38f123..721a4778829 100644 --- a/pkg/dynamicaccess/mock/act.go +++ b/pkg/dynamicaccess/mock/act.go @@ -10,26 +10,26 @@ import ( ) type ActMock struct { - AddFunc func(key []byte, val []byte) error - LookupFunc func(key []byte) ([]byte, error) + AddFunc func(root swarm.Address, key []byte, val []byte) (swarm.Address, error) + LookupFunc func(root swarm.Address, key []byte) ([]byte, error) LoadFunc func(addr swarm.Address) error StoreFunc func() (swarm.Address, error) } var _ dynamicaccess.Act = (*ActMock)(nil) -func (act *ActMock) Add(key []byte, val []byte) error { +func (act *ActMock) Add(root swarm.Address, key []byte, val []byte) (swarm.Address, error) { if act.AddFunc == nil { - return nil + return swarm.EmptyAddress, nil } - return act.AddFunc(key, val) + return act.AddFunc(root, key, val) } -func (act *ActMock) Lookup(key []byte) ([]byte, error) { +func (act *ActMock) Lookup(root swarm.Address, key []byte) ([]byte, error) { if act.LookupFunc == nil { return make([]byte, 0), nil } - return act.LookupFunc(key) + return act.LookupFunc(root, key) } func (act *ActMock) Load(addr swarm.Address) error { @@ -46,7 +46,9 @@ func (act *ActMock) Store() (swarm.Address, error) { return act.StoreFunc() } -func NewActMock(addFunc func(key []byte, val []byte) error, getFunc func(key []byte) ([]byte, error)) dynamicaccess.Act { +func NewActMock( + addFunc func(swarm.Address, []byte, []byte) (swarm.Address, error), + getFunc func(swarm.Address, []byte) ([]byte, error)) dynamicaccess.Act { return &ActMock{ AddFunc: addFunc, LookupFunc: getFunc, diff --git a/pkg/kvs/kvs.go b/pkg/kvs/kvs.go new file mode 100644 index 00000000000..65c2a0be8b9 --- /dev/null +++ b/pkg/kvs/kvs.go @@ -0,0 +1,34 @@ +package kvs + +import ( + "errors" + + "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/pkg/kvs/manifest" + "github.com/ethersphere/bee/pkg/kvs/memory" + "github.com/ethersphere/bee/pkg/swarm" +) + +var ErrInvalidKvsType = errors.New("kvs: invalid type") + +type KeyValueStore interface { + Get(rootHash swarm.Address, key []byte) ([]byte, error) + Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) +} + +// func NewDefaultKeyValueStore(storer api.Storer) (KeyValueStore, error) { +// return NewKeyValueStore(storer, memory.KvsTypeMemory) +// } + +func NewKeyValueStore(storer api.Storer, kvsType string) (KeyValueStore, error) { + switch kvsType { + case "": + return memory.NewMemoryKeyValueStore() + case memory.KvsTypeMemory: + return memory.NewMemoryKeyValueStore() + case manifest.KvsTypeManifest: + return manifest.NewManifestKeyValueStore(storer) + default: + return nil, ErrInvalidKvsType + } +} diff --git a/pkg/kvs/manifest/kvs.go b/pkg/kvs/manifest/kvs.go new file mode 100644 index 00000000000..19ca983d54a --- /dev/null +++ b/pkg/kvs/manifest/kvs.go @@ -0,0 +1,86 @@ +package manifest + +import ( + "context" + "encoding/hex" + + "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/pkg/file/loadsave" + "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/pkg/file/redundancy" + "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/pkg/swarm" +) + +const ( + // KvsTypeManifest represents + KvsTypeManifest = "Manifest" +) + +type ManifestKeyValueStore interface { + Get(rootHash swarm.Address, key []byte) ([]byte, error) + Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) +} + +type manifestKeyValueStore struct { + storer api.Storer +} + +// TODO: pass context as dep. +func (m *manifestKeyValueStore) Get(rootHash swarm.Address, key []byte) ([]byte, error) { + ls := loadsave.NewReadonly(m.storer.ChunkStore()) + // existing manif + manif, err := manifest.NewSimpleManifestReference(rootHash, ls) + if err != nil { + return nil, err + } + entry, err := manif.Lookup(context.Background(), hex.EncodeToString(key)) + if err != nil { + return nil, err + } + ref := entry.Reference() + return ref.Bytes(), nil +} + +func (m *manifestKeyValueStore) Put(rootHash swarm.Address, key []byte, value []byte) (swarm.Address, error) { + factory := requestPipelineFactory(context.Background(), m.storer.Cache(), false, redundancy.NONE) + ls := loadsave.New(m.storer.ChunkStore(), m.storer.Cache(), factory) + // existing manif + manif, err := manifest.NewSimpleManifestReference(rootHash, ls) + if err != nil { + // new manif + manif, err = manifest.NewSimpleManifest(ls) + if err != nil { + return swarm.EmptyAddress, err + } + } + err = manif.Add(context.Background(), hex.EncodeToString(key), manifest.NewEntry(swarm.NewAddress(value), map[string]string{})) + if err != nil { + return swarm.EmptyAddress, err + } + manifRef, err := manif.Store(context.Background()) + if err != nil { + return swarm.EmptyAddress, err + } + + putter := m.storer.DirectUpload() + err = putter.Done(manifRef) + if err != nil { + return swarm.EmptyAddress, err + } + return manifRef, nil +} + +func NewManifestKeyValueStore(storer api.Storer) (ManifestKeyValueStore, error) { + return &manifestKeyValueStore{ + storer: storer, + }, nil +} + +func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { + return func() pipeline.Interface { + return builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) + } +} diff --git a/pkg/kvs/memory/kvs.go b/pkg/kvs/memory/kvs.go new file mode 100644 index 00000000000..3a1abc69c0e --- /dev/null +++ b/pkg/kvs/memory/kvs.go @@ -0,0 +1,67 @@ +package memory + +import ( + "encoding/hex" + "sync" + + "github.com/ethersphere/bee/pkg/swarm" +) + +const ( + // KvsTypeMemory represents + KvsTypeMemory = "Memory" +) + +type MemoryKeyValueStore interface { + Get(rootHash swarm.Address, key []byte) ([]byte, error) + Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) +} + +var lock = &sync.Mutex{} + +type single struct { + // TODO string -> []byte ? + memoryMock map[string][]byte +} + +var singleInMemorySwarm *single + +func getInMemorySwarm() *single { + if singleInMemorySwarm == nil { + lock.Lock() + defer lock.Unlock() + if singleInMemorySwarm == nil { + singleInMemorySwarm = &single{ + memoryMock: make(map[string][]byte)} + } + } + return singleInMemorySwarm +} + +func getMemory() map[string][]byte { + ch := make(chan *single) + go func() { + ch <- getInMemorySwarm() + }() + mem := <-ch + return mem.memoryMock +} + +type memoryKeyValueStore struct { +} + +func (m *memoryKeyValueStore) Get(rootHash swarm.Address, key []byte) ([]byte, error) { + mem := getMemory() + val := mem[hex.EncodeToString(key)] + return val, nil +} + +func (m *memoryKeyValueStore) Put(rootHash swarm.Address, key []byte, value []byte) (swarm.Address, error) { + mem := getMemory() + mem[hex.EncodeToString(key)] = value + return swarm.EmptyAddress, nil +} + +func NewMemoryKeyValueStore() (MemoryKeyValueStore, error) { + return &memoryKeyValueStore{}, nil +} From 0b0b29e2f15e5c4f35a8e4188225ee3097bf3e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Ujv=C3=A1ri?= <58116288+bosi95@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:53:35 +0100 Subject: [PATCH 14/22] Session refactor (#24) * pr comment fix * add comment to session.NewFromKeystore --- pkg/dynamicaccess/session.go | 9 ++++-- pkg/dynamicaccess/session_test.go | 51 ++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/pkg/dynamicaccess/session.go b/pkg/dynamicaccess/session.go index 9d7634ffd01..68cea8ccbfb 100644 --- a/pkg/dynamicaccess/session.go +++ b/pkg/dynamicaccess/session.go @@ -21,11 +21,15 @@ type session struct { } func (s *session) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { - x, _ := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes()) - if x == nil { + x, y := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes()) + if x == nil || y == nil { return nil, errors.New("shared secret is point at infinity") } + if len(nonces) == 0 { + return [][]byte{(*x).Bytes()}, nil + } + keys := make([][]byte, 0, len(nonces)) for _, nonce := range nonces { key, err := crypto.LegacyKeccak256(append(x.Bytes(), nonce...)) @@ -44,6 +48,7 @@ func NewDefaultSession(key *ecdsa.PrivateKey) Session { } } +// Currently implemented only in mock/session.go func NewFromKeystore(ks keystore.Service, tag, password string) Session { return nil } diff --git a/pkg/dynamicaccess/session_test.go b/pkg/dynamicaccess/session_test.go index 0cfee7691da..501d1abd2b6 100644 --- a/pkg/dynamicaccess/session_test.go +++ b/pkg/dynamicaccess/session_test.go @@ -52,9 +52,11 @@ func TestSessionKey(t *testing.T) { } si2 := dynamicaccess.NewDefaultSession(key2) - nonces := make([][]byte, 1) - if _, err := io.ReadFull(rand.Reader, nonces[0]); err != nil { - t.Fatal(err) + nonces := make([][]byte, 2) + for i := range nonces { + if _, err := io.ReadFull(rand.Reader, nonces[i]); err != nil { + t.Fatal(err) + } } keys1, err := si1.Key(&key2.PublicKey, nonces) @@ -66,6 +68,38 @@ func TestSessionKey(t *testing.T) { t.Fatal(err) } + if !bytes.Equal(keys1[0], keys2[0]) { + t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) + } + if !bytes.Equal(keys1[1], keys2[1]) { + t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) + } +} + +func TestSessionKeyWithoutNonces(t *testing.T) { + t.Parallel() + + key1, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + si1 := dynamicaccess.NewDefaultSession(key1) + + key2, err := crypto.GenerateSecp256k1Key() + if err != nil { + t.Fatal(err) + } + si2 := dynamicaccess.NewDefaultSession(key2) + + keys1, err := si1.Key(&key2.PublicKey, nil) + if err != nil { + t.Fatal(err) + } + keys2, err := si2.Key(&key1.PublicKey, nil) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(keys1[0], keys2[0]) { t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) } @@ -81,6 +115,7 @@ func TestSessionKeyFromKeystore(t *testing.T) { password2 := "password2" si1 := mock.NewFromKeystore(ks, tag1, password1, mockKeyFunc) + // si1 := dynamicaccess.NewFromKeystore(ks, tag1, password1) exists, err := ks.Exists(tag1) if err != nil { t.Fatal(err) @@ -97,6 +132,7 @@ func TestSessionKeyFromKeystore(t *testing.T) { } si2 := mock.NewFromKeystore(ks, tag2, password2, mockKeyFunc) + // si2 := dynamicaccess.NewFromKeystore(ks, tag2, password2) exists, err = ks.Exists(tag2) if err != nil { t.Fatal(err) @@ -113,8 +149,10 @@ func TestSessionKeyFromKeystore(t *testing.T) { } nonces := make([][]byte, 1) - if _, err := io.ReadFull(rand.Reader, nonces[0]); err != nil { - t.Fatal(err) + for i := range nonces { + if _, err := io.ReadFull(rand.Reader, nonces[i]); err != nil { + t.Fatal(err) + } } keys1, err := si1.Key(&key2.PublicKey, nonces) @@ -129,4 +167,7 @@ func TestSessionKeyFromKeystore(t *testing.T) { if !bytes.Equal(keys1[0], keys2[0]) { t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) } + // if !bytes.Equal(keys1[1], keys2[1]) { + // t.Fatalf("shared secrets do not match %s, %s", hex.EncodeToString(keys1[0]), hex.EncodeToString(keys2[0])) + // } } From 5a35a8e8dd9a96cf30af02f3ab69f721a07faf10 Mon Sep 17 00:00:00 2001 From: rolandlor <33499567+rolandlor@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:48:22 +0100 Subject: [PATCH 15/22] Access logic refactor (#25) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactors access logic --------- Co-authored-by: Peter Ott Co-authored-by: Ferenc Sárai Co-authored-by: Bálint Ujvári Co-authored-by: Peter Ott --- pkg/dynamicaccess/accesslogic.go | 121 +++++++++++--------------- pkg/dynamicaccess/accesslogic_test.go | 25 ++---- pkg/dynamicaccess/controller.go | 2 +- pkg/dynamicaccess/grantee.go | 23 +++-- pkg/dynamicaccess/grantee_manager.go | 10 +-- pkg/dynamicaccess/grantee_test.go | 18 ++-- pkg/dynamicaccess/session.go | 3 + 7 files changed, 90 insertions(+), 112 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 4b5abcd739e..591c9557a36 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -2,7 +2,6 @@ package dynamicaccess import ( "crypto/ecdsa" - "fmt" encryption "github.com/ethersphere/bee/pkg/encryption" "github.com/ethersphere/bee/pkg/swarm" @@ -11,44 +10,44 @@ import ( var hashFunc = sha3.NewLegacyKeccak256 -// Logic has the responsibility to return a ref for a given grantee and create new encrypted reference for a grantee -type Logic interface { +// Read-only interface for the ACT +type Decryptor interface { + // DecryptRef will return a decrypted reference, for given encrypted reference and grantee + DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) + // Embedding the Session interface + Session +} + +// Control interface for the ACT (does write operations) +type Control interface { + // Embedding the Decryptor interface + Decryptor // Adds a new grantee to the ACT - AddNewGranteeToContent(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey) (swarm.Address, error) - // Get will return a decrypted reference, for given encrypted reference and grantee - Get(rootHash swarm.Address, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) + AddGrantee(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) (swarm.Address, error) + // Encrypts a Swarm reference for a given grantee + EncryptRef(rootHash swarm.Address, grantee *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) } type ActLogic struct { - session Session - act Act + Session + act Act } -var _ Logic = (*ActLogic)(nil) +var _ Decryptor = (*ActLogic)(nil) // Adds a new publisher to an empty act func (al ActLogic) AddPublisher(rootHash swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) { accessKey := encryption.GenerateRandomKey(encryption.KeyLength) - keys, err := al.getKeys(publisher) - if err != nil { - return swarm.EmptyAddress, err - } - lookupKey := keys[0] - accessKeyEncryptionKey := keys[1] - - accessKeyCipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) - encryptedAccessKey, err := accessKeyCipher.Encrypt([]byte(accessKey)) - if err != nil { - return swarm.EmptyAddress, err - } - - return al.act.Add(rootHash, lookupKey, encryptedAccessKey) + return al.AddGrantee(rootHash, publisher, publisher, &accessKey) } // Encrypts a SWARM reference for a publisher func (al ActLogic) EncryptRef(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { - accessKey := al.getAccessKey(rootHash, publisherPubKey) + accessKey, err := al.getAccessKey(rootHash, publisherPubKey) + if err != nil { + return swarm.EmptyAddress, err + } refCipher := encryption.New(accessKey, 0, uint32(0), hashFunc) encryptedRef, _ := refCipher.Encrypt(ref.Bytes()) @@ -56,9 +55,20 @@ func (al ActLogic) EncryptRef(rootHash swarm.Address, publisherPubKey *ecdsa.Pub } // Adds a new grantee to the ACT -func (al ActLogic) AddNewGranteeToContent(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey) (swarm.Address, error) { - // Get previously generated access key - accessKey := al.getAccessKey(rootHash, publisherPubKey) +func (al ActLogic) AddGrantee(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKeyPointer *encryption.Key) (swarm.Address, error) { + var accessKey encryption.Key + var err error // Declare the "err" variable + + if accessKeyPointer == nil { + // Get previously generated access key + accessKey, err = al.getAccessKey(rootHash, publisherPubKey) + if err != nil { + return swarm.EmptyAddress, err + } + } else { + // This is a newly created access key, because grantee is publisher (they are the same) + accessKey = *accessKeyPointer + } // Encrypt the access key for the new Grantee keys, err := al.getKeys(granteePubKey) @@ -77,62 +87,37 @@ func (al ActLogic) AddNewGranteeToContent(rootHash swarm.Address, publisherPubKe // Add the new encrypted access key for the Act return al.act.Add(rootHash, lookupKey, granteeEncryptedAccessKey) - } // Will return the access key for a publisher (public key) -func (al *ActLogic) getAccessKey(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey) []byte { +func (al *ActLogic) getAccessKey(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey) ([]byte, error) { keys, err := al.getKeys(publisherPubKey) if err != nil { - return nil + return nil, err } publisherLookupKey := keys[0] publisherAKDecryptionKey := keys[1] - + // no need to constructor call if value not found in act accessKeyDecryptionCipher := encryption.New(encryption.Key(publisherAKDecryptionKey), 0, uint32(0), hashFunc) - encryptedAK, err := al.getEncryptedAccessKey(rootHash, publisherLookupKey) + encryptedAK, err := al.act.Lookup(rootHash, publisherLookupKey) if err != nil { - return nil + return nil, err } - accessKey, err := accessKeyDecryptionCipher.Decrypt(encryptedAK) - if err != nil { - return nil - } + return accessKeyDecryptionCipher.Decrypt(encryptedAK) - return accessKey } -func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { - // Generate lookup key and access key decryption - oneByteArray := []byte{1} - zeroByteArray := []byte{0} - - keys, err := al.session.Key(publicKey, [][]byte{zeroByteArray, oneByteArray}) - if err != nil { - return nil, err - } - return keys, nil -} +var oneByteArray = []byte{1} +var zeroByteArray = []byte{0} -// Gets the encrypted access key for a given grantee -func (al *ActLogic) getEncryptedAccessKey(rootHash swarm.Address, lookup_key []byte) ([]byte, error) { - val, err := al.act.Lookup(rootHash, lookup_key) - if err != nil { - return nil, err - } - return val, nil +// Generate lookup key and access key decryption key for a given public key +func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { + return al.Session.Key(publicKey, [][]byte{zeroByteArray, oneByteArray}) } -// Get will return a decrypted reference, for given encrypted reference and grantee -func (al ActLogic) Get(rootHash swarm.Address, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { - if encryped_ref.Compare(swarm.EmptyAddress) == 0 { - return swarm.EmptyAddress, fmt.Errorf("encrypted ref not provided") - } - if grantee == nil { - return swarm.EmptyAddress, fmt.Errorf("grantee not provided") - } - +// DecryptRef will return a decrypted reference, for given encrypted reference and grantee +func (al ActLogic) DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { keys, err := al.getKeys(grantee) if err != nil { return swarm.EmptyAddress, err @@ -141,7 +126,7 @@ func (al ActLogic) Get(rootHash swarm.Address, encryped_ref swarm.Address, grant accessKeyDecryptionKey := keys[1] // Lookup encrypted access key from the ACT manifest - encryptedAccessKey, err := al.getEncryptedAccessKey(rootHash, lookupKey) + encryptedAccessKey, err := al.act.Lookup(rootHash, lookupKey) if err != nil { return swarm.EmptyAddress, err } @@ -163,9 +148,9 @@ func (al ActLogic) Get(rootHash swarm.Address, encryped_ref swarm.Address, grant return swarm.NewAddress(ref), nil } -func NewLogic(s Session, act Act) ActLogic { +func NewLogic(S Session, act Act) ActLogic { return ActLogic{ - session: s, + Session: S, act: act, } } diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index b87bac84ffd..1a6da8af80b 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -39,7 +39,7 @@ func generateFixPrivateKey(input int64) ecdsa.PrivateKey { return privateKey } -func TestGet_Success(t *testing.T) { +func TestDecryptRef_Success(t *testing.T) { id0 := generateFixPrivateKey(0) var mockStorer = mockstorer.New() act := dynamicaccess.NewInManifestAct(mockStorer) @@ -61,7 +61,7 @@ func TestGet_Success(t *testing.T) { t.Error(err) } - acutalRef, err := al.Get(ref, encryptedRef, &id0.PublicKey) + acutalRef, err := al.DecryptRef(ref, encryptedRef, &id0.PublicKey) if err != nil { t.Errorf("There was an error while calling Get: ") t.Error(err) @@ -73,8 +73,7 @@ func TestGet_Success(t *testing.T) { } } -// This test function tests those cases where different parameters are missing -func TestGet_Error(t *testing.T) { +func TestDecryptRef_Error(t *testing.T) { id0 := generateFixPrivateKey(0) act := dynamicaccess.NewInMemoryAct() @@ -88,21 +87,11 @@ func TestGet_Error(t *testing.T) { encryptedRef, _ := al.EncryptRef(ref, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) - r, err := al.Get(swarm.RandAddress(t), encryptedRef, &id0.PublicKey) + r, err := al.DecryptRef(swarm.RandAddress(t), encryptedRef, nil) if err == nil { t.Logf("r: %s", r.String()) t.Errorf("Get should give back encrypted access key not found error!") } - - refTwo, _ := al.Get(swarm.RandAddress(t), swarm.EmptyAddress, &id0.PublicKey) - if swarm.EmptyAddress.Compare(refTwo) != 0 { - t.Errorf("Get should give back empty string if encrypted ref not provided!") - } - - _, err = al.Get(swarm.RandAddress(t), encryptedRef, nil) - if err == nil { - t.Errorf("Get should give back error if grantee not provided!") - } } func TestAddPublisher(t *testing.T) { @@ -136,7 +125,7 @@ func TestAddPublisher(t *testing.T) { } } -func TestAdd_New_Grantee_To_Content(t *testing.T) { +func TestAddNewGranteeToContent(t *testing.T) { id0 := generateFixPrivateKey(0) id1 := generateFixPrivateKey(1) @@ -153,12 +142,12 @@ func TestAdd_New_Grantee_To_Content(t *testing.T) { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - ref, err = al.AddNewGranteeToContent(ref, &id0.PublicKey, &id1.PublicKey) + ref, err = al.AddGrantee(ref, &id0.PublicKey, &id1.PublicKey, nil) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - ref, err = al.AddNewGranteeToContent(ref, &id0.PublicKey, &id2.PublicKey) + ref, err = al.AddGrantee(ref, &id0.PublicKey, &id2.PublicKey, nil) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index 9ced8a4d873..b1c6e306934 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -22,7 +22,7 @@ func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.A if err != nil { return swarm.EmptyAddress, err } - addr, err := c.accessLogic.Get(swarm.EmptyAddress, enryptedRef, publisher) + addr, err := c.accessLogic.DecryptRef(swarm.EmptyAddress, enryptedRef, publisher) return addr, err } diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index dfd7015e49f..d85ebf217ea 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -4,29 +4,29 @@ import ( "crypto/ecdsa" ) -type Grantee interface { - AddGrantees(topic string, addList []*ecdsa.PublicKey) error - RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error - GetGrantees(topic string) []*ecdsa.PublicKey +type GranteeList interface { + Add(topic string, addList []*ecdsa.PublicKey) error + Remove(topic string, removeList []*ecdsa.PublicKey) error + Get(topic string) []*ecdsa.PublicKey } -type defaultGrantee struct { +type GranteeListStruct struct { grantees map[string][]*ecdsa.PublicKey } -func (g *defaultGrantee) GetGrantees(topic string) []*ecdsa.PublicKey { +func (g *GranteeListStruct) Get(topic string) []*ecdsa.PublicKey { grantees := g.grantees[topic] keys := make([]*ecdsa.PublicKey, len(grantees)) copy(keys, grantees) return keys } -func (g *defaultGrantee) AddGrantees(topic string, addList []*ecdsa.PublicKey) error { +func (g *GranteeListStruct) Add(topic string, addList []*ecdsa.PublicKey) error { g.grantees[topic] = append(g.grantees[topic], addList...) return nil } -func (g *defaultGrantee) RemoveGrantees(topic string, removeList []*ecdsa.PublicKey) error { +func (g *GranteeListStruct) Remove(topic string, removeList []*ecdsa.PublicKey) error { for _, remove := range removeList { for i, grantee := range g.grantees[topic] { if *grantee == *remove { @@ -36,10 +36,9 @@ func (g *defaultGrantee) RemoveGrantees(topic string, removeList []*ecdsa.Public } } - return nil } -func NewGrantee() Grantee { - return &defaultGrantee{grantees: make(map[string][]*ecdsa.PublicKey)} -} \ No newline at end of file +func NewGrantee() *GranteeListStruct { + return &GranteeListStruct{grantees: make(map[string][]*ecdsa.PublicKey)} +} diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index e6884f77bea..0627db9794a 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -21,7 +21,7 @@ var _ GranteeManager = (*granteeManager)(nil) type granteeManager struct { accessLogic ActLogic - granteeList Grantee + granteeList GranteeList } func NewGranteeManager(al ActLogic) *granteeManager { @@ -29,17 +29,17 @@ func NewGranteeManager(al ActLogic) *granteeManager { } func (gm *granteeManager) Get(topic string) []*ecdsa.PublicKey { - return gm.granteeList.GetGrantees(topic) + return gm.granteeList.Get(topic) } func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { - return gm.granteeList.AddGrantees(topic, addList) + return gm.granteeList.Add(topic, addList) } func (gm *granteeManager) Publish(rootHash swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { ref, err := gm.accessLogic.AddPublisher(rootHash, publisher) - for _, grantee := range gm.granteeList.GetGrantees(topic) { - ref, err = gm.accessLogic.AddNewGranteeToContent(ref, publisher, grantee) + for _, grantee := range gm.granteeList.Get(topic) { + ref, err = gm.accessLogic.AddGrantee(ref, publisher, grantee, nil) } return ref, err } diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 7418a741d77..7962690ccb4 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -10,6 +10,8 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" ) +var _ dynamicaccess.GranteeList = (*dynamicaccess.GranteeListStruct)(nil) + func TestGranteeAddGrantees(t *testing.T) { grantee := dynamicaccess.NewGrantee() @@ -25,13 +27,13 @@ func TestGranteeAddGrantees(t *testing.T) { addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} exampleTopic := "topic" - err = grantee.AddGrantees(exampleTopic, addList) + err = grantee.Add(exampleTopic, addList) if err != nil { t.Errorf("Expected no error, got %v", err) } - grantees := grantee.GetGrantees(exampleTopic) + grantees := grantee.Get(exampleTopic) if !reflect.DeepEqual(grantees, addList) { t.Errorf("Expected grantees %v, got %v", addList, grantees) } @@ -52,18 +54,18 @@ func TestRemoveGrantees(t *testing.T) { addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} exampleTopic := "topic" - err = grantee.AddGrantees(exampleTopic, addList) + err = grantee.Add(exampleTopic, addList) if err != nil { t.Errorf("Expected no error, got %v", err) } removeList := []*ecdsa.PublicKey{&key1.PublicKey} - err = grantee.RemoveGrantees(exampleTopic, removeList) + err = grantee.Remove(exampleTopic, removeList) if err != nil { t.Errorf("Expected no error, got %v", err) } - grantees := grantee.GetGrantees(exampleTopic) + grantees := grantee.Get(exampleTopic) expectedGrantees := []*ecdsa.PublicKey{&key2.PublicKey} for i, grantee := range grantees { @@ -88,15 +90,15 @@ func TestGetGrantees(t *testing.T) { addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} exampleTopic := "topic" - err = grantee.AddGrantees(exampleTopic, addList) + err = grantee.Add(exampleTopic, addList) if err != nil { t.Errorf("Expected no error, got %v", err) } - grantees := grantee.GetGrantees(exampleTopic) + grantees := grantee.Get(exampleTopic) for i, grantee := range grantees { if grantee != addList[i] { t.Errorf("Expected grantee %v, got %v", addList[i], grantee) } } -} \ No newline at end of file +} diff --git a/pkg/dynamicaccess/session.go b/pkg/dynamicaccess/session.go index 68cea8ccbfb..b2718aedd67 100644 --- a/pkg/dynamicaccess/session.go +++ b/pkg/dynamicaccess/session.go @@ -21,6 +21,9 @@ type session struct { } func (s *session) Key(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { + if publicKey == nil { + return nil, errors.New("invalid public key") + } x, y := publicKey.Curve.ScalarMult(publicKey.X, publicKey.Y, s.key.D.Bytes()) if x == nil || y == nil { return nil, errors.New("shared secret is point at infinity") From 85b97b49af1bde058e3e42535f8444c302b1596f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Wed, 27 Mar 2024 09:00:12 +0100 Subject: [PATCH 16/22] (refactor:) PR comments (#23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * grantee-refactor * Dried up code, related to AddPublisher - AddNewGranteeToContent * Refactor * removed getEncryptedAccessKey * Renamed AddGrentees, RemoveGrantees, etc to Add, Remove, etc * (refactor:) PR comments * (refactor:) compile check * removed encrypted_ref, grantee check (validation) * changed interface * comments * some more comments * refactor kvs and add load and store * (refactor:) Use ref * renamed defaultGrantee to granteeList * removed null encrypted test in in TestGet_Error * refactor kvs: pass kvs IF argument instead of storing it * Refactor according to the result of the workshop * refactor kvs IF and mock * fix merge errors and Logic/get_error test * (test:) Add test for put/get after kvs.Save --------- Co-authored-by: Roland Seres Co-authored-by: Peter Ott Co-authored-by: Ferenc Sárai Co-authored-by: Bálint Ujvári Co-authored-by: Peter Ott --- pkg/dynamicaccess/accesslogic.go | 39 ++++--- pkg/dynamicaccess/accesslogic_test.go | 81 +++++-------- pkg/dynamicaccess/act.go | 65 ----------- pkg/dynamicaccess/act_test.go | 106 ----------------- pkg/dynamicaccess/controller.go | 18 +-- pkg/dynamicaccess/controller_test.go | 7 +- pkg/dynamicaccess/grantee_manager.go | 11 +- pkg/dynamicaccess/grantee_manager_test.go | 8 +- pkg/dynamicaccess/history.go | 17 +-- pkg/dynamicaccess/history_test.go | 28 ++--- pkg/dynamicaccess/mock/act.go | 56 --------- pkg/dynamicaccess/mock/history.go | 14 +-- pkg/kvs/kvs.go | 80 +++++++++---- pkg/kvs/kvs_test.go | 132 ++++++++++++++++++++++ pkg/kvs/manifest/kvs.go | 86 -------------- pkg/kvs/{memory => mock}/kvs.go | 31 +++-- 16 files changed, 304 insertions(+), 475 deletions(-) delete mode 100644 pkg/dynamicaccess/act.go delete mode 100644 pkg/dynamicaccess/act_test.go delete mode 100644 pkg/dynamicaccess/mock/act.go create mode 100644 pkg/kvs/kvs_test.go delete mode 100644 pkg/kvs/manifest/kvs.go rename pkg/kvs/{memory => mock}/kvs.go (55%) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 591c9557a36..ad33ba5eb16 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" encryption "github.com/ethersphere/bee/pkg/encryption" + "github.com/ethersphere/bee/pkg/kvs" "github.com/ethersphere/bee/pkg/swarm" "golang.org/x/crypto/sha3" ) @@ -13,7 +14,7 @@ var hashFunc = sha3.NewLegacyKeccak256 // Read-only interface for the ACT type Decryptor interface { // DecryptRef will return a decrypted reference, for given encrypted reference and grantee - DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) + DecryptRef(storage kvs.KeyValueStore, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) // Embedding the Session interface Session } @@ -23,28 +24,27 @@ type Control interface { // Embedding the Decryptor interface Decryptor // Adds a new grantee to the ACT - AddGrantee(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) (swarm.Address, error) + AddGrantee(storage kvs.KeyValueStore, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) error // Encrypts a Swarm reference for a given grantee - EncryptRef(rootHash swarm.Address, grantee *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) + EncryptRef(storage kvs.KeyValueStore, grantee *ecdsa.PublicKey, ref swarm.Address) error } type ActLogic struct { Session - act Act } var _ Decryptor = (*ActLogic)(nil) // Adds a new publisher to an empty act -func (al ActLogic) AddPublisher(rootHash swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) { +func (al ActLogic) AddPublisher(storage kvs.KeyValueStore, publisher *ecdsa.PublicKey) error { accessKey := encryption.GenerateRandomKey(encryption.KeyLength) - return al.AddGrantee(rootHash, publisher, publisher, &accessKey) + return al.AddGrantee(storage, publisher, publisher, &accessKey) } // Encrypts a SWARM reference for a publisher -func (al ActLogic) EncryptRef(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { - accessKey, err := al.getAccessKey(rootHash, publisherPubKey) +func (al ActLogic) EncryptRef(storage kvs.KeyValueStore, publisherPubKey *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) { + accessKey, err := al.getAccessKey(storage, publisherPubKey) if err != nil { return swarm.EmptyAddress, err } @@ -55,15 +55,15 @@ func (al ActLogic) EncryptRef(rootHash swarm.Address, publisherPubKey *ecdsa.Pub } // Adds a new grantee to the ACT -func (al ActLogic) AddGrantee(rootHash swarm.Address, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKeyPointer *encryption.Key) (swarm.Address, error) { +func (al ActLogic) AddGrantee(storage kvs.KeyValueStore, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKeyPointer *encryption.Key) error { var accessKey encryption.Key var err error // Declare the "err" variable if accessKeyPointer == nil { // Get previously generated access key - accessKey, err = al.getAccessKey(rootHash, publisherPubKey) + accessKey, err = al.getAccessKey(storage, publisherPubKey) if err != nil { - return swarm.EmptyAddress, err + return err } } else { // This is a newly created access key, because grantee is publisher (they are the same) @@ -73,7 +73,7 @@ func (al ActLogic) AddGrantee(rootHash swarm.Address, publisherPubKey, granteePu // Encrypt the access key for the new Grantee keys, err := al.getKeys(granteePubKey) if err != nil { - return swarm.EmptyAddress, err + return err } lookupKey := keys[0] accessKeyEncryptionKey := keys[1] @@ -82,15 +82,15 @@ func (al ActLogic) AddGrantee(rootHash swarm.Address, publisherPubKey, granteePu cipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) granteeEncryptedAccessKey, err := cipher.Encrypt(accessKey) if err != nil { - return swarm.EmptyAddress, err + return err } // Add the new encrypted access key for the Act - return al.act.Add(rootHash, lookupKey, granteeEncryptedAccessKey) + return storage.Put(lookupKey, granteeEncryptedAccessKey) } // Will return the access key for a publisher (public key) -func (al *ActLogic) getAccessKey(rootHash swarm.Address, publisherPubKey *ecdsa.PublicKey) ([]byte, error) { +func (al *ActLogic) getAccessKey(storage kvs.KeyValueStore, publisherPubKey *ecdsa.PublicKey) ([]byte, error) { keys, err := al.getKeys(publisherPubKey) if err != nil { return nil, err @@ -99,7 +99,7 @@ func (al *ActLogic) getAccessKey(rootHash swarm.Address, publisherPubKey *ecdsa. publisherAKDecryptionKey := keys[1] // no need to constructor call if value not found in act accessKeyDecryptionCipher := encryption.New(encryption.Key(publisherAKDecryptionKey), 0, uint32(0), hashFunc) - encryptedAK, err := al.act.Lookup(rootHash, publisherLookupKey) + encryptedAK, err := storage.Get(publisherLookupKey) if err != nil { return nil, err } @@ -117,7 +117,7 @@ func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { } // DecryptRef will return a decrypted reference, for given encrypted reference and grantee -func (al ActLogic) DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { +func (al ActLogic) DecryptRef(storage kvs.KeyValueStore, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { keys, err := al.getKeys(grantee) if err != nil { return swarm.EmptyAddress, err @@ -126,7 +126,7 @@ func (al ActLogic) DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address accessKeyDecryptionKey := keys[1] // Lookup encrypted access key from the ACT manifest - encryptedAccessKey, err := al.act.Lookup(rootHash, lookupKey) + encryptedAccessKey, err := storage.Get(lookupKey) if err != nil { return swarm.EmptyAddress, err } @@ -148,9 +148,8 @@ func (al ActLogic) DecryptRef(rootHash swarm.Address, encryped_ref swarm.Address return swarm.NewAddress(ref), nil } -func NewLogic(S Session, act Act) ActLogic { +func NewLogic(S Session) ActLogic { return ActLogic{ Session: S, - act: act, } } diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index 1a6da8af80b..cb5ff0a6c78 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -8,15 +8,15 @@ import ( "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" + kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" "github.com/ethersphere/bee/pkg/swarm" ) // Generates a new test environment with a fix private key -func setupAccessLogic2(act dynamicaccess.Act) dynamicaccess.ActLogic { +func setupAccessLogic2() dynamicaccess.ActLogic { privateKey := generateFixPrivateKey(1000) diffieHellman := dynamicaccess.NewDefaultSession(&privateKey) - al := dynamicaccess.NewLogic(diffieHellman, act) + al := dynamicaccess.NewLogic(diffieHellman) return al } @@ -41,10 +41,9 @@ func generateFixPrivateKey(input int64) ecdsa.PrivateKey { func TestDecryptRef_Success(t *testing.T) { id0 := generateFixPrivateKey(0) - var mockStorer = mockstorer.New() - act := dynamicaccess.NewInManifestAct(mockStorer) - al := setupAccessLogic2(act) - ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) + s := kvsmock.New() + al := setupAccessLogic2() + err := al.AddPublisher(s, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } @@ -54,14 +53,14 @@ func TestDecryptRef_Success(t *testing.T) { expectedRef := swarm.NewAddress(byteRef) t.Logf("encryptedRef: %s", expectedRef.String()) - encryptedRef, err := al.EncryptRef(ref, &id0.PublicKey, expectedRef) + encryptedRef, err := al.EncryptRef(s, &id0.PublicKey, expectedRef) t.Logf("encryptedRef: %s", encryptedRef.String()) if err != nil { t.Errorf("There was an error while calling EncryptRef: ") t.Error(err) } - acutalRef, err := al.DecryptRef(ref, encryptedRef, &id0.PublicKey) + acutalRef, err := al.DecryptRef(s, encryptedRef, &id0.PublicKey) if err != nil { t.Errorf("There was an error while calling Get: ") t.Error(err) @@ -76,18 +75,18 @@ func TestDecryptRef_Success(t *testing.T) { func TestDecryptRef_Error(t *testing.T) { id0 := generateFixPrivateKey(0) - act := dynamicaccess.NewInMemoryAct() - al := setupAccessLogic2(act) - ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) + s := kvsmock.New() + al := setupAccessLogic2() + err := al.AddPublisher(s, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } expectedRef := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" - encryptedRef, _ := al.EncryptRef(ref, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) + encryptedRef, _ := al.EncryptRef(s, &id0.PublicKey, swarm.NewAddress([]byte(expectedRef))) - r, err := al.DecryptRef(swarm.RandAddress(t), encryptedRef, nil) + r, err := al.DecryptRef(s, encryptedRef, nil) if err == nil { t.Logf("r: %s", r.String()) t.Errorf("Get should give back encrypted access key not found error!") @@ -97,9 +96,10 @@ func TestDecryptRef_Error(t *testing.T) { func TestAddPublisher(t *testing.T) { id0 := generateFixPrivateKey(0) savedLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" - act := dynamicaccess.NewInMemoryAct() - al := setupAccessLogic2(act) - ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) + s := kvsmock.New() + + al := setupAccessLogic2() + err := al.AddPublisher(s, &id0.PublicKey) if err != nil { t.Errorf("AddPublisher: expected no error, got %v", err) } @@ -109,7 +109,7 @@ func TestAddPublisher(t *testing.T) { t.Errorf("DecodeString: expected no error, got %v", err) } - encryptedAccessKey, err := act.Lookup(ref, decodedSavedLookupKey) + encryptedAccessKey, err := s.Get(decodedSavedLookupKey) if err != nil { t.Errorf("Lookup: expected no error, got %v", err) } @@ -120,7 +120,7 @@ func TestAddPublisher(t *testing.T) { if len(decodedEncryptedAccessKey) != 64 { t.Errorf("AddPublisher: expected encrypted access key length 64, got %d", len(decodedEncryptedAccessKey)) } - if act == nil { + if s == nil { t.Errorf("AddPublisher: expected act, got nil") } } @@ -135,19 +135,19 @@ func TestAddNewGranteeToContent(t *testing.T) { firstAddedGranteeLookupKey := "e221a2abf64357260e8f2c937ee938aed98dce097e537c1a3fd4caf73510dbe4" secondAddedGranteeLookupKey := "8fe8dff7cd15a6a0095c1b25071a5691e7c901fd0b95857a96c0e4659b48716a" - act := dynamicaccess.NewInMemoryAct() - al := setupAccessLogic2(act) - ref, err := al.AddPublisher(swarm.EmptyAddress, &id0.PublicKey) + s := kvsmock.New() + al := setupAccessLogic2() + err := al.AddPublisher(s, &id0.PublicKey) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - ref, err = al.AddGrantee(ref, &id0.PublicKey, &id1.PublicKey, nil) + err = al.AddGrantee(s, &id0.PublicKey, &id1.PublicKey, nil) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - ref, err = al.AddGrantee(ref, &id0.PublicKey, &id2.PublicKey, nil) + err = al.AddGrantee(s, &id0.PublicKey, &id2.PublicKey, nil) if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } @@ -156,7 +156,7 @@ func TestAddNewGranteeToContent(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ := act.Lookup(ref, lookupKeyAsByte) + result, _ := s.Get(lookupKeyAsByte) hexEncodedEncryptedAK := hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) @@ -166,7 +166,7 @@ func TestAddNewGranteeToContent(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ = act.Lookup(ref, lookupKeyAsByte) + result, _ = s.Get(lookupKeyAsByte) hexEncodedEncryptedAK = hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) @@ -176,36 +176,9 @@ func TestAddNewGranteeToContent(t *testing.T) { if err != nil { t.Errorf("AddNewGrantee: expected no error, got %v", err) } - result, _ = act.Lookup(ref, lookupKeyAsByte) + result, _ = s.Get(lookupKeyAsByte) hexEncodedEncryptedAK = hex.EncodeToString(result) if len(hexEncodedEncryptedAK) != 64 { t.Errorf("AddNewGrantee: expected encrypted access key length 64, got %d", len(hexEncodedEncryptedAK)) } } - -func TestEncryptRef(t *testing.T) { - ref := "39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559" - savedEncryptedRef := "230cdcfb2e67adddb2822b38f70105213ab3e4f97d03560bfbfbb218f487c5303e9aa9a97e62aa1a8003f162679e7c65e1c8e3aacaec2043fd5d2a4a7d69285e" - - id0 := generateFixPrivateKey(0) - act := dynamicaccess.NewInMemoryAct() - al := setupAccessLogic2(act) - decodedLookupKey, err := hex.DecodeString("bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a") - if err != nil { - t.Errorf("EncryptRef: expected no error, got %v", err) - } - - addRef, err := act.Add(swarm.EmptyAddress, decodedLookupKey, []byte("42")) - if err != nil { - t.Errorf("Add: expected no error, got %v", err) - } - - encryptedRefValue, err := al.EncryptRef(addRef, &id0.PublicKey, swarm.NewAddress([]byte(ref))) - if err != nil { - t.Errorf("EncryptRef: expected no error, got %v", err) - } - - if encryptedRefValue.String() != savedEncryptedRef { - t.Errorf("EncryptRef: expected encrypted ref, got empty address") - } -} diff --git a/pkg/dynamicaccess/act.go b/pkg/dynamicaccess/act.go deleted file mode 100644 index f7595b5b1ec..00000000000 --- a/pkg/dynamicaccess/act.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2024 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 dynamicaccess - -import ( - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/kvs" - kvsmanifest "github.com/ethersphere/bee/pkg/kvs/manifest" - kvsmemory "github.com/ethersphere/bee/pkg/kvs/memory" - "github.com/ethersphere/bee/pkg/swarm" -) - -// Act represents an interface for accessing and manipulating data. -type Act interface { - // Add adds a key-value pair to the data store. - Add(rootHash swarm.Address, key []byte, val []byte) (swarm.Address, error) - - // Lookup retrieves the value associated with the given key from the data store. - Lookup(rootHash swarm.Address, key []byte) ([]byte, error) - - // Load loads the data store from the given address. - //Load(addr swarm.Address) error - - // Store stores the current state of the data store and returns the address of the ACT. - //Store() (swarm.Address, error) -} - -// inKvsAct is an implementation of the Act interface that uses kvs storage. -type inKvsAct struct { - storage kvs.KeyValueStore -} - -// Add adds a key-value pair to the in-memory data store. -func (act *inKvsAct) Add(rootHash swarm.Address, key []byte, val []byte) (swarm.Address, error) { - return act.storage.Put(rootHash, key, val) -} - -// Lookup retrieves the value associated with the given key from the in-memory data store. -func (act *inKvsAct) Lookup(rootHash swarm.Address, key []byte) ([]byte, error) { - return act.storage.Get(rootHash, key) -} - -// NewInMemoryAct creates a new instance of the Act interface with in-memory storage. -func NewInMemoryAct() Act { - s, err := kvs.NewKeyValueStore(nil, kvsmemory.KvsTypeMemory) - if err != nil { - return nil - } - return &inKvsAct{ - storage: s, - } -} - -// NewInManifestAct creates a new instance of the Act interface with manifest storage. -func NewInManifestAct(storer api.Storer) Act { - s, err := kvs.NewKeyValueStore(storer, kvsmanifest.KvsTypeManifest) - if err != nil { - return nil - } - return &inKvsAct{ - storage: s, - } -} diff --git a/pkg/dynamicaccess/act_test.go b/pkg/dynamicaccess/act_test.go deleted file mode 100644 index 6522a76b9ed..00000000000 --- a/pkg/dynamicaccess/act_test.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2024 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 dynamicaccess_test - -import ( - "bytes" - "encoding/hex" - "testing" - - "github.com/ethersphere/bee/pkg/dynamicaccess" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" -) - -type ActType int - -const ( - Memory ActType = iota - Manifest -) - -func (a ActType) String() string { - return [...]string{"Memory", "Manifest"}[a] -} - -var mockStorer = mockstorer.New() - -var acts = map[ActType]func() dynamicaccess.Act{ - Memory: dynamicaccess.NewInMemoryAct, - Manifest: func() dynamicaccess.Act { return dynamicaccess.NewInManifestAct(mockStorer) }, -} - -func TestActAddLookup(t *testing.T) { - for actType, actCreate := range acts { - t.Logf("Running test for ActType: %s", actType) - act := actCreate() - - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - - ref, err := act.Add(swarm.EmptyAddress, lookupKey, encryptedAccesskey) - if err != nil { - t.Errorf("Add() should not return an error: %v", err) - } - - key, err := act.Lookup(ref, lookupKey) - if err != nil { - t.Errorf("Lookup() should not return an error: %v", err) - } - - if !bytes.Equal(key, encryptedAccesskey) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) - } - } -} - -func TestActAddLookupWithNew(t *testing.T) { - for actType, actCreate := range acts { - t.Logf("Running test for ActType: %s", actType) - act1 := actCreate() - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - - ref, err := act1.Add(swarm.EmptyAddress, lookupKey, encryptedAccesskey) - if err != nil { - t.Fatalf("Add() should not return an error: %v", err) - } - - act2 := actCreate() - key, err := act2.Lookup(ref, lookupKey) - if err != nil { - t.Fatalf("Lookup() should not return an error: %v", err) - } - - if !bytes.Equal(key, encryptedAccesskey) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) - } - } -} - -/* -func TestActStoreLoad(t *testing.T) { - - act := dynamicaccess.NewInMemoryAct() - lookupKey := swarm.RandAddress(t).Bytes() - encryptedAccesskey := swarm.RandAddress(t).Bytes() - err := act.Add(lookupKey, encryptedAccesskey) - if err != nil { - t.Error("Add() should not return an error") - } - - swarm_ref, err := act.Store() - if err != nil { - t.Error("Store() should not return an error") - } - - actualAct := dynamicaccess.NewInMemoryAct() - actualAct.Load(swarm_ref) - actualEak, _ := actualAct.Lookup(lookupKey) - if !bytes.Equal(actualEak, encryptedAccesskey) { - t.Errorf("actualAct.Load() value is not the expected %s != %s", hex.EncodeToString(actualEak), hex.EncodeToString(encryptedAccesskey)) - } -} -*/ diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index b1c6e306934..d118e22489f 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -3,6 +3,7 @@ package dynamicaccess import ( "crypto/ecdsa" + kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" "github.com/ethersphere/bee/pkg/swarm" ) @@ -18,29 +19,30 @@ type defaultController struct { } func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) { - _, err := c.history.Lookup(timestamp) + kvs, err := c.history.Lookup(timestamp) if err != nil { return swarm.EmptyAddress, err } - addr, err := c.accessLogic.DecryptRef(swarm.EmptyAddress, enryptedRef, publisher) + addr, err := c.accessLogic.DecryptRef(kvs, enryptedRef, publisher) return addr, err } func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { - act, err := c.history.Lookup(0) + kvs, err := c.history.Lookup(0) if err != nil { return swarm.EmptyAddress, err } - var actRef swarm.Address - if act == nil { + if kvs == nil { // new feed - actRef, err = c.granteeManager.Publish(swarm.EmptyAddress, publisher, topic) + // TODO: putter session to create kvs + kvs = kvsmock.New() + _, err = c.granteeManager.Publish(kvs, publisher, topic) if err != nil { return swarm.EmptyAddress, err } } - //FIXME: check if ACT is consistent with the grantee list - return c.accessLogic.EncryptRef(actRef, publisher, ref) + //FIXME: check if kvs is consistent with the grantee list + return c.accessLogic.EncryptRef(kvs, publisher, ref) } func NewController(history History, granteeManager GranteeManager, accessLogic ActLogic) Controller { diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index 8f876232b05..63f80059e08 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -12,6 +12,7 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" "github.com/ethersphere/bee/pkg/dynamicaccess/mock" "github.com/ethersphere/bee/pkg/encryption" + kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" "github.com/ethersphere/bee/pkg/swarm" "golang.org/x/crypto/sha3" ) @@ -22,10 +23,10 @@ func mockTestHistory(key, val []byte) dynamicaccess.History { var ( h = mock.NewHistory() now = time.Now() - act = dynamicaccess.NewInMemoryAct() + s = kvsmock.New() ) - act.Add(swarm.EmptyAddress, key, val) - h.Insert(now.AddDate(-3, 0, 0).Unix(), act) + _ = s.Put(key, val) + h.Insert(now.AddDate(-3, 0, 0).Unix(), s) return h } diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index 0627db9794a..004a933b006 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -3,13 +3,14 @@ package dynamicaccess import ( "crypto/ecdsa" + "github.com/ethersphere/bee/pkg/kvs" "github.com/ethersphere/bee/pkg/swarm" ) type GranteeManager interface { Get(topic string) []*ecdsa.PublicKey Add(topic string, addList []*ecdsa.PublicKey) error - Publish(rootHash swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) + Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) // HandleGrantees(topic string, addList, removeList []*ecdsa.PublicKey) *Act @@ -36,10 +37,10 @@ func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { return gm.granteeList.Add(topic, addList) } -func (gm *granteeManager) Publish(rootHash swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { - ref, err := gm.accessLogic.AddPublisher(rootHash, publisher) +func (gm *granteeManager) Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { + err := gm.accessLogic.AddPublisher(kvs, publisher) for _, grantee := range gm.granteeList.Get(topic) { - ref, err = gm.accessLogic.AddGrantee(ref, publisher, grantee, nil) + err = gm.accessLogic.AddGrantee(kvs, publisher, grantee, nil) } - return ref, err + return swarm.EmptyAddress, err } diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index 2144fd1410a..7ac43425e10 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -8,13 +8,12 @@ import ( "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/swarm" + kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" ) func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.ActLogic { - act := dynamicaccess.NewInMemoryAct() si := dynamicaccess.NewDefaultSession(privateKey) - al := dynamicaccess.NewLogic(si, act) + al := dynamicaccess.NewLogic(si) return al } @@ -33,6 +32,7 @@ func TestAdd(t *testing.T) { if err != nil { t.Errorf("Add() returned an error") } - m.Publish(swarm.EmptyAddress, &pub.PublicKey, "topic") + s := kvsmock.New() + m.Publish(s, &pub.PublicKey, "topic") fmt.Println("") } diff --git a/pkg/dynamicaccess/history.go b/pkg/dynamicaccess/history.go index e2705fffeac..63ec00847a6 100644 --- a/pkg/dynamicaccess/history.go +++ b/pkg/dynamicaccess/history.go @@ -2,34 +2,35 @@ package dynamicaccess import ( "github.com/ethereum/go-ethereum/common" + "github.com/ethersphere/bee/pkg/kvs" ) type History interface { - Add(timestamp int64, act Act) error - Get(timestamp int64) (Act, error) - Lookup(at int64) (Act, error) + Add(timestamp int64, kvs kvs.KeyValueStore) error + Get(timestamp int64) (kvs.KeyValueStore, error) + Lookup(at int64) (kvs.KeyValueStore, error) } var _ History = (*history)(nil) type history struct { - history map[int64]*Act + history map[int64]*kvs.KeyValueStore } func NewHistory(topic []byte, owner common.Address) *history { - return &history{history: make(map[int64]*Act)} + return &history{history: make(map[int64]*kvs.KeyValueStore)} } -func (h *history) Add(timestamp int64, act Act) error { +func (h *history) Add(timestamp int64, kvs kvs.KeyValueStore) error { return nil } -func (h *history) Lookup(at int64) (Act, error) { +func (h *history) Lookup(at int64) (kvs.KeyValueStore, error) { return nil, nil } -func (h *history) Get(timestamp int64) (Act, error) { +func (h *history) Get(timestamp int64) (kvs.KeyValueStore, error) { // get the feed return nil, nil } diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index e501e075697..c2164df7d39 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -7,7 +7,7 @@ import ( "github.com/ethersphere/bee/pkg/dynamicaccess" "github.com/ethersphere/bee/pkg/dynamicaccess/mock" - "github.com/ethersphere/bee/pkg/swarm" + kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" "github.com/stretchr/testify/assert" ) @@ -32,8 +32,8 @@ func TestHistoryLookup(t *testing.T) { for _, tt := range tests { t.Run("", func(t *testing.T) { - actAt, _ := h.Lookup(tt.input) - output, _ := actAt.Lookup(swarm.EmptyAddress, []byte("key1")) + sAt, _ := h.Lookup(tt.input) + output, _ := sAt.Get([]byte("key1")) assert.Equal(t, output, hex.EncodeToString([]byte(tt.expected))) }) } @@ -41,19 +41,19 @@ func TestHistoryLookup(t *testing.T) { func prepareTestHistory() dynamicaccess.History { var ( - h = mock.NewHistory() - now = time.Now() - act1 = dynamicaccess.NewInMemoryAct() - act2 = dynamicaccess.NewInMemoryAct() - act3 = dynamicaccess.NewInMemoryAct() + h = mock.NewHistory() + now = time.Now() + s1 = kvsmock.New() + s2 = kvsmock.New() + s3 = kvsmock.New() ) - act1.Add(swarm.EmptyAddress, []byte("key1"), []byte("value1")) - act2.Add(swarm.EmptyAddress, []byte("key1"), []byte("value2")) - act3.Add(swarm.EmptyAddress, []byte("key1"), []byte("value3")) + s1.Put([]byte("key1"), []byte("value1")) + s2.Put([]byte("key1"), []byte("value2")) + s3.Put([]byte("key1"), []byte("value3")) - h.Insert(now.AddDate(-3, 0, 0).Unix(), act1) - h.Insert(now.AddDate(-2, 0, 0).Unix(), act2) - h.Insert(now.AddDate(-1, 0, 0).Unix(), act3) + h.Insert(now.AddDate(-3, 0, 0).Unix(), s1) + h.Insert(now.AddDate(-2, 0, 0).Unix(), s2) + h.Insert(now.AddDate(-1, 0, 0).Unix(), s3) return h } diff --git a/pkg/dynamicaccess/mock/act.go b/pkg/dynamicaccess/mock/act.go deleted file mode 100644 index 721a4778829..00000000000 --- a/pkg/dynamicaccess/mock/act.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2024 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 mock - -import ( - "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/swarm" -) - -type ActMock struct { - AddFunc func(root swarm.Address, key []byte, val []byte) (swarm.Address, error) - LookupFunc func(root swarm.Address, key []byte) ([]byte, error) - LoadFunc func(addr swarm.Address) error - StoreFunc func() (swarm.Address, error) -} - -var _ dynamicaccess.Act = (*ActMock)(nil) - -func (act *ActMock) Add(root swarm.Address, key []byte, val []byte) (swarm.Address, error) { - if act.AddFunc == nil { - return swarm.EmptyAddress, nil - } - return act.AddFunc(root, key, val) -} - -func (act *ActMock) Lookup(root swarm.Address, key []byte) ([]byte, error) { - if act.LookupFunc == nil { - return make([]byte, 0), nil - } - return act.LookupFunc(root, key) -} - -func (act *ActMock) Load(addr swarm.Address) error { - if act.LoadFunc == nil { - return nil - } - return act.LoadFunc(addr) -} - -func (act *ActMock) Store() (swarm.Address, error) { - if act.StoreFunc == nil { - return swarm.EmptyAddress, nil - } - return act.StoreFunc() -} - -func NewActMock( - addFunc func(swarm.Address, []byte, []byte) (swarm.Address, error), - getFunc func(swarm.Address, []byte) ([]byte, error)) dynamicaccess.Act { - return &ActMock{ - AddFunc: addFunc, - LookupFunc: getFunc, - } -} diff --git a/pkg/dynamicaccess/mock/history.go b/pkg/dynamicaccess/mock/history.go index 68559c2277a..91b544a0760 100644 --- a/pkg/dynamicaccess/mock/history.go +++ b/pkg/dynamicaccess/mock/history.go @@ -6,31 +6,31 @@ import ( "time" "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/dynamicaccess" "github.com/ethersphere/bee/pkg/feeds" + "github.com/ethersphere/bee/pkg/kvs" "github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/swarm" ) type historyMock struct { - history map[int64]dynamicaccess.Act + history map[int64]kvs.KeyValueStore } func NewHistory() *historyMock { - return &historyMock{history: make(map[int64]dynamicaccess.Act)} + return &historyMock{history: make(map[int64]kvs.KeyValueStore)} } -func (h *historyMock) Add(timestamp int64, act dynamicaccess.Act) error { +func (h *historyMock) Add(timestamp int64, act kvs.KeyValueStore) error { h.history[timestamp] = act return nil } -func (h *historyMock) Insert(timestamp int64, act dynamicaccess.Act) *historyMock { +func (h *historyMock) Insert(timestamp int64, act kvs.KeyValueStore) *historyMock { h.Add(timestamp, act) return h } -func (h *historyMock) Lookup(at int64) (dynamicaccess.Act, error) { +func (h *historyMock) Lookup(at int64) (kvs.KeyValueStore, error) { keys := []int64{} for k := range h.history { keys = append(keys, k) @@ -52,7 +52,7 @@ func (h *historyMock) Lookup(at int64) (dynamicaccess.Act, error) { return nil, nil } -func (h *historyMock) Get(timestamp int64) (dynamicaccess.Act, error) { +func (h *historyMock) Get(timestamp int64) (kvs.KeyValueStore, error) { return h.history[timestamp], nil } diff --git a/pkg/kvs/kvs.go b/pkg/kvs/kvs.go index 65c2a0be8b9..91731f24af3 100644 --- a/pkg/kvs/kvs.go +++ b/pkg/kvs/kvs.go @@ -1,34 +1,70 @@ package kvs import ( - "errors" + "context" + "encoding/hex" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/kvs/manifest" - "github.com/ethersphere/bee/pkg/kvs/memory" + "github.com/ethersphere/bee/pkg/file" + "github.com/ethersphere/bee/pkg/manifest" + "github.com/ethersphere/bee/pkg/storer" "github.com/ethersphere/bee/pkg/swarm" ) -var ErrInvalidKvsType = errors.New("kvs: invalid type") - type KeyValueStore interface { - Get(rootHash swarm.Address, key []byte) ([]byte, error) - Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) + Get(key []byte) ([]byte, error) + Put(key, value []byte) error + Save() (swarm.Address, error) +} + +type keyValueStore struct { + manifest manifest.Interface + putter storer.PutterSession +} + +var _ KeyValueStore = (*keyValueStore)(nil) + +// TODO: pass context as dep. +func (s *keyValueStore) Get(key []byte) ([]byte, error) { + entry, err := s.manifest.Lookup(context.Background(), hex.EncodeToString(key)) + if err != nil { + return nil, err + } + ref := entry.Reference() + return ref.Bytes(), nil +} + +func (s *keyValueStore) Put(key []byte, value []byte) error { + return s.manifest.Add(context.Background(), hex.EncodeToString(key), manifest.NewEntry(swarm.NewAddress(value), map[string]string{})) +} + +func (s *keyValueStore) Save() (swarm.Address, error) { + ref, err := s.manifest.Store(context.Background()) + if err != nil { + return swarm.ZeroAddress, err + } + err = s.putter.Done(ref) + if err != nil { + return swarm.ZeroAddress, err + } + return ref, nil } -// func NewDefaultKeyValueStore(storer api.Storer) (KeyValueStore, error) { -// return NewKeyValueStore(storer, memory.KvsTypeMemory) -// } - -func NewKeyValueStore(storer api.Storer, kvsType string) (KeyValueStore, error) { - switch kvsType { - case "": - return memory.NewMemoryKeyValueStore() - case memory.KvsTypeMemory: - return memory.NewMemoryKeyValueStore() - case manifest.KvsTypeManifest: - return manifest.NewManifestKeyValueStore(storer) - default: - return nil, ErrInvalidKvsType +func New(ls file.LoadSaver, putter storer.PutterSession, rootHash swarm.Address) KeyValueStore { + var ( + manif manifest.Interface + err error + ) + if swarm.ZeroAddress.Equal(rootHash) || swarm.EmptyAddress.Equal(rootHash) { + manif, err = manifest.NewSimpleManifest(ls) + } else { + manif, err = manifest.NewSimpleManifestReference(rootHash, ls) + } + if err != nil { + return nil + } + + return &keyValueStore{ + manifest: manif, + putter: putter, } } diff --git a/pkg/kvs/kvs_test.go b/pkg/kvs/kvs_test.go new file mode 100644 index 00000000000..234802de2e3 --- /dev/null +++ b/pkg/kvs/kvs_test.go @@ -0,0 +1,132 @@ +// Copyright 2024 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 kvs_test + +import ( + "bytes" + "context" + "encoding/hex" + "testing" + + "github.com/ethersphere/bee/pkg/file" + "github.com/ethersphere/bee/pkg/file/loadsave" + "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/pkg/file/redundancy" + "github.com/ethersphere/bee/pkg/kvs" + "github.com/ethersphere/bee/pkg/storage" + mockstorer "github.com/ethersphere/bee/pkg/storer/mock" + "github.com/ethersphere/bee/pkg/swarm" +) + +var mockStorer = mockstorer.New() + +func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { + return func() pipeline.Interface { + return builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) + } +} + +func createLs() file.LoadSaver { + return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE)) +} + +func keyValuePair(t *testing.T) ([]byte, []byte) { + return swarm.RandAddress(t).Bytes(), swarm.RandAddress(t).Bytes() +} + +func TestKvsAddLookup(t *testing.T) { + ls := createLs() + + putter := mockStorer.DirectUpload() + s := kvs.New(ls, putter, swarm.ZeroAddress) + + lookupKey, encryptedAccesskey := keyValuePair(t) + + err := s.Put(lookupKey, encryptedAccesskey) + if err != nil { + t.Errorf("Add() should not return an error: %v", err) + } + + key, err := s.Get(lookupKey) + if err != nil { + t.Errorf("Lookup() should not return an error: %v", err) + } + + if !bytes.Equal(key, encryptedAccesskey) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) + } + +} + +func TestKvsAddLookupWithSave(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + s1 := kvs.New(ls, putter, swarm.ZeroAddress) + lookupKey, encryptedAccesskey := keyValuePair(t) + + err := s1.Put(lookupKey, encryptedAccesskey) + if err != nil { + t.Fatalf("Add() should not return an error: %v", err) + } + ref, err := s1.Save() + if err != nil { + t.Fatalf("Save() should not return an error: %v", err) + } + s2 := kvs.New(ls, putter, ref) + key, err := s2.Get(lookupKey) + if err != nil { + t.Fatalf("Lookup() should not return an error: %v", err) + } + + if !bytes.Equal(key, encryptedAccesskey) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) + } + +} + +func TestKvsAddSaveAdd(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + kvs1 := kvs.New(ls, putter, swarm.ZeroAddress) + kvs1key1, kvs1val1 := keyValuePair(t) + + err := kvs1.Put(kvs1key1, kvs1val1) + if err != nil { + t.Fatalf("Add() should not return an error: %v", err) + } + ref, err := kvs1.Save() + if err != nil { + t.Fatalf("Save() should not return an error: %v", err) + } + + // New KVS + kvs2 := kvs.New(ls, putter, ref) + + kvs2key1, kvs2val1 := keyValuePair(t) + + // put after save + kvs2.Put(kvs2key1, kvs2val1) + + // get after save + kvs2get1, err := kvs2.Get(kvs2key1) + if err != nil { + t.Fatalf("Lookup() should not return an error: %v", err) + } + if !bytes.Equal(kvs2get1, kvs2val1) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(kvs2key1), hex.EncodeToString(kvs2val1)) + } + + // get before Save + kvs2get2, err := kvs2.Get(kvs1key1) + + if err != nil { + t.Fatalf("Lookup() should not return an error: %v", err) + } + if !bytes.Equal(kvs2get2, kvs1val1) { + t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(kvs2get2), hex.EncodeToString(kvs1val1)) + } + +} diff --git a/pkg/kvs/manifest/kvs.go b/pkg/kvs/manifest/kvs.go deleted file mode 100644 index 19ca983d54a..00000000000 --- a/pkg/kvs/manifest/kvs.go +++ /dev/null @@ -1,86 +0,0 @@ -package manifest - -import ( - "context" - "encoding/hex" - - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" -) - -const ( - // KvsTypeManifest represents - KvsTypeManifest = "Manifest" -) - -type ManifestKeyValueStore interface { - Get(rootHash swarm.Address, key []byte) ([]byte, error) - Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) -} - -type manifestKeyValueStore struct { - storer api.Storer -} - -// TODO: pass context as dep. -func (m *manifestKeyValueStore) Get(rootHash swarm.Address, key []byte) ([]byte, error) { - ls := loadsave.NewReadonly(m.storer.ChunkStore()) - // existing manif - manif, err := manifest.NewSimpleManifestReference(rootHash, ls) - if err != nil { - return nil, err - } - entry, err := manif.Lookup(context.Background(), hex.EncodeToString(key)) - if err != nil { - return nil, err - } - ref := entry.Reference() - return ref.Bytes(), nil -} - -func (m *manifestKeyValueStore) Put(rootHash swarm.Address, key []byte, value []byte) (swarm.Address, error) { - factory := requestPipelineFactory(context.Background(), m.storer.Cache(), false, redundancy.NONE) - ls := loadsave.New(m.storer.ChunkStore(), m.storer.Cache(), factory) - // existing manif - manif, err := manifest.NewSimpleManifestReference(rootHash, ls) - if err != nil { - // new manif - manif, err = manifest.NewSimpleManifest(ls) - if err != nil { - return swarm.EmptyAddress, err - } - } - err = manif.Add(context.Background(), hex.EncodeToString(key), manifest.NewEntry(swarm.NewAddress(value), map[string]string{})) - if err != nil { - return swarm.EmptyAddress, err - } - manifRef, err := manif.Store(context.Background()) - if err != nil { - return swarm.EmptyAddress, err - } - - putter := m.storer.DirectUpload() - err = putter.Done(manifRef) - if err != nil { - return swarm.EmptyAddress, err - } - return manifRef, nil -} - -func NewManifestKeyValueStore(storer api.Storer) (ManifestKeyValueStore, error) { - return &manifestKeyValueStore{ - storer: storer, - }, nil -} - -func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { - return func() pipeline.Interface { - return builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) - } -} diff --git a/pkg/kvs/memory/kvs.go b/pkg/kvs/mock/kvs.go similarity index 55% rename from pkg/kvs/memory/kvs.go rename to pkg/kvs/mock/kvs.go index 3a1abc69c0e..1c2866137df 100644 --- a/pkg/kvs/memory/kvs.go +++ b/pkg/kvs/mock/kvs.go @@ -1,22 +1,13 @@ -package memory +package mock import ( "encoding/hex" "sync" + "github.com/ethersphere/bee/pkg/kvs" "github.com/ethersphere/bee/pkg/swarm" ) -const ( - // KvsTypeMemory represents - KvsTypeMemory = "Memory" -) - -type MemoryKeyValueStore interface { - Get(rootHash swarm.Address, key []byte) ([]byte, error) - Put(rootHash swarm.Address, key, value []byte) (swarm.Address, error) -} - var lock = &sync.Mutex{} type single struct { @@ -47,21 +38,27 @@ func getMemory() map[string][]byte { return mem.memoryMock } -type memoryKeyValueStore struct { +type mockKeyValueStore struct { } -func (m *memoryKeyValueStore) Get(rootHash swarm.Address, key []byte) ([]byte, error) { +var _ kvs.KeyValueStore = (*mockKeyValueStore)(nil) + +func (m *mockKeyValueStore) Get(key []byte) ([]byte, error) { mem := getMemory() val := mem[hex.EncodeToString(key)] return val, nil } -func (m *memoryKeyValueStore) Put(rootHash swarm.Address, key []byte, value []byte) (swarm.Address, error) { +func (m *mockKeyValueStore) Put(key []byte, value []byte) error { mem := getMemory() mem[hex.EncodeToString(key)] = value - return swarm.EmptyAddress, nil + return nil +} + +func (s *mockKeyValueStore) Save() (swarm.Address, error) { + return swarm.ZeroAddress, nil } -func NewMemoryKeyValueStore() (MemoryKeyValueStore, error) { - return &memoryKeyValueStore{}, nil +func New() kvs.KeyValueStore { + return &mockKeyValueStore{} } From 68ca69f49f8b917909bd9f48750d42f6b3b89a6a Mon Sep 17 00:00:00 2001 From: Kexort Date: Thu, 28 Mar 2024 10:58:49 +0100 Subject: [PATCH 17/22] Add referenced mock kvs (#26) --- pkg/kvs/mock/kvs.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/kvs/mock/kvs.go b/pkg/kvs/mock/kvs.go index 1c2866137df..fc091a88417 100644 --- a/pkg/kvs/mock/kvs.go +++ b/pkg/kvs/mock/kvs.go @@ -12,7 +12,7 @@ var lock = &sync.Mutex{} type single struct { // TODO string -> []byte ? - memoryMock map[string][]byte + memoryMock map[string]map[string][]byte } var singleInMemorySwarm *single @@ -23,13 +23,13 @@ func getInMemorySwarm() *single { defer lock.Unlock() if singleInMemorySwarm == nil { singleInMemorySwarm = &single{ - memoryMock: make(map[string][]byte)} + memoryMock: make(map[string]map[string][]byte)} } } return singleInMemorySwarm } -func getMemory() map[string][]byte { +func getMemory() map[string]map[string][]byte { ch := make(chan *single) go func() { ch <- getInMemorySwarm() @@ -39,26 +39,34 @@ func getMemory() map[string][]byte { } type mockKeyValueStore struct { + address swarm.Address } var _ kvs.KeyValueStore = (*mockKeyValueStore)(nil) func (m *mockKeyValueStore) Get(key []byte) ([]byte, error) { mem := getMemory() - val := mem[hex.EncodeToString(key)] + val := mem[m.address.String()][hex.EncodeToString(key)] return val, nil } func (m *mockKeyValueStore) Put(key []byte, value []byte) error { mem := getMemory() - mem[hex.EncodeToString(key)] = value + if _, ok := mem[m.address.String()]; !ok { + mem[m.address.String()] = make(map[string][]byte) + } + mem[m.address.String()][hex.EncodeToString(key)] = value return nil } -func (s *mockKeyValueStore) Save() (swarm.Address, error) { - return swarm.ZeroAddress, nil +func (m *mockKeyValueStore) Save() (swarm.Address, error) { + return m.address, nil } func New() kvs.KeyValueStore { - return &mockKeyValueStore{} + return &mockKeyValueStore{address: swarm.EmptyAddress} +} + +func NewReference(address swarm.Address) kvs.KeyValueStore { + return &mockKeyValueStore{address: address} } From 0c06870003c7f7a4fd2e4ff30150cbac7109ceb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Thu, 28 Mar 2024 14:10:17 +0100 Subject: [PATCH 18/22] Act kvs test (#27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * (test:) Refactor tests * (fix:) Save reset counter --------- Co-authored-by: Ferenc Sárai --- pkg/kvs/kvs.go | 17 +++- pkg/kvs/kvs_test.go | 221 ++++++++++++++++++++++++++------------------ 2 files changed, 145 insertions(+), 93 deletions(-) diff --git a/pkg/kvs/kvs.go b/pkg/kvs/kvs.go index 91731f24af3..1106f2ceee8 100644 --- a/pkg/kvs/kvs.go +++ b/pkg/kvs/kvs.go @@ -1,8 +1,13 @@ +// Copyright 2024 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 kvs import ( "context" "encoding/hex" + "errors" "github.com/ethersphere/bee/pkg/file" "github.com/ethersphere/bee/pkg/manifest" @@ -19,6 +24,7 @@ type KeyValueStore interface { type keyValueStore struct { manifest manifest.Interface putter storer.PutterSession + putCnt int } var _ KeyValueStore = (*keyValueStore)(nil) @@ -34,10 +40,18 @@ func (s *keyValueStore) Get(key []byte) ([]byte, error) { } func (s *keyValueStore) Put(key []byte, value []byte) error { - return s.manifest.Add(context.Background(), hex.EncodeToString(key), manifest.NewEntry(swarm.NewAddress(value), map[string]string{})) + err := s.manifest.Add(context.Background(), hex.EncodeToString(key), manifest.NewEntry(swarm.NewAddress(value), map[string]string{})) + if err != nil { + return err + } + s.putCnt++ + return nil } func (s *keyValueStore) Save() (swarm.Address, error) { + if s.putCnt == 0 { + return swarm.ZeroAddress, errors.New("nothing to save") + } ref, err := s.manifest.Store(context.Background()) if err != nil { return swarm.ZeroAddress, err @@ -46,6 +60,7 @@ func (s *keyValueStore) Save() (swarm.Address, error) { if err != nil { return swarm.ZeroAddress, err } + s.putCnt = 0 return ref, nil } diff --git a/pkg/kvs/kvs_test.go b/pkg/kvs/kvs_test.go index 234802de2e3..309250dacff 100644 --- a/pkg/kvs/kvs_test.go +++ b/pkg/kvs/kvs_test.go @@ -5,9 +5,7 @@ package kvs_test import ( - "bytes" "context" - "encoding/hex" "testing" "github.com/ethersphere/bee/pkg/file" @@ -19,6 +17,7 @@ import ( "github.com/ethersphere/bee/pkg/storage" mockstorer "github.com/ethersphere/bee/pkg/storer/mock" "github.com/ethersphere/bee/pkg/swarm" + "github.com/stretchr/testify/assert" ) var mockStorer = mockstorer.New() @@ -37,96 +36,134 @@ func keyValuePair(t *testing.T) ([]byte, []byte) { return swarm.RandAddress(t).Bytes(), swarm.RandAddress(t).Bytes() } -func TestKvsAddLookup(t *testing.T) { - ls := createLs() - - putter := mockStorer.DirectUpload() - s := kvs.New(ls, putter, swarm.ZeroAddress) - - lookupKey, encryptedAccesskey := keyValuePair(t) - - err := s.Put(lookupKey, encryptedAccesskey) - if err != nil { - t.Errorf("Add() should not return an error: %v", err) - } - - key, err := s.Get(lookupKey) - if err != nil { - t.Errorf("Lookup() should not return an error: %v", err) - } - - if !bytes.Equal(key, encryptedAccesskey) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) - } - -} - -func TestKvsAddLookupWithSave(t *testing.T) { - ls := createLs() - putter := mockStorer.DirectUpload() - s1 := kvs.New(ls, putter, swarm.ZeroAddress) - lookupKey, encryptedAccesskey := keyValuePair(t) - - err := s1.Put(lookupKey, encryptedAccesskey) - if err != nil { - t.Fatalf("Add() should not return an error: %v", err) - } - ref, err := s1.Save() - if err != nil { - t.Fatalf("Save() should not return an error: %v", err) - } - s2 := kvs.New(ls, putter, ref) - key, err := s2.Get(lookupKey) - if err != nil { - t.Fatalf("Lookup() should not return an error: %v", err) - } - - if !bytes.Equal(key, encryptedAccesskey) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(key), hex.EncodeToString(encryptedAccesskey)) - } - +func TestKvs(t *testing.T) { + + s := kvs.New(createLs(), mockStorer.DirectUpload(), swarm.ZeroAddress) + key, val := keyValuePair(t) + + t.Run("Get non-existent key should return error", func(t *testing.T) { + _, err := s.Get([]byte{1}) + assert.Error(t, err) + }) + + t.Run("Multiple Get with same key, no error", func(t *testing.T) { + err := s.Put(key, val) + assert.NoError(t, err) + + // get #1 + v, err := s.Get(key) + assert.NoError(t, err) + assert.Equal(t, val, v) + // get #2 + v, err = s.Get(key) + assert.NoError(t, err) + assert.Equal(t, val, v) + }) + + t.Run("Get should return value equal to put value", func(t *testing.T) { + var ( + key1 []byte = []byte{1} + key2 []byte = []byte{2} + key3 []byte = []byte{3} + ) + testCases := []struct { + name string + key []byte + val []byte + }{ + { + name: "Test key = 1", + key: key1, + val: []byte{11}, + }, + { + name: "Test key = 2", + key: key2, + val: []byte{22}, + }, + { + name: "Test overwrite key = 1", + key: key1, + val: []byte{111}, + }, + { + name: "Test key = 3", + key: key3, + val: []byte{33}, + }, + { + name: "Test key = 3 with same value", + key: key3, + val: []byte{33}, + }, + { + name: "Test key = 3 with value for key1", + key: key3, + val: []byte{11}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := s.Put(tc.key, tc.val) + assert.NoError(t, err) + retVal, err := s.Get(tc.key) + assert.NoError(t, err) + assert.Equal(t, tc.val, retVal) + }) + } + }) } -func TestKvsAddSaveAdd(t *testing.T) { - ls := createLs() - putter := mockStorer.DirectUpload() - kvs1 := kvs.New(ls, putter, swarm.ZeroAddress) - kvs1key1, kvs1val1 := keyValuePair(t) - - err := kvs1.Put(kvs1key1, kvs1val1) - if err != nil { - t.Fatalf("Add() should not return an error: %v", err) - } - ref, err := kvs1.Save() - if err != nil { - t.Fatalf("Save() should not return an error: %v", err) - } - - // New KVS - kvs2 := kvs.New(ls, putter, ref) - - kvs2key1, kvs2val1 := keyValuePair(t) - - // put after save - kvs2.Put(kvs2key1, kvs2val1) - - // get after save - kvs2get1, err := kvs2.Get(kvs2key1) - if err != nil { - t.Fatalf("Lookup() should not return an error: %v", err) - } - if !bytes.Equal(kvs2get1, kvs2val1) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(kvs2key1), hex.EncodeToString(kvs2val1)) - } - - // get before Save - kvs2get2, err := kvs2.Get(kvs1key1) - - if err != nil { - t.Fatalf("Lookup() should not return an error: %v", err) - } - if !bytes.Equal(kvs2get2, kvs1val1) { - t.Errorf("Get() value is not the expected %s != %s", hex.EncodeToString(kvs2get2), hex.EncodeToString(kvs1val1)) - } - +func TestKvs_Save(t *testing.T) { + key1, val1 := keyValuePair(t) + key2, val2 := keyValuePair(t) + t.Run("Save empty KVS return error", func(t *testing.T) { + s := kvs.New(createLs(), mockStorer.DirectUpload(), swarm.ZeroAddress) + _, err := s.Save() + assert.Error(t, err) + }) + t.Run("Save not empty KVS return valid swarm address", func(t *testing.T) { + s := kvs.New(createLs(), mockStorer.DirectUpload(), swarm.ZeroAddress) + s.Put(key1, val1) + ref, err := s.Save() + assert.NoError(t, err) + assert.True(t, ref.IsValidNonEmpty()) + }) + t.Run("Save KVS with one item, no error, pre-save value exist", func(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + s1 := kvs.New(ls, putter, swarm.ZeroAddress) + + err := s1.Put(key1, val1) + assert.NoError(t, err) + + ref, err := s1.Save() + assert.NoError(t, err) + + s2 := kvs.New(ls, putter, ref) + val, err := s2.Get(key1) + assert.NoError(t, err) + assert.Equal(t, val1, val) + }) + t.Run("Save KVS and add one item, no error, after-save value exist", func(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + + kvs1 := kvs.New(ls, putter, swarm.ZeroAddress) + + err := kvs1.Put(key1, val1) + assert.NoError(t, err) + ref, err := kvs1.Save() + assert.NoError(t, err) + + // New KVS + kvs2 := kvs.New(ls, putter, ref) + err = kvs2.Put(key2, val2) + assert.NoError(t, err) + + val, err := kvs2.Get(key2) + assert.NoError(t, err) + assert.Equal(t, val2, val) + }) } From a328ff6915b885a9257133cf70016543eb1dff44 Mon Sep 17 00:00:00 2001 From: Kexort Date: Tue, 2 Apr 2024 11:36:26 +0200 Subject: [PATCH 19/22] Small refactor + al test (#28) Adds TestDecryptRefWithGrantee_Success and replaces generateFixPrivateKey with getPrivKey Co-authored-by: Peter Ott --- pkg/dynamicaccess/accesslogic.go | 14 ++-- pkg/dynamicaccess/accesslogic_test.go | 107 +++++++++++++++++++------- pkg/dynamicaccess/publish.go | 12 --- pkg/dynamicaccess/publish_test.go | 11 --- pkg/dynamicaccess/timestamp.go | 10 --- pkg/dynamicaccess/timestamp_test.go | 1 - 6 files changed, 87 insertions(+), 68 deletions(-) delete mode 100644 pkg/dynamicaccess/publish.go delete mode 100644 pkg/dynamicaccess/publish_test.go delete mode 100644 pkg/dynamicaccess/timestamp.go delete mode 100644 pkg/dynamicaccess/timestamp_test.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index ad33ba5eb16..6c632a58351 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -14,7 +14,7 @@ var hashFunc = sha3.NewLegacyKeccak256 // Read-only interface for the ACT type Decryptor interface { // DecryptRef will return a decrypted reference, for given encrypted reference and grantee - DecryptRef(storage kvs.KeyValueStore, encryped_ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) + DecryptRef(storage kvs.KeyValueStore, encryptedRef swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) // Embedding the Session interface Session } @@ -26,14 +26,14 @@ type Control interface { // Adds a new grantee to the ACT AddGrantee(storage kvs.KeyValueStore, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) error // Encrypts a Swarm reference for a given grantee - EncryptRef(storage kvs.KeyValueStore, grantee *ecdsa.PublicKey, ref swarm.Address) error + EncryptRef(storage kvs.KeyValueStore, grantee *ecdsa.PublicKey, ref swarm.Address) (swarm.Address, error) } type ActLogic struct { Session } -var _ Decryptor = (*ActLogic)(nil) +var _ Control = (*ActLogic)(nil) // Adds a new publisher to an empty act func (al ActLogic) AddPublisher(storage kvs.KeyValueStore, publisher *ecdsa.PublicKey) error { @@ -116,9 +116,9 @@ func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([][]byte, error) { return al.Session.Key(publicKey, [][]byte{zeroByteArray, oneByteArray}) } -// DecryptRef will return a decrypted reference, for given encrypted reference and grantee -func (al ActLogic) DecryptRef(storage kvs.KeyValueStore, encryped_ref swarm.Address, grantee *ecdsa.PublicKey) (swarm.Address, error) { - keys, err := al.getKeys(grantee) +// DecryptRef will return a decrypted reference, for given encrypted reference and publisher +func (al ActLogic) DecryptRef(storage kvs.KeyValueStore, encryptedRef swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) { + keys, err := al.getKeys(publisher) if err != nil { return swarm.EmptyAddress, err } @@ -140,7 +140,7 @@ func (al ActLogic) DecryptRef(storage kvs.KeyValueStore, encryped_ref swarm.Addr // Decrypt reference refCipher := encryption.New(accessKey, 0, uint32(0), hashFunc) - ref, err := refCipher.Decrypt(encryped_ref.Bytes()) + ref, err := refCipher.Decrypt(encryptedRef.Bytes()) if err != nil { return swarm.EmptyAddress, err } diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index cb5ff0a6c78..8c2f2a6489f 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -3,10 +3,11 @@ package dynamicaccess_test import ( "crypto/ecdsa" "crypto/elliptic" + "crypto/rand" "encoding/hex" - "math/big" "testing" + "github.com/ethersphere/bee/pkg/crypto" "github.com/ethersphere/bee/pkg/dynamicaccess" kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" "github.com/ethersphere/bee/pkg/swarm" @@ -14,33 +15,42 @@ import ( // Generates a new test environment with a fix private key func setupAccessLogic2() dynamicaccess.ActLogic { - privateKey := generateFixPrivateKey(1000) - diffieHellman := dynamicaccess.NewDefaultSession(&privateKey) + privateKey := getPrivKey(1) + diffieHellman := dynamicaccess.NewDefaultSession(privateKey) al := dynamicaccess.NewLogic(diffieHellman) return al } -// Generates a fixed identity with private and public key. The private key is generated from the input -func generateFixPrivateKey(input int64) ecdsa.PrivateKey { - fixedD := big.NewInt(input) - curve := elliptic.P256() - x, y := curve.ScalarBaseMult(fixedD.Bytes()) +func getPrivKey(keyNumber int) *ecdsa.PrivateKey { + var keyHex string - privateKey := ecdsa.PrivateKey{ - PublicKey: ecdsa.PublicKey{ - Curve: curve, - X: x, - Y: y, - }, - D: fixedD, + switch keyNumber { + case 0: + keyHex = "a786dd84b61485de12146fd9c4c02d87e8fd95f0542765cb7fc3d2e428c0bcfa" + case 1: + keyHex = "b786dd84b61485de12146fd9c4c02d87e8fd95f0542765cb7fc3d2e428c0bcfb" + case 2: + keyHex = "c786dd84b61485de12146fd9c4c02d87e8fd95f0542765cb7fc3d2e428c0bcfc" + default: + panic("Invalid key number") } - return privateKey + data, err := hex.DecodeString(keyHex) + if err != nil { + panic(err) + } + + privKey, err := crypto.DecodeSecp256k1PrivateKey(data) + if err != nil { + panic(err) + } + + return privKey } func TestDecryptRef_Success(t *testing.T) { - id0 := generateFixPrivateKey(0) + id0 := getPrivKey(0) s := kvsmock.New() al := setupAccessLogic2() err := al.AddPublisher(s, &id0.PublicKey) @@ -72,8 +82,51 @@ func TestDecryptRef_Success(t *testing.T) { } } +func TestDecryptRefWithGrantee_Success(t *testing.T) { + id0, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + diffieHellman := dynamicaccess.NewDefaultSession(id0) + al := dynamicaccess.NewLogic(diffieHellman) + + s := kvsmock.New() + err := al.AddPublisher(s, &id0.PublicKey) + if err != nil { + t.Errorf("AddPublisher: expected no error, got %v", err) + } + + id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + err = al.AddGrantee(s, &id0.PublicKey, &id1.PublicKey, nil) + if err != nil { + t.Errorf("AddNewGrantee: expected no error, got %v", err) + } + + byteRef, _ := hex.DecodeString("39a5ea87b141fe44aa609c3327ecd896c0e2122897f5f4bbacf74db1033c5559") + + expectedRef := swarm.NewAddress(byteRef) + t.Logf("encryptedRef: %s", expectedRef.String()) + + encryptedRef, err := al.EncryptRef(s, &id0.PublicKey, expectedRef) + t.Logf("encryptedRef: %s", encryptedRef.String()) + if err != nil { + t.Errorf("There was an error while calling EncryptRef: ") + t.Error(err) + } + + diffieHellman2 := dynamicaccess.NewDefaultSession(id1) + granteeAccessLogic := dynamicaccess.NewLogic(diffieHellman2) + acutalRef, err := granteeAccessLogic.DecryptRef(s, encryptedRef, &id0.PublicKey) + if err != nil { + t.Errorf("There was an error while calling Get: ") + t.Error(err) + } + + if expectedRef.Compare(acutalRef) != 0 { + + t.Errorf("Get gave back wrong Swarm reference!") + } +} + func TestDecryptRef_Error(t *testing.T) { - id0 := generateFixPrivateKey(0) + id0 := getPrivKey(0) s := kvsmock.New() al := setupAccessLogic2() @@ -89,13 +142,13 @@ func TestDecryptRef_Error(t *testing.T) { r, err := al.DecryptRef(s, encryptedRef, nil) if err == nil { t.Logf("r: %s", r.String()) - t.Errorf("Get should give back encrypted access key not found error!") + t.Errorf("Get should return encrypted access key not found error!") } } func TestAddPublisher(t *testing.T) { - id0 := generateFixPrivateKey(0) - savedLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" + id0 := getPrivKey(0) + savedLookupKey := "b6ee086390c280eeb9824c331a4427596f0c8510d5564bc1b6168d0059a46e2b" s := kvsmock.New() al := setupAccessLogic2() @@ -127,13 +180,13 @@ func TestAddPublisher(t *testing.T) { func TestAddNewGranteeToContent(t *testing.T) { - id0 := generateFixPrivateKey(0) - id1 := generateFixPrivateKey(1) - id2 := generateFixPrivateKey(2) + id0 := getPrivKey(0) + id1 := getPrivKey(1) + id2 := getPrivKey(2) - publisherLookupKey := "bc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a" - firstAddedGranteeLookupKey := "e221a2abf64357260e8f2c937ee938aed98dce097e537c1a3fd4caf73510dbe4" - secondAddedGranteeLookupKey := "8fe8dff7cd15a6a0095c1b25071a5691e7c901fd0b95857a96c0e4659b48716a" + publisherLookupKey := "b6ee086390c280eeb9824c331a4427596f0c8510d5564bc1b6168d0059a46e2b" + firstAddedGranteeLookupKey := "a13678e81f9d939b9401a3ad7e548d2ceb81c50f8c76424296e83a1ad79c0df0" + secondAddedGranteeLookupKey := "d5e9a6499ca74f5b8b958a4b89b7338045b2baa9420e115443a8050e26986564" s := kvsmock.New() al := setupAccessLogic2() diff --git a/pkg/dynamicaccess/publish.go b/pkg/dynamicaccess/publish.go deleted file mode 100644 index f913288e4d5..00000000000 --- a/pkg/dynamicaccess/publish.go +++ /dev/null @@ -1,12 +0,0 @@ -package dynamicaccess - -type Publish interface { - upload(ref string) (string, error) -} - -type DefaultPublish struct { -} - -func (d *DefaultPublish) upload(ref string) (string, error) { - return "default", nil -} diff --git a/pkg/dynamicaccess/publish_test.go b/pkg/dynamicaccess/publish_test.go deleted file mode 100644 index d31069da4a3..00000000000 --- a/pkg/dynamicaccess/publish_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package dynamicaccess - -import "testing" - -func TestUpload(t *testing.T) { - p := &DefaultPublish{} - _, err := p.upload("test") - if err != nil { - t.Errorf("Error uploading file: %v", err) - } -} diff --git a/pkg/dynamicaccess/timestamp.go b/pkg/dynamicaccess/timestamp.go deleted file mode 100644 index 48347d33a7c..00000000000 --- a/pkg/dynamicaccess/timestamp.go +++ /dev/null @@ -1,10 +0,0 @@ -package dynamicaccess - -// container interface bee-ből a manifest -type Timestamp interface{} - -type defaultTimeStamp struct{} - -func NewTimestamp() Timestamp { - return &defaultTimeStamp{} -} diff --git a/pkg/dynamicaccess/timestamp_test.go b/pkg/dynamicaccess/timestamp_test.go deleted file mode 100644 index e39ccbcf0c5..00000000000 --- a/pkg/dynamicaccess/timestamp_test.go +++ /dev/null @@ -1 +0,0 @@ -package dynamicaccess From 507716da3f384850a66ed46c382f136c1fd9dd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Ujv=C3=A1ri?= <58116288+bosi95@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:05:25 +0200 Subject: [PATCH 20/22] Persist grantee list on swarm (#30) * Persist grantee list on swarm * accesslogic refactor * Refactor grantee list tests Co-authored-by: Roland Seres --- pkg/dynamicaccess/accesslogic.go | 5 +- pkg/dynamicaccess/controller.go | 6 +- pkg/dynamicaccess/controller_test.go | 4 +- pkg/dynamicaccess/grantee.go | 130 ++++++++++-- pkg/dynamicaccess/grantee_manager.go | 25 +-- pkg/dynamicaccess/grantee_manager_test.go | 6 +- pkg/dynamicaccess/grantee_test.go | 236 +++++++++++++++------- pkg/dynamicaccess/mock/container.go | 20 -- pkg/dynamicaccess/mock/grantee.go | 51 +++++ 9 files changed, 352 insertions(+), 131 deletions(-) delete mode 100644 pkg/dynamicaccess/mock/container.go create mode 100644 pkg/dynamicaccess/mock/grantee.go diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 6c632a58351..593e02d630c 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -76,10 +76,11 @@ func (al ActLogic) AddGrantee(storage kvs.KeyValueStore, publisherPubKey, grante return err } lookupKey := keys[0] - accessKeyEncryptionKey := keys[1] + // accessKeyDecryptionKey is used for encryption of the access key + accessKeyDecryptionKey := keys[1] // Encrypt the access key for the new Grantee - cipher := encryption.New(encryption.Key(accessKeyEncryptionKey), 0, uint32(0), hashFunc) + cipher := encryption.New(encryption.Key(accessKeyDecryptionKey), 0, uint32(0), hashFunc) granteeEncryptedAccessKey, err := cipher.Encrypt(accessKey) if err != nil { return err diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index d118e22489f..df39fa23c32 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -9,7 +9,7 @@ import ( type Controller interface { DownloadHandler(timestamp int64, enryptedRef swarm.Address, publisher *ecdsa.PublicKey, tag string) (swarm.Address, error) - UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) + UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) } type defaultController struct { @@ -27,7 +27,7 @@ func (c *defaultController) DownloadHandler(timestamp int64, enryptedRef swarm.A return addr, err } -func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { +func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.PublicKey) (swarm.Address, error) { kvs, err := c.history.Lookup(0) if err != nil { return swarm.EmptyAddress, err @@ -36,7 +36,7 @@ func (c *defaultController) UploadHandler(ref swarm.Address, publisher *ecdsa.Pu // new feed // TODO: putter session to create kvs kvs = kvsmock.New() - _, err = c.granteeManager.Publish(kvs, publisher, topic) + _, err = c.granteeManager.Publish(kvs, publisher) if err != nil { return swarm.EmptyAddress, err } diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index 63f80059e08..24107123ab5 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -72,9 +72,9 @@ func TestEncrypt(t *testing.T) { eref, ref := prepareEncryptedChunkReference(ak) key1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - gm.Add("topic", []*ecdsa.PublicKey{&key1.PublicKey}) + gm.Add([]*ecdsa.PublicKey{&key1.PublicKey}) - addr, _ := c.UploadHandler(ref, &pk.PublicKey, "topic") + addr, _ := c.UploadHandler(ref, &pk.PublicKey) if !addr.Equal(eref) { t.Fatalf("Decrypted chunk address: %s is not the expected: %s", addr, eref) } diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index d85ebf217ea..afbe5349818 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -1,44 +1,134 @@ package dynamicaccess import ( + "context" "crypto/ecdsa" + "crypto/elliptic" + "fmt" + + "github.com/ethersphere/bee/pkg/file" + "github.com/ethersphere/bee/pkg/storer" + "github.com/ethersphere/bee/pkg/swarm" +) + +const ( + publicKeyLen = 65 ) type GranteeList interface { - Add(topic string, addList []*ecdsa.PublicKey) error - Remove(topic string, removeList []*ecdsa.PublicKey) error - Get(topic string) []*ecdsa.PublicKey + Add(addList []*ecdsa.PublicKey) error + Remove(removeList []*ecdsa.PublicKey) error + Get() []*ecdsa.PublicKey + Save() (swarm.Address, error) } type GranteeListStruct struct { - grantees map[string][]*ecdsa.PublicKey + grantees []byte + loadSave file.LoadSaver + putter storer.PutterSession +} + +var _ GranteeList = (*GranteeListStruct)(nil) + +func (g *GranteeListStruct) Get() []*ecdsa.PublicKey { + return g.deserialize(g.grantees) +} + +func (g *GranteeListStruct) serialize(publicKeys []*ecdsa.PublicKey) []byte { + b := make([]byte, 0, len(publicKeys)*publicKeyLen) + for _, key := range publicKeys { + b = append(b, g.serializePublicKey(key)...) + } + return b +} + +func (g *GranteeListStruct) serializePublicKey(pub *ecdsa.PublicKey) []byte { + return elliptic.Marshal(pub.Curve, pub.X, pub.Y) } -func (g *GranteeListStruct) Get(topic string) []*ecdsa.PublicKey { - grantees := g.grantees[topic] - keys := make([]*ecdsa.PublicKey, len(grantees)) - copy(keys, grantees) - return keys +func (g *GranteeListStruct) deserialize(data []byte) []*ecdsa.PublicKey { + if len(data) == 0 { + return nil + } + + p := make([]*ecdsa.PublicKey, 0, len(data)/publicKeyLen) + for i := 0; i < len(data); i += publicKeyLen { + pubKey := g.deserializeBytes(data[i : i+publicKeyLen]) + if pubKey == nil { + return nil + } + p = append(p, pubKey) + } + return p } -func (g *GranteeListStruct) Add(topic string, addList []*ecdsa.PublicKey) error { - g.grantees[topic] = append(g.grantees[topic], addList...) +func (g *GranteeListStruct) deserializeBytes(data []byte) *ecdsa.PublicKey { + curve := elliptic.P256() + x, y := elliptic.Unmarshal(curve, data) + return &ecdsa.PublicKey{Curve: curve, X: x, Y: y} +} + +func (g *GranteeListStruct) Add(addList []*ecdsa.PublicKey) error { + if len(addList) == 0 { + return fmt.Errorf("no public key provided") + } + + data := g.serialize(addList) + g.grantees = append(g.grantees, data...) return nil } -func (g *GranteeListStruct) Remove(topic string, removeList []*ecdsa.PublicKey) error { - for _, remove := range removeList { - for i, grantee := range g.grantees[topic] { - if *grantee == *remove { - g.grantees[topic][i] = g.grantees[topic][len(g.grantees[topic])-1] - g.grantees[topic] = g.grantees[topic][:len(g.grantees[topic])-1] +func (g *GranteeListStruct) Save() (swarm.Address, error) { + refBytes, err := g.loadSave.Save(context.Background(), g.grantees) + if err != nil { + return swarm.ZeroAddress, fmt.Errorf("grantee save error: %w", err) + } + address := swarm.NewAddress(refBytes) + err = g.putter.Done(address) + if err != nil { + return swarm.ZeroAddress, err + } + return address, nil +} + +func (g *GranteeListStruct) Remove(keysToRemove []*ecdsa.PublicKey) error { + if len(keysToRemove) == 0 { + return fmt.Errorf("nothing to remove") + } + grantees := g.deserialize(g.grantees) + if grantees == nil { + return fmt.Errorf("no grantee found") + } + + for _, remove := range keysToRemove { + for i, grantee := range grantees { + if grantee.Equal(remove) { + grantees[i] = grantees[len(grantees)-1] + grantees = grantees[:len(grantees)-1] } } } - + g.grantees = g.serialize(grantees) return nil } -func NewGrantee() *GranteeListStruct { - return &GranteeListStruct{grantees: make(map[string][]*ecdsa.PublicKey)} +func NewGranteeList(ls file.LoadSaver, putter storer.PutterSession, reference swarm.Address) GranteeList { + var ( + data []byte + err error + ) + if swarm.ZeroAddress.Equal(reference) || swarm.EmptyAddress.Equal(reference) { + data = []byte{} + } else { + data, err = ls.Load(context.Background(), reference.Bytes()) + } + if err != nil { + return nil + } + + return &GranteeListStruct{ + grantees: data, + loadSave: ls, + putter: putter, + } } diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index 004a933b006..eaa9cc9ffd9 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -3,16 +3,17 @@ package dynamicaccess import ( "crypto/ecdsa" + "github.com/ethersphere/bee/pkg/dynamicaccess/mock" "github.com/ethersphere/bee/pkg/kvs" "github.com/ethersphere/bee/pkg/swarm" ) type GranteeManager interface { - Get(topic string) []*ecdsa.PublicKey - Add(topic string, addList []*ecdsa.PublicKey) error - Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) + Get() []*ecdsa.PublicKey + Add(addList []*ecdsa.PublicKey) error + Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey) (swarm.Address, error) - // HandleGrantees(topic string, addList, removeList []*ecdsa.PublicKey) *Act + // HandleGrantees(addList, removeList []*ecdsa.PublicKey) *Act // Load(grantee Grantee) // Save() @@ -22,24 +23,24 @@ var _ GranteeManager = (*granteeManager)(nil) type granteeManager struct { accessLogic ActLogic - granteeList GranteeList + granteeList *mock.GranteeListStructMock } func NewGranteeManager(al ActLogic) *granteeManager { - return &granteeManager{accessLogic: al, granteeList: NewGrantee()} + return &granteeManager{accessLogic: al, granteeList: mock.NewGranteeList()} } -func (gm *granteeManager) Get(topic string) []*ecdsa.PublicKey { - return gm.granteeList.Get(topic) +func (gm *granteeManager) Get() []*ecdsa.PublicKey { + return gm.granteeList.Get() } -func (gm *granteeManager) Add(topic string, addList []*ecdsa.PublicKey) error { - return gm.granteeList.Add(topic, addList) +func (gm *granteeManager) Add(addList []*ecdsa.PublicKey) error { + return gm.granteeList.Add(addList) } -func (gm *granteeManager) Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey, topic string) (swarm.Address, error) { +func (gm *granteeManager) Publish(kvs kvs.KeyValueStore, publisher *ecdsa.PublicKey) (swarm.Address, error) { err := gm.accessLogic.AddPublisher(kvs, publisher) - for _, grantee := range gm.granteeList.Get(topic) { + for _, grantee := range gm.granteeList.Get() { err = gm.accessLogic.AddGrantee(kvs, publisher, grantee, nil) } return swarm.EmptyAddress, err diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index 7ac43425e10..d458e007088 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -24,15 +24,15 @@ func TestAdd(t *testing.T) { id1, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) id2, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - err := m.Add("topic", []*ecdsa.PublicKey{&id1.PublicKey}) + err := m.Add([]*ecdsa.PublicKey{&id1.PublicKey}) if err != nil { t.Errorf("Add() returned an error") } - err = m.Add("topic", []*ecdsa.PublicKey{&id2.PublicKey}) + err = m.Add([]*ecdsa.PublicKey{&id2.PublicKey}) if err != nil { t.Errorf("Add() returned an error") } s := kvsmock.New() - m.Publish(s, &pub.PublicKey, "topic") + m.Publish(s, &pub.PublicKey) fmt.Println("") } diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 7962690ccb4..5b7a9bc5402 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -1,104 +1,202 @@ package dynamicaccess_test import ( + "context" "crypto/ecdsa" "crypto/elliptic" "crypto/rand" - "reflect" "testing" "github.com/ethersphere/bee/pkg/dynamicaccess" + "github.com/ethersphere/bee/pkg/file" + "github.com/ethersphere/bee/pkg/file/loadsave" + "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/pkg/file/redundancy" + "github.com/ethersphere/bee/pkg/storage" + mockstorer "github.com/ethersphere/bee/pkg/storer/mock" + "github.com/ethersphere/bee/pkg/swarm" + "github.com/stretchr/testify/assert" ) -var _ dynamicaccess.GranteeList = (*dynamicaccess.GranteeListStruct)(nil) +var mockStorer = mockstorer.New() -func TestGranteeAddGrantees(t *testing.T) { - grantee := dynamicaccess.NewGrantee() - - key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - exampleTopic := "topic" - err = grantee.Add(exampleTopic, addList) - - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - grantees := grantee.Get(exampleTopic) - if !reflect.DeepEqual(grantees, addList) { - t.Errorf("Expected grantees %v, got %v", addList, grantees) +func requestPipelineFactory(ctx context.Context, s storage.Putter, encrypt bool, rLevel redundancy.Level) func() pipeline.Interface { + return func() pipeline.Interface { + return builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) } } -func TestRemoveGrantees(t *testing.T) { - grantee := dynamicaccess.NewGrantee() +func createLs() file.LoadSaver { + return loadsave.New(mockStorer.ChunkStore(), mockStorer.Cache(), requestPipelineFactory(context.Background(), mockStorer.Cache(), false, redundancy.NONE)) +} +func generateKeyListFixture() ([]*ecdsa.PublicKey, error) { key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - if err != nil { - t.Errorf("Expected no error, got %v", err) - } - key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + key3, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - exampleTopic := "topic" - err = grantee.Add(exampleTopic, addList) - if err != nil { - t.Errorf("Expected no error, got %v", err) + return nil, err } + return []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey, &key3.PublicKey}, nil +} - removeList := []*ecdsa.PublicKey{&key1.PublicKey} - err = grantee.Remove(exampleTopic, removeList) +func TestGranteeAddGet(t *testing.T) { + putter := mockStorer.DirectUpload() + gl := dynamicaccess.NewGranteeList(createLs(), putter, swarm.ZeroAddress) + keys, err := generateKeyListFixture() if err != nil { - t.Errorf("Expected no error, got %v", err) + t.Errorf("key generation error: %v", err) } - grantees := grantee.Get(exampleTopic) - expectedGrantees := []*ecdsa.PublicKey{&key2.PublicKey} + t.Run("Get empty grantee list should return error", func(t *testing.T) { + val := gl.Get() + assert.Nil(t, val) + }) + + t.Run("Get should return value equal to put value", func(t *testing.T) { + var ( + addList1 []*ecdsa.PublicKey = []*ecdsa.PublicKey{keys[0]} + addList2 []*ecdsa.PublicKey = []*ecdsa.PublicKey{keys[1], keys[0]} + addList3 []*ecdsa.PublicKey = keys + ) + testCases := []struct { + name string + list []*ecdsa.PublicKey + }{ + { + name: "Test list = 1", + list: addList1, + }, + { + name: "Test list = 2", + list: addList2, + }, + { + name: "Test list = 3", + list: addList3, + }, + { + name: "Test empty add list", + list: nil, + }, + } - for i, grantee := range grantees { - if grantee != expectedGrantees[i] { - t.Errorf("Expected grantee %v, got %v", expectedGrantees[i], grantee) + expList := []*ecdsa.PublicKey{} + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := gl.Add(tc.list) + if tc.list == nil { + assert.Error(t, err) + } else { + assert.NoError(t, err) + expList = append(expList, tc.list...) + retVal := gl.Get() + assert.Equal(t, expList, retVal) + } + }) } - } + }) } -func TestGetGrantees(t *testing.T) { - grantee := dynamicaccess.NewGrantee() - - key1, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) +func TestGranteeRemove(t *testing.T) { + putter := mockStorer.DirectUpload() + gl := dynamicaccess.NewGranteeList(createLs(), putter, swarm.ZeroAddress) + keys, err := generateKeyListFixture() if err != nil { - t.Errorf("Expected no error, got %v", err) + t.Errorf("key generation error: %v", err) } - key2, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - if err != nil { - t.Errorf("Expected no error, got %v", err) - } + t.Run("Add should NOT return error", func(t *testing.T) { + err := gl.Add(keys) + assert.NoError(t, err) + retVal := gl.Get() + assert.Equal(t, keys, retVal) + }) + removeList1 := []*ecdsa.PublicKey{keys[0]} + removeList2 := []*ecdsa.PublicKey{keys[2], keys[1]} + t.Run("Remove the first item should return NO error", func(t *testing.T) { + err := gl.Remove(removeList1) + assert.NoError(t, err) + retVal := gl.Get() + assert.Equal(t, removeList2, retVal) + }) + t.Run("Remove non-existent item should return NO error", func(t *testing.T) { + err := gl.Remove(removeList1) + assert.NoError(t, err) + retVal := gl.Get() + assert.Equal(t, removeList2, retVal) + }) + t.Run("Remove second and third item should return NO error", func(t *testing.T) { + err := gl.Remove(removeList2) + assert.NoError(t, err) + retVal := gl.Get() + assert.Nil(t, retVal) + }) + t.Run("Remove from empty grantee list should return error", func(t *testing.T) { + err := gl.Remove(removeList1) + assert.Error(t, err) + retVal := gl.Get() + assert.Nil(t, retVal) + }) + t.Run("Remove empty remove list should return error", func(t *testing.T) { + err := gl.Remove(nil) + assert.Error(t, err) + retVal := gl.Get() + assert.Nil(t, retVal) + }) +} - addList := []*ecdsa.PublicKey{&key1.PublicKey, &key2.PublicKey} - exampleTopic := "topic" - err = grantee.Add(exampleTopic, addList) +func TestGranteeSave(t *testing.T) { + keys, err := generateKeyListFixture() if err != nil { - t.Errorf("Expected no error, got %v", err) - } - - grantees := grantee.Get(exampleTopic) - for i, grantee := range grantees { - if grantee != addList[i] { - t.Errorf("Expected grantee %v, got %v", addList[i], grantee) - } + t.Errorf("key generation error: %v", err) } + t.Run("Save empty grantee list return NO error", func(t *testing.T) { + gl := dynamicaccess.NewGranteeList(createLs(), mockStorer.DirectUpload(), swarm.ZeroAddress) + _, err := gl.Save() + assert.NoError(t, err) + }) + t.Run("Save not empty grantee list return valid swarm address", func(t *testing.T) { + gl := dynamicaccess.NewGranteeList(createLs(), mockStorer.DirectUpload(), swarm.ZeroAddress) + err = gl.Add(keys) + ref, err := gl.Save() + assert.NoError(t, err) + assert.True(t, ref.IsValidNonEmpty()) + }) + t.Run("Save grantee list with one item, no error, pre-save value exist", func(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + gl1 := dynamicaccess.NewGranteeList(ls, putter, swarm.ZeroAddress) + + err := gl1.Add(keys) + assert.NoError(t, err) + + ref, err := gl1.Save() + assert.NoError(t, err) + + gl2 := dynamicaccess.NewGranteeList(ls, putter, ref) + val := gl2.Get() + assert.NoError(t, err) + assert.Equal(t, keys, val) + }) + t.Run("Save grantee list and add one item, no error, after-save value exist", func(t *testing.T) { + ls := createLs() + putter := mockStorer.DirectUpload() + + gl1 := dynamicaccess.NewGranteeList(ls, putter, swarm.ZeroAddress) + + err := gl1.Add(keys) + assert.NoError(t, err) + ref, err := gl1.Save() + assert.NoError(t, err) + + // New KVS + gl2 := dynamicaccess.NewGranteeList(ls, putter, ref) + err = gl2.Add(keys) + assert.NoError(t, err) + + val := gl2.Get() + assert.Equal(t, append(keys, keys...), val) + }) } diff --git a/pkg/dynamicaccess/mock/container.go b/pkg/dynamicaccess/mock/container.go deleted file mode 100644 index 3cad9badd39..00000000000 --- a/pkg/dynamicaccess/mock/container.go +++ /dev/null @@ -1,20 +0,0 @@ -package mock - -type ContainerMock struct { - AddFunc func(string, string, string) error - GetFunc func(string, string, string) (string, error) -} - -func (ma *ContainerMock) Add(ref string, publisher string, tag string) error { - if ma.AddFunc == nil { - return nil - } - return ma.AddFunc(ref, publisher, tag) -} - -func (ma *ContainerMock) Get(ref string, publisher string, tag string) (string, error) { - if ma.GetFunc == nil { - return "", nil - } - return ma.GetFunc(ref, publisher, tag) -} diff --git a/pkg/dynamicaccess/mock/grantee.go b/pkg/dynamicaccess/mock/grantee.go new file mode 100644 index 00000000000..f4bd90740ab --- /dev/null +++ b/pkg/dynamicaccess/mock/grantee.go @@ -0,0 +1,51 @@ +package mock + +import ( + "crypto/ecdsa" + + "github.com/ethersphere/bee/pkg/swarm" +) + +type GranteeListMock interface { + Add(publicKeys []*ecdsa.PublicKey) error + Remove(removeList []*ecdsa.PublicKey) error + Get() []*ecdsa.PublicKey + Save() (swarm.Address, error) +} + +type GranteeListStructMock struct { + grantees []*ecdsa.PublicKey +} + +func (g *GranteeListStructMock) Get() []*ecdsa.PublicKey { + grantees := g.grantees + keys := make([]*ecdsa.PublicKey, len(grantees)) + copy(keys, grantees) + return keys +} + +func (g *GranteeListStructMock) Add(addList []*ecdsa.PublicKey) error { + g.grantees = append(g.grantees, addList...) + return nil +} + +func (g *GranteeListStructMock) Remove(removeList []*ecdsa.PublicKey) error { + for _, remove := range removeList { + for i, grantee := range g.grantees { + if *grantee == *remove { + g.grantees[i] = g.grantees[len(g.grantees)-1] + g.grantees = g.grantees[:len(g.grantees)-1] + } + } + } + + return nil +} + +func (g *GranteeListStructMock) Save() (swarm.Address, error) { + return swarm.EmptyAddress, nil +} + +func NewGranteeList() *GranteeListStructMock { + return &GranteeListStructMock{grantees: []*ecdsa.PublicKey{}} +} From f37a2c29e32e9e04ebcd5ef5d8e84a8e1049b3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Ar=C3=A1nyi?= Date: Wed, 3 Apr 2024 16:21:58 +0400 Subject: [PATCH 21/22] Merging Swarm 2.0 master (#32) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(stamper): global lock stamper across multiple upload sessions (#4578) * fix: strategy and fetch timeout parsing (#4579) * feat: neighborhood suggester config (#4580) * feat: add codeql.yml (#4334) * feat: add reserveSizeWithinRadius to status protocol (#4585) * fix: missing 200 response (#4526) * feat: pinned reference integrity check API (#4573) * fix(redundancy/getter): wait for recovery and return error (#4581) * fix(pushsync): store the chunk locally when no peers are available fo… (#4597) * fix(redundancy): on by default when downloading (#4602) * fix: add missing openapi spec (#4598) * feat: bzz resource info API (#4588) * fix(redundancy): bzz unit test (#4603) * feat: redundancy ci (#4591) * chore: bump github.com/quic-go/quic-go from 0.38.1 to 0.38.2 (#4534) * feat: split input file to chunks with specified redundancy (#4600) * perf(getter): cancel inflight requests if enough chunks are fetched for recovery (#4608) * fix: store dir error info (#4605) * chore: remove repetitive words (#4611) * fix: use neighborhood suggester only on mainnet (#4612) * feat: alternative withdrawal address (#4606) * fix(seg65) (#4604) * fix(getter): redundancy getter cleanup (#4610) * feat: v2 (#4615) * fix(pin_integrity): changed route and added openapi (#4616) * fix: missing v2 in the makefile and goreleaser (#4622) --- .github/workflows/beekeeper.yml | 6 + .github/workflows/codeql.yml | 76 ++++ .goreleaser.yml | 50 +- Makefile | 14 +- cmd/bee/cmd/cmd.go | 138 +++--- cmd/bee/cmd/cmd_test.go | 2 +- cmd/bee/cmd/db.go | 10 +- cmd/bee/cmd/db_test.go | 18 +- cmd/bee/cmd/deploy.go | 4 +- cmd/bee/cmd/init.go | 2 +- cmd/bee/cmd/split.go | 171 +++++-- cmd/bee/cmd/split_test.go | 120 ++++- cmd/bee/cmd/start.go | 31 +- cmd/bee/cmd/start_dev.go | 2 +- cmd/bee/cmd/start_unix.go | 2 +- cmd/bee/cmd/start_windows.go | 2 +- cmd/bee/cmd/timebomb.go | 4 +- cmd/bee/cmd/version.go | 2 +- cmd/bee/cmd/version_test.go | 4 +- cmd/bee/main.go | 2 +- go.mod | 4 +- go.sum | 4 +- openapi/Swarm.yaml | 102 +++++ openapi/SwarmCommon.yaml | 98 +++- openapi/SwarmDebug.yaml | 45 +- pkg/accounting/accounting.go | 12 +- pkg/accounting/accounting_test.go | 12 +- pkg/accounting/export_test.go | 2 +- pkg/accounting/metrics.go | 2 +- pkg/accounting/mock/accounting.go | 4 +- pkg/addressbook/addressbook.go | 6 +- pkg/addressbook/addressbook_test.go | 10 +- pkg/api/accounting.go | 4 +- pkg/api/accounting_test.go | 12 +- pkg/api/api.go | 82 ++-- pkg/api/api_test.go | 101 ++-- pkg/api/auth_test.go | 10 +- pkg/api/balances.go | 8 +- pkg/api/balances_test.go | 14 +- pkg/api/bytes.go | 25 +- pkg/api/bytes_test.go | 16 +- pkg/api/bzz.go | 105 +++-- pkg/api/bzz_test.go | 77 ++-- pkg/api/chequebook.go | 12 +- pkg/api/chequebook_test.go | 20 +- pkg/api/chunk.go | 38 +- pkg/api/chunk_address.go | 4 +- pkg/api/chunk_stream.go | 14 +- pkg/api/chunk_stream_test.go | 12 +- pkg/api/chunk_test.go | 22 +- pkg/api/cors_test.go | 6 +- pkg/api/debugstorage.go | 4 +- pkg/api/debugstorage_test.go | 6 +- pkg/api/dirs.go | 35 +- pkg/api/dirs_test.go | 16 +- pkg/api/export_test.go | 5 +- pkg/api/feed.go | 22 +- pkg/api/feed_test.go | 24 +- pkg/api/health.go | 4 +- pkg/api/health_test.go | 6 +- pkg/api/logger.go | 4 +- pkg/api/logger_test.go | 8 +- pkg/api/metrics.go | 7 +- pkg/api/metrics_test.go | 2 +- pkg/api/node.go | 2 +- pkg/api/node_test.go | 2 +- pkg/api/p2p.go | 6 +- pkg/api/p2p_test.go | 12 +- pkg/api/peer.go | 6 +- pkg/api/peer_test.go | 16 +- pkg/api/pin.go | 60 ++- pkg/api/pin_test.go | 66 ++- pkg/api/pingpong.go | 6 +- pkg/api/pingpong_test.go | 12 +- pkg/api/postage.go | 12 +- pkg/api/postage_test.go | 26 +- pkg/api/pss.go | 10 +- pkg/api/pss_test.go | 26 +- pkg/api/rchash.go | 6 +- pkg/api/readiness_test.go | 4 +- pkg/api/redistribution.go | 6 +- pkg/api/redistribution_test.go | 14 +- pkg/api/router.go | 25 +- pkg/api/settlements.go | 10 +- pkg/api/settlements_test.go | 14 +- pkg/api/soc.go | 12 +- pkg/api/soc_test.go | 14 +- pkg/api/staking.go | 6 +- pkg/api/staking_test.go | 16 +- pkg/api/status.go | 49 +- pkg/api/status_test.go | 50 +- pkg/api/stewardship.go | 8 +- pkg/api/stewardship_test.go | 16 +- pkg/api/subdomain.go | 6 +- pkg/api/subdomain_test.go | 14 +- pkg/api/tag.go | 8 +- pkg/api/tag_test.go | 12 +- pkg/api/topology.go | 2 +- pkg/api/topology_test.go | 2 +- pkg/api/transaction.go | 8 +- pkg/api/transaction_test.go | 12 +- pkg/api/util.go | 4 +- pkg/api/util_test.go | 4 +- pkg/api/wallet.go | 105 ++++- pkg/api/wallet_test.go | 214 ++++++++- pkg/api/welcome_message.go | 2 +- pkg/api/welcome_message_test.go | 8 +- pkg/auth/auth.go | 7 +- pkg/auth/auth_test.go | 4 +- pkg/auth/handler.go | 2 +- pkg/bigint/bigint_test.go | 2 +- pkg/blocker/blocker.go | 6 +- pkg/blocker/blocker_test.go | 10 +- pkg/bmt/benchmark_test.go | 8 +- pkg/bmt/bmt.go | 2 +- pkg/bmt/bmt_test.go | 8 +- pkg/bmt/proof_test.go | 4 +- pkg/bmt/reference/reference_test.go | 2 +- pkg/bmtpool/bmtpool.go | 4 +- pkg/bzz/address.go | 4 +- pkg/bzz/address_test.go | 4 +- pkg/bzz/utilities_test.go | 6 +- pkg/cac/cac.go | 4 +- pkg/cac/cac_test.go | 6 +- pkg/crypto/clef/clef.go | 4 +- pkg/crypto/clef/clef_test.go | 6 +- pkg/crypto/crypto.go | 2 +- pkg/crypto/crypto_test.go | 4 +- pkg/crypto/dh_test.go | 2 +- pkg/crypto/mock/signer.go | 4 +- pkg/crypto/signer.go | 2 +- pkg/crypto/signer_test.go | 4 +- pkg/discovery/discovery.go | 2 +- pkg/discovery/mock/mock.go | 2 +- pkg/encryption/chunk_encryption.go | 13 +- pkg/encryption/elgamal/encryption.go | 4 +- pkg/encryption/elgamal/encryption_test.go | 6 +- pkg/encryption/encryption_test.go | 6 +- pkg/encryption/mock/chunk_encryption.go | 2 +- pkg/encryption/mock/mock.go | 2 +- pkg/encryption/mock/mock_test.go | 2 +- pkg/encryption/store/decrypt_store.go | 24 +- pkg/feeds/epochs/epoch.go | 4 +- pkg/feeds/epochs/finder.go | 6 +- pkg/feeds/epochs/lookup_benchmark_test.go | 10 +- pkg/feeds/epochs/lookup_test.go | 10 +- pkg/feeds/epochs/updater.go | 6 +- pkg/feeds/factory/factory.go | 8 +- pkg/feeds/feed.go | 8 +- pkg/feeds/getter.go | 6 +- pkg/feeds/putter.go | 10 +- pkg/feeds/sequence/lookup_benchmark_test.go | 10 +- pkg/feeds/sequence/lookup_test.go | 10 +- pkg/feeds/sequence/sequence.go | 8 +- pkg/feeds/testing/lookup.go | 10 +- pkg/file/addresses/addresses_getter.go | 4 +- pkg/file/addresses/addresses_getter_test.go | 12 +- pkg/file/buffer.go | 2 +- pkg/file/buffer_test.go | 6 +- pkg/file/file.go | 2 +- pkg/file/file_test.go | 12 +- pkg/file/io.go | 2 +- pkg/file/joiner/joiner.go | 43 +- pkg/file/joiner/joiner_test.go | 87 ++-- pkg/file/loadsave/loadsave.go | 12 +- pkg/file/loadsave/loadsave_test.go | 12 +- pkg/file/pipeline/bmt/bmt.go | 6 +- pkg/file/pipeline/bmt/bmt_test.go | 6 +- pkg/file/pipeline/builder/builder.go | 20 +- pkg/file/pipeline/builder/builder_test.go | 10 +- pkg/file/pipeline/encryption/encryption.go | 4 +- .../pipeline/encryption/encryption_test.go | 8 +- pkg/file/pipeline/feeder/feeder.go | 4 +- pkg/file/pipeline/feeder/feeder_test.go | 4 +- pkg/file/pipeline/hashtrie/hashtrie.go | 10 +- pkg/file/pipeline/hashtrie/hashtrie_test.go | 30 +- pkg/file/pipeline/mock/writer.go | 2 +- pkg/file/pipeline/store/store.go | 6 +- pkg/file/pipeline/store/store_test.go | 10 +- pkg/file/redundancy/getter/getter.go | 430 +++++++++++------- pkg/file/redundancy/getter/getter_test.go | 56 +-- pkg/file/redundancy/getter/strategies.go | 160 ++----- pkg/file/redundancy/level.go | 2 +- pkg/file/redundancy/redundancy.go | 4 +- pkg/file/redundancy/redundancy_test.go | 8 +- pkg/file/redundancy/span.go | 2 +- pkg/file/span.go | 2 +- pkg/file/splitter/internal/job.go | 23 +- pkg/file/splitter/internal/job_test.go | 8 +- pkg/file/splitter/splitter.go | 8 +- pkg/file/splitter/splitter_test.go | 10 +- pkg/file/testing/chunk.go | 2 +- pkg/file/testing/vector.go | 2 +- pkg/file/utils.go | 4 +- pkg/hive/hive.go | 16 +- pkg/hive/hive_test.go | 24 +- pkg/hive/metrics.go | 2 +- pkg/jsonhttp/handlers_test.go | 2 +- pkg/jsonhttp/jsonhttp_test.go | 2 +- pkg/jsonhttp/jsonhttptest/jsonhttptest.go | 2 +- .../jsonhttptest/jsonhttptest_test.go | 4 +- pkg/keystore/file/key.go | 4 +- pkg/keystore/file/service.go | 2 +- pkg/keystore/file/service_test.go | 4 +- pkg/keystore/mem/service.go | 2 +- pkg/keystore/mem/service_test.go | 4 +- pkg/keystore/test/test.go | 4 +- pkg/log/example_test.go | 2 +- pkg/log/formatter_test.go | 6 +- pkg/log/httpaccess/http_access.go | 4 +- pkg/log/logger.go | 2 +- pkg/log/logger_test.go | 2 +- pkg/log/metrics.go | 2 +- pkg/manifest/manifest.go | 4 +- pkg/manifest/mantaray.go | 6 +- pkg/manifest/mantaray/node_test.go | 2 +- pkg/manifest/mantaray/persist_test.go | 2 +- pkg/manifest/mantaray/walker_test.go | 2 +- pkg/manifest/simple.go | 6 +- pkg/manifest/simple/manifest_test.go | 4 +- pkg/manifest/simple/walker_test.go | 2 +- pkg/metrics/metrics_test.go | 2 +- pkg/node/bootstrap.go | 54 +-- pkg/node/chain.go | 30 +- pkg/node/devnode.go | 80 ++-- pkg/node/node.go | 122 ++--- pkg/node/statestore.go | 14 +- pkg/p2p/libp2p/connections_test.go | 18 +- pkg/p2p/libp2p/export_test.go | 2 +- pkg/p2p/libp2p/headers.go | 8 +- pkg/p2p/libp2p/headers_test.go | 6 +- .../libp2p/internal/blocklist/blocklist.go | 6 +- .../internal/blocklist/blocklist_test.go | 8 +- .../libp2p/internal/blocklist/export_test.go | 2 +- .../libp2p/internal/breaker/breaker_test.go | 2 +- .../libp2p/internal/handshake/handshake.go | 16 +- .../internal/handshake/handshake_test.go | 16 +- pkg/p2p/libp2p/internal/handshake/metrics.go | 2 +- .../libp2p/internal/handshake/mock/stream.go | 2 +- pkg/p2p/libp2p/internal/reacher/metrics.go | 2 +- pkg/p2p/libp2p/internal/reacher/reacher.go | 4 +- .../libp2p/internal/reacher/reacher_test.go | 8 +- pkg/p2p/libp2p/libp2p.go | 32 +- pkg/p2p/libp2p/libp2p_test.go | 20 +- pkg/p2p/libp2p/metrics.go | 2 +- pkg/p2p/libp2p/peer.go | 4 +- pkg/p2p/libp2p/protocols_test.go | 6 +- pkg/p2p/libp2p/static_resolver_test.go | 2 +- pkg/p2p/libp2p/stream.go | 2 +- pkg/p2p/libp2p/tracing_test.go | 6 +- pkg/p2p/libp2p/welcome_message_test.go | 4 +- pkg/p2p/mock/mock.go | 6 +- pkg/p2p/p2p.go | 4 +- pkg/p2p/p2p_test.go | 2 +- pkg/p2p/protobuf/main_test.go | 2 +- pkg/p2p/protobuf/protobuf.go | 2 +- pkg/p2p/protobuf/protobuf_test.go | 6 +- pkg/p2p/specwrapper_test.go | 2 +- pkg/p2p/streamtest/streamtest.go | 6 +- pkg/p2p/streamtest/streamtest_test.go | 6 +- pkg/pingpong/metrics.go | 2 +- pkg/pingpong/mock/mock.go | 2 +- pkg/pingpong/pingpong.go | 12 +- pkg/pingpong/pingpong_test.go | 14 +- pkg/postage/batch_test.go | 4 +- pkg/postage/batchservice/batchservice.go | 6 +- pkg/postage/batchservice/batchservice_test.go | 16 +- pkg/postage/batchstore/metrics.go | 2 +- pkg/postage/batchstore/mock/store.go | 6 +- pkg/postage/batchstore/mock/store_test.go | 4 +- pkg/postage/batchstore/store.go | 6 +- pkg/postage/batchstore/store_test.go | 22 +- pkg/postage/export_test.go | 2 +- pkg/postage/listener/listener.go | 10 +- pkg/postage/listener/listener_test.go | 14 +- pkg/postage/listener/metrics.go | 2 +- pkg/postage/mock/service.go | 2 +- pkg/postage/mock/stamper.go | 4 +- pkg/postage/noop.go | 2 +- pkg/postage/postagecontract/contract.go | 8 +- pkg/postage/postagecontract/contract_test.go | 18 +- pkg/postage/postagecontract/mock/contract.go | 2 +- pkg/postage/service.go | 8 +- pkg/postage/service_test.go | 16 +- pkg/postage/stamp.go | 6 +- pkg/postage/stamp_test.go | 12 +- pkg/postage/stamper.go | 14 +- pkg/postage/stamper_test.go | 10 +- pkg/postage/stampissuer.go | 16 +- pkg/postage/stampissuer_test.go | 8 +- pkg/postage/testing/batch.go | 2 +- pkg/postage/testing/chainstate.go | 2 +- pkg/postage/testing/stamp.go | 6 +- pkg/pricer/headerutils/utilities.go | 4 +- pkg/pricer/headerutils/utilities_test.go | 6 +- pkg/pricer/mock/pricer.go | 2 +- pkg/pricer/pricer.go | 2 +- pkg/pricing/export_test.go | 2 +- pkg/pricing/pricing.go | 10 +- pkg/pricing/pricing_test.go | 14 +- pkg/pss/metrics.go | 2 +- pkg/pss/mining_test.go | 4 +- pkg/pss/pss.go | 10 +- pkg/pss/pss_test.go | 16 +- pkg/pss/trojan.go | 10 +- pkg/pss/trojan_test.go | 6 +- pkg/puller/export_test.go | 2 +- pkg/puller/intervalstore/store_test.go | 10 +- pkg/puller/metrics.go | 2 +- pkg/puller/puller.go | 18 +- pkg/puller/puller_test.go | 22 +- pkg/pullsync/metrics.go | 2 +- pkg/pullsync/mock/pullsync.go | 4 +- pkg/pullsync/pullsync.go | 22 +- pkg/pullsync/pullsync_test.go | 22 +- pkg/pusher/inflight.go | 2 +- pkg/pusher/metrics.go | 2 +- pkg/pusher/pusher.go | 16 +- pkg/pusher/pusher_test.go | 24 +- pkg/pushsync/metrics.go | 2 +- pkg/pushsync/mock/mock.go | 4 +- pkg/pushsync/pushsync.go | 32 +- pkg/pushsync/pushsync_test.go | 32 +- pkg/rate/rate_test.go | 2 +- pkg/ratelimit/ratelimit_test.go | 2 +- pkg/replicas/export_test.go | 2 +- pkg/replicas/getter.go | 8 +- pkg/replicas/getter_test.go | 12 +- pkg/replicas/putter.go | 8 +- pkg/replicas/putter_test.go | 12 +- pkg/replicas/replica_test.go | 8 +- pkg/replicas/replicas.go | 6 +- pkg/resolver/cidv1/cidv1.go | 4 +- pkg/resolver/cidv1/cidv1_test.go | 6 +- pkg/resolver/client/client.go | 2 +- pkg/resolver/client/ens/ens.go | 6 +- .../client/ens/ens_integration_test.go | 4 +- pkg/resolver/client/ens/ens_test.go | 6 +- pkg/resolver/client/mock/mock.go | 4 +- pkg/resolver/mock/resolver.go | 4 +- pkg/resolver/multiresolver/config_test.go | 2 +- pkg/resolver/multiresolver/export_test.go | 2 +- pkg/resolver/multiresolver/multiresolver.go | 8 +- .../multiresolver/multiresolver_test.go | 10 +- pkg/resolver/resolver.go | 2 +- pkg/retrieval/export_test.go | 4 +- pkg/retrieval/main_test.go | 4 +- pkg/retrieval/metrics.go | 2 +- pkg/retrieval/retrieval.go | 32 +- pkg/retrieval/retrieval_test.go | 40 +- pkg/salud/metrics.go | 2 +- pkg/salud/salud.go | 10 +- pkg/salud/salud_test.go | 14 +- pkg/settlement/interface.go | 2 +- pkg/settlement/pseudosettle/export_test.go | 2 +- pkg/settlement/pseudosettle/metrics.go | 2 +- pkg/settlement/pseudosettle/pseudosettle.go | 14 +- .../pseudosettle/pseudosettle_test.go | 22 +- pkg/settlement/swap/addressbook.go | 4 +- pkg/settlement/swap/chequebook/cashout.go | 6 +- .../swap/chequebook/cashout_test.go | 12 +- pkg/settlement/swap/chequebook/cheque.go | 4 +- pkg/settlement/swap/chequebook/cheque_test.go | 8 +- pkg/settlement/swap/chequebook/chequebook.go | 10 +- .../swap/chequebook/chequebook_test.go | 10 +- pkg/settlement/swap/chequebook/chequestore.go | 6 +- .../swap/chequebook/chequestore_test.go | 6 +- pkg/settlement/swap/chequebook/common_test.go | 2 +- pkg/settlement/swap/chequebook/contract.go | 2 +- pkg/settlement/swap/chequebook/factory.go | 6 +- .../swap/chequebook/factory_test.go | 10 +- pkg/settlement/swap/chequebook/init.go | 12 +- .../swap/chequebook/mock/chequebook.go | 2 +- .../swap/chequestore/mock/chequestore.go | 2 +- pkg/settlement/swap/erc20/erc20.go | 6 +- pkg/settlement/swap/erc20/erc20_test.go | 6 +- pkg/settlement/swap/erc20/mock/erc20.go | 2 +- pkg/settlement/swap/headers/utilities.go | 2 +- pkg/settlement/swap/headers/utilities_test.go | 4 +- pkg/settlement/swap/metrics.go | 2 +- pkg/settlement/swap/mock/swap.go | 8 +- .../swap/priceoracle/priceoracle.go | 6 +- .../swap/priceoracle/priceoracle_test.go | 8 +- pkg/settlement/swap/swap.go | 14 +- pkg/settlement/swap/swap_test.go | 18 +- .../swap/swapprotocol/export_test.go | 2 +- .../swap/swapprotocol/swapprotocol.go | 16 +- .../swap/swapprotocol/swapprotocol_test.go | 20 +- pkg/sharky/metrics.go | 2 +- pkg/sharky/recovery_test.go | 2 +- pkg/sharky/shard_test.go | 2 +- pkg/sharky/sharky_test.go | 2 +- pkg/shed/db_test.go | 2 +- pkg/shed/example_store_test.go | 8 +- pkg/shed/metrics.go | 2 +- pkg/skippeers/skippeers.go | 2 +- pkg/skippeers/skippeers_test.go | 4 +- pkg/soc/soc.go | 6 +- pkg/soc/soc_test.go | 43 +- pkg/soc/testing/soc.go | 8 +- pkg/soc/validator.go | 2 +- pkg/soc/validator_test.go | 8 +- pkg/spinlock/wait_test.go | 2 +- pkg/statestore/leveldb/leveldb.go | 4 +- pkg/statestore/leveldb/leveldb_test.go | 8 +- pkg/statestore/mock/store.go | 2 +- pkg/statestore/mock/store_test.go | 6 +- pkg/statestore/storeadapter/migration.go | 4 +- pkg/statestore/storeadapter/storeadapter.go | 6 +- .../storeadapter/storeadapter_test.go | 10 +- pkg/statestore/test/store.go | 2 +- pkg/status/internal/pb/status.pb.go | 90 ++-- pkg/status/internal/pb/status.proto | 1 + pkg/status/status.go | 44 +- pkg/status/status_test.go | 19 +- pkg/steward/mock/steward.go | 4 +- pkg/steward/steward.go | 14 +- pkg/steward/steward_test.go | 16 +- pkg/storage/cache/cache.go | 4 +- pkg/storage/cache/cache_test.go | 6 +- pkg/storage/cache/metrics.go | 2 +- pkg/storage/chunkstore.go | 2 +- .../inmemchunkstore/inmemchunkstore.go | 4 +- .../inmemchunkstore/inmemchunkstore_test.go | 4 +- pkg/storage/inmemchunkstore/transaction.go | 4 +- .../inmemchunkstore/transaction_test.go | 4 +- pkg/storage/inmemstore/inmembatch.go | 2 +- pkg/storage/inmemstore/inmemstore.go | 2 +- pkg/storage/inmemstore/inmemstore_test.go | 4 +- pkg/storage/inmemstore/transaction.go | 2 +- pkg/storage/inmemstore/transaction_test.go | 4 +- pkg/storage/leveldbstore/batch.go | 2 +- pkg/storage/leveldbstore/recovery.go | 4 +- pkg/storage/leveldbstore/recovery_test.go | 6 +- pkg/storage/leveldbstore/store.go | 2 +- pkg/storage/leveldbstore/store_test.go | 4 +- pkg/storage/leveldbstore/transaction.go | 4 +- pkg/storage/leveldbstore/transaction_test.go | 4 +- pkg/storage/metrics.go | 4 +- pkg/storage/migration/index.go | 2 +- pkg/storage/migration/index_test.go | 6 +- pkg/storage/migration/migration.go | 4 +- pkg/storage/migration/migration_test.go | 10 +- pkg/storage/migration/steps_chain.go | 2 +- pkg/storage/migration/steps_chain_test.go | 6 +- pkg/storage/repository.go | 4 +- pkg/storage/storagetest/batch.go | 2 +- pkg/storage/storagetest/benchmark.go | 6 +- pkg/storage/storagetest/chunkstore.go | 8 +- pkg/storage/storagetest/storage.go | 8 +- pkg/storage/storagetest/transaction.go | 8 +- pkg/storage/testing/chunk.go | 12 +- pkg/storage/transaction.go | 2 +- pkg/storage/transaction_test.go | 2 +- pkg/storageincentives/agent.go | 22 +- pkg/storageincentives/agent_test.go | 26 +- pkg/storageincentives/events_test.go | 2 +- pkg/storageincentives/metrics.go | 2 +- pkg/storageincentives/proof.go | 14 +- pkg/storageincentives/proof_test.go | 20 +- .../redistribution/inclusionproof.go | 8 +- .../redistribution/redistribution.go | 8 +- .../redistribution/redistribution_test.go | 18 +- pkg/storageincentives/redistributionstate.go | 12 +- .../redistributionstate_test.go | 10 +- pkg/storageincentives/soc_mine_test.go | 10 +- pkg/storageincentives/staking/contract.go | 8 +- .../staking/contract_test.go | 12 +- .../staking/mock/contract.go | 2 +- pkg/storer/cachestore.go | 6 +- pkg/storer/cachestore_test.go | 12 +- pkg/storer/compact.go | 6 +- pkg/storer/compact_test.go | 12 +- pkg/storer/debug.go | 10 +- pkg/storer/debug_test.go | 6 +- pkg/storer/export_test.go | 6 +- pkg/storer/internal/cache/cache.go | 6 +- pkg/storer/internal/cache/cache_test.go | 12 +- pkg/storer/internal/cache/export_test.go | 6 +- pkg/storer/internal/chunkstamp/chunkstamp.go | 8 +- .../internal/chunkstamp/chunkstamp_test.go | 14 +- pkg/storer/internal/chunkstamp/export_test.go | 2 +- pkg/storer/internal/chunkstore/chunkstore.go | 8 +- .../internal/chunkstore/chunkstore_test.go | 14 +- pkg/storer/internal/chunkstore/helpers.go | 4 +- .../internal/chunkstore/helpers_test.go | 12 +- pkg/storer/internal/chunkstore/recovery.go | 8 +- .../internal/chunkstore/recovery_test.go | 12 +- pkg/storer/internal/chunkstore/transaction.go | 8 +- .../internal/chunkstore/transaction_test.go | 16 +- pkg/storer/internal/events/subscribe_test.go | 2 +- pkg/storer/internal/internal.go | 8 +- pkg/storer/internal/pinning/export_test.go | 4 +- pkg/storer/internal/pinning/pinning.go | 10 +- pkg/storer/internal/pinning/pinning_test.go | 12 +- pkg/storer/internal/reserve/items.go | 8 +- pkg/storer/internal/reserve/items_test.go | 8 +- pkg/storer/internal/reserve/reserve.go | 14 +- pkg/storer/internal/reserve/reserve_test.go | 22 +- pkg/storer/internal/stampindex/export_test.go | 2 +- pkg/storer/internal/stampindex/stampindex.go | 8 +- .../internal/stampindex/stampindex_test.go | 12 +- pkg/storer/internal/upload/uploadstore.go | 12 +- .../internal/upload/uploadstore_test.go | 12 +- pkg/storer/metrics.go | 6 +- pkg/storer/migration/all_steps.go | 6 +- pkg/storer/migration/all_steps_test.go | 8 +- pkg/storer/migration/refCntSize.go | 12 +- pkg/storer/migration/refCntSize_test.go | 10 +- pkg/storer/migration/step_01.go | 2 +- pkg/storer/migration/step_01_test.go | 4 +- pkg/storer/migration/step_02.go | 6 +- pkg/storer/migration/step_02_test.go | 10 +- pkg/storer/migration/step_03.go | 8 +- pkg/storer/migration/step_03_test.go | 14 +- pkg/storer/migration/step_04.go | 10 +- pkg/storer/migration/step_04_test.go | 12 +- pkg/storer/migration/step_05.go | 6 +- pkg/storer/migration/step_05_test.go | 22 +- pkg/storer/mock/forgetting.go | 4 +- pkg/storer/mock/mockreserve.go | 6 +- pkg/storer/mock/mockstorer.go | 12 +- pkg/storer/mock/mockstorer_test.go | 10 +- pkg/storer/netstore.go | 8 +- pkg/storer/netstore_test.go | 12 +- pkg/storer/pinstore.go | 8 +- pkg/storer/pinstore_test.go | 8 +- pkg/storer/recover.go | 8 +- pkg/storer/reserve.go | 18 +- pkg/storer/reserve_test.go | 26 +- pkg/storer/sample.go | 16 +- pkg/storer/sample_test.go | 10 +- pkg/storer/storer.go | 81 ++-- pkg/storer/storer_test.go | 28 +- pkg/storer/subscribe_push.go | 4 +- pkg/storer/subscribe_push_test.go | 6 +- pkg/storer/uploadstore.go | 10 +- pkg/storer/uploadstore_test.go | 8 +- pkg/storer/validate.go | 160 +++++-- pkg/swarm/distance_test.go | 2 +- pkg/swarm/hasher_test.go | 2 +- pkg/swarm/swarm_test.go | 2 +- pkg/swarm/test_helpers.go | 2 +- pkg/swarm/test_helpers_test.go | 2 +- pkg/swarm/utilities_test.go | 2 +- pkg/topology/kademlia/binprefix.go | 2 +- pkg/topology/kademlia/export_test.go | 6 +- .../kademlia/internal/metrics/metrics.go | 6 +- .../kademlia/internal/metrics/metrics_test.go | 10 +- .../kademlia/internal/waitnext/waitnext.go | 2 +- .../internal/waitnext/waitnext_test.go | 4 +- pkg/topology/kademlia/kademlia.go | 22 +- pkg/topology/kademlia/kademlia_test.go | 30 +- pkg/topology/kademlia/metrics.go | 2 +- pkg/topology/kademlia/mock/kademlia.go | 6 +- pkg/topology/lightnode/container.go | 8 +- pkg/topology/lightnode/container_test.go | 8 +- pkg/topology/lightnode/metrics.go | 2 +- pkg/topology/mock/mock.go | 6 +- pkg/topology/pslice/pslice.go | 4 +- pkg/topology/pslice/pslice_test.go | 4 +- pkg/topology/topology.go | 4 +- pkg/tracing/tracing.go | 4 +- pkg/tracing/tracing_test.go | 8 +- pkg/transaction/backend.go | 2 +- pkg/transaction/backend_test.go | 4 +- pkg/transaction/backendmock/backend.go | 2 +- pkg/transaction/backendsimulation/backend.go | 2 +- pkg/transaction/event_test.go | 4 +- pkg/transaction/mock/transaction.go | 2 +- pkg/transaction/monitor.go | 2 +- pkg/transaction/monitor_test.go | 6 +- pkg/transaction/monitormock/monitor.go | 2 +- pkg/transaction/transaction.go | 8 +- pkg/transaction/transaction_test.go | 20 +- pkg/transaction/wrapped/metrics.go | 2 +- pkg/transaction/wrapped/wrapped.go | 2 +- pkg/traversal/traversal.go | 14 +- pkg/traversal/traversal_test.go | 18 +- pkg/util/nbhdutil/miner.go | 4 +- pkg/util/nbhdutil/miner_test.go | 6 +- pkg/util/nbhdutil/neighborhoodsuggestion.go | 53 +++ .../nbhdutil/neighborhoodsuggestion_test.go | 86 ++++ pkg/util/testutil/helpers.go | 4 +- pkg/util/testutil/helpers_test.go | 2 +- pkg/util/testutil/pseudorand/reader.go | 2 +- pkg/util/testutil/pseudorand/reader_test.go | 2 +- 587 files changed, 4474 insertions(+), 3083 deletions(-) create mode 100644 .github/workflows/codeql.yml create mode 100644 pkg/util/nbhdutil/neighborhoodsuggestion.go create mode 100644 pkg/util/nbhdutil/neighborhoodsuggestion_test.go diff --git a/.github/workflows/beekeeper.yml b/.github/workflows/beekeeper.yml index 95a09cfc1dc..da44ec4d14a 100644 --- a/.github/workflows/beekeeper.yml +++ b/.github/workflows/beekeeper.yml @@ -162,6 +162,12 @@ jobs: - name: Test staking id: stake run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-stake + - name: Test withdraw + id: withdraw + run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks ci-withdraw; do echo "waiting for withdraw..."; sleep .3; done' + - name: Test redundancy + id: redundancy + run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-redundancy - name: Collect debug artifacts if: failure() run: | diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000000..51c624e6cbd --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,76 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" +permissions: read-all +on: + push: + branches: [ "master" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '23 1 * * 2' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.goreleaser.yml b/.goreleaser.yml index 9e26e592582..88bf9d55c85 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -15,11 +15,11 @@ builds: - -trimpath ldflags: - -s -w - - -X github.com/ethersphere/bee.version={{ .Version }} - - -X github.com/ethersphere/bee.commitHash={{ .ShortCommit }} - - -X github.com/ethersphere/bee.commitTime={{ .CommitTimestamp }} - - -X github.com/ethersphere/bee/pkg/api.Version={{ .Env.BEE_API_VERSION }} - - -X github.com/ethersphere/bee/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} + - -X github.com/ethersphere/bee/v2.version={{ .Version }} + - -X github.com/ethersphere/bee/v2.commitHash={{ .ShortCommit }} + - -X github.com/ethersphere/bee/v2.commitTime={{ .CommitTimestamp }} + - -X github.com/ethersphere/bee/v2/pkg/api.Version={{ .Env.BEE_API_VERSION }} + - -X github.com/ethersphere/bee/v2/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} env: - CGO_ENABLED=0 goos: @@ -39,11 +39,11 @@ builds: - -trimpath ldflags: - -s -w - - -X github.com/ethersphere/bee.version={{ .Version }} - - -X github.com/ethersphere/bee.commitHash={{ .ShortCommit }} - - -X github.com/ethersphere/bee.commitTime={{ .CommitTimestamp }} - - -X github.com/ethersphere/bee/pkg/api.Version={{ .Env.BEE_API_VERSION }} - - -X github.com/ethersphere/bee/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} + - -X github.com/ethersphere/bee/v2.version={{ .Version }} + - -X github.com/ethersphere/bee/v2.commitHash={{ .ShortCommit }} + - -X github.com/ethersphere/bee/v2.commitTime={{ .CommitTimestamp }} + - -X github.com/ethersphere/bee/v2/pkg/api.Version={{ .Env.BEE_API_VERSION }} + - -X github.com/ethersphere/bee/v2/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} env: - CGO_ENABLED=0 goos: @@ -65,11 +65,11 @@ builds: - -trimpath ldflags: - -s -w - - -X github.com/ethersphere/bee.version={{ .Version }} - - -X github.com/ethersphere/bee.commitHash={{ .ShortCommit }} - - -X github.com/ethersphere/bee.commitTime={{ .CommitTimestamp }} - - -X github.com/ethersphere/bee/pkg/api.Version={{ .Env.BEE_API_VERSION }} - - -X github.com/ethersphere/bee/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} + - -X github.com/ethersphere/bee/v2.version={{ .Version }} + - -X github.com/ethersphere/bee/v2.commitHash={{ .ShortCommit }} + - -X github.com/ethersphere/bee/v2.commitTime={{ .CommitTimestamp }} + - -X github.com/ethersphere/bee/v2/pkg/api.Version={{ .Env.BEE_API_VERSION }} + - -X github.com/ethersphere/bee/v2/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} env: - CGO_ENABLED=0 goos: @@ -85,11 +85,11 @@ builds: - -trimpath ldflags: - -s -w - - -X github.com/ethersphere/bee.version={{ .Version }} - - -X github.com/ethersphere/bee.commitHash={{ .ShortCommit }} - - -X github.com/ethersphere/bee.commitTime={{ .CommitTimestamp }} - - -X github.com/ethersphere/bee/pkg/api.Version={{ .Env.BEE_API_VERSION }} - - -X github.com/ethersphere/bee/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} + - -X github.com/ethersphere/bee/v2.version={{ .Version }} + - -X github.com/ethersphere/bee/v2.commitHash={{ .ShortCommit }} + - -X github.com/ethersphere/bee/v2.commitTime={{ .CommitTimestamp }} + - -X github.com/ethersphere/bee/v2/pkg/api.Version={{ .Env.BEE_API_VERSION }} + - -X github.com/ethersphere/bee/v2/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} env: - CGO_ENABLED=0 goos: @@ -104,11 +104,11 @@ builds: - -trimpath ldflags: - -s -w - - -X github.com/ethersphere/bee.version={{ .Version }} - - -X github.com/ethersphere/bee.commitHash={{ .ShortCommit }} - - -X github.com/ethersphere/bee.commitTime={{ .CommitTimestamp }} - - -X github.com/ethersphere/bee/pkg/api.Version={{ .Env.BEE_API_VERSION }} - - -X github.com/ethersphere/bee/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} + - -X github.com/ethersphere/bee/v2.version={{ .Version }} + - -X github.com/ethersphere/bee/v2.commitHash={{ .ShortCommit }} + - -X github.com/ethersphere/bee/v2.commitTime={{ .CommitTimestamp }} + - -X github.com/ethersphere/bee/v2/pkg/api.Version={{ .Env.BEE_API_VERSION }} + - -X github.com/ethersphere/bee/v2/pkg/debugapi.Version={{ .Env.BEE_DEBUG_API_VERSION }} env: - CGO_ENABLED=0 goos: diff --git a/Makefile b/Makefile index f245354331c..46da4995b14 100644 --- a/Makefile +++ b/Makefile @@ -20,13 +20,13 @@ COMMIT_HASH ?= "$(shell git describe --long --dirty --always --match "" || true) CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)" COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)" LDFLAGS ?= -s -w \ --X github.com/ethersphere/bee.version="$(VERSION)" \ --X github.com/ethersphere/bee.commitHash="$(COMMIT_HASH)" \ --X github.com/ethersphere/bee.commitTime="$(COMMIT_TIME)" \ --X github.com/ethersphere/bee/pkg/api.Version="$(BEE_API_VERSION)" \ --X github.com/ethersphere/bee/pkg/api.DebugVersion="$(BEE_DEBUG_API_VERSION)" \ --X github.com/ethersphere/bee/pkg/p2p/libp2p.reachabilityOverridePublic="$(REACHABILITY_OVERRIDE_PUBLIC)" \ --X github.com/ethersphere/bee/pkg/postage/listener.batchFactorOverridePublic="$(BATCHFACTOR_OVERRIDE_PUBLIC)" +-X github.com/ethersphere/bee/v2.version="$(VERSION)" \ +-X github.com/ethersphere/bee/v2.commitHash="$(COMMIT_HASH)" \ +-X github.com/ethersphere/bee/v2.commitTime="$(COMMIT_TIME)" \ +-X github.com/ethersphere/bee/v2/pkg/api.Version="$(BEE_API_VERSION)" \ +-X github.com/ethersphere/bee/v2/pkg/api.DebugVersion="$(BEE_DEBUG_API_VERSION)" \ +-X github.com/ethersphere/bee/v2/pkg/p2p/libp2p.reachabilityOverridePublic="$(REACHABILITY_OVERRIDE_PUBLIC)" \ +-X github.com/ethersphere/bee/v2/pkg/postage/listener.batchFactorOverridePublic="$(BATCHFACTOR_OVERRIDE_PUBLIC)" .PHONY: all all: build lint test-race binary diff --git a/cmd/bee/cmd/cmd.go b/cmd/bee/cmd/cmd.go index ffe6bc06d01..7082adf4d19 100644 --- a/cmd/bee/cmd/cmd.go +++ b/cmd/bee/cmd/cmd.go @@ -13,78 +13,80 @@ import ( "strings" "time" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/swarm" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/cobra" "github.com/spf13/viper" ) const ( - optionNameDataDir = "data-dir" - optionNameCacheCapacity = "cache-capacity" - optionNameDBOpenFilesLimit = "db-open-files-limit" - optionNameDBBlockCacheCapacity = "db-block-cache-capacity" - optionNameDBWriteBufferSize = "db-write-buffer-size" - optionNameDBDisableSeeksCompaction = "db-disable-seeks-compaction" - optionNamePassword = "password" - optionNamePasswordFile = "password-file" - optionNameAPIAddr = "api-addr" - optionNameP2PAddr = "p2p-addr" - optionNameNATAddr = "nat-addr" - optionNameP2PWSEnable = "p2p-ws-enable" - optionNameDebugAPIEnable = "debug-api-enable" - optionNameDebugAPIAddr = "debug-api-addr" - optionNameBootnodes = "bootnode" - optionNameNetworkID = "network-id" - optionWelcomeMessage = "welcome-message" - optionCORSAllowedOrigins = "cors-allowed-origins" - optionNameTracingEnabled = "tracing-enable" - optionNameTracingEndpoint = "tracing-endpoint" - optionNameTracingHost = "tracing-host" - optionNameTracingPort = "tracing-port" - optionNameTracingServiceName = "tracing-service-name" - optionNameVerbosity = "verbosity" - optionNamePaymentThreshold = "payment-threshold" - optionNamePaymentTolerance = "payment-tolerance-percent" - optionNamePaymentEarly = "payment-early-percent" - optionNameResolverEndpoints = "resolver-options" - optionNameBootnodeMode = "bootnode-mode" - optionNameClefSignerEnable = "clef-signer-enable" - optionNameClefSignerEndpoint = "clef-signer-endpoint" - optionNameClefSignerEthereumAddress = "clef-signer-ethereum-address" - optionNameSwapEndpoint = "swap-endpoint" // deprecated: use rpc endpoint instead - optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint" - optionNameSwapFactoryAddress = "swap-factory-address" - optionNameSwapInitialDeposit = "swap-initial-deposit" - optionNameSwapEnable = "swap-enable" - optionNameChequebookEnable = "chequebook-enable" - optionNameSwapDeploymentGasPrice = "swap-deployment-gas-price" - optionNameFullNode = "full-node" - optionNamePostageContractAddress = "postage-stamp-address" - optionNamePostageContractStartBlock = "postage-stamp-start-block" - optionNamePriceOracleAddress = "price-oracle-address" - optionNameRedistributionAddress = "redistribution-address" - optionNameStakingAddress = "staking-address" - optionNameBlockTime = "block-time" - optionWarmUpTime = "warmup-time" - optionNameMainNet = "mainnet" - optionNameRetrievalCaching = "cache-retrieval" - optionNameDevReserveCapacity = "dev-reserve-capacity" - optionNameResync = "resync" - optionNamePProfBlock = "pprof-profile" - optionNamePProfMutex = "pprof-mutex" - optionNameStaticNodes = "static-nodes" - optionNameAllowPrivateCIDRs = "allow-private-cidrs" - optionNameSleepAfter = "sleep-after" - optionNameRestrictedAPI = "restricted" - optionNameTokenEncryptionKey = "token-encryption-key" - optionNameAdminPasswordHash = "admin-password" - optionNameUsePostageSnapshot = "use-postage-snapshot" - optionNameStorageIncentivesEnable = "storage-incentives-enable" - optionNameStateStoreCacheCapacity = "statestore-cache-capacity" - optionNameTargetNeighborhood = "target-neighborhood" + optionNameDataDir = "data-dir" + optionNameCacheCapacity = "cache-capacity" + optionNameDBOpenFilesLimit = "db-open-files-limit" + optionNameDBBlockCacheCapacity = "db-block-cache-capacity" + optionNameDBWriteBufferSize = "db-write-buffer-size" + optionNameDBDisableSeeksCompaction = "db-disable-seeks-compaction" + optionNamePassword = "password" + optionNamePasswordFile = "password-file" + optionNameAPIAddr = "api-addr" + optionNameP2PAddr = "p2p-addr" + optionNameNATAddr = "nat-addr" + optionNameP2PWSEnable = "p2p-ws-enable" + optionNameDebugAPIEnable = "debug-api-enable" + optionNameDebugAPIAddr = "debug-api-addr" + optionNameBootnodes = "bootnode" + optionNameNetworkID = "network-id" + optionWelcomeMessage = "welcome-message" + optionCORSAllowedOrigins = "cors-allowed-origins" + optionNameTracingEnabled = "tracing-enable" + optionNameTracingEndpoint = "tracing-endpoint" + optionNameTracingHost = "tracing-host" + optionNameTracingPort = "tracing-port" + optionNameTracingServiceName = "tracing-service-name" + optionNameVerbosity = "verbosity" + optionNamePaymentThreshold = "payment-threshold" + optionNamePaymentTolerance = "payment-tolerance-percent" + optionNamePaymentEarly = "payment-early-percent" + optionNameResolverEndpoints = "resolver-options" + optionNameBootnodeMode = "bootnode-mode" + optionNameClefSignerEnable = "clef-signer-enable" + optionNameClefSignerEndpoint = "clef-signer-endpoint" + optionNameClefSignerEthereumAddress = "clef-signer-ethereum-address" + optionNameSwapEndpoint = "swap-endpoint" // deprecated: use rpc endpoint instead + optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint" + optionNameSwapFactoryAddress = "swap-factory-address" + optionNameSwapInitialDeposit = "swap-initial-deposit" + optionNameSwapEnable = "swap-enable" + optionNameChequebookEnable = "chequebook-enable" + optionNameSwapDeploymentGasPrice = "swap-deployment-gas-price" + optionNameFullNode = "full-node" + optionNamePostageContractAddress = "postage-stamp-address" + optionNamePostageContractStartBlock = "postage-stamp-start-block" + optionNamePriceOracleAddress = "price-oracle-address" + optionNameRedistributionAddress = "redistribution-address" + optionNameStakingAddress = "staking-address" + optionNameBlockTime = "block-time" + optionWarmUpTime = "warmup-time" + optionNameMainNet = "mainnet" + optionNameRetrievalCaching = "cache-retrieval" + optionNameDevReserveCapacity = "dev-reserve-capacity" + optionNameResync = "resync" + optionNamePProfBlock = "pprof-profile" + optionNamePProfMutex = "pprof-mutex" + optionNameStaticNodes = "static-nodes" + optionNameAllowPrivateCIDRs = "allow-private-cidrs" + optionNameSleepAfter = "sleep-after" + optionNameRestrictedAPI = "restricted" + optionNameTokenEncryptionKey = "token-encryption-key" + optionNameAdminPasswordHash = "admin-password" + optionNameUsePostageSnapshot = "use-postage-snapshot" + optionNameStorageIncentivesEnable = "storage-incentives-enable" + optionNameStateStoreCacheCapacity = "statestore-cache-capacity" + optionNameTargetNeighborhood = "target-neighborhood" + optionNameNeighborhoodSuggester = "neighborhood-suggester" + optionNameWhitelistedWithdrawalAddress = "withdrawal-addresses-whitelist" ) // nolint:gochecknoinits @@ -302,6 +304,8 @@ func (c *command) setAllFlags(cmd *cobra.Command) { cmd.Flags().Bool(optionNameStorageIncentivesEnable, true, "enable storage incentives feature") cmd.Flags().Uint64(optionNameStateStoreCacheCapacity, 100_000, "lru memory caching capacity in number of statestore entries") cmd.Flags().String(optionNameTargetNeighborhood, "", "neighborhood to target in binary format (ex: 111111001) for mining the initial overlay") + cmd.Flags().String(optionNameNeighborhoodSuggester, "https://api.swarmscan.io/v1/network/neighborhoods/suggestion", "suggester for target neighborhood") + cmd.Flags().StringSlice(optionNameWhitelistedWithdrawalAddress, []string{}, "withdrawal target addresses") } func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) { diff --git a/cmd/bee/cmd/cmd_test.go b/cmd/bee/cmd/cmd_test.go index 7844e4eb342..e7a8cfdb11d 100644 --- a/cmd/bee/cmd/cmd_test.go +++ b/cmd/bee/cmd/cmd_test.go @@ -9,7 +9,7 @@ import ( "os" "testing" - "github.com/ethersphere/bee/cmd/bee/cmd" + "github.com/ethersphere/bee/v2/cmd/bee/cmd" ) var homeDir string diff --git a/cmd/bee/cmd/db.go b/cmd/bee/cmd/db.go index ec94ff7f6d8..882aa02f3b0 100644 --- a/cmd/bee/cmd/db.go +++ b/cmd/bee/cmd/db.go @@ -18,11 +18,11 @@ import ( "strings" "time" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/cobra" ) diff --git a/cmd/bee/cmd/db_test.go b/cmd/bee/cmd/db_test.go index 02dcb66b571..3b07d3bf1ea 100644 --- a/cmd/bee/cmd/db_test.go +++ b/cmd/bee/cmd/db_test.go @@ -12,15 +12,15 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/cmd/bee/cmd" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/postage" - storagetest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - kademlia "github.com/ethersphere/bee/pkg/topology/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/cmd/bee/cmd" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/postage" + storagetest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + kademlia "github.com/ethersphere/bee/v2/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestDBExportImport(t *testing.T) { diff --git a/cmd/bee/cmd/deploy.go b/cmd/bee/cmd/deploy.go index 7b3e8e57734..988918bd074 100644 --- a/cmd/bee/cmd/deploy.go +++ b/cmd/bee/cmd/deploy.go @@ -8,8 +8,8 @@ import ( "fmt" "strings" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" "github.com/spf13/cobra" ) diff --git a/cmd/bee/cmd/init.go b/cmd/bee/cmd/init.go index ea56381eea9..3df6b7aeb18 100644 --- a/cmd/bee/cmd/init.go +++ b/cmd/bee/cmd/init.go @@ -8,7 +8,7 @@ import ( "fmt" "strings" - "github.com/ethersphere/bee/pkg/node" + "github.com/ethersphere/bee/v2/pkg/node" "github.com/spf13/cobra" ) diff --git a/cmd/bee/cmd/split.go b/cmd/bee/cmd/split.go index e173ae186fa..e5db047a43e 100644 --- a/cmd/bee/cmd/split.go +++ b/cmd/bee/cmd/split.go @@ -9,41 +9,62 @@ import ( "fmt" "io" "os" + "path/filepath" "strings" + "sync/atomic" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/cobra" ) // putter is a putter that stores all the split chunk addresses of a file type putter struct { - chunkAddresses []string + cb func(chunk swarm.Chunk) error } -func (s *putter) Put(ctx context.Context, chunk swarm.Chunk) error { - s.chunkAddresses = append(s.chunkAddresses, chunk.Address().String()) - return nil +func (s *putter) Put(_ context.Context, chunk swarm.Chunk) error { + return s.cb(chunk) +} +func newPutter(cb func(ch swarm.Chunk) error) *putter { + return &putter{ + cb: cb, + } } var _ storage.Putter = (*putter)(nil) type pipelineFunc func(context.Context, io.Reader) (swarm.Address, error) -func requestPipelineFn(s storage.Putter, encrypt bool) pipelineFunc { +func requestPipelineFn(s storage.Putter, encrypt bool, rLevel redundancy.Level) pipelineFunc { return func(ctx context.Context, r io.Reader) (swarm.Address, error) { - pipe := builder.NewPipelineBuilder(ctx, s, encrypt, 0) + pipe := builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) return builder.FeedPipeline(ctx, pipe, r) } } func (c *command) initSplitCmd() error { - optionNameInputFile := "input-file" - optionNameOutputFile := "output-file" cmd := &cobra.Command{ Use: "split", - Short: "Split a file into a list chunks. The 1st line is the root hash", + Short: "Split a file into chunks", + } + + splitRefs(cmd) + splitChunks(cmd) + c.root.AddCommand(cmd) + return nil +} + +func splitRefs(cmd *cobra.Command) { + optionNameInputFile := "input-file" + optionNameOutputFile := "output-file" + optionNameRedundancyLevel := "r-level" + + c := &cobra.Command{ + Use: "refs", + Short: "Write only the chunk reference to the output file", RunE: func(cmd *cobra.Command, args []string) error { inputFileName, err := cmd.Flags().GetString(optionNameInputFile) if err != nil { @@ -53,6 +74,10 @@ func (c *command) initSplitCmd() error { if err != nil { return fmt.Errorf("get output file name: %w", err) } + rLevel, err := cmd.Flags().GetInt(optionNameRedundancyLevel) + if err != nil { + return fmt.Errorf("get redundancy level: %w", err) + } v, err := cmd.Flags().GetString(optionNameVerbosity) if err != nil { @@ -70,44 +95,124 @@ func (c *command) initSplitCmd() error { } defer reader.Close() - logger.Info("splitting", "file", inputFileName) - store := new(putter) - - p := requestPipelineFn(store, false) - address, err := p(context.Background(), reader) - if err != nil { - return fmt.Errorf("bmt pipeline: %w", err) - } - + logger.Info("splitting", "file", inputFileName, "rLevel", rLevel) logger.Info("writing output", "file", outputFileName) + + var refs []string + store := newPutter(func(ch swarm.Chunk) error { + refs = append(refs, ch.Address().String()) + return nil + }) writer, err := os.OpenFile(outputFileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) if err != nil { return fmt.Errorf("open output file: %w", err) } defer writer.Close() - logger.Debug("write root", "hash", address) - _, err = writer.WriteString(fmt.Sprintf("%s\n", address)) + p := requestPipelineFn(store, false, redundancy.Level(rLevel)) + rootRef, err := p(context.Background(), reader) + if err != nil { + return fmt.Errorf("pipeline: %w", err) + } + + logger.Debug("write root", "hash", rootRef) + _, err = writer.WriteString(fmt.Sprintf("%s\n", rootRef)) if err != nil { return fmt.Errorf("write root hash: %w", err) } - for _, chunkAddress := range store.chunkAddresses { - logger.Debug("write chunk", "hash", chunkAddress) - _, err = writer.WriteString(fmt.Sprintf("%s\n", chunkAddress)) + for _, ref := range refs { + logger.Debug("write chunk", "hash", ref) + _, err = writer.WriteString(fmt.Sprintf("%s\n", ref)) if err != nil { return fmt.Errorf("write chunk address: %w", err) } } - logger.Info("done", "hashes", len(store.chunkAddresses)) + logger.Info("done", "root", rootRef.String(), "chunks", len(refs)) return nil }, } - cmd.Flags().String(optionNameVerbosity, "info", "verbosity level") - cmd.Flags().String(optionNameInputFile, "", "input file") - cmd.Flags().String(optionNameOutputFile, "", "output file") - cmd.MarkFlagsRequiredTogether(optionNameInputFile, optionNameOutputFile) + c.Flags().String(optionNameInputFile, "", "input file") + c.Flags().String(optionNameOutputFile, "", "output file") + c.Flags().Int(optionNameRedundancyLevel, 0, "redundancy level") + c.Flags().String(optionNameVerbosity, "info", "verbosity level") - c.root.AddCommand(cmd) - return nil + c.MarkFlagsRequiredTogether(optionNameInputFile, optionNameOutputFile) + + cmd.AddCommand(c) +} + +func splitChunks(cmd *cobra.Command) { + optionNameInputFile := "input-file" + optionNameOutputDir := "output-dir" + optionNameRedundancyLevel := "r-level" + + c := &cobra.Command{ + Use: "chunks", + Short: "Write the chunks to the output directory", + RunE: func(cmd *cobra.Command, args []string) error { + inputFileName, err := cmd.Flags().GetString(optionNameInputFile) + if err != nil { + return fmt.Errorf("get input file name: %w", err) + } + outputDir, err := cmd.Flags().GetString(optionNameOutputDir) + if err != nil { + return fmt.Errorf("get output file name: %w", err) + } + info, err := os.Stat(outputDir) + if err != nil { + return fmt.Errorf("stat output dir: %w", err) + } + if !info.IsDir() { + return fmt.Errorf("output dir %s is not a directory", outputDir) + } + rLevel, err := cmd.Flags().GetInt(optionNameRedundancyLevel) + if err != nil { + return fmt.Errorf("get redundancy level: %w", err) + } + v, err := cmd.Flags().GetString(optionNameVerbosity) + if err != nil { + return fmt.Errorf("get verbosity: %w", err) + } + v = strings.ToLower(v) + logger, err := newLogger(cmd, v) + if err != nil { + return fmt.Errorf("new logger: %w", err) + } + reader, err := os.Open(inputFileName) + if err != nil { + return fmt.Errorf("open input file: %w", err) + } + defer reader.Close() + + logger.Info("splitting", "file", inputFileName, "rLevel", rLevel) + logger.Info("writing output", "dir", outputDir) + + var chunksCount atomic.Int64 + store := newPutter(func(chunk swarm.Chunk) error { + filePath := filepath.Join(outputDir, chunk.Address().String()) + err := os.WriteFile(filePath, chunk.Data(), 0644) + if err != nil { + return err + } + chunksCount.Add(1) + return nil + }) + + p := requestPipelineFn(store, false, redundancy.Level(rLevel)) + rootRef, err := p(context.Background(), reader) + if err != nil { + return fmt.Errorf("pipeline: %w", err) + } + logger.Info("done", "root", rootRef.String(), "chunks", chunksCount.Load()) + return nil + }, + } + c.Flags().String(optionNameInputFile, "", "input file") + c.Flags().String(optionNameOutputDir, "", "output dir") + c.Flags().Int(optionNameRedundancyLevel, 0, "redundancy level") + c.Flags().String(optionNameVerbosity, "info", "verbosity level") + c.MarkFlagsRequiredTogether(optionNameInputFile, optionNameOutputDir) + + cmd.AddCommand(c) } diff --git a/cmd/bee/cmd/split_test.go b/cmd/bee/cmd/split_test.go index 4151a69b5b7..4e819d6f46e 100644 --- a/cmd/bee/cmd/split_test.go +++ b/cmd/bee/cmd/split_test.go @@ -6,17 +6,26 @@ package cmd_test import ( "bufio" + "bytes" + "context" crand "crypto/rand" + "io" "math/rand" "os" "path" + "path/filepath" + "sync" "testing" - "github.com/ethersphere/bee/cmd/bee/cmd" - "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/v2/cmd/bee/cmd" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) -func TestDBSplit(t *testing.T) { +func TestDBSplitRefs(t *testing.T) { t.Parallel() s := (rand.Intn(10) + 10) * 1024 // rand between 10 and 20 KB @@ -34,7 +43,7 @@ func TestDBSplit(t *testing.T) { outputFileName := path.Join(t.TempDir(), "output") - err = newCommand(t, cmd.WithArgs("split", "--input-file", inputFileName, "--output-file", outputFileName)).Execute() + err = newCommand(t, cmd.WithArgs("split", "refs", "--input-file", inputFileName, "--output-file", outputFileName)).Execute() if err != nil { t.Fatal(err) } @@ -60,3 +69,106 @@ func TestDBSplit(t *testing.T) { t.Fatalf("got %d hashes, want %d", gotHashes, wantHashes) } } + +func TestDBSplitChunks(t *testing.T) { + t.Parallel() + + s := (rand.Intn(10) + 10) * 1024 // rand between 10 and 20 KB + buf := make([]byte, s) + _, err := crand.Read(buf) + if err != nil { + t.Fatal(err) + } + + inputFileName := path.Join(t.TempDir(), "input") + err = os.WriteFile(inputFileName, buf, 0644) + if err != nil { + t.Fatal(err) + } + + dir := path.Join(t.TempDir(), "chunks") + err = os.Mkdir(dir, os.ModePerm) + if err != nil { + t.Fatal(err) + } + + err = newCommand(t, cmd.WithArgs("split", "chunks", "--input-file", inputFileName, "--output-dir", dir, "--r-level", "3")).Execute() + if err != nil { + t.Fatal(err) + } + + // split the file manually and compare output with the split commands output. + putter := &putter{chunks: make(map[string]swarm.Chunk)} + p := requestPipelineFn(putter, false, redundancy.Level(3)) + _, err = p(context.Background(), bytes.NewReader(buf)) + if err != nil { + t.Fatal(err) + } + + entries, err := os.ReadDir(dir) + if err != nil { + t.Fatal(err) + } + + if len(entries) != len(putter.chunks) { + t.Fatal("number of chunks does not match") + } + for _, entry := range entries { + ref := entry.Name() + if _, ok := putter.chunks[ref]; !ok { + t.Fatalf("chunk %s not found", ref) + } + err, ok := compare(filepath.Join(dir, ref), putter.chunks[ref]) + if err != nil { + t.Fatal(err) + } + if !ok { + t.Fatalf("chunk %s does not match", ref) + } + delete(putter.chunks, ref) + } + + if len(putter.chunks) != 0 { + t.Fatalf("want 0 chunks left, got %d", len(putter.chunks)) + } +} + +func compare(path string, chunk swarm.Chunk) (error, bool) { + f, err := os.Open(path) + if err != nil { + return err, false + } + defer f.Close() + + b, err := io.ReadAll(f) + if err != nil { + return err, false + } + + if !bytes.Equal(b, chunk.Data()) { + return nil, false + } + + return nil, true +} + +type putter struct { + chunks map[string]swarm.Chunk + mu sync.Mutex +} + +func (s *putter) Put(_ context.Context, chunk swarm.Chunk) error { + s.mu.Lock() + defer s.mu.Unlock() + s.chunks[chunk.Address().String()] = chunk + return nil +} + +type pipelineFunc func(context.Context, io.Reader) (swarm.Address, error) + +func requestPipelineFn(s storage.Putter, encrypt bool, rLevel redundancy.Level) pipelineFunc { + return func(ctx context.Context, r io.Reader) (swarm.Address, error) { + pipe := builder.NewPipelineBuilder(ctx, s, encrypt, rLevel) + return builder.FeedPipeline(ctx, pipe, r) + } +} diff --git a/cmd/bee/cmd/start.go b/cmd/bee/cmd/start.go index ee287a2104a..4e967285428 100644 --- a/cmd/bee/cmd/start.go +++ b/cmd/bee/cmd/start.go @@ -23,18 +23,18 @@ import ( "github.com/ethereum/go-ethereum/accounts/external" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethersphere/bee" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/clef" - "github.com/ethersphere/bee/pkg/keystore" - filekeystore "github.com/ethersphere/bee/pkg/keystore/file" - memkeystore "github.com/ethersphere/bee/pkg/keystore/mem" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/resolver/multiresolver" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/clef" + "github.com/ethersphere/bee/v2/pkg/keystore" + filekeystore "github.com/ethersphere/bee/v2/pkg/keystore/file" + memkeystore "github.com/ethersphere/bee/v2/pkg/keystore/mem" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/resolver/multiresolver" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/kardianos/service" "github.com/spf13/cobra" ) @@ -287,6 +287,11 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo blockchainRpcEndpoint = swapEndpoint } + var neighborhoodSuggester string + if networkID == chaincfg.Mainnet.NetworkID { + neighborhoodSuggester = c.config.GetString(optionNameNeighborhoodSuggester) + } + b, err := node.NewBee(ctx, c.config.GetString(optionNameP2PAddr), signerConfig.publicKey, signerConfig.signer, networkID, logger, signerConfig.libp2pPrivateKey, signerConfig.pssPrivateKey, &node.Options{ DataDir: c.config.GetString(optionNameDataDir), CacheCapacity: c.config.GetUint64(optionNameCacheCapacity), @@ -339,6 +344,8 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo EnableStorageIncentives: c.config.GetBool(optionNameStorageIncentivesEnable), StatestoreCacheCapacity: c.config.GetUint64(optionNameStateStoreCacheCapacity), TargetNeighborhood: c.config.GetString(optionNameTargetNeighborhood), + NeighborhoodSuggester: neighborhoodSuggester, + WhitelistedWithdrawalAddress: c.config.GetStringSlice(optionNameWhitelistedWithdrawalAddress), }) return b, err diff --git a/cmd/bee/cmd/start_dev.go b/cmd/bee/cmd/start_dev.go index 39b9e32d35b..a372094bf20 100644 --- a/cmd/bee/cmd/start_dev.go +++ b/cmd/bee/cmd/start_dev.go @@ -11,7 +11,7 @@ import ( "strings" "syscall" - "github.com/ethersphere/bee/pkg/node" + "github.com/ethersphere/bee/v2/pkg/node" "github.com/kardianos/service" "github.com/spf13/cobra" ) diff --git a/cmd/bee/cmd/start_unix.go b/cmd/bee/cmd/start_unix.go index e50f8e54bfb..19e3d5b7807 100644 --- a/cmd/bee/cmd/start_unix.go +++ b/cmd/bee/cmd/start_unix.go @@ -9,7 +9,7 @@ package cmd import ( "errors" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" ) func isWindowsService() (bool, error) { diff --git a/cmd/bee/cmd/start_windows.go b/cmd/bee/cmd/start_windows.go index 419cc3f7eb0..3153e80041c 100644 --- a/cmd/bee/cmd/start_windows.go +++ b/cmd/bee/cmd/start_windows.go @@ -13,7 +13,7 @@ import ( "golang.org/x/sys/windows/svc/debug" "golang.org/x/sys/windows/svc/eventlog" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" ) func isWindowsService() (bool, error) { diff --git a/cmd/bee/cmd/timebomb.go b/cmd/bee/cmd/timebomb.go index c1013795757..f53f74627c3 100644 --- a/cmd/bee/cmd/timebomb.go +++ b/cmd/bee/cmd/timebomb.go @@ -8,8 +8,8 @@ import ( "strconv" "time" - "github.com/ethersphere/bee" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/pkg/log" ) const ( diff --git a/cmd/bee/cmd/version.go b/cmd/bee/cmd/version.go index c438838f13d..d5ea260d859 100644 --- a/cmd/bee/cmd/version.go +++ b/cmd/bee/cmd/version.go @@ -5,7 +5,7 @@ package cmd import ( - "github.com/ethersphere/bee" + "github.com/ethersphere/bee/v2" "github.com/spf13/cobra" ) diff --git a/cmd/bee/cmd/version_test.go b/cmd/bee/cmd/version_test.go index 9bbc327bf6f..982e5e0edcf 100644 --- a/cmd/bee/cmd/version_test.go +++ b/cmd/bee/cmd/version_test.go @@ -8,8 +8,8 @@ import ( "bytes" "testing" - "github.com/ethersphere/bee" - "github.com/ethersphere/bee/cmd/bee/cmd" + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/cmd/bee/cmd" ) func TestVersionCmd(t *testing.T) { diff --git a/cmd/bee/main.go b/cmd/bee/main.go index 575ffeb4498..a7b953b8cd0 100644 --- a/cmd/bee/main.go +++ b/cmd/bee/main.go @@ -8,7 +8,7 @@ import ( "fmt" "os" - "github.com/ethersphere/bee/cmd/bee/cmd" + "github.com/ethersphere/bee/v2/cmd/bee/cmd" ) func main() { diff --git a/go.mod b/go.mod index 5d3e61c85ec..2bb64394f18 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/ethersphere/bee +module github.com/ethersphere/bee/v2 go 1.21 @@ -148,7 +148,7 @@ require ( github.com/prometheus/statsd_exporter v0.22.7 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-20 v0.3.3 // indirect - github.com/quic-go/quic-go v0.38.1 // indirect + github.com/quic-go/quic-go v0.38.2 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/shirou/gopsutil v3.21.5+incompatible // indirect diff --git a/go.sum b/go.sum index c2938b6ec32..6799b8b5a71 100644 --- a/go.sum +++ b/go.sum @@ -793,8 +793,8 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-20 v0.3.3 h1:17/glZSLI9P9fDAeyCHBFSWSqJcwx1byhLwP5eUIDCM= github.com/quic-go/qtls-go1-20 v0.3.3/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= -github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZaE= -github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= +github.com/quic-go/quic-go v0.38.2 h1:VWv/6gxIoB8hROQJhx1JEyiegsUQ+zMN3em3kynTGdg= +github.com/quic-go/quic-go v0.38.2/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= diff --git a/openapi/Swarm.yaml b/openapi/Swarm.yaml index 61b446d1095..72e41ec5665 100644 --- a/openapi/Swarm.yaml +++ b/openapi/Swarm.yaml @@ -179,6 +179,26 @@ paths: $ref: "SwarmCommon.yaml#/components/responses/400" default: description: Default response + head: + summary: Requests the headers containing the content type and length for the reference + tags: + - Bytes + parameters: + - in: path + name: address + schema: + $ref: "SwarmCommon.yaml#/components/schemas/SwarmAddress" + required: true + description: Swarm address of chunk + responses: + "200": + description: Chunk exists + "400": + $ref: "SwarmCommon.yaml#/components/responses/400" + "404": + $ref: "SwarmCommon.yaml#/components/responses/404" + default: + description: Default response "/chunks": post: @@ -332,6 +352,26 @@ paths: $ref: "SwarmCommon.yaml#/components/responses/500" default: description: Default response + head: + summary: Get the headers containing the content type and length for the reference + tags: + - BZZ + parameters: + - in: path + name: address + schema: + $ref: "SwarmCommon.yaml#/components/schemas/SwarmAddress" + required: true + description: Swarm address of chunk + responses: + "200": + description: Chunk exists + "400": + $ref: "SwarmCommon.yaml#/components/responses/400" + "404": + $ref: "SwarmCommon.yaml#/components/responses/404" + default: + description: Default response "/bzz/{reference}/{path}": get: @@ -598,6 +638,30 @@ paths: default: description: Default response + "/pins/check": + get: + summary: Validate pinned chunks integerity + tags: + - Pinning + parameters: + - in: query + name: ref + schema: + $ref: "SwarmCommon.yaml#/components/schemas/SwarmOnlyReference" + required: false + description: The number of items to skip before starting to collect the result set. + responses: + "200": + description: List of checked root hash references + content: + application/json: + schema: + $ref: "SwarmCommon.yaml#/components/schemas/PinCheckResponse" + "500": + $ref: "SwarmCommon.yaml#/components/responses/500" + default: + description: Default response + "/pss/send/{topic}/{targets}": post: summary: Send to recipient or target with Postal Service for Swarm @@ -1913,6 +1977,44 @@ paths: default: description: Default response + "/rchash/{depth}/{anchor1}/{anchor2}": + get: + summary: Get reserve commitment hash with sample proofs + tags: + - RChash + parameters: + - in: path + name: depth + schema: + type: integer + minimum: 0 + default: 0 + required: true + description: The storage depth. + - in: path + name: anchor1 + schema: + $ref: "#/components/schemas/HexString" + required: true + description: The first anchor. + - in: path + name: anchor2 + schema: + $ref: "#/components/schemas/HexString" + required: true + description: The second anchor. + responses: + "200": + description: Reserve sample response + content: + application/json: + schema: + $ref: "SwarmCommon.yaml#/components/schemas/ApiRCHashResponse" + "500": + $ref: "SwarmCommon.yaml#/components/responses/500" + default: + description: Default response + components: securitySchemes: basicAuth: diff --git a/openapi/SwarmCommon.yaml b/openapi/SwarmCommon.yaml index 07119cc6894..21ede2e5400 100644 --- a/openapi/SwarmCommon.yaml +++ b/openapi/SwarmCommon.yaml @@ -1,6 +1,6 @@ openapi: 3.0.3 info: - version: 3.2.6 + version: 3.2.7 title: Common Data Types description: | \*****bzzz***** @@ -602,15 +602,28 @@ components: - $ref: "#/components/schemas/SwarmAddress" - $ref: "#/components/schemas/SwarmEncryptedReference" + PinCheckResponse: + type: object + properties: + reference: + $ref: "#/components/schemas/SwarmOnlyReference" + total: + type: integer + missing: + type: integer + invalid: + type: integer + SwarmOnlyReferencesList: type: object properties: - references: + reference: type: array nullable: false items: $ref: "#/components/schemas/SwarmOnlyReference" + SwarmReference: oneOf: - $ref: "#/components/schemas/SwarmAddress" @@ -839,6 +852,8 @@ components: type: integer reserveSize: type: integer + reserveSizeWithinRadius: + type: interger pullsyncRate: type: number storageRadius: @@ -864,6 +879,83 @@ components: items: $ref: "#/components/schemas/StatusSnapshotResponse" + ApiChunkInclusionProof: + type: object + properties: + chunkSpan: + minimum: 0 + type: integer + postageProof: + $ref: '#/components/schemas/ApiPostageProof' + proofSegments: + items: + type: string + nullable: true + type: array + proofSegments2: + items: + type: string + nullable: true + type: array + proofSegments3: + items: + type: string + nullable: true + type: array + proveSegment: + type: string + proveSegment2: + type: string + socProof: + items: + $ref: '#/components/schemas/ApiSOCProof' + nullable: true + type: array + + ApiChunkInclusionProofs: + type: object + properties: + proof1: + $ref: '#/components/schemas/ApiChunkInclusionProof' + proof2: + $ref: '#/components/schemas/ApiChunkInclusionProof' + proofLast: + $ref: '#/components/schemas/ApiChunkInclusionProof' + + ApiPostageProof: + type: object + properties: + index: + type: string + postageId: + type: string + signature: + type: string + timeStamp: + type: string + + ApiRCHashResponse: + type: object + properties: + duration: + type: integer + hash: + $ref: '#/components/schemas/SwarmAddress' + proofs: + $ref: '#/components/schemas/ApiChunkInclusionProofs' + + ApiSOCProof: + type: object + properties: + chunkAddr: + type: string + identifier: + type: string + signature: + type: string + signer: + type: string + headers: SwarmTag: description: "Tag UID" @@ -1041,6 +1133,8 @@ components: description: "Determines if the download data should be cached on the node. By default the download will be cached" responses: + "200": + description: OK. "204": description: The resource was deleted successfully. "400": diff --git a/openapi/SwarmDebug.yaml b/openapi/SwarmDebug.yaml index 11d7b1a5fdb..516fba3399d 100644 --- a/openapi/SwarmDebug.yaml +++ b/openapi/SwarmDebug.yaml @@ -1,6 +1,6 @@ openapi: 3.0.3 info: - version: 4.1.0 + version: 4.1.1 title: Bee Debug API description: "A list of the currently provided debug interfaces to interact with the bee node" @@ -689,6 +689,41 @@ paths: $ref: "SwarmCommon.yaml#/components/responses/500" default: description: Default response + "/wallet/withdraw/{coin}": + post: + summary: Allows withdrawals of BZZ or xDAI to provided (whitelisted) address + tags: + - Wallet + parameters: + - in: query + name: amount + required: true + schema: + $ref: "#/components/schemas/BigInt" + - in: query + name: address + required: true + schema: + $ref: "#/components/schemas/EthereumAddress" + - in: path + name: coin + required: true + schema: + $ref: "#/components/schemas/SwarmAddress" + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/WalletTxResponse' + description: OK + "400": + $ref: "SwarmCommon.yaml#/components/responses/400" + description: Amount greater than ballance or coin is other than BZZ/xDAI + "500": + $ref: "SwarmCommon.yaml#/components/responses/500" + default: + description: Default response "/transactions": get: @@ -1133,3 +1168,11 @@ paths: $ref: "SwarmCommon.yaml#/components/responses/400" default: description: Default response. + +components: + schemas: + WalletTxResponse: + type: object + properties: + transactionHash: + $ref: "#/components/schemas/TransactionHash" diff --git a/pkg/accounting/accounting.go b/pkg/accounting/accounting.go index 787e794b865..5e92596c94f 100644 --- a/pkg/accounting/accounting.go +++ b/pkg/accounting/accounting.go @@ -15,12 +15,12 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/pricing" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/pricing" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/accounting/accounting_test.go b/pkg/accounting/accounting_test.go index f240325f944..509b5e5e14b 100644 --- a/pkg/accounting/accounting_test.go +++ b/pkg/accounting/accounting_test.go @@ -12,13 +12,13 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - p2pmock "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + p2pmock "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/accounting/export_test.go b/pkg/accounting/export_test.go index 85046388c9a..5358b288067 100644 --- a/pkg/accounting/export_test.go +++ b/pkg/accounting/export_test.go @@ -7,7 +7,7 @@ package accounting import ( "time" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func (a *Accounting) SetTimeNow(f func() time.Time) { diff --git a/pkg/accounting/metrics.go b/pkg/accounting/metrics.go index 573bab6ed29..e38bdbbd989 100644 --- a/pkg/accounting/metrics.go +++ b/pkg/accounting/metrics.go @@ -5,7 +5,7 @@ package accounting import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/accounting/mock/accounting.go b/pkg/accounting/mock/accounting.go index 14f0bb9189f..e5e0d98130e 100644 --- a/pkg/accounting/mock/accounting.go +++ b/pkg/accounting/mock/accounting.go @@ -11,8 +11,8 @@ import ( "math/big" "sync" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Service is the mock Accounting service. diff --git a/pkg/addressbook/addressbook.go b/pkg/addressbook/addressbook.go index 3a2eba66493..eafba314d09 100644 --- a/pkg/addressbook/addressbook.go +++ b/pkg/addressbook/addressbook.go @@ -9,9 +9,9 @@ import ( "fmt" "strings" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const keyPrefix = "addressbook_entry_" diff --git a/pkg/addressbook/addressbook_test.go b/pkg/addressbook/addressbook_test.go index 360d7c197f9..1b5c22490b5 100644 --- a/pkg/addressbook/addressbook_test.go +++ b/pkg/addressbook/addressbook_test.go @@ -9,11 +9,11 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/accounting.go b/pkg/api/accounting.go index ad8b476fc35..fce1056bbb7 100644 --- a/pkg/api/accounting.go +++ b/pkg/api/accounting.go @@ -7,8 +7,8 @@ package api import ( "net/http" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) const ( diff --git a/pkg/api/accounting_test.go b/pkg/api/accounting_test.go index a5e8c28aff9..7a807aa811e 100644 --- a/pkg/api/accounting_test.go +++ b/pkg/api/accounting_test.go @@ -11,12 +11,12 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestAccountingInfo(t *testing.T) { diff --git a/pkg/api/api.go b/pkg/api/api.go index 7d6ee42e175..72100cc0d9b 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -27,38 +27,38 @@ import ( "unicode/utf8" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/auth" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/pingpong" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/client/ens" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/settlement" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/steward" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/lightnode" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/auth" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/pingpong" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/settlement" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/steward" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/transaction" "github.com/go-playground/validator/v10" "github.com/gorilla/mux" "github.com/hashicorp/go-multierror" @@ -131,6 +131,10 @@ type Storer interface { storer.Debugger } +type PinIntegrity interface { + Check(ctx context.Context, logger log.Logger, pin string, out chan storer.PinStat) +} + type Service struct { auth auth.Authenticator storer Storer @@ -174,7 +178,9 @@ type Service struct { batchStore postage.Storer stamperStore storage.Store - syncStatus func() (bool, error) + pinIntegrity PinIntegrity + + syncStatus func() (bool, error) swap swap.Interface transaction transaction.Service @@ -191,6 +197,8 @@ type Service struct { erc20Service erc20.Service chainID int64 + whitelistedWithdrawalAddress []common.Address + preMapHooks map[string]func(v string) (string, error) validate *validator.Validate @@ -242,11 +250,13 @@ type ExtraOptions struct { Steward steward.Interface SyncStatus func() (bool, error) NodeStatus *status.Service + PinIntegrity PinIntegrity } func New( publicKey, pssPublicKey ecdsa.PublicKey, ethereumAddress common.Address, + whitelistedWithdrawalAddress []string, logger log.Logger, transaction transaction.Service, batchStore postage.Storer, @@ -296,6 +306,10 @@ func New( }) s.stamperStore = stamperStore + for _, v := range whitelistedWithdrawalAddress { + s.whitelistedWithdrawalAddress = append(s.whitelistedWithdrawalAddress, common.HexToAddress(v)) + } + return s } @@ -348,6 +362,8 @@ func (s *Service) Configure(signer crypto.Signer, auth auth.Authenticator, trace return "", err } } + + s.pinIntegrity = e.PinIntegrity } func (s *Service) SetProbe(probe *Probe) { diff --git a/pkg/api/api_test.go b/pkg/api/api_test.go index b06e5808479..164709b7ca9 100644 --- a/pkg/api/api_test.go +++ b/pkg/api/api_test.go @@ -23,53 +23,53 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - accountingmock "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/auth" - mockauth "github.com/ethersphere/bee/pkg/auth/mock" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - p2pmock "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/pingpong" - "github.com/ethersphere/bee/pkg/postage" - mockbatchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - contractMock "github.com/ethersphere/bee/pkg/postage/postagecontract/mock" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/resolver" - resolverMock "github.com/ethersphere/bee/pkg/resolver/mock" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - chequebookmock "github.com/ethersphere/bee/pkg/settlement/swap/chequebook/mock" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - swapmock "github.com/ethersphere/bee/pkg/settlement/swap/mock" - "github.com/ethersphere/bee/pkg/spinlock" - statestore "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/steward" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - mock2 "github.com/ethersphere/bee/pkg/storageincentives/staking/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/lightnode" - topologymock "github.com/ethersphere/bee/pkg/topology/mock" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + accountingmock "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/auth" + mockauth "github.com/ethersphere/bee/v2/pkg/auth/mock" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + p2pmock "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/pingpong" + "github.com/ethersphere/bee/v2/pkg/postage" + mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + contractMock "github.com/ethersphere/bee/v2/pkg/postage/postagecontract/mock" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/resolver" + resolverMock "github.com/ethersphere/bee/v2/pkg/resolver/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + chequebookmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + statestore "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/steward" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + mock2 "github.com/ethersphere/bee/v2/pkg/storageincentives/staking/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + topologymock "github.com/ethersphere/bee/v2/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/gorilla/websocket" "resenje.org/web" ) @@ -131,6 +131,8 @@ type testServerOptions struct { BeeMode api.BeeNodeMode RedistributionAgent *storageincentives.Agent NodeStatus *status.Service + PinIntegrity api.PinIntegrity + WhitelistedAddr string } func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.Conn, string, *chanStorer) { @@ -201,6 +203,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket. SyncStatus: o.SyncStatus, Staking: o.StakingContract, NodeStatus: o.NodeStatus, + PinIntegrity: o.PinIntegrity, } // By default bee mode is set to full mode. @@ -208,7 +211,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket. o.BeeMode = api.FullMode } - s := api.New(o.PublicKey, o.PSSPublicKey, o.EthereumAddress, o.Logger, transaction, o.BatchStore, o.BeeMode, true, true, backend, o.CORSAllowedOrigins, inmemstore.New()) + s := api.New(o.PublicKey, o.PSSPublicKey, o.EthereumAddress, []string{o.WhitelistedAddr}, o.Logger, transaction, o.BatchStore, o.BeeMode, true, true, backend, o.CORSAllowedOrigins, inmemstore.New()) testutil.CleanupCloser(t, s) s.SetP2P(o.P2P) @@ -393,7 +396,7 @@ func TestParseName(t *testing.T) { pk, _ := crypto.GenerateSecp256k1Key() signer := crypto.NewDefaultSigner(pk) - s := api.New(pk.PublicKey, pk.PublicKey, common.Address{}, log, nil, nil, 1, false, false, nil, []string{"*"}, inmemstore.New()) + s := api.New(pk.PublicKey, pk.PublicKey, common.Address{}, nil, log, nil, nil, 1, false, false, nil, []string{"*"}, inmemstore.New()) s.Configure(signer, nil, nil, api.Options{}, api.ExtraOptions{Resolver: tC.res}, 1, nil) s.MountAPI() diff --git a/pkg/api/auth_test.go b/pkg/api/auth_test.go index 496d1a8f2dd..f2cb0a99d59 100644 --- a/pkg/api/auth_test.go +++ b/pkg/api/auth_test.go @@ -9,11 +9,11 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/auth/mock" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/auth/mock" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" ) // nolint:paralleltest diff --git a/pkg/api/balances.go b/pkg/api/balances.go index 94400669597..f55b8aeec32 100644 --- a/pkg/api/balances.go +++ b/pkg/api/balances.go @@ -8,10 +8,10 @@ import ( "errors" "net/http" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/balances_test.go b/pkg/api/balances_test.go index 4cb985fefc0..174196d253a 100644 --- a/pkg/api/balances_test.go +++ b/pkg/api/balances_test.go @@ -11,13 +11,13 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestBalances(t *testing.T) { diff --git a/pkg/api/bytes.go b/pkg/api/bytes.go index 4cb90c1b763..9b5d9b902d6 100644 --- a/pkg/api/bytes.go +++ b/pkg/api/bytes.go @@ -11,16 +11,15 @@ import ( "net/http" "strconv" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/gorilla/mux" "github.com/opentracing/opentracing-go/ext" - "github.com/opentracing/opentracing-go/log" olog "github.com/opentracing/opentracing-go/log" ) @@ -63,7 +62,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { default: jsonhttp.InternalServerError(w, "cannot get or create tag") } - ext.LogError(span, err, log.String("action", "tag.create")) + ext.LogError(span, err, olog.String("action", "tag.create")) return } span.SetTag("tagID", tag) @@ -90,7 +89,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { default: jsonhttp.BadRequest(w, nil) } - ext.LogError(span, err, log.String("action", "new.StamperPutter")) + ext.LogError(span, err, olog.String("action", "new.StamperPutter")) return } @@ -111,7 +110,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { default: jsonhttp.InternalServerError(ow, "split write all failed") } - ext.LogError(span, err, log.String("action", "split.WriteAll")) + ext.LogError(span, err, olog.String("action", "split.WriteAll")) return } @@ -122,7 +121,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { logger.Debug("done split failed", "error", err) logger.Error(nil, "done split failed") jsonhttp.InternalServerError(ow, "done split failed") - ext.LogError(span, err, log.String("action", "putter.Done")) + ext.LogError(span, err, olog.String("action", "putter.Done")) return } @@ -154,7 +153,7 @@ func (s *Service) bytesGetHandler(w http.ResponseWriter, r *http.Request) { ContentTypeHeader: {"application/octet-stream"}, } - s.downloadHandler(logger, w, r, paths.Address, additionalHeaders, true) + s.downloadHandler(logger, w, r, paths.Address, additionalHeaders, true, false) } func (s *Service) bytesHeadHandler(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/api/bytes_test.go b/pkg/api/bytes_test.go index abae06bc2c6..e2acc99a9d6 100644 --- a/pkg/api/bytes_test.go +++ b/pkg/api/bytes_test.go @@ -12,14 +12,14 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - mockbatchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "gitlab.com/nolash/go-mockbytes" ) diff --git a/pkg/api/bzz.go b/pkg/api/bzz.go index 2cf1d66d53d..65ded851f12 100644 --- a/pkg/api/bzz.go +++ b/pkg/api/bzz.go @@ -21,20 +21,20 @@ import ( olog "github.com/opentracing/opentracing-go/log" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/file/redundancy/getter" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/file/redundancy/getter" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/ethersphere/langos" "github.com/gorilla/mux" ) @@ -299,18 +299,36 @@ func (s *Service) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { paths.Path = strings.TrimRight(paths.Path, "/") + "/" // NOTE: leave one slash if there was some. } - s.serveReference(logger, paths.Address, paths.Path, w, r) + s.serveReference(logger, paths.Address, paths.Path, w, r, false) } -func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathVar string, w http.ResponseWriter, r *http.Request) { +func (s *Service) bzzHeadHandler(w http.ResponseWriter, r *http.Request) { + logger := tracing.NewLoggerWithTraceID(r.Context(), s.logger.WithName("head_bzz_by_path").Build()) + + paths := struct { + Address swarm.Address `map:"address,resolve" validate:"required"` + Path string `map:"path"` + }{} + if response := s.mapStructure(mux.Vars(r), &paths); response != nil { + response("invalid path params", logger, w) + return + } + + if strings.HasSuffix(paths.Path, "/") { + paths.Path = strings.TrimRight(paths.Path, "/") + "/" // NOTE: leave one slash if there was some. + } + + s.serveReference(logger, paths.Address, paths.Path, w, r, true) +} + +func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathVar string, w http.ResponseWriter, r *http.Request, headerOnly bool) { loggerV1 := logger.V(1).Build() headers := struct { - Cache *bool `map:"Swarm-Cache"` - Strategy getter.Strategy `map:"Swarm-Redundancy-Strategy"` - FallbackMode bool `map:"Swarm-Redundancy-Fallback-Mode"` - ChunkRetrievalTimeout string `map:"Swarm-Chunk-Retrieval-Timeout"` - LookaheadBufferSize *string `map:"Swarm-Lookahead-Buffer-Size"` + Cache *bool `map:"Swarm-Cache"` + Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"` + FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"` + ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"` }{} if response := s.mapStructure(r.Header, &headers); response != nil { @@ -326,7 +344,12 @@ func (s *Service) serveReference(logger log.Logger, address swarm.Address, pathV feedDereferenced := false ctx := r.Context() - ctx = getter.SetConfigInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout, getter.DefaultStrategyTimeout.String()) + ctx, err := getter.SetConfigInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout, logger) + if err != nil { + logger.Error(err, err.Error()) + jsonhttp.BadRequest(w, "could not parse headers") + return + } FETCH: // read manifest entry @@ -398,7 +421,7 @@ FETCH: // index document exists logger.Debug("bzz download: serving path", "path", pathWithIndex) - s.serveManifestEntry(logger, w, r, indexDocumentManifestEntry, !feedDereferenced) + s.serveManifestEntry(logger, w, r, indexDocumentManifestEntry, !feedDereferenced, headerOnly) return } } @@ -441,7 +464,7 @@ FETCH: // index document exists logger.Debug("bzz download: serving path", "path", pathWithIndex) - s.serveManifestEntry(logger, w, r, indexDocumentManifestEntry, !feedDereferenced) + s.serveManifestEntry(logger, w, r, indexDocumentManifestEntry, !feedDereferenced, headerOnly) return } } @@ -455,7 +478,7 @@ FETCH: // error document exists logger.Debug("bzz download: serving path", "path", errorDocumentPath) - s.serveManifestEntry(logger, w, r, errorDocumentManifestEntry, !feedDereferenced) + s.serveManifestEntry(logger, w, r, errorDocumentManifestEntry, !feedDereferenced, headerOnly) return } } @@ -469,7 +492,7 @@ FETCH: } // serve requested path - s.serveManifestEntry(logger, w, r, me, !feedDereferenced) + s.serveManifestEntry(logger, w, r, me, !feedDereferenced, headerOnly) } func (s *Service) serveManifestEntry( @@ -477,7 +500,7 @@ func (s *Service) serveManifestEntry( w http.ResponseWriter, r *http.Request, manifestEntry manifest.Entry, - etag bool, + etag, headersOnly bool, ) { additionalHeaders := http.Header{} mtdt := manifestEntry.Metadata() @@ -490,17 +513,17 @@ func (s *Service) serveManifestEntry( additionalHeaders[ContentTypeHeader] = []string{mimeType} } - s.downloadHandler(logger, w, r, manifestEntry.Reference(), additionalHeaders, etag) + s.downloadHandler(logger, w, r, manifestEntry.Reference(), additionalHeaders, etag, headersOnly) } // downloadHandler contains common logic for dowloading Swarm file from API -func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *http.Request, reference swarm.Address, additionalHeaders http.Header, etag bool) { +func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *http.Request, reference swarm.Address, additionalHeaders http.Header, etag, headersOnly bool) { headers := struct { - Cache *bool `map:"Swarm-Cache"` - Strategy getter.Strategy `map:"Swarm-Redundancy-Strategy"` - FallbackMode bool `map:"Swarm-Redundancy-Fallback-Mode"` - ChunkRetrievalTimeout string `map:"Swarm-Chunk-Retrieval-Timeout"` - LookaheadBufferSize *int `map:"Swarm-Lookahead-Buffer-Size"` + Strategy *getter.Strategy `map:"Swarm-Redundancy-Strategy"` + FallbackMode *bool `map:"Swarm-Redundancy-Fallback-Mode"` + ChunkRetrievalTimeout *string `map:"Swarm-Chunk-Retrieval-Timeout"` + LookaheadBufferSize *int `map:"Swarm-Lookahead-Buffer-Size"` + Cache *bool `map:"Swarm-Cache"` }{} if response := s.mapStructure(r.Header, &headers); response != nil { @@ -513,7 +536,13 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h } ctx := r.Context() - ctx = getter.SetConfigInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout, getter.DefaultStrategyTimeout.String()) + ctx, err := getter.SetConfigInContext(ctx, headers.Strategy, headers.FallbackMode, headers.ChunkRetrievalTimeout, logger) + if err != nil { + logger.Error(err, err.Error()) + jsonhttp.BadRequest(w, "could not parse headers") + return + } + reader, l, err := joiner.New(ctx, s.storer.Download(cache), s.storer.Cache(), reference) if err != nil { if errors.Is(err, storage.ErrNotFound) || errors.Is(err, topology.ErrNotFound) { @@ -537,6 +566,12 @@ func (s *Service) downloadHandler(logger log.Logger, w http.ResponseWriter, r *h } w.Header().Set(ContentLengthHeader, strconv.FormatInt(l, 10)) w.Header().Set("Access-Control-Expose-Headers", ContentDispositionHeader) + + if headersOnly { + w.WriteHeader(http.StatusOK) + return + } + bufSize := lookaheadBufferSize(l) if headers.LookaheadBufferSize != nil { bufSize = *(headers.LookaheadBufferSize) diff --git a/pkg/api/bzz_test.go b/pkg/api/bzz_test.go index 634d4eb0166..7d1e1b27bfe 100644 --- a/pkg/api/bzz_test.go +++ b/pkg/api/bzz_test.go @@ -16,21 +16,20 @@ import ( "strconv" "strings" "testing" - "time" - - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/manifest" - mockbatchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil/pseudorand" + + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/manifest" + mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil/pseudorand" ) // nolint:paralleltest,tparallel,thelper @@ -63,7 +62,9 @@ import ( // using redundancy to reconstruct the file and find the file recoverable. // // nolint:thelper -func TestBzzUploadDownloadWithRedundancy(t *testing.T) { +func TestBzzUploadDownloadWithRedundancy_FLAKY(t *testing.T) { + t.Skip("flaky") + t.Parallel() fileUploadResource := "/bzz" fileDownloadResource := func(addr string) string { return "/bzz/" + addr + "/" } @@ -73,7 +74,6 @@ func TestBzzUploadDownloadWithRedundancy(t *testing.T) { if err != nil { t.Fatal(err) } - fetchTimeout := 100 * time.Millisecond store := mockstorer.NewForgettingStore(inmemchunkstore.New()) storerMock := mockstorer.NewWithChunkStore(store) client, _, _, _ := newTestServer(t, testServerOptions{ @@ -131,7 +131,6 @@ func TestBzzUploadDownloadWithRedundancy(t *testing.T) { jsonhttptest.WithRequestHeader(api.SwarmRedundancyLevelHeader, "0"), jsonhttptest.WithRequestHeader(api.SwarmRedundancyStrategyHeader, "0"), jsonhttptest.WithRequestHeader(api.SwarmRedundancyFallbackModeHeader, "false"), - jsonhttptest.WithRequestHeader(api.SwarmChunkRetrievalTimeoutHeader, fetchTimeout.String()), jsonhttptest.WithPutResponseBody(&body), ) @@ -151,30 +150,42 @@ func TestBzzUploadDownloadWithRedundancy(t *testing.T) { if rLevel == 0 { t.Skip("NA") } - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - req, err := http.NewRequestWithContext(ctx, "GET", fileDownloadResource(refResponse.Reference.String()), nil) + req, err := http.NewRequestWithContext(context.Background(), "GET", fileDownloadResource(refResponse.Reference.String()), nil) if err != nil { t.Fatal(err) } req.Header.Set(api.SwarmRedundancyStrategyHeader, "0") req.Header.Set(api.SwarmRedundancyFallbackModeHeader, "false") - req.Header.Set(api.SwarmChunkRetrievalTimeoutHeader, fetchTimeout.String()) - _, err = client.Do(req) - if !errors.Is(err, context.DeadlineExceeded) { - t.Fatalf("expected error %v; got %v", io.ErrUnexpectedEOF, err) + resp, err := client.Do(req) + if err != nil { + t.Fatal(err) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + t.Fatalf("expected status %d; got %d", http.StatusOK, resp.StatusCode) + } + _, err = dataReader.Seek(0, io.SeekStart) + if err != nil { + t.Fatal(err) + } + ok, err := dataReader.Equal(resp.Body) + if err != nil { + t.Fatal(err) + } + if ok { + t.Fatal("there should be missing data") } }) t.Run("download with redundancy should succeed", func(t *testing.T) { - req, err := http.NewRequestWithContext(context.TODO(), "GET", fileDownloadResource(refResponse.Reference.String()), nil) + req, err := http.NewRequestWithContext(context.Background(), "GET", fileDownloadResource(refResponse.Reference.String()), nil) if err != nil { t.Fatal(err) } req.Header.Set(api.SwarmRedundancyStrategyHeader, "3") req.Header.Set(api.SwarmRedundancyFallbackModeHeader, "true") - req.Header.Set(api.SwarmChunkRetrievalTimeoutHeader, fetchTimeout.String()) resp, err := client.Do(req) if err != nil { @@ -507,8 +518,18 @@ func TestBzzFiles(t *testing.T) { jsonhttptest.WithRequestHeader(api.ContentTypeHeader, "text/html; charset=utf-8"), jsonhttptest.WithNonEmptyResponseHeader(api.SwarmTagHeader), ) - }) + t.Run("head", func(t *testing.T) { + rootHash := "65148cd89b58e91616773f5acea433f7b5a6274f2259e25f4893a332b74a7e28" + + jsonhttptest.Request(t, client, http.MethodHead, fileDownloadResource(rootHash), http.StatusOK, + jsonhttptest.WithRequestHeader(api.SwarmPostageBatchIdHeader, batchOkStr), + jsonhttptest.WithRequestBody(bytes.NewReader(simpleData)), + jsonhttptest.WithRequestHeader(api.ContentTypeHeader, "text/html; charset=utf-8"), + jsonhttptest.WithExpectedContentLength(21), + ) + }) + }) } // TestRangeRequests validates that all endpoints are serving content with diff --git a/pkg/api/chequebook.go b/pkg/api/chequebook.go index b1ee31361ff..33cd75d9767 100644 --- a/pkg/api/chequebook.go +++ b/pkg/api/chequebook.go @@ -10,13 +10,13 @@ import ( "net/http" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/chequebook_test.go b/pkg/api/chequebook_test.go index f12d41be999..b9b9cbdef32 100644 --- a/pkg/api/chequebook_test.go +++ b/pkg/api/chequebook_test.go @@ -13,16 +13,16 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook/mock" - swapmock "github.com/ethersphere/bee/pkg/settlement/swap/mock" - - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock" + swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestChequebookBalance(t *testing.T) { diff --git a/pkg/api/chunk.go b/pkg/api/chunk.go index 25e1d6c65ed..a572cacdcdf 100644 --- a/pkg/api/chunk.go +++ b/pkg/api/chunk.go @@ -12,12 +12,13 @@ import ( "net/http" "strconv" - "github.com/ethersphere/bee/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/soc" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) @@ -111,10 +112,31 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) { chunk, err := cac.NewWithDataSpan(data) if err != nil { + // not a valid cac chunk. Check if it's a replica soc chunk. logger.Debug("chunk upload: create chunk failed", "error", err) - logger.Error(nil, "chunk upload: create chunk error") - jsonhttp.InternalServerError(ow, "create chunk error") - return + + // FromChunk only uses the chunk data to recreate the soc chunk. So the address is irrelevant. + sch, err := soc.FromChunk(swarm.NewChunk(swarm.EmptyAddress, data)) + if err != nil { + logger.Debug("chunk upload: create soc chunk from data failed", "error", err) + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } + chunk, err = sch.Chunk() + if err != nil { + logger.Debug("chunk upload: create chunk from soc failed", "error", err) + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } + + if !soc.Valid(chunk) { + logger.Debug("chunk upload: invalid soc chunk") + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } } err = putter.Put(r.Context(), chunk) diff --git a/pkg/api/chunk_address.go b/pkg/api/chunk_address.go index 7c99225c078..6f214a0ea03 100644 --- a/pkg/api/chunk_address.go +++ b/pkg/api/chunk_address.go @@ -7,8 +7,8 @@ package api import ( "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/chunk_stream.go b/pkg/api/chunk_stream.go index 005ba5020d1..4ae045a9d4f 100644 --- a/pkg/api/chunk_stream.go +++ b/pkg/api/chunk_stream.go @@ -10,13 +10,13 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/websocket" ) diff --git a/pkg/api/chunk_stream_test.go b/pkg/api/chunk_stream_test.go index 24a3bdab841..47c8e860b51 100644 --- a/pkg/api/chunk_stream_test.go +++ b/pkg/api/chunk_stream_test.go @@ -10,12 +10,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/api" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/spinlock" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/websocket" ) diff --git a/pkg/api/chunk_test.go b/pkg/api/chunk_test.go index 21c98a8c011..c0e1fe9de9c 100644 --- a/pkg/api/chunk_test.go +++ b/pkg/api/chunk_test.go @@ -13,17 +13,17 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - mockbatchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/spinlock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // nolint:paralleltest,tparallel diff --git a/pkg/api/cors_test.go b/pkg/api/cors_test.go index c8b9fae3512..73c3b343414 100644 --- a/pkg/api/cors_test.go +++ b/pkg/api/cors_test.go @@ -9,8 +9,8 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestCORSHeaders(t *testing.T) { @@ -137,7 +137,7 @@ func TestCors(t *testing.T) { expectedMethods: "POST", }, { endpoint: "bzz/0101011", - expectedMethods: "GET", + expectedMethods: "GET, HEAD", }, { endpoint: "chunks", diff --git a/pkg/api/debugstorage.go b/pkg/api/debugstorage.go index 13325997b19..d3e209b0dc2 100644 --- a/pkg/api/debugstorage.go +++ b/pkg/api/debugstorage.go @@ -7,8 +7,8 @@ package api import ( "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/tracing" ) func (s *Service) debugStorage(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/api/debugstorage_test.go b/pkg/api/debugstorage_test.go index 72d8800b882..bb12a5585fd 100644 --- a/pkg/api/debugstorage_test.go +++ b/pkg/api/debugstorage_test.go @@ -8,9 +8,9 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/storer" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/storer" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" ) func TestDebugStorage(t *testing.T) { diff --git a/pkg/api/dirs.go b/pkg/api/dirs.go index 06aff9c59d6..f54a02807c9 100644 --- a/pkg/api/dirs.go +++ b/pkg/api/dirs.go @@ -18,16 +18,16 @@ import ( "strconv" "strings" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" olog "github.com/opentracing/opentracing-go/log" @@ -276,25 +276,14 @@ func (m *multipartReader) Next() (*FileInfo, error) { if filePath == "" { filePath = part.FormName() } - if filePath == "" { - return nil, errors.New("filepath missing") - } fileName := filepath.Base(filePath) contentType := part.Header.Get(ContentTypeHeader) - if contentType == "" { - return nil, errors.New("content-type missing") - } contentLength := part.Header.Get(ContentLengthHeader) - if contentLength == "" { - return nil, errors.New("content-length missing") - } - fileSize, err := strconv.ParseInt(contentLength, 10, 64) - if err != nil { - return nil, errors.New("invalid file size") - } + + fileSize, _ := strconv.ParseInt(contentLength, 10, 64) return &FileInfo{ Path: filePath, diff --git a/pkg/api/dirs_test.go b/pkg/api/dirs_test.go index b43e9b3bca4..d49f0d281d6 100644 --- a/pkg/api/dirs_test.go +++ b/pkg/api/dirs_test.go @@ -17,14 +17,14 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/manifest" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/manifest" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // nolint:paralleltest diff --git a/pkg/api/export_test.go b/pkg/api/export_test.go index 030a27d9001..812ce522ba0 100644 --- a/pkg/api/export_test.go +++ b/pkg/api/export_test.go @@ -5,8 +5,8 @@ package api import ( - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type ( @@ -95,6 +95,7 @@ type ( PostageStampBucketsResponse = postageStampBucketsResponse BucketData = bucketData WalletResponse = walletResponse + WalletTxResponse = walletTxResponse GetStakeResponse = getStakeResponse WithdrawAllStakeResponse = withdrawAllStakeResponse StatusSnapshotResponse = statusSnapshotResponse diff --git a/pkg/api/feed.go b/pkg/api/feed.go index 23961e6d5fc..09fdf6515ec 100644 --- a/pkg/api/feed.go +++ b/pkg/api/feed.go @@ -13,17 +13,17 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/manifest/mantaray" - "github.com/ethersphere/bee/pkg/manifest/simple" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/manifest/simple" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/feed_test.go b/pkg/api/feed_test.go index e71e8d77b04..a35b9ce3423 100644 --- a/pkg/api/feed_test.go +++ b/pkg/api/feed_test.go @@ -14,18 +14,18 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/postage" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - testingsoc "github.com/ethersphere/bee/pkg/soc/testing" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/postage" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ownerString = "8d3766440f0d7b949a5e32995d09619a7f86e632" diff --git a/pkg/api/health.go b/pkg/api/health.go index 3d6e132a015..33b6481b6ee 100644 --- a/pkg/api/health.go +++ b/pkg/api/health.go @@ -7,8 +7,8 @@ package api import ( "net/http" - "github.com/ethersphere/bee" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) type healthStatusResponse struct { diff --git a/pkg/api/health_test.go b/pkg/api/health_test.go index fb5f49e2b57..3446e167895 100644 --- a/pkg/api/health_test.go +++ b/pkg/api/health_test.go @@ -8,9 +8,9 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestHealth(t *testing.T) { diff --git a/pkg/api/logger.go b/pkg/api/logger.go index cb371d6a851..95efc08e428 100644 --- a/pkg/api/logger.go +++ b/pkg/api/logger.go @@ -11,8 +11,8 @@ import ( "regexp" "strings" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log" "github.com/gorilla/mux" ) diff --git a/pkg/api/logger_test.go b/pkg/api/logger_test.go index e29341355a1..b8420b79067 100644 --- a/pkg/api/logger_test.go +++ b/pkg/api/logger_test.go @@ -11,10 +11,10 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index 9146d1079a4..7635468f4e3 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -9,8 +9,8 @@ import ( "strconv" "time" - "github.com/ethersphere/bee" - m "github.com/ethersphere/bee/pkg/metrics" + "github.com/ethersphere/bee/v2" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" ) @@ -108,9 +108,6 @@ type UpgradedResponseWriter interface { http.Pusher http.Hijacker http.Flusher - // staticcheck SA1019 CloseNotifier interface is required by gorilla compress handler - // nolint:staticcheck - http.CloseNotifier } type responseWriter struct { diff --git a/pkg/api/metrics_test.go b/pkg/api/metrics_test.go index eb2f8db0481..299f0321eef 100644 --- a/pkg/api/metrics_test.go +++ b/pkg/api/metrics_test.go @@ -7,7 +7,7 @@ package api_test import ( "testing" - "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/v2/pkg/api" ) func TestToFileSizeBucket(t *testing.T) { diff --git a/pkg/api/node.go b/pkg/api/node.go index 9a14da4685b..9a3f6228538 100644 --- a/pkg/api/node.go +++ b/pkg/api/node.go @@ -7,7 +7,7 @@ package api import ( "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) type BeeNodeMode uint diff --git a/pkg/api/node_test.go b/pkg/api/node_test.go index 9cb3c6d8b90..5a076c4685d 100644 --- a/pkg/api/node_test.go +++ b/pkg/api/node_test.go @@ -7,7 +7,7 @@ package api_test import ( "testing" - "github.com/ethersphere/bee/pkg/api" + "github.com/ethersphere/bee/v2/pkg/api" ) func TestBeeNodeMode_String(t *testing.T) { diff --git a/pkg/api/p2p.go b/pkg/api/p2p.go index 3ae0ee4a259..9494b9ccbd0 100644 --- a/pkg/api/p2p.go +++ b/pkg/api/p2p.go @@ -9,9 +9,9 @@ import ( "net/http" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/p2p_test.go b/pkg/api/p2p_test.go index e184906734a..5cf9de6124c 100644 --- a/pkg/api/p2p_test.go +++ b/pkg/api/p2p_test.go @@ -11,12 +11,12 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/peer.go b/pkg/api/peer.go index a6dfc8f7aeb..3213b55a8ef 100644 --- a/pkg/api/peer.go +++ b/pkg/api/peer.go @@ -8,9 +8,9 @@ import ( "errors" "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/peer_test.go b/pkg/api/peer_test.go index eb1ec3ffb6a..0697a6277d2 100644 --- a/pkg/api/peer_test.go +++ b/pkg/api/peer_test.go @@ -11,14 +11,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/pin.go b/pkg/api/pin.go index 7c80e5f196b..6fc115fd1b1 100644 --- a/pkg/api/pin.go +++ b/pkg/api/pin.go @@ -5,14 +5,16 @@ package api import ( + "encoding/json" "errors" "net/http" "sync" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/traversal" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/traversal" "github.com/gorilla/mux" "golang.org/x/sync/semaphore" ) @@ -199,3 +201,53 @@ func (s *Service) listPinnedRootHashes(w http.ResponseWriter, r *http.Request) { References: pinned, }) } + +type PinIntegrityResponse struct { + Reference swarm.Address `json:"reference"` + Total int `json:"total"` + Missing int `json:"missing"` + Invalid int `json:"invalid"` +} + +func (s *Service) pinIntegrityHandler(w http.ResponseWriter, r *http.Request) { + logger := s.logger.WithName("get_pin_integrity").Build() + + querie := struct { + Ref swarm.Address `map:"ref"` + }{} + + if response := s.mapStructure(r.URL.Query(), &querie); response != nil { + response("invalid query params", logger, w) + return + } + + out := make(chan storer.PinStat) + + go s.pinIntegrity.Check(r.Context(), logger, querie.Ref.String(), out) + + flusher, ok := w.(http.Flusher) + if !ok { + http.NotFound(w, r) + return + } + + w.Header().Set("Transfer-Encoding", "chunked") + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.WriteHeader(http.StatusOK) + flusher.Flush() + + enc := json.NewEncoder(w) + + for v := range out { + resp := PinIntegrityResponse{ + Reference: v.Ref, + Total: v.Total, + Missing: v.Missing, + Invalid: v.Invalid, + } + if err := enc.Encode(resp); err != nil { + break + } + flusher.Flush() + } +} diff --git a/pkg/api/pin_test.go b/pkg/api/pin_test.go index 751b93b1d65..a85c34a9594 100644 --- a/pkg/api/pin_test.go +++ b/pkg/api/pin_test.go @@ -5,16 +5,21 @@ package api_test import ( + "context" "net/http" "strings" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + storer "github.com/ethersphere/bee/v2/pkg/storer" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func checkPinHandlers(t *testing.T, client *http.Client, rootHash string, createPin bool) { @@ -185,3 +190,52 @@ func TestPinHandlersInvalidInputs(t *testing.T) { } } } + +const pinRef = "620fcd78c7ce54da2d1b7cc2274a02e190cbe8fecbc3bd244690ab6517ce8f39" + +func TestIntegrityHandler(t *testing.T) { + + t.Parallel() + + t.Run("ok", func(t *testing.T) { + t.Parallel() + testServer, _, _, _ := newTestServer(t, testServerOptions{ + PinIntegrity: &mockPinIntegrity{ + Store: inmemstore.New(), + tester: t, + }, + }) + + endp := "/pins/check?ref=" + pinRef + + // When probe is not set health endpoint should indicate that node is not healthy + jsonhttptest.Request(t, testServer, http.MethodGet, endp, http.StatusOK, jsonhttptest.WithExpectedResponse(nil)) + }) + + t.Run("wrong hash format", func(t *testing.T) { + t.Parallel() + testServer, _, _, _ := newTestServer(t, testServerOptions{ + PinIntegrity: &mockPinIntegrity{ + Store: inmemstore.New(), + tester: t, + }, + }) + + endp := "/pins/check?ref=0xbadhash" + + // When probe is not set health endpoint should indicate that node is not healthy + jsonhttptest.Request(t, testServer, http.MethodGet, endp, http.StatusBadRequest, jsonhttptest.WithExpectedResponse(nil)) + }) +} + +type mockPinIntegrity struct { + tester *testing.T + Store storage.Store +} + +func (p *mockPinIntegrity) Check(ctx context.Context, logger log.Logger, pin string, out chan storer.PinStat) { + if pin != pinRef { + p.tester.Fatal("bad pin", pin) + } + close(out) +} diff --git a/pkg/api/pingpong.go b/pkg/api/pingpong.go index 0c3bbc45323..6cb1c4ae23e 100644 --- a/pkg/api/pingpong.go +++ b/pkg/api/pingpong.go @@ -8,9 +8,9 @@ import ( "errors" "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/pingpong_test.go b/pkg/api/pingpong_test.go index b97bdd77413..4dffae5b0e6 100644 --- a/pkg/api/pingpong_test.go +++ b/pkg/api/pingpong_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/p2p" - pingpongmock "github.com/ethersphere/bee/pkg/pingpong/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/p2p" + pingpongmock "github.com/ethersphere/bee/v2/pkg/pingpong/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestPingpong(t *testing.T) { diff --git a/pkg/api/postage.go b/pkg/api/postage.go index 457b0dc0f63..ba1f1499d9f 100644 --- a/pkg/api/postage.go +++ b/pkg/api/postage.go @@ -13,12 +13,12 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/gorilla/mux" ) diff --git a/pkg/api/postage_test.go b/pkg/api/postage_test.go index a7055ed098a..ebf808c1c7a 100644 --- a/pkg/api/postage_test.go +++ b/pkg/api/postage_test.go @@ -18,19 +18,19 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - contractMock "github.com/ethersphere/bee/pkg/postage/postagecontract/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/sctx" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/transaction/backendmock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + contractMock "github.com/ethersphere/bee/v2/pkg/postage/postagecontract/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/sctx" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" ) func TestPostageCreateStamp(t *testing.T) { diff --git a/pkg/api/pss.go b/pkg/api/pss.go index aa87a6165c8..ef1c3a84d47 100644 --- a/pkg/api/pss.go +++ b/pkg/api/pss.go @@ -14,11 +14,11 @@ import ( "strings" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" "github.com/gorilla/websocket" ) diff --git a/pkg/api/pss_test.go b/pkg/api/pss_test.go index d40a4889d4e..6624e6d8d21 100644 --- a/pkg/api/pss_test.go +++ b/pkg/api/pss_test.go @@ -19,19 +19,19 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/pushsync" - "github.com/ethersphere/bee/pkg/spinlock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/pushsync" + "github.com/ethersphere/bee/v2/pkg/spinlock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/gorilla/websocket" ) diff --git a/pkg/api/rchash.go b/pkg/api/rchash.go index ad7a25f9992..3aec3e3836a 100644 --- a/pkg/api/rchash.go +++ b/pkg/api/rchash.go @@ -10,9 +10,9 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/readiness_test.go b/pkg/api/readiness_test.go index f91419af8cb..52677214919 100644 --- a/pkg/api/readiness_test.go +++ b/pkg/api/readiness_test.go @@ -8,8 +8,8 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestReadiness(t *testing.T) { diff --git a/pkg/api/redistribution.go b/pkg/api/redistribution.go index ba335342a9c..5df3fbf0682 100644 --- a/pkg/api/redistribution.go +++ b/pkg/api/redistribution.go @@ -8,9 +8,9 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/tracing" ) type redistributionStatusResponse struct { diff --git a/pkg/api/redistribution_test.go b/pkg/api/redistribution_test.go index b13f4d9af93..88bf00abe51 100644 --- a/pkg/api/redistribution_test.go +++ b/pkg/api/redistribution_test.go @@ -11,13 +11,13 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - statestore "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - "github.com/ethersphere/bee/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + statestore "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + "github.com/ethersphere/bee/v2/pkg/transaction/mock" ) func TestRedistributionStatus(t *testing.T) { diff --git a/pkg/api/router.go b/pkg/api/router.go index 7c854543b88..18c2bfb9a46 100644 --- a/pkg/api/router.go +++ b/pkg/api/router.go @@ -11,10 +11,10 @@ import ( "net/http/pprof" "strings" - "github.com/ethersphere/bee/pkg/auth" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/log/httpaccess" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/auth" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/log/httpaccess" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -220,7 +220,7 @@ func (s *Service) mountAPI() { handle("/chunks", jsonhttp.MethodHandler{ "POST": web.ChainHandlers( - jsonhttp.NewMaxBodyBytesHandler(swarm.ChunkWithSpanSize), + jsonhttp.NewMaxBodyBytesHandler(swarm.SocMaxChunkSize), web.FinalHandlerFunc(s.chunkUploadHandler), ), }) @@ -270,6 +270,9 @@ func (s *Service) mountAPI() { s.newTracingHandler("bzz-download"), web.FinalHandlerFunc(s.bzzDownloadHandler), ), + "HEAD": web.ChainHandlers( + web.FinalHandlerFunc(s.bzzHeadHandler), + ), }) handle("/pss/send/{topic}/{targets}", web.ChainHandlers( @@ -312,6 +315,12 @@ func (s *Service) mountAPI() { })), ) + handle("/pins/check", web.ChainHandlers( + web.FinalHandler(jsonhttp.MethodHandler{ + "GET": http.HandlerFunc(s.pinIntegrityHandler), + }), + )) + handle("/pins/{reference}", web.ChainHandlers( web.FinalHandler(jsonhttp.MethodHandler{ "GET": http.HandlerFunc(s.getPinnedRootHash), @@ -488,6 +497,12 @@ func (s *Service) mountBusinessDebug(restricted bool) { handle("/wallet", jsonhttp.MethodHandler{ "GET": http.HandlerFunc(s.walletHandler), }) + handle("/wallet/withdraw/{coin}", jsonhttp.MethodHandler{ + "POST": web.ChainHandlers( + s.gasConfigMiddleware("wallet withdraw"), + web.FinalHandlerFunc(s.walletWithdrawHandler), + ), + }) } } diff --git a/pkg/api/settlements.go b/pkg/api/settlements.go index 83ff7480f51..b6564925d13 100644 --- a/pkg/api/settlements.go +++ b/pkg/api/settlements.go @@ -9,11 +9,11 @@ import ( "math/big" "net/http" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/settlement" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/settlement" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/settlements_test.go b/pkg/api/settlements_test.go index bc06f540452..86f2e2e42e1 100644 --- a/pkg/api/settlements_test.go +++ b/pkg/api/settlements_test.go @@ -11,13 +11,13 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/settlement" - "github.com/ethersphere/bee/pkg/settlement/swap/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/settlement" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestSettlements(t *testing.T) { diff --git a/pkg/api/soc.go b/pkg/api/soc.go index 6dfafadda28..0abf338deb9 100644 --- a/pkg/api/soc.go +++ b/pkg/api/soc.go @@ -9,12 +9,12 @@ import ( "io" "net/http" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/soc_test.go b/pkg/api/soc_test.go index 5e9fe93d901..79e72ffb603 100644 --- a/pkg/api/soc_test.go +++ b/pkg/api/soc_test.go @@ -13,13 +13,13 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - testingsoc "github.com/ethersphere/bee/pkg/soc/testing" - "github.com/ethersphere/bee/pkg/spinlock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing" + "github.com/ethersphere/bee/v2/pkg/spinlock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // nolint:paralleltest diff --git a/pkg/api/staking.go b/pkg/api/staking.go index 77e8a7e836c..5ca5b06d409 100644 --- a/pkg/api/staking.go +++ b/pkg/api/staking.go @@ -9,10 +9,10 @@ import ( "math/big" "net/http" - "github.com/ethersphere/bee/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/storageincentives/staking" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" "github.com/gorilla/mux" ) diff --git a/pkg/api/staking_test.go b/pkg/api/staking_test.go index 8f10d4f6e24..e6f4d0b2296 100644 --- a/pkg/api/staking_test.go +++ b/pkg/api/staking_test.go @@ -12,14 +12,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bigint" - - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - stakingContractMock "github.com/ethersphere/bee/pkg/storageincentives/staking/mock" + "github.com/ethersphere/bee/v2/pkg/bigint" + + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + stakingContractMock "github.com/ethersphere/bee/v2/pkg/storageincentives/staking/mock" ) func TestDepositStake(t *testing.T) { diff --git a/pkg/api/status.go b/pkg/api/status.go index af0b5b99a27..b20cafb15a7 100644 --- a/pkg/api/status.go +++ b/pkg/api/status.go @@ -11,23 +11,24 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) type statusSnapshotResponse struct { - Peer string `json:"peer"` - Proximity uint8 `json:"proximity"` - BeeMode string `json:"beeMode"` - ReserveSize uint64 `json:"reserveSize"` - PullsyncRate float64 `json:"pullsyncRate"` - StorageRadius uint8 `json:"storageRadius"` - ConnectedPeers uint64 `json:"connectedPeers"` - NeighborhoodSize uint64 `json:"neighborhoodSize"` - RequestFailed bool `json:"requestFailed,omitempty"` - BatchCommitment uint64 `json:"batchCommitment"` - IsReachable bool `json:"isReachable"` + Peer string `json:"peer"` + Proximity uint8 `json:"proximity"` + BeeMode string `json:"beeMode"` + ReserveSize uint64 `json:"reserveSize"` + ReserveSizeWithinRadius uint64 `json:"reserveSizeWithinRadius"` + PullsyncRate float64 `json:"pullsyncRate"` + StorageRadius uint8 `json:"storageRadius"` + ConnectedPeers uint64 `json:"connectedPeers"` + NeighborhoodSize uint64 `json:"neighborhoodSize"` + RequestFailed bool `json:"requestFailed,omitempty"` + BatchCommitment uint64 `json:"batchCommitment"` + IsReachable bool `json:"isReachable"` } type statusResponse struct { @@ -70,15 +71,16 @@ func (s *Service) statusGetHandler(w http.ResponseWriter, _ *http.Request) { } jsonhttp.OK(w, statusSnapshotResponse{ - Peer: s.overlay.String(), - BeeMode: ss.BeeMode, - ReserveSize: ss.ReserveSize, - PullsyncRate: ss.PullsyncRate, - StorageRadius: uint8(ss.StorageRadius), - ConnectedPeers: ss.ConnectedPeers, - NeighborhoodSize: ss.NeighborhoodSize, - BatchCommitment: ss.BatchCommitment, - IsReachable: ss.IsReachable, + Peer: s.overlay.String(), + BeeMode: ss.BeeMode, + ReserveSize: ss.ReserveSize, + ReserveSizeWithinRadius: ss.ReserveSizeWithinRadius, + PullsyncRate: ss.PullsyncRate, + StorageRadius: uint8(ss.StorageRadius), + ConnectedPeers: ss.ConnectedPeers, + NeighborhoodSize: ss.NeighborhoodSize, + BatchCommitment: ss.BatchCommitment, + IsReachable: ss.IsReachable, }) } @@ -118,6 +120,7 @@ func (s *Service) statusGetPeersHandler(w http.ResponseWriter, r *http.Request) } else { snapshot.BeeMode = ss.BeeMode snapshot.ReserveSize = ss.ReserveSize + snapshot.ReserveSizeWithinRadius = ss.ReserveSizeWithinRadius snapshot.PullsyncRate = ss.PullsyncRate snapshot.StorageRadius = uint8(ss.StorageRadius) snapshot.ConnectedPeers = ss.ConnectedPeers diff --git a/pkg/api/status_test.go b/pkg/api/status_test.go index b7a9b92dc57..cc2c568abf4 100644 --- a/pkg/api/status_test.go +++ b/pkg/api/status_test.go @@ -8,12 +8,12 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/topology" ) func TestGetStatus(t *testing.T) { @@ -26,21 +26,23 @@ func TestGetStatus(t *testing.T) { mode := api.FullMode ssr := api.StatusSnapshotResponse{ - BeeMode: mode.String(), - ReserveSize: 128, - PullsyncRate: 64, - StorageRadius: 8, - ConnectedPeers: 0, - NeighborhoodSize: 0, - BatchCommitment: 1, - IsReachable: true, + BeeMode: mode.String(), + ReserveSize: 128, + ReserveSizeWithinRadius: 64, + PullsyncRate: 64, + StorageRadius: 8, + ConnectedPeers: 0, + NeighborhoodSize: 0, + BatchCommitment: 1, + IsReachable: true, } ssMock := &statusSnapshotMock{ - syncRate: ssr.PullsyncRate, - reserveSize: int(ssr.ReserveSize), - storageRadius: ssr.StorageRadius, - commitment: ssr.BatchCommitment, + syncRate: ssr.PullsyncRate, + reserveSize: int(ssr.ReserveSize), + reserveSizeWithinRadius: ssr.ReserveSizeWithinRadius, + storageRadius: ssr.StorageRadius, + commitment: ssr.BatchCommitment, } statusSvc := status.NewService( @@ -109,13 +111,17 @@ func (m *topologyPeersIterNoopMock) IsReachable() bool { // - status.SyncReporter // - postage.CommitmentGetter type statusSnapshotMock struct { - syncRate float64 - reserveSize int - storageRadius uint8 - commitment uint64 + syncRate float64 + reserveSize int + reserveSizeWithinRadius uint64 + storageRadius uint8 + commitment uint64 } func (m *statusSnapshotMock) SyncRate() float64 { return m.syncRate } func (m *statusSnapshotMock) ReserveSize() int { return m.reserveSize } func (m *statusSnapshotMock) StorageRadius() uint8 { return m.storageRadius } func (m *statusSnapshotMock) Commitment() (uint64, error) { return m.commitment, nil } +func (m *statusSnapshotMock) ReserveSizeWithinRadius() uint64 { + return m.reserveSizeWithinRadius +} diff --git a/pkg/api/stewardship.go b/pkg/api/stewardship.go index e617549d88f..99d330f78cc 100644 --- a/pkg/api/stewardship.go +++ b/pkg/api/stewardship.go @@ -8,11 +8,11 @@ import ( "errors" "net/http" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" "github.com/gorilla/mux" ) diff --git a/pkg/api/stewardship_test.go b/pkg/api/stewardship_test.go index 005b0bd66ad..e0f93957de5 100644 --- a/pkg/api/stewardship_test.go +++ b/pkg/api/stewardship_test.go @@ -9,14 +9,14 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/steward/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/steward/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // nolint:paralleltest diff --git a/pkg/api/subdomain.go b/pkg/api/subdomain.go index 2e90c4ac1ce..5d5cede467a 100644 --- a/pkg/api/subdomain.go +++ b/pkg/api/subdomain.go @@ -8,8 +8,8 @@ import ( "net/http" "strings" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/gorilla/mux" ) @@ -28,5 +28,5 @@ func (s *Service) subdomainHandler(w http.ResponseWriter, r *http.Request) { paths.Path = strings.TrimRight(paths.Path, "/") + "/" // NOTE: leave one slash if there was some. } - s.serveReference(logger, paths.Subdomain, paths.Path, w, r) + s.serveReference(logger, paths.Subdomain, paths.Path, w, r, false) } diff --git a/pkg/api/subdomain_test.go b/pkg/api/subdomain_test.go index 9dfd0143bde..6f8efc0b0f2 100644 --- a/pkg/api/subdomain_test.go +++ b/pkg/api/subdomain_test.go @@ -10,13 +10,13 @@ import ( "path" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/log" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - resolverMock "github.com/ethersphere/bee/pkg/resolver/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/log" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + resolverMock "github.com/ethersphere/bee/v2/pkg/resolver/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestSubdomains(t *testing.T) { diff --git a/pkg/api/tag.go b/pkg/api/tag.go index 8241c25d285..6a38fd7a65b 100644 --- a/pkg/api/tag.go +++ b/pkg/api/tag.go @@ -11,10 +11,10 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/jsonhttp" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/gorilla/mux" ) diff --git a/pkg/api/tag_test.go b/pkg/api/tag_test.go index dea820e3860..d3b8edeb4dc 100644 --- a/pkg/api/tag_test.go +++ b/pkg/api/tag_test.go @@ -11,14 +11,14 @@ import ( "strconv" "testing" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func tagsWithIdResource(id uint64) string { return fmt.Sprintf("/tags/%d", id) } diff --git a/pkg/api/topology.go b/pkg/api/topology.go index 9721454ea44..3cae56313c3 100644 --- a/pkg/api/topology.go +++ b/pkg/api/topology.go @@ -10,7 +10,7 @@ import ( "io" "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) func (s *Service) topologyHandler(w http.ResponseWriter, _ *http.Request) { diff --git a/pkg/api/topology_test.go b/pkg/api/topology_test.go index a7d90994821..ebd22532f3b 100644 --- a/pkg/api/topology_test.go +++ b/pkg/api/topology_test.go @@ -8,7 +8,7 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestTopologyOK(t *testing.T) { diff --git a/pkg/api/transaction.go b/pkg/api/transaction.go index 71eecdd8c95..6f93be7ca57 100644 --- a/pkg/api/transaction.go +++ b/pkg/api/transaction.go @@ -12,10 +12,10 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/transaction" "github.com/gorilla/mux" ) diff --git a/pkg/api/transaction_test.go b/pkg/api/transaction_test.go index 7c202aa9def..46e066c4091 100644 --- a/pkg/api/transaction_test.go +++ b/pkg/api/transaction_test.go @@ -14,12 +14,12 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/mock" ) func TestTransactionStoredTransaction(t *testing.T) { diff --git a/pkg/api/util.go b/pkg/api/util.go index 950be4ab068..a1ad148f6d5 100644 --- a/pkg/api/util.go +++ b/pkg/api/util.go @@ -15,8 +15,8 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/hashicorp/go-multierror" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/api/util_test.go b/pkg/api/util_test.go index 5f8dd3564b4..6aa55fbf891 100644 --- a/pkg/api/util_test.go +++ b/pkg/api/util_test.go @@ -14,8 +14,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/api/wallet.go b/pkg/api/wallet.go index c98e83b5987..5cdd0de087d 100644 --- a/pkg/api/wallet.go +++ b/pkg/api/wallet.go @@ -5,11 +5,18 @@ package api import ( + "math/big" "net/http" + "strings" + + "slices" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/gorilla/mux" ) type walletResponse struct { @@ -47,3 +54,97 @@ func (s *Service) walletHandler(w http.ResponseWriter, r *http.Request) { WalletAddress: s.ethereumAddress, }) } + +type walletTxResponse struct { + TransactionHash common.Hash `json:"transactionHash"` +} + +func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) { + logger := s.logger.WithName("post_wallet_withdraw").Build() + + queries := struct { + Amount *big.Int `map:"amount" validate:"required"` + Address *common.Address `map:"address" validate:"required"` + }{} + + if response := s.mapStructure(r.URL.Query(), &queries); response != nil { + response("invalid query params", logger, w) + return + } + + path := struct { + Coin *string `map:"coin" validate:"required"` + }{} + + if response := s.mapStructure(mux.Vars(r), &path); response != nil { + response("invalid query params", logger, w) + return + } + + var bzz bool + + if strings.EqualFold("BZZ", *path.Coin) { + bzz = true + } else if !strings.EqualFold("NativeToken", *path.Coin) { + jsonhttp.BadRequest(w, "only BZZ or NativeToken options are accepted") + return + } + + if !slices.Contains(s.whitelistedWithdrawalAddress, *queries.Address) { + jsonhttp.BadRequest(w, "provided address not whitelisted") + return + } + + if bzz { + currentBalance, err := s.erc20Service.BalanceOf(r.Context(), s.ethereumAddress) + if err != nil { + logger.Error(err, "unable to get balance") + jsonhttp.InternalServerError(w, "unable to get balance") + return + } + + if queries.Amount.Cmp(currentBalance) > 0 { + logger.Error(err, "not enough balance") + jsonhttp.BadRequest(w, "not enough balance") + return + } + + txHash, err := s.erc20Service.Transfer(r.Context(), *queries.Address, queries.Amount) + if err != nil { + logger.Error(err, "unable to transfer") + jsonhttp.InternalServerError(w, "unable to transfer amount") + return + } + jsonhttp.OK(w, walletTxResponse{TransactionHash: txHash}) + return + } + + nativeToken, err := s.chainBackend.BalanceAt(r.Context(), s.ethereumAddress, nil) + if err != nil { + logger.Error(err, "unable to acquire balance from the chain backend") + jsonhttp.InternalServerError(w, "unable to acquire balance from the chain backend") + return + } + + if queries.Amount.Cmp(nativeToken) > 0 { + jsonhttp.BadRequest(w, "not enough balance") + return + } + + req := &transaction.TxRequest{ + To: queries.Address, + GasPrice: sctx.GetGasPrice(r.Context()), + GasLimit: sctx.GetGasLimitWithDefault(r.Context(), 300_000), + Value: queries.Amount, + Description: "native token withdraw", + } + + txHash, err := s.transaction.Send(r.Context(), req, transaction.DefaultTipBoostPercent) + if err != nil { + logger.Error(err, "unable to transfer") + jsonhttp.InternalServerError(w, "unable to transfer") + return + } + + jsonhttp.OK(w, walletTxResponse{TransactionHash: txHash}) +} diff --git a/pkg/api/wallet_test.go b/pkg/api/wallet_test.go index a5a881f7b24..c6f7449d51a 100644 --- a/pkg/api/wallet_test.go +++ b/pkg/api/wallet_test.go @@ -11,12 +11,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/bigint" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - "github.com/ethersphere/bee/pkg/transaction/backendmock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" ) func TestWallet(t *testing.T) { @@ -86,3 +88,203 @@ func TestWallet(t *testing.T) { })) }) } + +func TestWalletWithdraw(t *testing.T) { + t.Parallel() + + t.Run("address not whitelisted", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{DebugAPI: true}) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BZZ?address=0xaf&amount=99999999", http.StatusBadRequest, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "provided address not whitelisted", + Code: 400, + })) + }) + + t.Run("invalid coin type", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{DebugAPI: true}) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BTC?address=0xaf&amount=99999999", http.StatusBadRequest, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "only BZZ or NativeToken options are accepted", + Code: 400, + })) + }) + + t.Run("BZZ erc20 balance error", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BZZ?address=0xaf&amount=99999999", http.StatusInternalServerError, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "unable to get balance", + Code: 500, + })) + }) + + t.Run("BZZ erc20 balance insufficient", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + Erc20Opts: []erc20mock.Option{ + erc20mock.WithBalanceOfFunc(func(ctx context.Context, address common.Address) (*big.Int, error) { + return big.NewInt(88888888), nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BZZ?address=0xaf&amount=99999999", http.StatusBadRequest, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "not enough balance", + Code: 400, + })) + }) + + t.Run("BZZ erc20 transfer error", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + Erc20Opts: []erc20mock.Option{ + erc20mock.WithBalanceOfFunc(func(ctx context.Context, address common.Address) (*big.Int, error) { + return big.NewInt(100000000), nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BZZ?address=0xaf&amount=99999999", http.StatusInternalServerError, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "unable to transfer amount", + Code: 500, + })) + }) + + t.Run("BZZ erc20 transfer ok", func(t *testing.T) { + t.Parallel() + + txHash := common.HexToHash("0x00f") + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + Erc20Opts: []erc20mock.Option{ + erc20mock.WithBalanceOfFunc(func(ctx context.Context, address common.Address) (*big.Int, error) { + return big.NewInt(100000000), nil + }), + erc20mock.WithTransferFunc(func(ctx context.Context, address common.Address, value *big.Int) (common.Hash, error) { + if address != common.HexToAddress("0xaf") { + t.Fatalf("want addr 0xaf, got %s", address) + } + if value.Cmp(big.NewInt(99999999)) != 0 { + t.Fatalf("want value 99999999, got %s", value) + } + return txHash, nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/BZZ?address=0xaf&amount=99999999", http.StatusOK, + jsonhttptest.WithExpectedJSONResponse(api.WalletTxResponse{ + TransactionHash: txHash, + })) + }) + + t.Run("native balance error", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/NativeToken?address=0xaf&amount=99999999", http.StatusInternalServerError, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "unable to acquire balance from the chain backend", + Code: 500, + })) + }) + + t.Run("native insufficient balance", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + BackendOpts: []backendmock.Option{ + backendmock.WithBalanceAt(func(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error) { + return big.NewInt(99999990), nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/NativeToken?address=0xaf&amount=99999999", http.StatusBadRequest, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "not enough balance", + Code: 400, + })) + }) + + t.Run("native backend send error", func(t *testing.T) { + t.Parallel() + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + BackendOpts: []backendmock.Option{ + backendmock.WithBalanceAt(func(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error) { + return big.NewInt(100000000), nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/NativeToken?address=0xaf&amount=99999999", http.StatusInternalServerError, + jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{ + Message: "unable to transfer", + Code: 500, + })) + }) + + t.Run("native ok", func(t *testing.T) { + t.Parallel() + + txHash := common.HexToHash("0x00f") + + srv, _, _, _ := newTestServer(t, testServerOptions{ + DebugAPI: true, + WhitelistedAddr: "0xaf", + BackendOpts: []backendmock.Option{ + backendmock.WithBalanceAt(func(ctx context.Context, address common.Address, block *big.Int) (*big.Int, error) { + return big.NewInt(100000000), nil + }), + }, + TransactionOpts: []transactionmock.Option{ + transactionmock.WithSendFunc(func(ctx context.Context, tx *transaction.TxRequest, i int) (common.Hash, error) { + if tx.Value.Cmp(big.NewInt(99999999)) != 0 { + t.Fatalf("bad value, want 99999999, got %s", tx.Value) + } + if tx.To.Cmp(common.HexToAddress("0xaf")) != 0 { + t.Fatalf("bad address, want 0xaf, got %s", tx.To) + } + return txHash, nil + }), + }, + }) + + jsonhttptest.Request(t, srv, http.MethodPost, "/wallet/withdraw/NativeToken?address=0xaf&amount=99999999", http.StatusOK, + jsonhttptest.WithExpectedJSONResponse(api.WalletTxResponse{ + TransactionHash: txHash, + })) + }) +} diff --git a/pkg/api/welcome_message.go b/pkg/api/welcome_message.go index 0d51d4977f7..e19b9b01a9b 100644 --- a/pkg/api/welcome_message.go +++ b/pkg/api/welcome_message.go @@ -8,7 +8,7 @@ import ( "encoding/json" "net/http" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) const welcomeMessageMaxRequestSize = 512 diff --git a/pkg/api/welcome_message_test.go b/pkg/api/welcome_message_test.go index 8bfc4075302..39d7c19a039 100644 --- a/pkg/api/welcome_message_test.go +++ b/pkg/api/welcome_message_test.go @@ -11,10 +11,10 @@ import ( "net/http" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" - "github.com/ethersphere/bee/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/p2p/mock" ) func TestGetWelcomeMessage(t *testing.T) { diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 5638c29c26c..ee3b8a65290 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -18,7 +18,7 @@ import ( "github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2/model" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" "golang.org/x/crypto/bcrypt" ) @@ -242,7 +242,7 @@ func (e encrypter) decrypt(data []byte) ([]byte, error) { func applyPolicies(e *casbin.Enforcer) error { _, err := e.AddPolicies([][]string{ - {"consumer", "/bytes/*", "GET"}, + {"consumer", "/bytes/*", "(GET)|(HEAD)"}, {"creator", "/bytes", "POST"}, {"consumer", "/chunks/*", "GET"}, {"creator", "/chunks", "POST"}, @@ -250,7 +250,7 @@ func applyPolicies(e *casbin.Enforcer) error { {"creator", "/bzz/*", "PATCH"}, {"creator", "/bzz", "POST"}, {"creator", "/bzz?*", "POST"}, - {"consumer", "/bzz/*/*", "GET"}, + {"consumer", "/bzz/*/*", "(GET)|(HEAD)"}, {"creator", "/tags", "GET"}, {"creator", "/tags?*", "GET"}, {"creator", "/tags", "POST"}, @@ -291,6 +291,7 @@ func applyPolicies(e *casbin.Enforcer) error { {"maintainer", "/chequebook/address", "GET"}, {"maintainer", "/chequebook/balance", "GET"}, {"maintainer", "/wallet", "GET"}, + {"maintainer", "/wallet/withdraw/*", "POST"}, {"maintainer", "/chunks/*", "(GET)|(DELETE)"}, {"maintainer", "/reservestate", "GET"}, {"maintainer", "/chainstate", "GET"}, diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go index 28f16b58e0e..0d107a764a2 100644 --- a/pkg/auth/auth_test.go +++ b/pkg/auth/auth_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/auth" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/auth" + "github.com/ethersphere/bee/v2/pkg/log" ) const ( diff --git a/pkg/auth/handler.go b/pkg/auth/handler.go index 2e79ee42e73..6a54b9269be 100644 --- a/pkg/auth/handler.go +++ b/pkg/auth/handler.go @@ -9,7 +9,7 @@ import ( "net/http" "strings" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) type auth interface { diff --git a/pkg/bigint/bigint_test.go b/pkg/bigint/bigint_test.go index 4cbde9034f9..f51aff05c46 100644 --- a/pkg/bigint/bigint_test.go +++ b/pkg/bigint/bigint_test.go @@ -11,7 +11,7 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/bigint" + "github.com/ethersphere/bee/v2/pkg/bigint" ) func TestMarshaling(t *testing.T) { diff --git a/pkg/blocker/blocker.go b/pkg/blocker/blocker.go index 151d8ad3dfb..5b916c81732 100644 --- a/pkg/blocker/blocker.go +++ b/pkg/blocker/blocker.go @@ -9,9 +9,9 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" "go.uber.org/atomic" ) diff --git a/pkg/blocker/blocker_test.go b/pkg/blocker/blocker_test.go index fc5ad1be247..269de291441 100644 --- a/pkg/blocker/blocker_test.go +++ b/pkg/blocker/blocker_test.go @@ -11,11 +11,11 @@ import ( "go.uber.org/goleak" - "github.com/ethersphere/bee/pkg/blocker" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/blocker" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) const ( diff --git a/pkg/bmt/benchmark_test.go b/pkg/bmt/benchmark_test.go index 55416437df1..2f49ce37179 100644 --- a/pkg/bmt/benchmark_test.go +++ b/pkg/bmt/benchmark_test.go @@ -8,10 +8,10 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/bmt/reference" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/bmt/reference" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "golang.org/x/sync/errgroup" ) diff --git a/pkg/bmt/bmt.go b/pkg/bmt/bmt.go index f314e012776..55091ceb3a5 100644 --- a/pkg/bmt/bmt.go +++ b/pkg/bmt/bmt.go @@ -8,7 +8,7 @@ import ( "encoding/binary" "hash" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var _ Hash = (*Hasher)(nil) diff --git a/pkg/bmt/bmt_test.go b/pkg/bmt/bmt_test.go index c74e5bdf0e8..9bb5589eb6a 100644 --- a/pkg/bmt/bmt_test.go +++ b/pkg/bmt/bmt_test.go @@ -13,10 +13,10 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/bmt/reference" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/bmt/reference" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "golang.org/x/sync/errgroup" ) diff --git a/pkg/bmt/proof_test.go b/pkg/bmt/proof_test.go index 1b7f6d3b3dd..d9b4ae19438 100644 --- a/pkg/bmt/proof_test.go +++ b/pkg/bmt/proof_test.go @@ -12,8 +12,8 @@ import ( "io" "testing" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestProofCorrectness(t *testing.T) { diff --git a/pkg/bmt/reference/reference_test.go b/pkg/bmt/reference/reference_test.go index e2dcc556d83..f11954d522c 100644 --- a/pkg/bmt/reference/reference_test.go +++ b/pkg/bmt/reference/reference_test.go @@ -12,7 +12,7 @@ import ( "io" "testing" - "github.com/ethersphere/bee/pkg/bmt/reference" + "github.com/ethersphere/bee/v2/pkg/bmt/reference" "golang.org/x/crypto/sha3" ) diff --git a/pkg/bmtpool/bmtpool.go b/pkg/bmtpool/bmtpool.go index d5187e49fb8..88c1ad32dba 100644 --- a/pkg/bmtpool/bmtpool.go +++ b/pkg/bmtpool/bmtpool.go @@ -7,8 +7,8 @@ package bmtpool import ( - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const Capacity = 32 diff --git a/pkg/bzz/address.go b/pkg/bzz/address.go index 41a32496ea3..42fa8fd90b4 100644 --- a/pkg/bzz/address.go +++ b/pkg/bzz/address.go @@ -16,8 +16,8 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/bzz/address_test.go b/pkg/bzz/address_test.go index c6ebe850396..969216d29d7 100644 --- a/pkg/bzz/address_test.go +++ b/pkg/bzz/address_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/bzz/utilities_test.go b/pkg/bzz/utilities_test.go index dad1110b504..7e4666b66ac 100644 --- a/pkg/bzz/utilities_test.go +++ b/pkg/bzz/utilities_test.go @@ -9,9 +9,9 @@ import ( ma "github.com/multiformats/go-multiaddr" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func Test_ContainsAddress(t *testing.T) { diff --git a/pkg/cac/cac.go b/pkg/cac/cac.go index 44af58d573b..70a20b8baf0 100644 --- a/pkg/cac/cac.go +++ b/pkg/cac/cac.go @@ -9,8 +9,8 @@ import ( "encoding/binary" "fmt" - "github.com/ethersphere/bee/pkg/bmtpool" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmtpool" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/cac/cac_test.go b/pkg/cac/cac_test.go index 0e70c2b392b..2f1384aa2a0 100644 --- a/pkg/cac/cac_test.go +++ b/pkg/cac/cac_test.go @@ -12,9 +12,9 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestNew(t *testing.T) { diff --git a/pkg/crypto/clef/clef.go b/pkg/crypto/clef/clef.go index 8c111f88f36..7d30ab6335a 100644 --- a/pkg/crypto/clef/clef.go +++ b/pkg/crypto/clef/clef.go @@ -17,8 +17,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) var ( diff --git a/pkg/crypto/clef/clef_test.go b/pkg/crypto/clef/clef_test.go index 79820c6bb8f..34573de4d1c 100644 --- a/pkg/crypto/clef/clef_test.go +++ b/pkg/crypto/clef/clef_test.go @@ -15,9 +15,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/clef" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/clef" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) type mockClef struct { diff --git a/pkg/crypto/crypto.go b/pkg/crypto/crypto.go index a2e0ba2e468..d10c14a9991 100644 --- a/pkg/crypto/crypto.go +++ b/pkg/crypto/crypto.go @@ -14,7 +14,7 @@ import ( "fmt" "github.com/btcsuite/btcd/btcec/v2" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/crypto/sha3" ) diff --git a/pkg/crypto/crypto_test.go b/pkg/crypto/crypto_test.go index 4911be7032f..8a477730108 100644 --- a/pkg/crypto/crypto_test.go +++ b/pkg/crypto/crypto_test.go @@ -11,8 +11,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestGenerateSecp256k1Key(t *testing.T) { diff --git a/pkg/crypto/dh_test.go b/pkg/crypto/dh_test.go index 67cb26ebbd2..a1dfbff6487 100644 --- a/pkg/crypto/dh_test.go +++ b/pkg/crypto/dh_test.go @@ -12,7 +12,7 @@ import ( "testing" "github.com/btcsuite/btcd/btcec/v2" - "github.com/ethersphere/bee/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto" ) func TestECDHCorrect(t *testing.T) { diff --git a/pkg/crypto/mock/signer.go b/pkg/crypto/mock/signer.go index 4cd7d82142a..0f007fd47e3 100644 --- a/pkg/crypto/mock/signer.go +++ b/pkg/crypto/mock/signer.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) type signerMock struct { diff --git a/pkg/crypto/signer.go b/pkg/crypto/signer.go index b7d1927aafe..150a05ef953 100644 --- a/pkg/crypto/signer.go +++ b/pkg/crypto/signer.go @@ -14,7 +14,7 @@ import ( btcecdsa "github.com/btcsuite/btcd/btcec/v2/ecdsa" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) var ( diff --git a/pkg/crypto/signer_test.go b/pkg/crypto/signer_test.go index 4c2294de1ef..b3b09ae04af 100644 --- a/pkg/crypto/signer_test.go +++ b/pkg/crypto/signer_test.go @@ -14,8 +14,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) func TestDefaultSigner(t *testing.T) { diff --git a/pkg/discovery/discovery.go b/pkg/discovery/discovery.go index a9dd5254f2e..fe65ba26fea 100644 --- a/pkg/discovery/discovery.go +++ b/pkg/discovery/discovery.go @@ -9,7 +9,7 @@ package discovery import ( "context" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Driver interface { diff --git a/pkg/discovery/mock/mock.go b/pkg/discovery/mock/mock.go index 48ca1d4ccb3..8fc9b861589 100644 --- a/pkg/discovery/mock/mock.go +++ b/pkg/discovery/mock/mock.go @@ -8,7 +8,7 @@ import ( "context" "sync" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Discovery struct { diff --git a/pkg/encryption/chunk_encryption.go b/pkg/encryption/chunk_encryption.go index 0cb6a901083..72f60fcdcd9 100644 --- a/pkg/encryption/chunk_encryption.go +++ b/pkg/encryption/chunk_encryption.go @@ -5,7 +5,7 @@ package encryption import ( - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/crypto/sha3" ) @@ -20,22 +20,21 @@ func NewChunkEncrypter() ChunkEncrypter { return &chunkEncrypter{} } func (c *chunkEncrypter) EncryptChunk(chunkData []byte) (Key, []byte, []byte, error) { key := GenerateRandomKey(KeyLength) - encryptedSpan, err := newSpanEncryption(key).Encrypt(chunkData[:8]) + encryptedSpan, err := NewSpanEncryption(key).Encrypt(chunkData[:8]) if err != nil { return nil, nil, nil, err } - encryptedData, err := newDataEncryption(key).Encrypt(chunkData[8:]) + encryptedData, err := NewDataEncryption(key).Encrypt(chunkData[8:]) if err != nil { return nil, nil, nil, err } return key, encryptedSpan, encryptedData, nil } -func newSpanEncryption(key Key) Interface { - refSize := int64(swarm.HashSize + KeyLength) - return New(key, 0, uint32(swarm.ChunkSize/refSize), sha3.NewLegacyKeccak256) +func NewSpanEncryption(key Key) Interface { + return New(key, 0, uint32(swarm.ChunkSize/KeyLength), sha3.NewLegacyKeccak256) } -func newDataEncryption(key Key) Interface { +func NewDataEncryption(key Key) Interface { return New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256) } diff --git a/pkg/encryption/elgamal/encryption.go b/pkg/encryption/elgamal/encryption.go index 6629bde3188..f3293b5f7ce 100644 --- a/pkg/encryption/elgamal/encryption.go +++ b/pkg/encryption/elgamal/encryption.go @@ -8,8 +8,8 @@ import ( "crypto/ecdsa" "hash" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/encryption" ) // New constructs an encryption interface (the modified blockcipher) with a base key derived from diff --git a/pkg/encryption/elgamal/encryption_test.go b/pkg/encryption/elgamal/encryption_test.go index da00b070701..ea14c77bc9f 100644 --- a/pkg/encryption/elgamal/encryption_test.go +++ b/pkg/encryption/elgamal/encryption_test.go @@ -10,9 +10,9 @@ import ( "io" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/encryption/elgamal" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/encryption/elgamal" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestElgamalCorrect(t *testing.T) { diff --git a/pkg/encryption/encryption_test.go b/pkg/encryption/encryption_test.go index 9c7f58db591..01d7c70d687 100644 --- a/pkg/encryption/encryption_test.go +++ b/pkg/encryption/encryption_test.go @@ -21,9 +21,9 @@ import ( "encoding/hex" "testing" - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "golang.org/x/crypto/sha3" ) diff --git a/pkg/encryption/mock/chunk_encryption.go b/pkg/encryption/mock/chunk_encryption.go index a49f5ba4b6d..48049ab58db 100644 --- a/pkg/encryption/mock/chunk_encryption.go +++ b/pkg/encryption/mock/chunk_encryption.go @@ -5,7 +5,7 @@ package mock import ( - "github.com/ethersphere/bee/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption" ) type chunkEncrypter struct { diff --git a/pkg/encryption/mock/mock.go b/pkg/encryption/mock/mock.go index 731b86fead3..66420fb2f1b 100644 --- a/pkg/encryption/mock/mock.go +++ b/pkg/encryption/mock/mock.go @@ -7,7 +7,7 @@ package mock import ( "errors" - "github.com/ethersphere/bee/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption" ) var _ encryption.Interface = (*Encryptor)(nil) diff --git a/pkg/encryption/mock/mock_test.go b/pkg/encryption/mock/mock_test.go index 69b7bf94e1d..97e52b7777c 100644 --- a/pkg/encryption/mock/mock_test.go +++ b/pkg/encryption/mock/mock_test.go @@ -9,7 +9,7 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/encryption/mock" + "github.com/ethersphere/bee/v2/pkg/encryption/mock" ) var errTest = errors.New("test error") diff --git a/pkg/encryption/store/decrypt_store.go b/pkg/encryption/store/decrypt_store.go index 7a9f0395e91..66a6341ae84 100644 --- a/pkg/encryption/store/decrypt_store.go +++ b/pkg/encryption/store/decrypt_store.go @@ -8,12 +8,11 @@ import ( "context" "encoding/binary" - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/redundancy" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "golang.org/x/crypto/sha3" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type decryptingStore struct { @@ -73,22 +72,13 @@ func DecryptChunkData(chunkData []byte, encryptionKey encryption.Key) ([]byte, e } func decrypt(chunkData []byte, key encryption.Key) ([]byte, []byte, error) { - decryptedSpan, err := newSpanEncryption(key).Decrypt(chunkData[:swarm.SpanSize]) + decryptedSpan, err := encryption.NewSpanEncryption(key).Decrypt(chunkData[:swarm.SpanSize]) if err != nil { return nil, nil, err } - decryptedData, err := newDataEncryption(key).Decrypt(chunkData[swarm.SpanSize:]) + decryptedData, err := encryption.NewDataEncryption(key).Decrypt(chunkData[swarm.SpanSize:]) if err != nil { return nil, nil, err } return decryptedSpan, decryptedData, nil } - -func newSpanEncryption(key encryption.Key) encryption.Interface { - refSize := int64(swarm.HashSize + encryption.KeyLength) - return encryption.New(key, 0, uint32(swarm.ChunkSize/refSize), sha3.NewLegacyKeccak256) -} - -func newDataEncryption(key encryption.Key) encryption.Interface { - return encryption.New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256) -} diff --git a/pkg/feeds/epochs/epoch.go b/pkg/feeds/epochs/epoch.go index b59f7ce2e00..dee107c44e6 100644 --- a/pkg/feeds/epochs/epoch.go +++ b/pkg/feeds/epochs/epoch.go @@ -10,8 +10,8 @@ import ( "encoding/binary" "fmt" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" ) const ( diff --git a/pkg/feeds/epochs/finder.go b/pkg/feeds/epochs/finder.go index ad826ac1c01..a85ab309e76 100644 --- a/pkg/feeds/epochs/finder.go +++ b/pkg/feeds/epochs/finder.go @@ -8,9 +8,9 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/feeds" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/feeds" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var _ feeds.Lookup = (*finder)(nil) diff --git a/pkg/feeds/epochs/lookup_benchmark_test.go b/pkg/feeds/epochs/lookup_benchmark_test.go index 2226e94bbef..8f964bc553b 100644 --- a/pkg/feeds/epochs/lookup_benchmark_test.go +++ b/pkg/feeds/epochs/lookup_benchmark_test.go @@ -9,11 +9,11 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/epochs" - feedstesting "github.com/ethersphere/bee/pkg/feeds/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/epochs" + feedstesting "github.com/ethersphere/bee/v2/pkg/feeds/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" ) func BenchmarkFinder(b *testing.B) { diff --git a/pkg/feeds/epochs/lookup_test.go b/pkg/feeds/epochs/lookup_test.go index 7318940532a..e89d8b62b74 100644 --- a/pkg/feeds/epochs/lookup_test.go +++ b/pkg/feeds/epochs/lookup_test.go @@ -7,11 +7,11 @@ package epochs_test import ( "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/epochs" - feedstesting "github.com/ethersphere/bee/pkg/feeds/testing" - storage "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/epochs" + feedstesting "github.com/ethersphere/bee/v2/pkg/feeds/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) func TestFinder_FLAKY(t *testing.T) { diff --git a/pkg/feeds/epochs/updater.go b/pkg/feeds/epochs/updater.go index 70629d2d18c..b36d77e7d96 100644 --- a/pkg/feeds/epochs/updater.go +++ b/pkg/feeds/epochs/updater.go @@ -7,9 +7,9 @@ package epochs import ( "context" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - storage "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) var _ feeds.Updater = (*updater)(nil) diff --git a/pkg/feeds/factory/factory.go b/pkg/feeds/factory/factory.go index ed20a3f1f43..1d555416407 100644 --- a/pkg/feeds/factory/factory.go +++ b/pkg/feeds/factory/factory.go @@ -5,10 +5,10 @@ package factory import ( - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/epochs" - "github.com/ethersphere/bee/pkg/feeds/sequence" - storage "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/epochs" + "github.com/ethersphere/bee/v2/pkg/feeds/sequence" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) type factory struct { diff --git a/pkg/feeds/feed.go b/pkg/feeds/feed.go index 30a113a78ed..7c9495cdfac 100644 --- a/pkg/feeds/feed.go +++ b/pkg/feeds/feed.go @@ -15,10 +15,10 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ErrFeedTypeNotFound = errors.New("no such feed type") diff --git a/pkg/feeds/getter.go b/pkg/feeds/getter.go index 19c002bee20..77b7599dd9e 100644 --- a/pkg/feeds/getter.go +++ b/pkg/feeds/getter.go @@ -11,9 +11,9 @@ import ( "fmt" "time" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Lookup is the interface for time based feed lookup diff --git a/pkg/feeds/putter.go b/pkg/feeds/putter.go index 21db4c6a1d7..633276f8f63 100644 --- a/pkg/feeds/putter.go +++ b/pkg/feeds/putter.go @@ -8,11 +8,11 @@ import ( "context" "encoding/binary" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Updater is the generic interface f diff --git a/pkg/feeds/sequence/lookup_benchmark_test.go b/pkg/feeds/sequence/lookup_benchmark_test.go index 44da69acd09..e81d8cc9a61 100644 --- a/pkg/feeds/sequence/lookup_benchmark_test.go +++ b/pkg/feeds/sequence/lookup_benchmark_test.go @@ -9,11 +9,11 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/sequence" - feedstesting "github.com/ethersphere/bee/pkg/feeds/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/sequence" + feedstesting "github.com/ethersphere/bee/v2/pkg/feeds/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" ) func BenchmarkFinder(b *testing.B) { diff --git a/pkg/feeds/sequence/lookup_test.go b/pkg/feeds/sequence/lookup_test.go index 8e0d17cc90b..4396736a519 100644 --- a/pkg/feeds/sequence/lookup_test.go +++ b/pkg/feeds/sequence/lookup_test.go @@ -7,11 +7,11 @@ package sequence_test import ( "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/sequence" - feedstesting "github.com/ethersphere/bee/pkg/feeds/testing" - storage "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/sequence" + feedstesting "github.com/ethersphere/bee/v2/pkg/feeds/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) func TestFinder(t *testing.T) { diff --git a/pkg/feeds/sequence/sequence.go b/pkg/feeds/sequence/sequence.go index f01c7a8dd84..5361086de4b 100644 --- a/pkg/feeds/sequence/sequence.go +++ b/pkg/feeds/sequence/sequence.go @@ -18,10 +18,10 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // DefaultLevels is the number of concurrent lookaheads diff --git a/pkg/feeds/testing/lookup.go b/pkg/feeds/testing/lookup.go index 1c70ec1183f..8c71098f5a6 100644 --- a/pkg/feeds/testing/lookup.go +++ b/pkg/feeds/testing/lookup.go @@ -15,11 +15,11 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Timeout struct { diff --git a/pkg/file/addresses/addresses_getter.go b/pkg/file/addresses/addresses_getter.go index 1ef32a9f4cd..6c9c4af82d9 100644 --- a/pkg/file/addresses/addresses_getter.go +++ b/pkg/file/addresses/addresses_getter.go @@ -7,8 +7,8 @@ package addresses import ( "context" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type addressesGetterStore struct { diff --git a/pkg/file/addresses/addresses_getter_test.go b/pkg/file/addresses/addresses_getter_test.go index a5fe9d00000..b71edbe8314 100644 --- a/pkg/file/addresses/addresses_getter_test.go +++ b/pkg/file/addresses/addresses_getter_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/addresses" - "github.com/ethersphere/bee/pkg/file/joiner" - filetest "github.com/ethersphere/bee/pkg/file/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/addresses" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + filetest "github.com/ethersphere/bee/v2/pkg/file/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestAddressesGetterIterateChunkAddresses(t *testing.T) { diff --git a/pkg/file/buffer.go b/pkg/file/buffer.go index 57e0381828d..976eca20fa0 100644 --- a/pkg/file/buffer.go +++ b/pkg/file/buffer.go @@ -7,7 +7,7 @@ package file import ( "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/file/buffer_test.go b/pkg/file/buffer_test.go index b1760f9948f..3416db1084a 100644 --- a/pkg/file/buffer_test.go +++ b/pkg/file/buffer_test.go @@ -12,9 +12,9 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // TestChunkPipe verifies that the reads are correctly buffered for diff --git a/pkg/file/file.go b/pkg/file/file.go index fa613cea218..40241cdabaa 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -9,7 +9,7 @@ import ( "context" "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Reader interface { diff --git a/pkg/file/file_test.go b/pkg/file/file_test.go index cc677336b64..f99fb081f0d 100644 --- a/pkg/file/file_test.go +++ b/pkg/file/file_test.go @@ -13,12 +13,12 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - test "github.com/ethersphere/bee/pkg/file/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + test "github.com/ethersphere/bee/v2/pkg/file/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/io.go b/pkg/file/io.go index 562b39742f6..8bb7ce54254 100644 --- a/pkg/file/io.go +++ b/pkg/file/io.go @@ -12,7 +12,7 @@ import ( "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // simpleReadCloser wraps a byte slice in a io.ReadCloser implementation. diff --git a/pkg/file/joiner/joiner.go b/pkg/file/joiner/joiner.go index dc9c850084c..fcd7e790c10 100644 --- a/pkg/file/joiner/joiner.go +++ b/pkg/file/joiner/joiner.go @@ -12,15 +12,15 @@ import ( "sync" "sync/atomic" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/encryption/store" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/file/redundancy/getter" - "github.com/ethersphere/bee/pkg/replicas" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption/store" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/file/redundancy/getter" + "github.com/ethersphere/bee/v2/pkg/replicas" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/sync/errgroup" ) @@ -67,9 +67,16 @@ func fingerprint(addrs []swarm.Address) string { // GetOrCreate returns a decoder for the given chunk address func (g *decoderCache) GetOrCreate(addrs []swarm.Address, shardCnt int) storage.Getter { + + // since a recovery decoder is not allowed, simply return the underlying netstore + if g.config.Strict && g.config.Strategy == getter.NONE { + return g.fetcher + } + if len(addrs) == shardCnt { return g.fetcher } + key := fingerprint(addrs) g.mu.Lock() defer g.mu.Unlock() @@ -80,10 +87,16 @@ func (g *decoderCache) GetOrCreate(addrs []swarm.Address, shardCnt int) storage. } return d } - remove := func() { + remove := func(err error) { g.mu.Lock() defer g.mu.Unlock() - g.cache[key] = nil + if err != nil { + // signals that a new getter is needed to reattempt to recover the data + delete(g.cache, key) + } else { + // signals that the chunks were fetched/recovered/cached so a future getter is not needed + g.cache[key] = nil + } } d = getter.New(addrs, shardCnt, g.fetcher, g.putter, remove, g.config) g.cache[key] = d @@ -129,7 +142,7 @@ func New(ctx context.Context, g storage.Getter, putter storage.Putter, address s maxBranching = rLevel.GetMaxShards() } } else { - // if root chunk has no redundancy, strategy is ignored and set to NONE and strict is set to true + // if root chunk has no redundancy, strategy is ignored and set to DATA and strict is set to true conf.Strategy = getter.DATA conf.Strict = true } @@ -222,7 +235,7 @@ func (j *joiner) readAtOffset( } // fast forward the cursor - sec := j.subtrieSection(data, cursor, pSize, parity, subTrieSize) + sec := j.subtrieSection(cursor, pSize, parity, subTrieSize) if cur+sec <= off { cur += sec continue @@ -277,7 +290,7 @@ func (j *joiner) getShards(payloadSize, parities int) int { } // brute-forces the subtrie size for each of the sections in this intermediate chunk -func (j *joiner) subtrieSection(data []byte, startIdx, payloadSize, parities int, subtrieSize int64) int64 { +func (j *joiner) subtrieSection(startIdx, payloadSize, parities int, subtrieSize int64) int64 { // assume we have a trie of size `y` then we can assume that all of // the forks except for the last one on the right are of equal size // this is due to how the splitter wraps levels. @@ -375,7 +388,7 @@ func (j *joiner) processChunkAddresses(ctx context.Context, fn swarm.AddressIter if j.refLength == encryption.ReferenceSize { cursor += swarm.HashSize * min(i, shardCnt) } - sec := j.subtrieSection(data, cursor, eSize, parity, subTrieSize) + sec := j.subtrieSection(cursor, eSize, parity, subTrieSize) if sec <= swarm.ChunkSize { continue } diff --git a/pkg/file/joiner/joiner_test.go b/pkg/file/joiner/joiner_test.go index 15d46bf220b..7938b1260ee 100644 --- a/pkg/file/joiner/joiner_test.go +++ b/pkg/file/joiner/joiner_test.go @@ -17,21 +17,21 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/file/redundancy/getter" - "github.com/ethersphere/bee/pkg/file/splitter" - filetest "github.com/ethersphere/bee/pkg/file/testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" - "github.com/ethersphere/bee/pkg/util/testutil/pseudorand" - "github.com/ethersphere/bee/pkg/util/testutil/racedetection" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/file/redundancy/getter" + "github.com/ethersphere/bee/v2/pkg/file/splitter" + filetest "github.com/ethersphere/bee/v2/pkg/file/testing" + "github.com/ethersphere/bee/v2/pkg/log" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil/pseudorand" "gitlab.com/nolash/go-mockbytes" "golang.org/x/sync/errgroup" ) @@ -88,7 +88,7 @@ func TestJoinerSingleChunk(t *testing.T) { } } -// TestJoinerDecryptingStore_NormalChunk verifies the the mock store that uses +// TestJoinerDecryptingStore_NormalChunk verifies the mock store that uses // the decrypting store manages to retrieve a normal chunk which is not encrypted func TestJoinerDecryptingStore_NormalChunk(t *testing.T) { t.Parallel() @@ -1109,12 +1109,19 @@ func TestJoinerRedundancy(t *testing.T) { if err != nil { t.Fatal(err) } - strategyTimeout := 100 * time.Millisecond // all data can be read back readCheck := func(t *testing.T, expErr error) { - ctx, cancel := context.WithTimeout(context.Background(), 15*strategyTimeout) - defer cancel() - ctx = getter.SetConfigInContext(ctx, getter.RACE, true, (10 * strategyTimeout).String(), strategyTimeout.String()) + ctx := context.Background() + + decodeTimeoutStr := time.Second.String() + fallback := true + s := getter.RACE + + ctx, err := getter.SetConfigInContext(ctx, &s, &fallback, &decodeTimeoutStr, log.Noop) + if err != nil { + t.Fatal(err) + } + joinReader, rootSpan, err := joiner.New(ctx, store, store, swarmAddr) if err != nil { t.Fatal(err) @@ -1159,14 +1166,14 @@ func TestJoinerRedundancy(t *testing.T) { } } t.Run("no recovery possible with no chunk stored", func(t *testing.T) { - readCheck(t, context.DeadlineExceeded) + readCheck(t, storage.ErrNotFound) }) if err := putter.store(shardCnt - 1); err != nil { t.Fatal(err) } t.Run("no recovery possible with 1 short of shardCnt chunks stored", func(t *testing.T) { - readCheck(t, context.DeadlineExceeded) + readCheck(t, storage.ErrNotFound) }) if err := putter.store(1); err != nil { @@ -1220,7 +1227,7 @@ func TestJoinerRedundancy(t *testing.T) { // nolint:thelper func TestJoinerRedundancyMultilevel(t *testing.T) { t.Parallel() - test := func(t *testing.T, rLevel redundancy.Level, encrypt bool, levels, size int) { + test := func(t *testing.T, rLevel redundancy.Level, encrypt bool, size int) { t.Helper() store := mockstorer.NewForgettingStore(inmemchunkstore.New()) testutil.CleanupCloser(t, store) @@ -1240,16 +1247,16 @@ func TestJoinerRedundancyMultilevel(t *testing.T) { expRead := swarm.ChunkSize buf := make([]byte, expRead) offset := mrand.Intn(size) * expRead - canReadRange := func(t *testing.T, s getter.Strategy, fallback bool, levels int, canRead bool) { + canReadRange := func(t *testing.T, s getter.Strategy, fallback bool, canRead bool) { ctx := context.Background() - strategyTimeout := 100 * time.Millisecond - decodingTimeout := 600 * time.Millisecond - if racedetection.IsOn() { - decodingTimeout *= 2 + + decodingTimeoutStr := (200 * time.Millisecond).String() + + ctx, err := getter.SetConfigInContext(ctx, &s, &fallback, &decodingTimeoutStr, log.Noop) + if err != nil { + t.Fatal(err) } - ctx = getter.SetConfigInContext(ctx, s, fallback, (2 * strategyTimeout).String(), strategyTimeout.String()) - ctx, cancel := context.WithTimeout(ctx, time.Duration(levels)*(3*strategyTimeout+decodingTimeout)) - defer cancel() + j, _, err := joiner.New(ctx, store, store, addr) if err != nil { t.Fatal(err) @@ -1280,39 +1287,39 @@ func TestJoinerRedundancyMultilevel(t *testing.T) { } } - // first sanity check and and recover a range + // first sanity check and recover a range t.Run("NONE w/o fallback CAN retrieve", func(t *testing.T) { store.Record() defer store.Unrecord() - canReadRange(t, getter.NONE, false, levels, true) + canReadRange(t, getter.NONE, false, true) }) // do not forget the root chunk store.Unmiss(swarm.NewAddress(addr.Bytes()[:swarm.HashSize])) // after we forget the chunks on the way to the range, we should not be able to retrieve t.Run("NONE w/o fallback CANNOT retrieve", func(t *testing.T) { - canReadRange(t, getter.NONE, false, levels, false) + canReadRange(t, getter.NONE, false, false) }) // we lost a data chunk, we cannot recover using DATA only strategy with no fallback t.Run("DATA w/o fallback CANNOT retrieve", func(t *testing.T) { - canReadRange(t, getter.DATA, false, levels, false) + canReadRange(t, getter.DATA, false, false) }) if rLevel == 0 { // allowing fallback mode will not help if no redundancy used for upload t.Run("DATA w fallback CANNOT retrieve", func(t *testing.T) { - canReadRange(t, getter.DATA, true, levels, false) + canReadRange(t, getter.DATA, true, false) }) return } // allowing fallback mode will make the range retrievable using erasure decoding t.Run("DATA w fallback CAN retrieve", func(t *testing.T) { - canReadRange(t, getter.DATA, true, levels, true) + canReadRange(t, getter.DATA, true, true) }) // after the reconstructed data is stored, we can retrieve the range using DATA only mode t.Run("after recovery, NONE w/o fallback CAN retrieve", func(t *testing.T) { - canReadRange(t, getter.NONE, false, levels, true) + canReadRange(t, getter.NONE, false, true) }) } r2level := []int{2, 1, 2, 3, 2} @@ -1342,7 +1349,7 @@ func TestJoinerRedundancyMultilevel(t *testing.T) { if r2level[rLevel] != levels || encrypt != encryptChunk[rLevel] { t.Skip("skipping to save time") } - test(t, rLevel, encrypt, levels, chunkCnt) + test(t, rLevel, encrypt, chunkCnt) }) switch levels { case 1: @@ -1353,7 +1360,7 @@ func TestJoinerRedundancyMultilevel(t *testing.T) { continue } t.Run(fmt.Sprintf("encrypt=%v levels=%d chunks=%d full", encrypt, levels, chunkCnt), func(t *testing.T) { - test(t, rLevel, encrypt, levels, chunkCnt) + test(t, rLevel, encrypt, chunkCnt) }) } } diff --git a/pkg/file/loadsave/loadsave.go b/pkg/file/loadsave/loadsave.go index 1d65e45ab6b..6a2a0bbf782 100644 --- a/pkg/file/loadsave/loadsave.go +++ b/pkg/file/loadsave/loadsave.go @@ -11,12 +11,12 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var errReadonlyLoadSave = errors.New("readonly manifest loadsaver") diff --git a/pkg/file/loadsave/loadsave_test.go b/pkg/file/loadsave/loadsave_test.go index 64154859757..f159b7056e6 100644 --- a/pkg/file/loadsave/loadsave_test.go +++ b/pkg/file/loadsave/loadsave_test.go @@ -11,12 +11,12 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/pipeline/bmt/bmt.go b/pkg/file/pipeline/bmt/bmt.go index 9f28b976226..669b20b8252 100644 --- a/pkg/file/pipeline/bmt/bmt.go +++ b/pkg/file/pipeline/bmt/bmt.go @@ -7,9 +7,9 @@ package bmt import ( "errors" - "github.com/ethersphere/bee/pkg/bmtpool" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmtpool" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/pipeline/bmt/bmt_test.go b/pkg/file/pipeline/bmt/bmt_test.go index fad40e3e3f7..109a9cc9d42 100644 --- a/pkg/file/pipeline/bmt/bmt_test.go +++ b/pkg/file/pipeline/bmt/bmt_test.go @@ -11,9 +11,9 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/bmt" - mock "github.com/ethersphere/bee/pkg/file/pipeline/mock" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/bmt" + mock "github.com/ethersphere/bee/v2/pkg/file/pipeline/mock" ) // TestStoreWriter tests that store writer stores the provided data and calls the next chain writer. diff --git a/pkg/file/pipeline/builder/builder.go b/pkg/file/pipeline/builder/builder.go index d022ed5724a..50a05e56c4d 100644 --- a/pkg/file/pipeline/builder/builder.go +++ b/pkg/file/pipeline/builder/builder.go @@ -10,16 +10,16 @@ import ( "fmt" "io" - "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/feeder" - "github.com/ethersphere/bee/pkg/file/pipeline/hashtrie" - "github.com/ethersphere/bee/pkg/file/pipeline/store" - "github.com/ethersphere/bee/pkg/file/redundancy" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/bmt" + enc "github.com/ethersphere/bee/v2/pkg/file/pipeline/encryption" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/feeder" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/hashtrie" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/store" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // NewPipelineBuilder returns the appropriate pipeline according to the specified parameters diff --git a/pkg/file/pipeline/builder/builder_test.go b/pkg/file/pipeline/builder/builder_test.go index 266474d9376..9f8070b1510 100644 --- a/pkg/file/pipeline/builder/builder_test.go +++ b/pkg/file/pipeline/builder/builder_test.go @@ -12,11 +12,11 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - test "github.com/ethersphere/bee/pkg/file/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + test "github.com/ethersphere/bee/v2/pkg/file/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestPartialWrites(t *testing.T) { diff --git a/pkg/file/pipeline/encryption/encryption.go b/pkg/file/pipeline/encryption/encryption.go index 0471c4121f0..905b031254e 100644 --- a/pkg/file/pipeline/encryption/encryption.go +++ b/pkg/file/pipeline/encryption/encryption.go @@ -5,8 +5,8 @@ package encryption import ( - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" ) type encryptionWriter struct { diff --git a/pkg/file/pipeline/encryption/encryption_test.go b/pkg/file/pipeline/encryption/encryption_test.go index 8c0811ee947..49306a7d27b 100644 --- a/pkg/file/pipeline/encryption/encryption_test.go +++ b/pkg/file/pipeline/encryption/encryption_test.go @@ -9,10 +9,10 @@ import ( "encoding/binary" "testing" - mockenc "github.com/ethersphere/bee/pkg/encryption/mock" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/encryption" - mock "github.com/ethersphere/bee/pkg/file/pipeline/mock" + mockenc "github.com/ethersphere/bee/v2/pkg/encryption/mock" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/encryption" + mock "github.com/ethersphere/bee/v2/pkg/file/pipeline/mock" ) var ( diff --git a/pkg/file/pipeline/feeder/feeder.go b/pkg/file/pipeline/feeder/feeder.go index 03d77cfb49c..8e5e29617a8 100644 --- a/pkg/file/pipeline/feeder/feeder.go +++ b/pkg/file/pipeline/feeder/feeder.go @@ -7,8 +7,8 @@ package feeder import ( "encoding/binary" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const span = swarm.SpanSize diff --git a/pkg/file/pipeline/feeder/feeder_test.go b/pkg/file/pipeline/feeder/feeder_test.go index 470dbd7f032..51c56dd6a3b 100644 --- a/pkg/file/pipeline/feeder/feeder_test.go +++ b/pkg/file/pipeline/feeder/feeder_test.go @@ -10,8 +10,8 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/feeder" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/feeder" ) // TestFeeder tests that partial writes work correctly. diff --git a/pkg/file/pipeline/hashtrie/hashtrie.go b/pkg/file/pipeline/hashtrie/hashtrie.go index b3c898c76e1..b9fa52b90b8 100644 --- a/pkg/file/pipeline/hashtrie/hashtrie.go +++ b/pkg/file/pipeline/hashtrie/hashtrie.go @@ -10,11 +10,11 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/replicas" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/replicas" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/pipeline/hashtrie/hashtrie_test.go b/pkg/file/pipeline/hashtrie/hashtrie_test.go index 4a966e265f3..7fb7cd4a542 100644 --- a/pkg/file/pipeline/hashtrie/hashtrie_test.go +++ b/pkg/file/pipeline/hashtrie/hashtrie_test.go @@ -12,21 +12,21 @@ import ( "sync/atomic" "testing" - 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" - "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/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" + bmtUtils "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/encryption" + dec "github.com/ethersphere/bee/v2/pkg/encryption/store" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/bmt" + enc "github.com/ethersphere/bee/v2/pkg/file/pipeline/encryption" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/hashtrie" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/mock" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/store" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/pipeline/mock/writer.go b/pkg/file/pipeline/mock/writer.go index af76e6339d1..19f505123b2 100644 --- a/pkg/file/pipeline/mock/writer.go +++ b/pkg/file/pipeline/mock/writer.go @@ -7,7 +7,7 @@ package mock import ( "sync" - "github.com/ethersphere/bee/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" ) type MockChainWriter struct { diff --git a/pkg/file/pipeline/store/store.go b/pkg/file/pipeline/store/store.go index ec3621900c8..c1d7f4f4949 100644 --- a/pkg/file/pipeline/store/store.go +++ b/pkg/file/pipeline/store/store.go @@ -8,9 +8,9 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/file/pipeline" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var errInvalidData = errors.New("store: invalid data") diff --git a/pkg/file/pipeline/store/store_test.go b/pkg/file/pipeline/store/store_test.go index a3a39bace05..d7db1c885e4 100644 --- a/pkg/file/pipeline/store/store_test.go +++ b/pkg/file/pipeline/store/store_test.go @@ -10,11 +10,11 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/file/pipeline" - mock "github.com/ethersphere/bee/pkg/file/pipeline/mock" - "github.com/ethersphere/bee/pkg/file/pipeline/store" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + mock "github.com/ethersphere/bee/v2/pkg/file/pipeline/mock" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/store" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestStoreWriter tests that store writer stores the provided data and calls the next chain writer. diff --git a/pkg/file/redundancy/getter/getter.go b/pkg/file/redundancy/getter/getter.go index 4e8da1b6390..85bbec34435 100644 --- a/pkg/file/redundancy/getter/getter.go +++ b/pkg/file/redundancy/getter/getter.go @@ -6,80 +6,81 @@ package getter import ( "context" - "io" + "errors" "sync" "sync/atomic" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/klauspost/reedsolomon" ) +var ( + errStrategyNotAllowed = errors.New("strategy not allowed") + errStrategyFailed = errors.New("strategy failed") +) + // decoder is a private implementation of storage.Getter // if retrieves children of an intermediate chunk potentially using erasure decoding // it caches sibling chunks if erasure decoding started already type decoder struct { - fetcher storage.Getter // network retrieval interface to fetch chunks - putter storage.Putter // interface to local storage to save reconstructed chunks - addrs []swarm.Address // all addresses of the intermediate chunk - inflight []atomic.Bool // locks to protect wait channels and RS buffer - cache map[string]int // map from chunk address shard position index - waits []chan struct{} // wait channels for each chunk - rsbuf [][]byte // RS buffer of data + parity shards for erasure decoding - ready chan struct{} // signal channel for successful retrieval of shardCnt chunks - lastLen int // length of the last data chunk in the RS buffer - shardCnt int // number of data shards - parityCnt int // number of parity shards - wg sync.WaitGroup // wait group to wait for all goroutines to finish - mu sync.Mutex // mutex to protect buffer - err error // error of the last erasure decoding - fetchedCnt atomic.Int32 // count successful retrievals - cancel func() // cancel function for RS decoding - remove func() // callback to remove decoder from decoders cache - config Config // configuration -} - -type Getter interface { - storage.Getter - io.Closer + fetcher storage.Getter // network retrieval interface to fetch chunks + putter storage.Putter // interface to local storage to save reconstructed chunks + addrs []swarm.Address // all addresses of the intermediate chunk + inflight []atomic.Bool // locks to protect wait channels and RS buffer + cache map[string]int // map from chunk address shard position index + waits []chan error // wait channels for each chunk + rsbuf [][]byte // RS buffer of data + parity shards for erasure decoding + goodRecovery chan struct{} // signal channel for successful retrieval of shardCnt chunks + badRecovery chan struct{} // signals that either the recovery has failed or not allowed to run + initRecovery chan struct{} // signals that the recovery has been initialized + lastLen int // length of the last data chunk in the RS buffer + shardCnt int // number of data shards + parityCnt int // number of parity shards + mu sync.Mutex // mutex to protect buffer + fetchedCnt atomic.Int32 // count successful retrievals + failedCnt atomic.Int32 // count successful retrievals + remove func(error) // callback to remove decoder from decoders cache + config Config // configuration + logger log.Logger } // New returns a decoder object used to retrieve children of an intermediate chunk -func New(addrs []swarm.Address, shardCnt int, g storage.Getter, p storage.Putter, remove func(), conf Config) Getter { - ctx, cancel := context.WithCancel(context.Background()) +func New(addrs []swarm.Address, shardCnt int, g storage.Getter, p storage.Putter, remove func(error), conf Config) storage.Getter { size := len(addrs) - rsg := &decoder{ - fetcher: g, - putter: p, - addrs: addrs, - inflight: make([]atomic.Bool, size), - cache: make(map[string]int, size), - waits: make([]chan struct{}, shardCnt), - rsbuf: make([][]byte, size), - ready: make(chan struct{}, 1), - cancel: cancel, - remove: remove, - shardCnt: shardCnt, - parityCnt: size - shardCnt, - config: conf, + d := &decoder{ + fetcher: g, + putter: p, + addrs: addrs, + inflight: make([]atomic.Bool, size), + cache: make(map[string]int, size), + waits: make([]chan error, size), + rsbuf: make([][]byte, size), + goodRecovery: make(chan struct{}), + badRecovery: make(chan struct{}), + initRecovery: make(chan struct{}), + remove: remove, + shardCnt: shardCnt, + parityCnt: size - shardCnt, + config: conf, + logger: conf.Logger.WithName("redundancy").Build(), } // after init, cache and wait channels are immutable, need no locking for i := 0; i < shardCnt; i++ { - rsg.cache[addrs[i].ByteString()] = i - rsg.waits[i] = make(chan struct{}) + d.cache[addrs[i].ByteString()] = i } - // prefetch chunks according to strategy - if !conf.Strict || conf.Strategy != NONE { - rsg.wg.Add(1) - go func() { - rsg.err = rsg.prefetch(ctx) - rsg.wg.Done() - }() + // after init, cache and wait channels are immutable, need no locking + for i := 0; i < size; i++ { + d.waits[i] = make(chan error) } - return rsg + + go d.prefetch() + + return d } // Get will call parities and other sibling chunks if the chunk address cannot be retrieved @@ -89,110 +90,206 @@ func (g *decoder) Get(ctx context.Context, addr swarm.Address) (swarm.Chunk, err if !ok { return nil, storage.ErrNotFound } - if g.fly(i, true) { - g.wg.Add(1) - go func() { - g.fetch(ctx, i) - g.wg.Done() - }() + err := g.fetch(ctx, i, true) + if err != nil { + return nil, err + } + return swarm.NewChunk(addr, g.getData(i)), nil +} + +// fetch retrieves a chunk from the netstore if it is the first time the chunk is fetched. +// If the fetch fails and waiting for the recovery is allowed, the function will wait +// for either a good or bad recovery signal. +func (g *decoder) fetch(ctx context.Context, i int, waitForRecovery bool) (err error) { + + waitRecovery := func(err error) error { + if !waitForRecovery { + return err + } + + select { + case <-g.badRecovery: + return storage.ErrNotFound + case <-g.goodRecovery: + g.logger.Debug("recovered chunk", "address", g.addrs[i]) + return nil + case <-ctx.Done(): + return ctx.Err() + } + } + + // recovery has started, wait for result instead of fetching from the network + select { + case <-g.initRecovery: + return waitRecovery(nil) + default: + } + + // first time + if g.fly(i) { + + fctx, cancel := context.WithTimeout(ctx, g.config.FetchTimeout) + defer cancel() + + // when the recovery is triggered, we can terminate any inflight requests. + // we do the extra bool check to not fire an unnecessary goroutine + if waitForRecovery { + go func() { + defer cancel() + select { + case <-g.initRecovery: + case <-fctx.Done(): + } + }() + } + + // retrieval + ch, err := g.fetcher.Get(fctx, g.addrs[i]) + if err != nil { + g.failedCnt.Add(1) + close(g.waits[i]) + return waitRecovery(err) + } + + g.fetchedCnt.Add(1) + g.setData(i, ch.Data()) + close(g.waits[i]) + return nil } + select { case <-g.waits[i]: case <-ctx.Done(): - return nil, ctx.Err() + return ctx.Err() } - return swarm.NewChunk(addr, g.getData(i)), nil -} -// setData sets the data shard in the RS buffer -func (g *decoder) setData(i int, chdata []byte) { - data := chdata - // pad the chunk with zeros if it is smaller than swarm.ChunkSize - if len(data) < swarm.ChunkWithSpanSize { - g.lastLen = len(data) - data = make([]byte, swarm.ChunkWithSpanSize) - copy(data, chdata) + if g.getData(i) != nil { + return nil } - g.rsbuf[i] = data -} -// getData returns the data shard from the RS buffer -func (g *decoder) getData(i int) []byte { - if i == g.shardCnt-1 && g.lastLen > 0 { - return g.rsbuf[i][:g.lastLen] // cut padding - } - return g.rsbuf[i] + return waitRecovery(storage.ErrNotFound) } -// fly commits to retrieve the chunk (fly and land) -// it marks a chunk as inflight and returns true unless it is already inflight -// the atomic bool implements a singleflight pattern -func (g *decoder) fly(i int, up bool) (success bool) { - return g.inflight[i].CompareAndSwap(!up, up) -} +func (g *decoder) prefetch() { + + var err error + defer func() { + if err != nil { + close(g.badRecovery) + } else { + close(g.goodRecovery) + } + g.remove(err) + }() + + s := g.config.Strategy + for ; s < strategyCnt; s++ { + + err = g.runStrategy(s) + if err != nil && s == DATA || s == RACE { + g.logger.Debug("failed strategy", "strategy", s) + } + + if err == nil || g.config.Strict { + break + } + } -// fetch retrieves a chunk from the underlying storage -// it must be called asynchonously and only once for each chunk (singleflight pattern) -// it races with erasure recovery which takes precedence even if it started later -// due to the fact that erasure recovery could only implement global locking on all shards -func (g *decoder) fetch(ctx context.Context, i int) { - fctx, cancel := context.WithTimeout(ctx, g.config.FetchTimeout) - defer cancel() - ch, err := g.fetcher.Get(fctx, g.addrs[i]) if err != nil { - _ = g.fly(i, false) // unset inflight return } - g.mu.Lock() - defer g.mu.Unlock() - if i < len(g.waits) { - select { - case <-g.waits[i]: // if chunk is retrieved, ignore - return - default: + close(g.initRecovery) + + err = g.recover() + if err == nil && s > DATA { + g.logger.Debug("successful recovery", "strategy", s) + } + +} + +func (g *decoder) runStrategy(s Strategy) error { + + // across the different strategies, the common goal is to fetch at least as many chunks + // as the number of data shards. + // DATA strategy has a max error tolerance of zero. + // RACE strategy has a max error tolerance of number of parity chunks. + var allowedErrs int + var m []int + + switch s { + case NONE: + return errStrategyNotAllowed + case DATA: + // only retrieve data shards + m = g.unattemptedDataShards() + allowedErrs = 0 + case PROX: + // proximity driven selective fetching + // NOT IMPLEMENTED + return errStrategyNotAllowed + case RACE: + allowedErrs = g.parityCnt + // retrieve all chunks at once enabling race among chunks + m = g.unattemptedDataShards() + for i := g.shardCnt; i < len(g.addrs); i++ { + m = append(m, i) } } - select { - case <-ctx.Done(): // if context is cancelled, ignore - _ = g.fly(i, false) // unset inflight - return - default: + if len(m) == 0 { + return nil } - // write chunk to rsbuf and signal waiters - g.setData(i, ch.Data()) // save the chunk in the RS buffer - if i < len(g.waits) { // if the chunk is a data shard - close(g.waits[i]) // signal that the chunk is retrieved + c := make(chan error, len(m)) + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + for _, i := range m { + go func(i int) { + c <- g.fetch(ctx, i, false) + }(i) } - // if all chunks are retrieved, signal ready - n := g.fetchedCnt.Add(1) - if n == int32(g.shardCnt) { - close(g.ready) // signal that just enough chunks are retrieved for decoding + for range c { + if g.fetchedCnt.Load() >= int32(g.shardCnt) { + return nil + } + if g.failedCnt.Load() > int32(allowedErrs) { + return errStrategyFailed + } } + + return nil } -// missing gathers missing data shards not yet retrieved -// it sets the chunk as inflight and returns the index of the missing data shards -func (g *decoder) missing() (m []int) { - for i := 0; i < g.shardCnt; i++ { - select { - case <-g.waits[i]: // if chunk is retrieved, ignore - continue - default: - } - _ = g.fly(i, true) // commit (RS) or will commit to retrieve the chunk - m = append(m, i) // remember the missing chunk +// recover wraps the stages of data shard recovery: +// 1. gather missing data shards +// 2. decode using Reed-Solomon decoder +// 3. save reconstructed chunks +func (g *decoder) recover() error { + // gather missing shards + m := g.missingDataShards() + if len(m) == 0 { + return nil // recovery is not needed as there are no missing data chunks } - return m + + // decode using Reed-Solomon decoder + if err := g.decode(); err != nil { + return err + } + + // save chunks + return g.save(m) } // decode uses Reed-Solomon erasure coding decoder to recover data shards // it must be called after shqrdcnt shards are retrieved -// it must be called under g.mu mutex protection -func (g *decoder) decode(ctx context.Context) error { +func (g *decoder) decode() error { + g.mu.Lock() + defer g.mu.Unlock() + enc, err := reedsolomon.New(g.shardCnt, g.parityCnt) if err != nil { return err @@ -202,51 +299,68 @@ func (g *decoder) decode(ctx context.Context) error { return enc.ReconstructData(g.rsbuf) } -// recover wraps the stages of data shard recovery: -// 1. gather missing data shards -// 2. decode using Reed-Solomon decoder -// 3. save reconstructed chunks -func (g *decoder) recover(ctx context.Context) error { - // buffer lock acquired - g.mu.Lock() - defer g.mu.Unlock() +func (g *decoder) unattemptedDataShards() (m []int) { + for i := 0; i < g.shardCnt; i++ { + select { + case <-g.waits[i]: // attempted + continue + default: + m = append(m, i) // remember the missing chunk + } + } + return m +} - // gather missing shards - m := g.missing() - if len(m) == 0 { - return nil +// it must be called under mutex protection +func (g *decoder) missingDataShards() (m []int) { + for i := 0; i < g.shardCnt; i++ { + if g.getData(i) == nil { + m = append(m, i) + } } + return m +} - // decode using Reed-Solomon decoder - if err := g.decode(ctx); err != nil { - return err +// setData sets the data shard in the RS buffer +func (g *decoder) setData(i int, chdata []byte) { + g.mu.Lock() + defer g.mu.Unlock() + + data := chdata + // pad the chunk with zeros if it is smaller than swarm.ChunkSize + if len(data) < swarm.ChunkWithSpanSize { + g.lastLen = len(data) + data = make([]byte, swarm.ChunkWithSpanSize) + copy(data, chdata) } + g.rsbuf[i] = data +} - // close wait channels for missing chunks - for _, i := range m { - close(g.waits[i]) +// getData returns the data shard from the RS buffer +func (g *decoder) getData(i int) []byte { + g.mu.Lock() + defer g.mu.Unlock() + if i == g.shardCnt-1 && g.lastLen > 0 { + return g.rsbuf[i][:g.lastLen] // cut padding } + return g.rsbuf[i] +} - // save chunks - return g.save(ctx, m) +// fly commits to retrieve the chunk (fly and land) +// it marks a chunk as inflight and returns true unless it is already inflight +// the atomic bool implements a singleflight pattern +func (g *decoder) fly(i int) (success bool) { + return g.inflight[i].CompareAndSwap(false, true) } // save iterate over reconstructed shards and puts the corresponding chunks to local storage -func (g *decoder) save(ctx context.Context, missing []int) error { +func (g *decoder) save(missing []int) error { + g.mu.Lock() + defer g.mu.Unlock() for _, i := range missing { - if err := g.putter.Put(ctx, swarm.NewChunk(g.addrs[i], g.rsbuf[i])); err != nil { + if err := g.putter.Put(context.Background(), swarm.NewChunk(g.addrs[i], g.rsbuf[i])); err != nil { return err } } return nil } - -// Close terminates the prefetch loop, waits for all goroutines to finish and -// removes the decoder from the cache -// it implements the io.Closer interface -func (g *decoder) Close() error { - g.cancel() - g.wg.Wait() - g.remove() - return nil -} diff --git a/pkg/file/redundancy/getter/getter_test.go b/pkg/file/redundancy/getter/getter_test.go index b18caa55c12..c229126d904 100644 --- a/pkg/file/redundancy/getter/getter_test.go +++ b/pkg/file/redundancy/getter/getter_test.go @@ -17,13 +17,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/file/redundancy/getter" - "github.com/ethersphere/bee/pkg/storage" - inmem "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil/racedetection" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/file/redundancy/getter" + "github.com/ethersphere/bee/v2/pkg/storage" + inmem "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/klauspost/reedsolomon" "golang.org/x/sync/errgroup" ) @@ -72,6 +71,7 @@ func TestGetterRACE(t *testing.T) { // TestGetterFallback tests the retrieval of chunks with missing data shards // using the strict or fallback mode starting with NONE and DATA strategies func TestGetterFallback(t *testing.T) { + t.Skip("removed strategy timeout") t.Run("GET", func(t *testing.T) { t.Run("NONE", func(t *testing.T) { t.Run("strict", func(t *testing.T) { @@ -94,10 +94,6 @@ func TestGetterFallback(t *testing.T) { func testDecodingRACE(t *testing.T, bufSize, shardCnt, erasureCnt int) { t.Helper() - strategyTimeout := 100 * time.Millisecond - if racedetection.On { - strategyTimeout *= 2 - } store := inmem.New() buf := make([][]byte, bufSize) addrs := initData(t, buf, shardCnt, store) @@ -113,30 +109,12 @@ func testDecodingRACE(t *testing.T, bufSize, shardCnt, erasureCnt int) { if len(addr.Bytes()) == 0 { t.Skip("no data shard erased") } - ctx, cancel := context.WithCancel(context.TODO()) - defer cancel() - conf := getter.Config{ - Strategy: getter.RACE, - FetchTimeout: 2 * strategyTimeout, - StrategyTimeout: strategyTimeout, - } - g := getter.New(addrs, shardCnt, store, store, func() {}, conf) - defer g.Close() + + g := getter.New(addrs, shardCnt, store, store, func(error) {}, getter.DefaultConfig) + parityCnt := len(buf) - shardCnt - q := make(chan error, 1) - go func() { - _, err := g.Get(ctx, addr) - q <- err - }() - err := context.DeadlineExceeded - wait := strategyTimeout * 2 - if racedetection.On { - wait *= 2 - } - select { - case err = <-q: - case <-time.After(wait): - } + _, err := g.Get(context.Background(), addr) + switch { case erasureCnt > parityCnt: t.Run("unable to recover", func(t *testing.T) { @@ -191,13 +169,11 @@ func testDecodingFallback(t *testing.T, s getter.Strategy, strict bool) { // create getter start := time.Now() conf := getter.Config{ - Strategy: s, - Strict: strict, - FetchTimeout: strategyTimeout / 2, - StrategyTimeout: strategyTimeout, + Strategy: s, + Strict: strict, + FetchTimeout: strategyTimeout / 2, } - g := getter.New(addrs, shardCnt, store, store, func() {}, conf) - defer g.Close() + g := getter.New(addrs, shardCnt, store, store, func(error) {}, conf) // launch delayed and erased chunk retrieval wg := sync.WaitGroup{} diff --git a/pkg/file/redundancy/getter/strategies.go b/pkg/file/redundancy/getter/strategies.go index bb5188e9cc2..e632f95f8c2 100644 --- a/pkg/file/redundancy/getter/strategies.go +++ b/pkg/file/redundancy/getter/strategies.go @@ -6,32 +6,33 @@ package getter import ( "context" - "errors" "fmt" "time" + + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/retrieval" ) const ( - DefaultStrategy = NONE // default prefetching strategy - DefaultStrict = true // default fallback modes - DefaultFetchTimeout = 30 * time.Second // timeout for each chunk retrieval - DefaultStrategyTimeout = 300 * time.Millisecond // timeout for each strategy + DefaultStrategy = DATA // default prefetching strategy + DefaultStrict = false // default fallback modes + DefaultFetchTimeout = retrieval.RetrieveChunkTimeout // timeout for each chunk retrieval ) type ( - strategyKey struct{} - modeKey struct{} - fetchTimeoutKey struct{} - strategyTimeoutKey struct{} - Strategy = int + strategyKey struct{} + modeKey struct{} + fetchTimeoutKey struct{} + loggerKey struct{} + Strategy = int ) // Config is the configuration for the getter - public type Config struct { - Strategy Strategy - Strict bool - FetchTimeout time.Duration - StrategyTimeout time.Duration + Strategy Strategy + Strict bool + FetchTimeout time.Duration + Logger log.Logger } const ( @@ -44,20 +45,17 @@ const ( // DefaultConfig is the default configuration for the getter var DefaultConfig = Config{ - Strategy: DefaultStrategy, - Strict: DefaultStrict, - FetchTimeout: DefaultFetchTimeout, - StrategyTimeout: DefaultStrategyTimeout, + Strategy: DefaultStrategy, + Strict: DefaultStrict, + FetchTimeout: DefaultFetchTimeout, + Logger: log.Noop, } // NewConfigFromContext returns a new Config based on the context func NewConfigFromContext(ctx context.Context, def Config) (conf Config, err error) { var ok bool conf = def - e := func(s string, errs ...error) error { - if len(errs) > 0 { - return fmt.Errorf("error setting %s from context: %w", s, errors.Join(errs...)) - } + e := func(s string) error { return fmt.Errorf("error setting %s from context", s) } if val := ctx.Value(strategyKey{}); val != nil { @@ -73,25 +71,18 @@ func NewConfigFromContext(ctx context.Context, def Config) (conf Config, err err } } if val := ctx.Value(fetchTimeoutKey{}); val != nil { - fetchTimeoutVal, ok := val.(string) + conf.FetchTimeout, ok = val.(time.Duration) if !ok { return conf, e("fetcher timeout") } - conf.FetchTimeout, err = time.ParseDuration(fetchTimeoutVal) - if err != nil { - return conf, e("fetcher timeout", err) - } } - if val := ctx.Value(strategyTimeoutKey{}); val != nil { - strategyTimeoutVal, ok := val.(string) + if val := ctx.Value(loggerKey{}); val != nil { + conf.Logger, ok = val.(log.Logger) if !ok { - return conf, e("fetcher timeout") - } - conf.StrategyTimeout, err = time.ParseDuration(strategyTimeoutVal) - if err != nil { - return conf, e("fetcher timeout", err) + return conf, e("strategy timeout") } } + return conf, nil } @@ -106,100 +97,35 @@ func SetStrict(ctx context.Context, strict bool) context.Context { } // SetFetchTimeout sets the timeout for each fetch -func SetFetchTimeout(ctx context.Context, timeout string) context.Context { +func SetFetchTimeout(ctx context.Context, timeout time.Duration) context.Context { return context.WithValue(ctx, fetchTimeoutKey{}, timeout) } -// SetStrategyTimeout sets the timeout for each strategy -func SetStrategyTimeout(ctx context.Context, timeout string) context.Context { - return context.WithValue(ctx, fetchTimeoutKey{}, timeout) +func SetLogger(ctx context.Context, l log.Logger) context.Context { + return context.WithValue(ctx, loggerKey{}, l) } // SetConfigInContext sets the config params in the context -func SetConfigInContext(ctx context.Context, s Strategy, fallbackmode bool, fetchTimeout, strategyTimeout string) context.Context { - ctx = SetStrategy(ctx, s) - ctx = SetStrict(ctx, !fallbackmode) - ctx = SetFetchTimeout(ctx, fetchTimeout) - ctx = SetStrategyTimeout(ctx, strategyTimeout) - return ctx -} - -func (g *decoder) prefetch(ctx context.Context) error { - if g.config.Strict && g.config.Strategy == NONE { - return nil +func SetConfigInContext(ctx context.Context, s *Strategy, fallbackmode *bool, fetchTimeout *string, logger log.Logger) (context.Context, error) { + if s != nil { + ctx = SetStrategy(ctx, *s) } - defer g.remove() - var cancels []func() - cancelAll := func() { - for _, cancel := range cancels { - cancel() - } - } - defer cancelAll() - run := func(s Strategy) error { - if s == PROX { // NOT IMPLEMENTED - return errors.New("strategy not implemented") - } - var stop <-chan time.Time - if s < RACE { - timer := time.NewTimer(g.config.StrategyTimeout) - defer timer.Stop() - stop = timer.C - } - lctx, cancel := context.WithCancel(ctx) - cancels = append(cancels, cancel) - prefetch(lctx, g, s) - - select { - // successfully retrieved shardCnt number of chunks - case <-g.ready: - cancelAll() - case <-stop: - return fmt.Errorf("prefetching with strategy %d timed out", s) - case <-ctx.Done(): - return nil - } - // call the erasure decoder - // if decoding is successful terminate the prefetch loop - return g.recover(ctx) // context to cancel when shardCnt chunks are retrieved - } - var err error - for s := g.config.Strategy; s < strategyCnt; s++ { - err = run(s) - if g.config.Strict || err == nil { - break - } + if fallbackmode != nil { + ctx = SetStrict(ctx, !(*fallbackmode)) } - return err -} - -// prefetch launches the retrieval of chunks based on the strategy -func prefetch(ctx context.Context, g *decoder, s Strategy) { - var m []int - switch s { - case NONE: - return - case DATA: - // only retrieve data shards - m = g.missing() - case PROX: - // proximity driven selective fetching - // NOT IMPLEMENTED - case RACE: - // retrieve all chunks at once enabling race among chunks - m = g.missing() - for i := g.shardCnt; i < len(g.addrs); i++ { - m = append(m, i) + if fetchTimeout != nil { + dur, err := time.ParseDuration(*fetchTimeout) + if err != nil { + return nil, err } + ctx = SetFetchTimeout(ctx, dur) } - for _, i := range m { - i := i - g.wg.Add(1) - go func() { - g.fetch(ctx, i) - g.wg.Done() - }() + + if logger != nil { + ctx = SetLogger(ctx, logger) } + + return ctx, nil } diff --git a/pkg/file/redundancy/level.go b/pkg/file/redundancy/level.go index f7b4f5c19f1..45b091da98b 100644 --- a/pkg/file/redundancy/level.go +++ b/pkg/file/redundancy/level.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Level is the redundancy level diff --git a/pkg/file/redundancy/redundancy.go b/pkg/file/redundancy/redundancy.go index 443dc0637b3..20ee7552d39 100644 --- a/pkg/file/redundancy/redundancy.go +++ b/pkg/file/redundancy/redundancy.go @@ -7,8 +7,8 @@ package redundancy import ( "fmt" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/klauspost/reedsolomon" ) diff --git a/pkg/file/redundancy/redundancy_test.go b/pkg/file/redundancy/redundancy_test.go index bb7aa35ba75..e6ad81a16a7 100644 --- a/pkg/file/redundancy/redundancy_test.go +++ b/pkg/file/redundancy/redundancy_test.go @@ -11,10 +11,10 @@ import ( "sync" "testing" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/bmt" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/bmt" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type mockEncoder struct { diff --git a/pkg/file/redundancy/span.go b/pkg/file/redundancy/span.go index eb71286fa43..9817729d3ae 100644 --- a/pkg/file/redundancy/span.go +++ b/pkg/file/redundancy/span.go @@ -5,7 +5,7 @@ package redundancy import ( - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // EncodeLevel encodes used redundancy level for uploading into span keeping the real byte count for the chunk. diff --git a/pkg/file/span.go b/pkg/file/span.go index 33c1ad66dc4..b8366233bd2 100644 --- a/pkg/file/span.go +++ b/pkg/file/span.go @@ -7,7 +7,7 @@ package file import ( "math" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var Spans []int64 diff --git a/pkg/file/splitter/internal/job.go b/pkg/file/splitter/internal/job.go index 90599defbf7..db34e5764c1 100644 --- a/pkg/file/splitter/internal/job.go +++ b/pkg/file/splitter/internal/job.go @@ -10,12 +10,11 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/file" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "golang.org/x/crypto/sha3" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/file" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // maximum amount of file tree levels this file hasher component can handle @@ -256,21 +255,13 @@ func (s *SimpleSplitterJob) encryptChunkData(chunkData []byte) ([]byte, encrypti func (s *SimpleSplitterJob) encrypt(chunkData []byte) (encryption.Key, []byte, []byte, error) { key := encryption.GenerateRandomKey(encryption.KeyLength) - encryptedSpan, err := s.newSpanEncryption(key).Encrypt(chunkData[:8]) + encryptedSpan, err := encryption.NewSpanEncryption(key).Encrypt(chunkData[:8]) if err != nil { return nil, nil, nil, err } - encryptedData, err := s.newDataEncryption(key).Encrypt(chunkData[8:]) + encryptedData, err := encryption.NewDataEncryption(key).Encrypt(chunkData[8:]) if err != nil { return nil, nil, nil, err } return key, encryptedSpan, encryptedData, nil } - -func (s *SimpleSplitterJob) newSpanEncryption(key encryption.Key) encryption.Interface { - return encryption.New(key, 0, uint32(swarm.ChunkSize/s.refSize), sha3.NewLegacyKeccak256) -} - -func (s *SimpleSplitterJob) newDataEncryption(key encryption.Key) encryption.Interface { - return encryption.New(key, int(swarm.ChunkSize), 0, sha3.NewLegacyKeccak256) -} diff --git a/pkg/file/splitter/internal/job_test.go b/pkg/file/splitter/internal/job_test.go index 757fb2fc028..bc7945c4b42 100644 --- a/pkg/file/splitter/internal/job_test.go +++ b/pkg/file/splitter/internal/job_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/file/splitter/internal" - test "github.com/ethersphere/bee/pkg/file/testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/splitter/internal" + test "github.com/ethersphere/bee/v2/pkg/file/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/file/splitter/splitter.go b/pkg/file/splitter/splitter.go index 8e74713b130..62015e5e666 100644 --- a/pkg/file/splitter/splitter.go +++ b/pkg/file/splitter/splitter.go @@ -11,10 +11,10 @@ import ( "fmt" "io" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/splitter/internal" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/splitter/internal" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // simpleSplitter wraps a non-optimized implementation of file.Splitter diff --git a/pkg/file/splitter/splitter_test.go b/pkg/file/splitter/splitter_test.go index 45bf804f542..c37d6d1f496 100644 --- a/pkg/file/splitter/splitter_test.go +++ b/pkg/file/splitter/splitter_test.go @@ -11,11 +11,11 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/splitter" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/splitter" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" mockbytes "gitlab.com/nolash/go-mockbytes" ) diff --git a/pkg/file/testing/chunk.go b/pkg/file/testing/chunk.go index f178dd99063..2f19164b0db 100644 --- a/pkg/file/testing/chunk.go +++ b/pkg/file/testing/chunk.go @@ -8,7 +8,7 @@ import ( "crypto/rand" "encoding/binary" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // GenerateTestRandomFileChunk generates one single chunk with arbitrary content and address diff --git a/pkg/file/testing/vector.go b/pkg/file/testing/vector.go index 076e064fafc..028f7eff2ce 100644 --- a/pkg/file/testing/vector.go +++ b/pkg/file/testing/vector.go @@ -7,7 +7,7 @@ package testing import ( "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" mockbytes "gitlab.com/nolash/go-mockbytes" ) diff --git a/pkg/file/utils.go b/pkg/file/utils.go index 35f21414b82..ce1f94d372a 100644 --- a/pkg/file/utils.go +++ b/pkg/file/utils.go @@ -8,8 +8,8 @@ import ( "bytes" "errors" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/hive/hive.go b/pkg/hive/hive.go index 7d129446754..a84c841f89e 100644 --- a/pkg/hive/hive.go +++ b/pkg/hive/hive.go @@ -20,14 +20,14 @@ import ( "golang.org/x/sync/semaphore" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/hive/pb" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/ratelimit" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/hive/pb" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/ratelimit" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr/net" ) diff --git a/pkg/hive/hive_test.go b/pkg/hive/hive_test.go index b3b0d55305d..324bac45895 100644 --- a/pkg/hive/hive_test.go +++ b/pkg/hive/hive_test.go @@ -16,18 +16,18 @@ import ( "github.com/ethereum/go-ethereum/common" ma "github.com/multiformats/go-multiaddr" - ab "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/hive" - "github.com/ethersphere/bee/pkg/hive/pb" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + ab "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/hive" + "github.com/ethersphere/bee/v2/pkg/hive/pb" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) var ( diff --git a/pkg/hive/metrics.go b/pkg/hive/metrics.go index c9a256f87b0..a09bcc09ffd 100644 --- a/pkg/hive/metrics.go +++ b/pkg/hive/metrics.go @@ -5,7 +5,7 @@ package hive import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/jsonhttp/handlers_test.go b/pkg/jsonhttp/handlers_test.go index 424d6ebfb29..7ede319580c 100644 --- a/pkg/jsonhttp/handlers_test.go +++ b/pkg/jsonhttp/handlers_test.go @@ -13,7 +13,7 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) func TestMethodHandler(t *testing.T) { diff --git a/pkg/jsonhttp/jsonhttp_test.go b/pkg/jsonhttp/jsonhttp_test.go index 6b107ffe8ee..cd6a378d5c5 100644 --- a/pkg/jsonhttp/jsonhttp_test.go +++ b/pkg/jsonhttp/jsonhttp_test.go @@ -13,7 +13,7 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) func TestRespond_defaults(t *testing.T) { diff --git a/pkg/jsonhttp/jsonhttptest/jsonhttptest.go b/pkg/jsonhttp/jsonhttptest/jsonhttptest.go index 7f5cabf35d2..1c436ec9373 100644 --- a/pkg/jsonhttp/jsonhttptest/jsonhttptest.go +++ b/pkg/jsonhttp/jsonhttptest/jsonhttptest.go @@ -18,7 +18,7 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" ) // Request is a testing helper function that makes an HTTP request using diff --git a/pkg/jsonhttp/jsonhttptest/jsonhttptest_test.go b/pkg/jsonhttp/jsonhttptest/jsonhttptest_test.go index 9f3a77a3f39..63b48556f37 100644 --- a/pkg/jsonhttp/jsonhttptest/jsonhttptest_test.go +++ b/pkg/jsonhttp/jsonhttptest/jsonhttptest_test.go @@ -19,8 +19,8 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/jsonhttp" - "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" + "github.com/ethersphere/bee/v2/pkg/jsonhttp" + "github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest" ) func TestRequest_statusCode(t *testing.T) { diff --git a/pkg/keystore/file/key.go b/pkg/keystore/file/key.go index fbec230f942..68e6a2e2edf 100644 --- a/pkg/keystore/file/key.go +++ b/pkg/keystore/file/key.go @@ -17,8 +17,8 @@ import ( "io" "github.com/btcsuite/btcd/btcec/v2" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/keystore" "github.com/google/uuid" "golang.org/x/crypto/scrypt" "golang.org/x/crypto/sha3" diff --git a/pkg/keystore/file/service.go b/pkg/keystore/file/service.go index 199de659406..01a5db72aeb 100644 --- a/pkg/keystore/file/service.go +++ b/pkg/keystore/file/service.go @@ -10,7 +10,7 @@ import ( "os" "path/filepath" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/keystore" ) // Service is the file-based keystore.Service implementation. diff --git a/pkg/keystore/file/service_test.go b/pkg/keystore/file/service_test.go index 70205afbaa9..4c115c7f79e 100644 --- a/pkg/keystore/file/service_test.go +++ b/pkg/keystore/file/service_test.go @@ -7,8 +7,8 @@ package file_test import ( "testing" - "github.com/ethersphere/bee/pkg/keystore/file" - "github.com/ethersphere/bee/pkg/keystore/test" + "github.com/ethersphere/bee/v2/pkg/keystore/file" + "github.com/ethersphere/bee/v2/pkg/keystore/test" ) func TestService(t *testing.T) { diff --git a/pkg/keystore/mem/service.go b/pkg/keystore/mem/service.go index 5d8d5ab0a7f..46868957d1e 100644 --- a/pkg/keystore/mem/service.go +++ b/pkg/keystore/mem/service.go @@ -9,7 +9,7 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/keystore" ) var _ keystore.Service = (*Service)(nil) diff --git a/pkg/keystore/mem/service_test.go b/pkg/keystore/mem/service_test.go index fcf5ec88381..ae3d4640cc0 100644 --- a/pkg/keystore/mem/service_test.go +++ b/pkg/keystore/mem/service_test.go @@ -7,8 +7,8 @@ package mem_test import ( "testing" - "github.com/ethersphere/bee/pkg/keystore/mem" - "github.com/ethersphere/bee/pkg/keystore/test" + "github.com/ethersphere/bee/v2/pkg/keystore/mem" + "github.com/ethersphere/bee/v2/pkg/keystore/test" ) func TestService(t *testing.T) { diff --git a/pkg/keystore/test/test.go b/pkg/keystore/test/test.go index c9cf9a4245d..5eb4a4c1b26 100644 --- a/pkg/keystore/test/test.go +++ b/pkg/keystore/test/test.go @@ -9,8 +9,8 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/keystore" ) // Service is a utility testing function that can be used to test diff --git a/pkg/log/example_test.go b/pkg/log/example_test.go index 8cbc3e8b920..bae4790b966 100644 --- a/pkg/log/example_test.go +++ b/pkg/log/example_test.go @@ -9,7 +9,7 @@ import ( "fmt" "os" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" ) func Example() { diff --git a/pkg/log/formatter_test.go b/pkg/log/formatter_test.go index 4ba6d920242..1db5697ce98 100644 --- a/pkg/log/formatter_test.go +++ b/pkg/log/formatter_test.go @@ -383,7 +383,7 @@ func TestPretty(t *testing.T) { exp: `{"Inner":"I am a log.Marshaler"}`, }, { val: (*marshalerTest)(nil), - exp: `""`, + exp: `""`, }, { val: marshalerPanicTest{"foobar"}, exp: `""`, @@ -395,7 +395,7 @@ func TestPretty(t *testing.T) { exp: `"I am a fmt.Stringer"`, }, { val: (*stringerTest)(nil), - exp: `""`, + exp: `""`, }, { val: stringerPanicTest{"foobar"}, exp: `""`, @@ -407,7 +407,7 @@ func TestPretty(t *testing.T) { exp: `"I am an error"`, }, { val: (*errorTest)(nil), - exp: `""`, + exp: `""`, }, { val: errorPanicTest{"foobar"}, exp: `""`, diff --git a/pkg/log/httpaccess/http_access.go b/pkg/log/httpaccess/http_access.go index 4b240534716..ab57f9d3b14 100644 --- a/pkg/log/httpaccess/http_access.go +++ b/pkg/log/httpaccess/http_access.go @@ -10,8 +10,8 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/tracing" ) // NewHTTPAccessSuppressLogHandler creates a diff --git a/pkg/log/logger.go b/pkg/log/logger.go index 98b554bc2a4..f40ffd59916 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -13,7 +13,7 @@ import ( "strings" "time" - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/hashicorp/go-multierror" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/log/logger_test.go b/pkg/log/logger_test.go index 6a92f92ef00..f7c23308808 100644 --- a/pkg/log/logger_test.go +++ b/pkg/log/logger_test.go @@ -381,7 +381,7 @@ func TestLoggerWithCaller(t *testing.T) { } }) t.Run("caller=CategoryAll, logCallerFunc=true", func(t *testing.T) { - const thisFunc = "github.com/ethersphere/bee/pkg/log.TestLoggerWithCaller.func3" + const thisFunc = "github.com/ethersphere/bee/v2/pkg/log.TestLoggerWithCaller.func3" logger, bb := newLogger(WithCaller(CategoryAll), WithCallerFunc()) diff --git a/pkg/log/metrics.go b/pkg/log/metrics.go index 85a12fa1bf6..2691868921a 100644 --- a/pkg/log/metrics.go +++ b/pkg/log/metrics.go @@ -5,7 +5,7 @@ package log import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/manifest/manifest.go b/pkg/manifest/manifest.go index 6ebee2eacdb..70d8c76db51 100644 --- a/pkg/manifest/manifest.go +++ b/pkg/manifest/manifest.go @@ -10,8 +10,8 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const DefaultManifestType = ManifestMantarayContentType diff --git a/pkg/manifest/mantaray.go b/pkg/manifest/mantaray.go index 908d7b4ad6d..f3b86e06b66 100644 --- a/pkg/manifest/mantaray.go +++ b/pkg/manifest/mantaray.go @@ -9,9 +9,9 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/manifest/mantaray" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/manifest/mantaray/node_test.go b/pkg/manifest/mantaray/node_test.go index a0647d085d0..aa2e2f5c355 100644 --- a/pkg/manifest/mantaray/node_test.go +++ b/pkg/manifest/mantaray/node_test.go @@ -11,7 +11,7 @@ import ( "strconv" "testing" - "github.com/ethersphere/bee/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" ) func TestNilPath(t *testing.T) { diff --git a/pkg/manifest/mantaray/persist_test.go b/pkg/manifest/mantaray/persist_test.go index e6feaee79aa..b6a6c47e699 100644 --- a/pkg/manifest/mantaray/persist_test.go +++ b/pkg/manifest/mantaray/persist_test.go @@ -11,7 +11,7 @@ import ( "sync" "testing" - "github.com/ethersphere/bee/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" ) func TestPersistIdempotence(t *testing.T) { diff --git a/pkg/manifest/mantaray/walker_test.go b/pkg/manifest/mantaray/walker_test.go index ad6553eef6c..67ab9c7d18c 100644 --- a/pkg/manifest/mantaray/walker_test.go +++ b/pkg/manifest/mantaray/walker_test.go @@ -10,7 +10,7 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" ) func TestWalkNode(t *testing.T) { diff --git a/pkg/manifest/simple.go b/pkg/manifest/simple.go index d6ae3828212..5bc9927bc1d 100644 --- a/pkg/manifest/simple.go +++ b/pkg/manifest/simple.go @@ -9,9 +9,9 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/manifest/simple" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/manifest/simple" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/manifest/simple/manifest_test.go b/pkg/manifest/simple/manifest_test.go index a8693b5ca8a..aa1345acd3d 100644 --- a/pkg/manifest/simple/manifest_test.go +++ b/pkg/manifest/simple/manifest_test.go @@ -9,8 +9,8 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/manifest/simple" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/manifest/simple" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestNilPath(t *testing.T) { diff --git a/pkg/manifest/simple/walker_test.go b/pkg/manifest/simple/walker_test.go index d6f2bac8170..c3877ce664e 100644 --- a/pkg/manifest/simple/walker_test.go +++ b/pkg/manifest/simple/walker_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/manifest/simple" + "github.com/ethersphere/bee/v2/pkg/manifest/simple" ) func TestWalkEntry(t *testing.T) { diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go index 42522cd40db..65029836e69 100644 --- a/pkg/metrics/metrics_test.go +++ b/pkg/metrics/metrics_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/node/bootstrap.go b/pkg/node/bootstrap.go index a1e48228da7..a0aa07bcd72 100644 --- a/pkg/node/bootstrap.go +++ b/pkg/node/bootstrap.go @@ -16,33 +16,33 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/feeds/factory" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/hive" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pricer" - "github.com/ethersphere/bee/pkg/pricing" - "github.com/ethersphere/bee/pkg/retrieval" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/kademlia" - "github.com/ethersphere/bee/pkg/topology/lightnode" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/feeds/factory" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/hive" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pricer" + "github.com/ethersphere/bee/v2/pkg/pricing" + "github.com/ethersphere/bee/v2/pkg/retrieval" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/transaction" "github.com/hashicorp/go-multierror" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/node/chain.go b/pkg/node/chain.go index c4cab943207..463c3d5c649 100644 --- a/pkg/node/chain.go +++ b/pkg/node/chain.go @@ -18,21 +18,21 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/settlement" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/settlement/swap/priceoracle" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/wrapped" + "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/settlement" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/wrapped" "github.com/ethersphere/go-sw3-abi/sw3abi" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/node/devnode.go b/pkg/node/devnode.go index 76b055b531f..b45715bd152 100644 --- a/pkg/node/devnode.go +++ b/pkg/node/devnode.go @@ -17,44 +17,44 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - mockAccounting "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/auth" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds/factory" - "github.com/ethersphere/bee/pkg/log" - mockP2P "github.com/ethersphere/bee/pkg/p2p/mock" - mockPingPong "github.com/ethersphere/bee/pkg/pingpong/mock" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchstore" - mockPost "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - mockPostContract "github.com/ethersphere/bee/pkg/postage/postagecontract/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/pushsync" - mockPushsync "github.com/ethersphere/bee/pkg/pushsync/mock" - resolverMock "github.com/ethersphere/bee/pkg/resolver/mock" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - mockchequebook "github.com/ethersphere/bee/pkg/settlement/swap/chequebook/mock" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - swapmock "github.com/ethersphere/bee/pkg/settlement/swap/mock" - "github.com/ethersphere/bee/pkg/statestore/leveldb" - mockSteward "github.com/ethersphere/bee/pkg/steward/mock" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - stakingContractMock "github.com/ethersphere/bee/pkg/storageincentives/staking/mock" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/lightnode" - mockTopology "github.com/ethersphere/bee/pkg/topology/mock" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/ioutil" + mockAccounting "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/auth" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds/factory" + "github.com/ethersphere/bee/v2/pkg/log" + mockP2P "github.com/ethersphere/bee/v2/pkg/p2p/mock" + mockPingPong "github.com/ethersphere/bee/v2/pkg/pingpong/mock" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore" + mockPost "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + mockPostContract "github.com/ethersphere/bee/v2/pkg/postage/postagecontract/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/pushsync" + mockPushsync "github.com/ethersphere/bee/v2/pkg/pushsync/mock" + resolverMock "github.com/ethersphere/bee/v2/pkg/resolver/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + mockchequebook "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + "github.com/ethersphere/bee/v2/pkg/statestore/leveldb" + mockSteward "github.com/ethersphere/bee/v2/pkg/steward/mock" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + stakingContractMock "github.com/ethersphere/bee/v2/pkg/storageincentives/staking/mock" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + mockTopology "github.com/ethersphere/bee/v2/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/ioutil" "github.com/hashicorp/go-multierror" "github.com/multiformats/go-multiaddr" "golang.org/x/sync/errgroup" @@ -202,7 +202,7 @@ func NewDevBee(logger log.Logger, o *DevOptions) (b *DevBee, err error) { return nil, fmt.Errorf("debug api listener: %w", err) } - debugApiService = api.New(mockKey.PublicKey, mockKey.PublicKey, overlayEthAddress, logger, mockTransaction, batchStore, api.DevMode, true, true, chainBackend, o.CORSAllowedOrigins, inmemstore.New()) + debugApiService = api.New(mockKey.PublicKey, mockKey.PublicKey, overlayEthAddress, nil, logger, mockTransaction, batchStore, api.DevMode, true, true, chainBackend, o.CORSAllowedOrigins, inmemstore.New()) debugAPIServer := &http.Server{ IdleTimeout: 30 * time.Second, ReadHeaderTimeout: 3 * time.Second, @@ -398,7 +398,7 @@ func NewDevBee(logger log.Logger, o *DevOptions) (b *DevBee, err error) { }), ) - apiService := api.New(mockKey.PublicKey, mockKey.PublicKey, overlayEthAddress, logger, mockTransaction, batchStore, api.DevMode, true, true, chainBackend, o.CORSAllowedOrigins, inmemstore.New()) + apiService := api.New(mockKey.PublicKey, mockKey.PublicKey, overlayEthAddress, nil, logger, mockTransaction, batchStore, api.DevMode, true, true, chainBackend, o.CORSAllowedOrigins, inmemstore.New()) apiService.Configure(signer, authenticator, tracer, api.Options{ CORSAllowedOrigins: o.CORSAllowedOrigins, diff --git a/pkg/node/node.go b/pkg/node/node.go index 214cad27d4f..2996b8d77d5 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -24,55 +24,55 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/auth" - "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds/factory" - "github.com/ethersphere/bee/pkg/hive" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/pingpong" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchservice" - "github.com/ethersphere/bee/pkg/postage/batchstore" - "github.com/ethersphere/bee/pkg/postage/listener" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/pricer" - "github.com/ethersphere/bee/pkg/pricing" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/puller" - "github.com/ethersphere/bee/pkg/pullsync" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/pushsync" - "github.com/ethersphere/bee/pkg/resolver/multiresolver" - "github.com/ethersphere/bee/pkg/retrieval" - "github.com/ethersphere/bee/pkg/salud" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/settlement/swap/priceoracle" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/steward" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/kademlia" - "github.com/ethersphere/bee/pkg/topology/lightnode" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" - "github.com/ethersphere/bee/pkg/util/ioutil" - "github.com/ethersphere/bee/pkg/util/nbhdutil" - "github.com/ethersphere/bee/pkg/util/syncutil" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/auth" + "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds/factory" + "github.com/ethersphere/bee/v2/pkg/hive" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/pingpong" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchservice" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore" + "github.com/ethersphere/bee/v2/pkg/postage/listener" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/pricer" + "github.com/ethersphere/bee/v2/pkg/pricing" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/puller" + "github.com/ethersphere/bee/v2/pkg/pullsync" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/pushsync" + "github.com/ethersphere/bee/v2/pkg/resolver/multiresolver" + "github.com/ethersphere/bee/v2/pkg/retrieval" + "github.com/ethersphere/bee/v2/pkg/salud" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/steward" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/util/ioutil" + "github.com/ethersphere/bee/v2/pkg/util/nbhdutil" + "github.com/ethersphere/bee/v2/pkg/util/syncutil" "github.com/hashicorp/go-multierror" ma "github.com/multiformats/go-multiaddr" promc "github.com/prometheus/client_golang/prometheus" @@ -171,6 +171,8 @@ type Options struct { EnableStorageIncentives bool StatestoreCacheCapacity uint64 TargetNeighborhood string + NeighborhoodSuggester string + WhitelistedWithdrawalAddress []string } const ( @@ -252,7 +254,7 @@ func NewBee( } b.stateStoreCloser = stateStore - // Check if the the batchstore exists. If not, we can assume it's missing + // Check if the batchstore exists. If not, we can assume it's missing // due to a migration or it's a fresh install. batchStoreExists, err := batchStoreExists(stateStore) if err != nil { @@ -282,9 +284,18 @@ func NewBee( if !nonceExists { // mine the overlay - if o.TargetNeighborhood != "" { - logger.Info("mining an overlay address for the fresh node to target the selected neighborhood", "target", o.TargetNeighborhood) - swarmAddress, nonce, err = nbhdutil.MineOverlay(ctx, *pubKey, networkID, o.TargetNeighborhood) + targetNeighborhood := o.TargetNeighborhood + if o.TargetNeighborhood == "" && o.NeighborhoodSuggester != "" { + logger.Info("fetching target neighborhood from suggester", "url", o.NeighborhoodSuggester) + targetNeighborhood, err = nbhdutil.FetchNeighborhood(&http.Client{}, o.NeighborhoodSuggester) + if err != nil { + return nil, fmt.Errorf("neighborhood suggestion: %w", err) + } + } + + if targetNeighborhood != "" { + logger.Info("mining an overlay address for the fresh node to target the selected neighborhood", "target", targetNeighborhood) + swarmAddress, nonce, err = nbhdutil.MineOverlay(ctx, *pubKey, networkID, targetNeighborhood) if err != nil { return nil, fmt.Errorf("mine overlay address: %w", err) } @@ -411,6 +422,7 @@ func NewBee( *publicKey, pssPrivateKey.PublicKey, overlayEthAddress, + o.WhitelistedWithdrawalAddress, logger, transactionService, batchStore, @@ -450,6 +462,7 @@ func NewBee( *publicKey, pssPrivateKey.PublicKey, overlayEthAddress, + o.WhitelistedWithdrawalAddress, logger, transactionService, batchStore, @@ -1079,11 +1092,12 @@ func NewBee( Steward: steward, SyncStatus: syncStatusFn, NodeStatus: nodeStatus, + PinIntegrity: localStore.PinIntegrity(), } if o.APIAddr != "" { if apiService == nil { - apiService = api.New(*publicKey, pssPrivateKey.PublicKey, overlayEthAddress, logger, transactionService, batchStore, beeNodeMode, o.ChequebookEnable, o.SwapEnable, chainBackend, o.CORSAllowedOrigins, stamperStore) + apiService = api.New(*publicKey, pssPrivateKey.PublicKey, overlayEthAddress, o.WhitelistedWithdrawalAddress, logger, transactionService, batchStore, beeNodeMode, o.ChequebookEnable, o.SwapEnable, chainBackend, o.CORSAllowedOrigins, stamperStore) apiService.SetProbe(probe) apiService.SetRedistributionAgent(agent) } diff --git a/pkg/node/statestore.go b/pkg/node/statestore.go index 9579e1487ef..958ce5f01e1 100644 --- a/pkg/node/statestore.go +++ b/pkg/node/statestore.go @@ -9,13 +9,13 @@ import ( "fmt" "path/filepath" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/statestore/storeadapter" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/cache" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/statestore/storeadapter" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/cache" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // InitStateStore will initialize the stateStore with the given path to the diff --git a/pkg/p2p/libp2p/connections_test.go b/pkg/p2p/libp2p/connections_test.go index 6f560e3ed7d..ae81ad481d0 100644 --- a/pkg/p2p/libp2p/connections_test.go +++ b/pkg/p2p/libp2p/connections_test.go @@ -16,15 +16,15 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" "github.com/libp2p/go-libp2p/p2p/host/eventbus" libp2pm "github.com/libp2p/go-libp2p" diff --git a/pkg/p2p/libp2p/export_test.go b/pkg/p2p/libp2p/export_test.go index 468d5bdbef8..f78b9f21275 100644 --- a/pkg/p2p/libp2p/export_test.go +++ b/pkg/p2p/libp2p/export_test.go @@ -7,7 +7,7 @@ package libp2p import ( "context" - handshake "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" + handshake "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake" libp2pm "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" diff --git a/pkg/p2p/libp2p/headers.go b/pkg/p2p/libp2p/headers.go index 10d81d094e0..af658073d82 100644 --- a/pkg/p2p/libp2p/headers.go +++ b/pkg/p2p/libp2p/headers.go @@ -8,10 +8,10 @@ import ( "context" "fmt" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/headers/pb" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/headers/pb" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func sendHeaders(ctx context.Context, headers p2p.Headers, stream *stream) error { diff --git a/pkg/p2p/libp2p/headers_test.go b/pkg/p2p/libp2p/headers_test.go index 62b9b62925e..5805dafa0d4 100644 --- a/pkg/p2p/libp2p/headers_test.go +++ b/pkg/p2p/libp2p/headers_test.go @@ -10,9 +10,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestHeaders(t *testing.T) { diff --git a/pkg/p2p/libp2p/internal/blocklist/blocklist.go b/pkg/p2p/libp2p/internal/blocklist/blocklist.go index 683d43bbeae..d5ecee4d24d 100644 --- a/pkg/p2p/libp2p/internal/blocklist/blocklist.go +++ b/pkg/p2p/libp2p/internal/blocklist/blocklist.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var keyPrefix = "blocklist-" diff --git a/pkg/p2p/libp2p/internal/blocklist/blocklist_test.go b/pkg/p2p/libp2p/internal/blocklist/blocklist_test.go index d0bc3e4108f..dd932fc6acf 100644 --- a/pkg/p2p/libp2p/internal/blocklist/blocklist_test.go +++ b/pkg/p2p/libp2p/internal/blocklist/blocklist_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/blocklist" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/blocklist" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestExist(t *testing.T) { diff --git a/pkg/p2p/libp2p/internal/blocklist/export_test.go b/pkg/p2p/libp2p/internal/blocklist/export_test.go index bf70482c379..76c7599ffa4 100644 --- a/pkg/p2p/libp2p/internal/blocklist/export_test.go +++ b/pkg/p2p/libp2p/internal/blocklist/export_test.go @@ -5,7 +5,7 @@ package blocklist import ( - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) func NewBlocklistWithCurrentTimeFn(store storage.StateStorer, currentTimeFn currentTimeFn) *Blocklist { diff --git a/pkg/p2p/libp2p/internal/breaker/breaker_test.go b/pkg/p2p/libp2p/internal/breaker/breaker_test.go index df02ab647de..2693037abbf 100644 --- a/pkg/p2p/libp2p/internal/breaker/breaker_test.go +++ b/pkg/p2p/libp2p/internal/breaker/breaker_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/breaker" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/breaker" ) func TestExecute(t *testing.T) { diff --git a/pkg/p2p/libp2p/internal/handshake/handshake.go b/pkg/p2p/libp2p/internal/handshake/handshake.go index 102fd00b68a..fb605073253 100644 --- a/pkg/p2p/libp2p/internal/handshake/handshake.go +++ b/pkg/p2p/libp2p/internal/handshake/handshake.go @@ -11,13 +11,13 @@ import ( "sync/atomic" "time" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake/pb" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/swarm" libp2ppeer "github.com/libp2p/go-libp2p/core/peer" ma "github.com/multiformats/go-multiaddr" @@ -326,7 +326,7 @@ func (s *Service) SetWelcomeMessage(msg string) (err error) { return nil } -// GetWelcomeMessage returns the the current handshake welcome message. +// GetWelcomeMessage returns the current handshake welcome message. func (s *Service) GetWelcomeMessage() string { return s.welcomeMessage.Load().(string) } diff --git a/pkg/p2p/libp2p/internal/handshake/handshake_test.go b/pkg/p2p/libp2p/internal/handshake/handshake_test.go index 5dc37116028..e0afcc56d70 100644 --- a/pkg/p2p/libp2p/internal/handshake/handshake_test.go +++ b/pkg/p2p/libp2p/internal/handshake/handshake_test.go @@ -12,14 +12,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/mock" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb" - "github.com/ethersphere/bee/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake/mock" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake/pb" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" libp2ppeer "github.com/libp2p/go-libp2p/core/peer" ma "github.com/multiformats/go-multiaddr" diff --git a/pkg/p2p/libp2p/internal/handshake/metrics.go b/pkg/p2p/libp2p/internal/handshake/metrics.go index e0313dd17cd..c8177d3f93e 100644 --- a/pkg/p2p/libp2p/internal/handshake/metrics.go +++ b/pkg/p2p/libp2p/internal/handshake/metrics.go @@ -5,7 +5,7 @@ package handshake import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/p2p/libp2p/internal/handshake/mock/stream.go b/pkg/p2p/libp2p/internal/handshake/mock/stream.go index 69ffcb7ce59..bebe17fe30a 100644 --- a/pkg/p2p/libp2p/internal/handshake/mock/stream.go +++ b/pkg/p2p/libp2p/internal/handshake/mock/stream.go @@ -7,7 +7,7 @@ package mock import ( "bytes" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) type Stream struct { diff --git a/pkg/p2p/libp2p/internal/reacher/metrics.go b/pkg/p2p/libp2p/internal/reacher/metrics.go index ab745943b2c..d3d90837a6f 100644 --- a/pkg/p2p/libp2p/internal/reacher/metrics.go +++ b/pkg/p2p/libp2p/internal/reacher/metrics.go @@ -5,7 +5,7 @@ package reacher import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/p2p/libp2p/internal/reacher/reacher.go b/pkg/p2p/libp2p/internal/reacher/reacher.go index da87d6049b1..ad888df4d0f 100644 --- a/pkg/p2p/libp2p/internal/reacher/reacher.go +++ b/pkg/p2p/libp2p/internal/reacher/reacher.go @@ -11,8 +11,8 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/libp2p/internal/reacher/reacher_test.go b/pkg/p2p/libp2p/internal/reacher/reacher_test.go index a842103115a..d60bb2cc9cc 100644 --- a/pkg/p2p/libp2p/internal/reacher/reacher_test.go +++ b/pkg/p2p/libp2p/internal/reacher/reacher_test.go @@ -10,10 +10,10 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/reacher" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/reacher" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ma "github.com/multiformats/go-multiaddr" "go.uber.org/atomic" ) diff --git a/pkg/p2p/libp2p/libp2p.go b/pkg/p2p/libp2p/libp2p.go index d7250a517fb..4671f4cde36 100644 --- a/pkg/p2p/libp2p/libp2p.go +++ b/pkg/p2p/libp2p/libp2p.go @@ -17,21 +17,21 @@ import ( "sync" "time" - "github.com/ethersphere/bee" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/bzz" - beecrypto "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/blocklist" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/breaker" - handshake "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/reacher" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/lightnode" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/bzz" + beecrypto "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/blocklist" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/breaker" + handshake "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/reacher" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/tracing" libp2p "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/event" @@ -54,7 +54,7 @@ import ( "go.uber.org/atomic" ocprom "contrib.go.opencensus.io/exporter/prometheus" - m2 "github.com/ethersphere/bee/pkg/metrics" + m2 "github.com/ethersphere/bee/v2/pkg/metrics" rcmgrObs "github.com/libp2p/go-libp2p/p2p/host/resource-manager" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/p2p/libp2p/libp2p_test.go b/pkg/p2p/libp2p/libp2p_test.go index 378d4dbc9d3..c467247547e 100644 --- a/pkg/p2p/libp2p/libp2p_test.go +++ b/pkg/p2p/libp2p/libp2p_test.go @@ -13,16 +13,16 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/lightnode" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/libp2p/metrics.go b/pkg/p2p/libp2p/metrics.go index b7f6e79a665..003970856d2 100644 --- a/pkg/p2p/libp2p/metrics.go +++ b/pkg/p2p/libp2p/metrics.go @@ -5,7 +5,7 @@ package libp2p import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/p2p/libp2p/peer.go b/pkg/p2p/libp2p/peer.go index c8eeb1578c2..5aa0f75713a 100644 --- a/pkg/p2p/libp2p/peer.go +++ b/pkg/p2p/libp2p/peer.go @@ -10,8 +10,8 @@ import ( "sort" "sync" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/libp2p/go-libp2p/core/network" libp2ppeer "github.com/libp2p/go-libp2p/core/peer" ma "github.com/multiformats/go-multiaddr" diff --git a/pkg/p2p/libp2p/protocols_test.go b/pkg/p2p/libp2p/protocols_test.go index b4f2fab91f8..ef2acf0d82b 100644 --- a/pkg/p2p/libp2p/protocols_test.go +++ b/pkg/p2p/libp2p/protocols_test.go @@ -12,9 +12,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/spinlock" libp2pm "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/host" protocol "github.com/libp2p/go-libp2p/core/protocol" diff --git a/pkg/p2p/libp2p/static_resolver_test.go b/pkg/p2p/libp2p/static_resolver_test.go index 992d7500004..4aff2ca41c6 100644 --- a/pkg/p2p/libp2p/static_resolver_test.go +++ b/pkg/p2p/libp2p/static_resolver_test.go @@ -8,7 +8,7 @@ import ( "net" "testing" - "github.com/ethersphere/bee/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/libp2p/stream.go b/pkg/p2p/libp2p/stream.go index 8535da7e82e..93e7ce6181a 100644 --- a/pkg/p2p/libp2p/stream.go +++ b/pkg/p2p/libp2p/stream.go @@ -9,7 +9,7 @@ import ( "io" "time" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" "github.com/libp2p/go-libp2p/core/network" ) diff --git a/pkg/p2p/libp2p/tracing_test.go b/pkg/p2p/libp2p/tracing_test.go index 5b54911ec3e..7e02f8e2d7c 100644 --- a/pkg/p2p/libp2p/tracing_test.go +++ b/pkg/p2p/libp2p/tracing_test.go @@ -10,9 +10,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/tracing" ) func TestTracing(t *testing.T) { diff --git a/pkg/p2p/libp2p/welcome_message_test.go b/pkg/p2p/libp2p/welcome_message_test.go index 839a8fb3f30..5e6ac7a2f2d 100644 --- a/pkg/p2p/libp2p/welcome_message_test.go +++ b/pkg/p2p/libp2p/welcome_message_test.go @@ -7,8 +7,8 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/p2p/libp2p" - "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p" + "github.com/ethersphere/bee/v2/pkg/p2p/libp2p/internal/handshake" ) func TestDynamicWelcomeMessage(t *testing.T) { diff --git a/pkg/p2p/mock/mock.go b/pkg/p2p/mock/mock.go index 092824da555..eacefd6846b 100644 --- a/pkg/p2p/mock/mock.go +++ b/pkg/p2p/mock/mock.go @@ -9,9 +9,9 @@ import ( "errors" "time" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/p2p.go b/pkg/p2p/p2p.go index 4f7897be592..a85b3d9d04b 100644 --- a/pkg/p2p/p2p.go +++ b/pkg/p2p/p2p.go @@ -13,8 +13,8 @@ import ( "io" "time" - "github.com/ethersphere/bee/pkg/bzz" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bzz" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/libp2p/go-libp2p/core/network" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/p2p_test.go b/pkg/p2p/p2p_test.go index ce01cac2b0a..3c6ce22ca22 100644 --- a/pkg/p2p/p2p_test.go +++ b/pkg/p2p/p2p_test.go @@ -7,7 +7,7 @@ package p2p_test import ( "testing" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" "github.com/libp2p/go-libp2p/core/network" ) diff --git a/pkg/p2p/protobuf/main_test.go b/pkg/p2p/protobuf/main_test.go index 82148f77600..68f9fc720bb 100644 --- a/pkg/p2p/protobuf/main_test.go +++ b/pkg/p2p/protobuf/main_test.go @@ -16,6 +16,6 @@ func TestMain(m *testing.M) { goleak.IgnoreTopFunction("time.Sleep"), goleak.IgnoreTopFunction("io.(*pipe).read"), goleak.IgnoreTopFunction("io.(*pipe).write"), - goleak.IgnoreTopFunction("github.com/ethersphere/bee/pkg/p2p/protobuf_test.newMessageWriter.func1"), + goleak.IgnoreTopFunction("github.com/ethersphere/bee/v2/pkg/p2p/protobuf_test.newMessageWriter.func1"), ) } diff --git a/pkg/p2p/protobuf/protobuf.go b/pkg/p2p/protobuf/protobuf.go index 7cd02832fc1..3153a6e0302 100644 --- a/pkg/p2p/protobuf/protobuf.go +++ b/pkg/p2p/protobuf/protobuf.go @@ -9,7 +9,7 @@ import ( "errors" "io" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ggio "github.com/gogo/protobuf/io" "github.com/gogo/protobuf/proto" ) diff --git a/pkg/p2p/protobuf/protobuf_test.go b/pkg/p2p/protobuf/protobuf_test.go index f161852ab10..5dd675b0687 100644 --- a/pkg/p2p/protobuf/protobuf_test.go +++ b/pkg/p2p/protobuf/protobuf_test.go @@ -12,9 +12,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/protobuf/internal/pb" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf/internal/pb" ) func TestReader_ReadMsg(t *testing.T) { diff --git a/pkg/p2p/specwrapper_test.go b/pkg/p2p/specwrapper_test.go index 36f5951849e..2275d2004e5 100644 --- a/pkg/p2p/specwrapper_test.go +++ b/pkg/p2p/specwrapper_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) func newTestProtocol(h p2p.HandlerFunc) p2p.ProtocolSpec { diff --git a/pkg/p2p/streamtest/streamtest.go b/pkg/p2p/streamtest/streamtest.go index 4acab84db25..a9892687240 100644 --- a/pkg/p2p/streamtest/streamtest.go +++ b/pkg/p2p/streamtest/streamtest.go @@ -12,9 +12,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/p2p/streamtest/streamtest_test.go b/pkg/p2p/streamtest/streamtest_test.go index 924cdfcc0e9..0b26d2da7ce 100644 --- a/pkg/p2p/streamtest/streamtest_test.go +++ b/pkg/p2p/streamtest/streamtest_test.go @@ -14,9 +14,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/swarm" ma "github.com/multiformats/go-multiaddr" ) diff --git a/pkg/pingpong/metrics.go b/pkg/pingpong/metrics.go index 9b177c0461d..155b3abdb8e 100644 --- a/pkg/pingpong/metrics.go +++ b/pkg/pingpong/metrics.go @@ -5,7 +5,7 @@ package pingpong import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/pingpong/mock/mock.go b/pkg/pingpong/mock/mock.go index 033e75a6943..66d5be1a521 100644 --- a/pkg/pingpong/mock/mock.go +++ b/pkg/pingpong/mock/mock.go @@ -8,7 +8,7 @@ import ( "context" "time" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Service struct { diff --git a/pkg/pingpong/pingpong.go b/pkg/pingpong/pingpong.go index 252d84dc6eb..ba09d7eaab1 100644 --- a/pkg/pingpong/pingpong.go +++ b/pkg/pingpong/pingpong.go @@ -13,12 +13,12 @@ import ( "io" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/pingpong/pb" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/pingpong/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/tracing" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/pingpong/pingpong_test.go b/pkg/pingpong/pingpong_test.go index 662b6684ddd..6e0298b7cb9 100644 --- a/pkg/pingpong/pingpong_test.go +++ b/pkg/pingpong/pingpong_test.go @@ -12,14 +12,14 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/pingpong" - "github.com/ethersphere/bee/pkg/pingpong/pb" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/pingpong" + "github.com/ethersphere/bee/v2/pkg/pingpong/pb" ) func TestPing(t *testing.T) { diff --git a/pkg/postage/batch_test.go b/pkg/postage/batch_test.go index e735639449e..e7b419d6e02 100644 --- a/pkg/postage/batch_test.go +++ b/pkg/postage/batch_test.go @@ -8,8 +8,8 @@ import ( "bytes" "testing" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" ) // TestBatchMarshalling tests the idempotence of binary marshal/unmarshal for a diff --git a/pkg/postage/batchservice/batchservice.go b/pkg/postage/batchservice/batchservice.go index ad7b26a6e93..4ec2611aa26 100644 --- a/pkg/postage/batchservice/batchservice.go +++ b/pkg/postage/batchservice/batchservice.go @@ -14,9 +14,9 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" "golang.org/x/crypto/sha3" ) diff --git a/pkg/postage/batchservice/batchservice_test.go b/pkg/postage/batchservice/batchservice_test.go index 9be023ff726..0fd2bfe4c14 100644 --- a/pkg/postage/batchservice/batchservice_test.go +++ b/pkg/postage/batchservice/batchservice_test.go @@ -13,14 +13,14 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchservice" - "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - mocks "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchservice" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + mocks "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) var ( diff --git a/pkg/postage/batchstore/metrics.go b/pkg/postage/batchstore/metrics.go index 30aca0fcd1f..518b18ae79b 100644 --- a/pkg/postage/batchstore/metrics.go +++ b/pkg/postage/batchstore/metrics.go @@ -5,7 +5,7 @@ package batchstore import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/postage/batchstore/mock/store.go b/pkg/postage/batchstore/mock/store.go index f3c10bf236d..f7d2d5aa847 100644 --- a/pkg/postage/batchstore/mock/store.go +++ b/pkg/postage/batchstore/mock/store.go @@ -10,9 +10,9 @@ import ( "math/big" "sync" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchstore" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore" + "github.com/ethersphere/bee/v2/pkg/storage" ) var _ postage.Storer = (*BatchStore)(nil) diff --git a/pkg/postage/batchstore/mock/store_test.go b/pkg/postage/batchstore/mock/store_test.go index 9ba544fafbd..824988f38f0 100644 --- a/pkg/postage/batchstore/mock/store_test.go +++ b/pkg/postage/batchstore/mock/store_test.go @@ -9,8 +9,8 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" ) func TestBatchStore(t *testing.T) { diff --git a/pkg/postage/batchstore/store.go b/pkg/postage/batchstore/store.go index a3cac65d5be..abad6987ac6 100644 --- a/pkg/postage/batchstore/store.go +++ b/pkg/postage/batchstore/store.go @@ -13,9 +13,9 @@ import ( "math/big" "sync/atomic" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/postage/batchstore/store_test.go b/pkg/postage/batchstore/store_test.go index 43e24014d33..090c77c3287 100644 --- a/pkg/postage/batchstore/store_test.go +++ b/pkg/postage/batchstore/store_test.go @@ -10,16 +10,16 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchstore" - mockpost "github.com/ethersphere/bee/pkg/postage/mock" - postagetest "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/statestore/leveldb" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore" + mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock" + postagetest "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/statestore/leveldb" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) var noopEvictFn = func([]byte) error { return nil } @@ -328,7 +328,7 @@ func TestBatchUpdate(t *testing.T) { // state after the batch is saved/updated. Unlike depth updates, value updates // that are above cumulative amount should NOT result in any radius changes. // Value updates that are less than or equal to the cumulative amount trigger - // the eviction for the the batch, as such, radius may be altered. + // the eviction for the batch, as such, radius may be altered. tcs := []testCase{ { diff --git a/pkg/postage/export_test.go b/pkg/postage/export_test.go index f453d8eadb8..b26f6415010 100644 --- a/pkg/postage/export_test.go +++ b/pkg/postage/export_test.go @@ -5,7 +5,7 @@ package postage import ( - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/postage/listener/listener.go b/pkg/postage/listener/listener.go index a7764fcd077..30b3b2ad81d 100644 --- a/pkg/postage/listener/listener.go +++ b/pkg/postage/listener/listener.go @@ -16,11 +16,11 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchservice" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/syncutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchservice" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/syncutil" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/postage/listener/listener_test.go b/pkg/postage/listener/listener_test.go index 7080d33cbdb..43c8675883d 100644 --- a/pkg/postage/listener/listener_test.go +++ b/pkg/postage/listener/listener_test.go @@ -16,13 +16,13 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/listener" - "github.com/ethersphere/bee/pkg/util/abiutil" - "github.com/ethersphere/bee/pkg/util/syncutil" - "github.com/ethersphere/bee/pkg/util/testutil" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/listener" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/util/syncutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) var ( diff --git a/pkg/postage/listener/metrics.go b/pkg/postage/listener/metrics.go index 99c22aeea16..8fb7b639884 100644 --- a/pkg/postage/listener/metrics.go +++ b/pkg/postage/listener/metrics.go @@ -5,7 +5,7 @@ package listener import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/postage/mock/service.go b/pkg/postage/mock/service.go index 84b2358dd27..b4fffd07761 100644 --- a/pkg/postage/mock/service.go +++ b/pkg/postage/mock/service.go @@ -9,7 +9,7 @@ import ( "math/big" "sync" - "github.com/ethersphere/bee/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage" ) type optionFunc func(*mockPostage) diff --git a/pkg/postage/mock/stamper.go b/pkg/postage/mock/stamper.go index 2c5b0a543f7..f95700eb5e5 100644 --- a/pkg/postage/mock/stamper.go +++ b/pkg/postage/mock/stamper.go @@ -5,8 +5,8 @@ package mock import ( - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type mockStamper struct{} diff --git a/pkg/postage/noop.go b/pkg/postage/noop.go index ea8387deee8..bf58dab9940 100644 --- a/pkg/postage/noop.go +++ b/pkg/postage/noop.go @@ -8,7 +8,7 @@ import ( "errors" "math/big" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var _ Storer = (*NoOpBatchStore)(nil) diff --git a/pkg/postage/postagecontract/contract.go b/pkg/postage/postagecontract/contract.go index 035d7a18f75..d66939b3d42 100644 --- a/pkg/postage/postagecontract/contract.go +++ b/pkg/postage/postagecontract/contract.go @@ -14,10 +14,10 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/postage/postagecontract/contract_test.go b/pkg/postage/postagecontract/contract_test.go index cd95342fcb2..dd47d44affe 100644 --- a/pkg/postage/postagecontract/contract_test.go +++ b/pkg/postage/postagecontract/contract_test.go @@ -14,15 +14,15 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/postage" - postagestoreMock "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postageMock "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/transaction" - transactionMock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/postage" + postagestoreMock "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postageMock "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/transaction" + transactionMock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" ) var postageStampContractABI = abiutil.MustParseABI(chaincfg.Testnet.PostageStampABI) diff --git a/pkg/postage/postagecontract/mock/contract.go b/pkg/postage/postagecontract/mock/contract.go index ff5b3a8220a..e9547622dae 100644 --- a/pkg/postage/postagecontract/mock/contract.go +++ b/pkg/postage/postagecontract/mock/contract.go @@ -9,7 +9,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" ) type contractMock struct { diff --git a/pkg/postage/service.go b/pkg/postage/service.go index 7621e00d281..f14e506370a 100644 --- a/pkg/postage/service.go +++ b/pkg/postage/service.go @@ -14,8 +14,8 @@ import ( "math/big" "sync" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" ) // loggerName is the tree path name of the logger for this package. @@ -174,8 +174,8 @@ func (ps *service) GetStampIssuer(batchID []byte) (*StampIssuer, func() error, e // save persists the specified stamp issuer to the stamperstore. func (ps *service) save(st *StampIssuer) error { - st.bucketMtx.Lock() - defer st.bucketMtx.Unlock() + st.mtx.Lock() + defer st.mtx.Unlock() if err := ps.store.Put(&StampIssuerItem{ Issuer: st, diff --git a/pkg/postage/service_test.go b/pkg/postage/service_test.go index c637b8e2630..f432565fb4a 100644 --- a/pkg/postage/service_test.go +++ b/pkg/postage/service_test.go @@ -13,14 +13,14 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - pstoremock "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + pstoremock "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // TestSaveLoad tests the idempotence of saving and loading the postage.Service diff --git a/pkg/postage/stamp.go b/pkg/postage/stamp.go index 4fff65797ad..dbe6fd5b2d7 100644 --- a/pkg/postage/stamp.go +++ b/pkg/postage/stamp.go @@ -10,9 +10,9 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // StampSize is the number of bytes in the serialisation of a stamp diff --git a/pkg/postage/stamp_test.go b/pkg/postage/stamp_test.go index ab98a197349..4fb9412f724 100644 --- a/pkg/postage/stamp_test.go +++ b/pkg/postage/stamp_test.go @@ -10,12 +10,12 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" ) // TestStampMarshalling tests the idempotence of binary marshal/unmarshals for Stamps. diff --git a/pkg/postage/stamper.go b/pkg/postage/stamper.go index 1ee16a8a133..ca063196546 100644 --- a/pkg/postage/stamper.go +++ b/pkg/postage/stamper.go @@ -8,10 +8,9 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "resenje.org/multex" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( @@ -30,19 +29,18 @@ type stamper struct { store storage.Store issuer *StampIssuer signer crypto.Signer - mu *multex.Multex } // NewStamper constructs a Stamper. func NewStamper(store storage.Store, issuer *StampIssuer, signer crypto.Signer) Stamper { - return &stamper{store, issuer, signer, multex.New()} + return &stamper{store, issuer, signer} } // Stamp takes chunk, see if the chunk can be included in the batch and // signs it with the owner of the batch of this Stamp issuer. func (st *stamper) Stamp(addr swarm.Address) (*Stamp, error) { - st.mu.Lock(addr.ByteString()) - defer st.mu.Unlock(addr.ByteString()) + st.issuer.mtx.Lock() + defer st.issuer.mtx.Unlock() item := &StampItem{ BatchID: st.issuer.data.BatchID, diff --git a/pkg/postage/stamper_test.go b/pkg/postage/stamper_test.go index 520d6da0faf..a1c589b145c 100644 --- a/pkg/postage/stamper_test.go +++ b/pkg/postage/stamper_test.go @@ -10,11 +10,11 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestStamperStamping tests if the stamp created by the stamper is valid. diff --git a/pkg/postage/stampissuer.go b/pkg/postage/stampissuer.go index 84b5292528a..77b632cf0f4 100644 --- a/pkg/postage/stampissuer.go +++ b/pkg/postage/stampissuer.go @@ -13,8 +13,8 @@ import ( "sync" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/vmihailenco/msgpack/v5" ) @@ -151,8 +151,8 @@ func (s stampIssuerData) Clone() stampIssuerData { // A StampIssuer instance extends a batch with bucket collision tracking // embedded in multiple Stampers, can be used concurrently. type StampIssuer struct { - data stampIssuerData - bucketMtx sync.Mutex + data stampIssuerData + mtx sync.Mutex } // NewStampIssuer constructs a StampIssuer as an extension of a batch for local @@ -177,10 +177,8 @@ func NewStampIssuer(label, keyID string, batchID []byte, batchAmount *big.Int, b // increment increments the count in the correct collision // bucket for a newly stamped chunk with given addr address. +// Must be mutex locked before usage. func (si *StampIssuer) increment(addr swarm.Address) (batchIndex []byte, batchTimestamp []byte, err error) { - si.bucketMtx.Lock() - defer si.bucketMtx.Unlock() - bIdx := toBucket(si.BucketDepth(), addr) bCnt := si.data.Buckets[bIdx] @@ -263,8 +261,8 @@ func (si *StampIssuer) ImmutableFlag() bool { } func (si *StampIssuer) Buckets() []uint32 { - si.bucketMtx.Lock() - defer si.bucketMtx.Unlock() + si.mtx.Lock() + defer si.mtx.Unlock() b := make([]uint32, len(si.data.Buckets)) copy(b, si.data.Buckets) return b diff --git a/pkg/postage/stampissuer_test.go b/pkg/postage/stampissuer_test.go index 9d99b7087ca..3a72b57f3d6 100644 --- a/pkg/postage/stampissuer_test.go +++ b/pkg/postage/stampissuer_test.go @@ -16,10 +16,10 @@ import ( "sync/atomic" "testing" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "golang.org/x/sync/errgroup" diff --git a/pkg/postage/testing/batch.go b/pkg/postage/testing/batch.go index a9c21c355ec..2e8349da220 100644 --- a/pkg/postage/testing/batch.go +++ b/pkg/postage/testing/batch.go @@ -12,7 +12,7 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage" ) const ( diff --git a/pkg/postage/testing/chainstate.go b/pkg/postage/testing/chainstate.go index dff5e07d490..edd1dc554b8 100644 --- a/pkg/postage/testing/chainstate.go +++ b/pkg/postage/testing/chainstate.go @@ -8,7 +8,7 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage" ) // NewChainState will create a new ChainState with random values. diff --git a/pkg/postage/testing/stamp.go b/pkg/postage/testing/stamp.go index def77bf582b..80ba4317e2a 100644 --- a/pkg/postage/testing/stamp.go +++ b/pkg/postage/testing/stamp.go @@ -9,9 +9,9 @@ import ( "encoding/binary" "io" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const signatureSize = 65 diff --git a/pkg/pricer/headerutils/utilities.go b/pkg/pricer/headerutils/utilities.go index f67b71b6de5..a85e56990b4 100644 --- a/pkg/pricer/headerutils/utilities.go +++ b/pkg/pricer/headerutils/utilities.go @@ -7,8 +7,8 @@ package headerutils import ( "encoding/binary" "errors" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/pricer/headerutils/utilities_test.go b/pkg/pricer/headerutils/utilities_test.go index 55ec77e500e..b2c62ee68d1 100644 --- a/pkg/pricer/headerutils/utilities_test.go +++ b/pkg/pricer/headerutils/utilities_test.go @@ -8,9 +8,9 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/pricer/headerutils" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/pricer/headerutils" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestMakePricingHeaders(t *testing.T) { diff --git a/pkg/pricer/mock/pricer.go b/pkg/pricer/mock/pricer.go index 49bc87b6923..5daf93debc7 100644 --- a/pkg/pricer/mock/pricer.go +++ b/pkg/pricer/mock/pricer.go @@ -5,7 +5,7 @@ package mock import ( - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type MockPricer struct { diff --git a/pkg/pricer/pricer.go b/pkg/pricer/pricer.go index a060c4a5a21..21cbde9a4b3 100644 --- a/pkg/pricer/pricer.go +++ b/pkg/pricer/pricer.go @@ -5,7 +5,7 @@ package pricer import ( - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Pricer returns pricing information for chunk hashes. diff --git a/pkg/pricing/export_test.go b/pkg/pricing/export_test.go index 30b2ad2b2b8..90d8a7e6ed4 100644 --- a/pkg/pricing/export_test.go +++ b/pkg/pricing/export_test.go @@ -7,7 +7,7 @@ package pricing import ( "context" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) func (s *Service) Init(ctx context.Context, p p2p.Peer) error { diff --git a/pkg/pricing/pricing.go b/pkg/pricing/pricing.go index bb105e87e68..32ec1515936 100644 --- a/pkg/pricing/pricing.go +++ b/pkg/pricing/pricing.go @@ -11,11 +11,11 @@ import ( "math/big" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/pricing/pb" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/pricing/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/pricing/pricing_test.go b/pkg/pricing/pricing_test.go index 1a721216562..70f758353d1 100644 --- a/pkg/pricing/pricing_test.go +++ b/pkg/pricing/pricing_test.go @@ -11,13 +11,13 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/pricing" - "github.com/ethersphere/bee/pkg/pricing/pb" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/pricing" + "github.com/ethersphere/bee/v2/pkg/pricing/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type testThresholdObserver struct { diff --git a/pkg/pss/metrics.go b/pkg/pss/metrics.go index ebf6ccbb14a..108f516215f 100644 --- a/pkg/pss/metrics.go +++ b/pkg/pss/metrics.go @@ -5,7 +5,7 @@ package pss import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/pss/mining_test.go b/pkg/pss/mining_test.go index 6c205a8c9df..4dd94e45bb2 100644 --- a/pkg/pss/mining_test.go +++ b/pkg/pss/mining_test.go @@ -10,8 +10,8 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/pss" ) func newTargets(length, depth int) pss.Targets { diff --git a/pkg/pss/pss.go b/pkg/pss/pss.go index b8758f82a5e..3a09db0b633 100644 --- a/pkg/pss/pss.go +++ b/pkg/pss/pss.go @@ -17,11 +17,11 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pushsync" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pushsync" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/pss/pss_test.go b/pkg/pss/pss_test.go index d211b763117..1d04237bbaa 100644 --- a/pkg/pss/pss_test.go +++ b/pkg/pss/pss_test.go @@ -10,14 +10,14 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/pushsync" - pushsyncmock "github.com/ethersphere/bee/pkg/pushsync/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/pushsync" + pushsyncmock "github.com/ethersphere/bee/v2/pkg/pushsync/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestSend creates a trojan chunk and sends it using push sync diff --git a/pkg/pss/trojan.go b/pkg/pss/trojan.go index 4e742875333..b6b404f2389 100644 --- a/pkg/pss/trojan.go +++ b/pkg/pss/trojan.go @@ -16,11 +16,11 @@ import ( "io" "github.com/btcsuite/btcd/btcec/v2" - "github.com/ethersphere/bee/pkg/bmtpool" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/encryption/elgamal" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmtpool" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/encryption/elgamal" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/sync/errgroup" ) diff --git a/pkg/pss/trojan_test.go b/pkg/pss/trojan_test.go index 134ff2837b6..1d78b56c3aa 100644 --- a/pkg/pss/trojan_test.go +++ b/pkg/pss/trojan_test.go @@ -9,9 +9,9 @@ import ( "context" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/pss" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/pss" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestWrap(t *testing.T) { diff --git a/pkg/puller/export_test.go b/pkg/puller/export_test.go index 7d7b7b5b47a..b57ae396b3f 100644 --- a/pkg/puller/export_test.go +++ b/pkg/puller/export_test.go @@ -4,7 +4,7 @@ package puller -import "github.com/ethersphere/bee/pkg/swarm" +import "github.com/ethersphere/bee/v2/pkg/swarm" var PeerIntervalKey = peerIntervalKey diff --git a/pkg/puller/intervalstore/store_test.go b/pkg/puller/intervalstore/store_test.go index 5e1a5e0ef23..b4e2be192db 100644 --- a/pkg/puller/intervalstore/store_test.go +++ b/pkg/puller/intervalstore/store_test.go @@ -20,11 +20,11 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/statestore/leveldb" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/statestore/leveldb" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // TestInmemoryStore tests basic functionality of InmemoryStore. diff --git a/pkg/puller/metrics.go b/pkg/puller/metrics.go index 715a285be63..2b77ad5e016 100644 --- a/pkg/puller/metrics.go +++ b/pkg/puller/metrics.go @@ -5,7 +5,7 @@ package puller import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/puller/puller.go b/pkg/puller/puller.go index f2cfd15eee0..0523f9c8141 100644 --- a/pkg/puller/puller.go +++ b/pkg/puller/puller.go @@ -15,15 +15,15 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/puller/intervalstore" - "github.com/ethersphere/bee/pkg/pullsync" - "github.com/ethersphere/bee/pkg/rate" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/puller/intervalstore" + "github.com/ethersphere/bee/v2/pkg/pullsync" + "github.com/ethersphere/bee/v2/pkg/rate" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ratelimit "golang.org/x/time/rate" ) diff --git a/pkg/puller/puller_test.go b/pkg/puller/puller_test.go index f76fe292432..2be411f370f 100644 --- a/pkg/puller/puller_test.go +++ b/pkg/puller/puller_test.go @@ -11,17 +11,17 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/puller" - "github.com/ethersphere/bee/pkg/puller/intervalstore" - mockps "github.com/ethersphere/bee/pkg/pullsync/mock" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storage" - resMock "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - kadMock "github.com/ethersphere/bee/pkg/topology/kademlia/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/puller" + "github.com/ethersphere/bee/v2/pkg/puller/intervalstore" + mockps "github.com/ethersphere/bee/v2/pkg/pullsync/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + resMock "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + kadMock "github.com/ethersphere/bee/v2/pkg/topology/kademlia/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/pullsync/metrics.go b/pkg/pullsync/metrics.go index 24d11cf892f..340732f2114 100644 --- a/pkg/pullsync/metrics.go +++ b/pkg/pullsync/metrics.go @@ -5,7 +5,7 @@ package pullsync import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/pullsync/mock/pullsync.go b/pkg/pullsync/mock/pullsync.go index acd54b51ebf..bb77934924f 100644 --- a/pkg/pullsync/mock/pullsync.go +++ b/pkg/pullsync/mock/pullsync.go @@ -9,8 +9,8 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/pullsync" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/pullsync" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var _ pullsync.Interface = (*PullSyncMock)(nil) diff --git a/pkg/pullsync/pullsync.go b/pkg/pullsync/pullsync.go index 42691cbbe0c..5caa6e050a6 100644 --- a/pkg/pullsync/pullsync.go +++ b/pkg/pullsync/pullsync.go @@ -16,17 +16,17 @@ import ( "sync/atomic" "time" - "github.com/ethersphere/bee/pkg/bitvector" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pullsync/pb" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bitvector" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pullsync/pb" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "resenje.org/multex" "resenje.org/singleflight" ) diff --git a/pkg/pullsync/pullsync_test.go b/pkg/pullsync/pullsync_test.go index 70f958e63dd..bf25216519e 100644 --- a/pkg/pullsync/pullsync_test.go +++ b/pkg/pullsync/pullsync_test.go @@ -11,17 +11,17 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/pullsync" - "github.com/ethersphere/bee/pkg/storage" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer" - mock "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/pullsync" + "github.com/ethersphere/bee/v2/pkg/storage" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer" + mock "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/pusher/inflight.go b/pkg/pusher/inflight.go index 075dfe7e2fa..788872d2652 100644 --- a/pkg/pusher/inflight.go +++ b/pkg/pusher/inflight.go @@ -7,7 +7,7 @@ package pusher import ( "sync" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type inflight struct { diff --git a/pkg/pusher/metrics.go b/pkg/pusher/metrics.go index 093c6ca036e..03e55bad2b8 100644 --- a/pkg/pusher/metrics.go +++ b/pkg/pusher/metrics.go @@ -5,7 +5,7 @@ package pusher import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/pusher/pusher.go b/pkg/pusher/pusher.go index 457af2f58a3..c570d5ca1c6 100644 --- a/pkg/pusher/pusher.go +++ b/pkg/pusher/pusher.go @@ -17,14 +17,14 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pushsync" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pushsync" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" olog "github.com/opentracing/opentracing-go/log" diff --git a/pkg/pusher/pusher_test.go b/pkg/pusher/pusher_test.go index 6f361b93e6b..39132c624bf 100644 --- a/pkg/pusher/pusher_test.go +++ b/pkg/pusher/pusher_test.go @@ -14,18 +14,18 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/pushsync" - pushsyncmock "github.com/ethersphere/bee/pkg/pushsync/mock" - "github.com/ethersphere/bee/pkg/spinlock" - storage "github.com/ethersphere/bee/pkg/storage" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/pushsync" + pushsyncmock "github.com/ethersphere/bee/v2/pkg/pushsync/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + storage "github.com/ethersphere/bee/v2/pkg/storage" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // time to wait for received response from pushsync diff --git a/pkg/pushsync/metrics.go b/pkg/pushsync/metrics.go index 96161162df2..d182cbffc20 100644 --- a/pkg/pushsync/metrics.go +++ b/pkg/pushsync/metrics.go @@ -5,7 +5,7 @@ package pushsync import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/pushsync/mock/mock.go b/pkg/pushsync/mock/mock.go index 3d74f7f62c5..6afac9f493f 100644 --- a/pkg/pushsync/mock/mock.go +++ b/pkg/pushsync/mock/mock.go @@ -7,8 +7,8 @@ package mock import ( "context" - "github.com/ethersphere/bee/pkg/pushsync" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/pushsync" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type mock struct { diff --git a/pkg/pushsync/pushsync.go b/pkg/pushsync/pushsync.go index 8f1597384a6..6a74b159e0d 100644 --- a/pkg/pushsync/pushsync.go +++ b/pkg/pushsync/pushsync.go @@ -12,21 +12,21 @@ import ( "fmt" "time" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pricer" - "github.com/ethersphere/bee/pkg/pushsync/pb" - "github.com/ethersphere/bee/pkg/skippeers" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pricer" + "github.com/ethersphere/bee/v2/pkg/pushsync/pb" + "github.com/ethersphere/bee/v2/pkg/skippeers" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" olog "github.com/opentracing/opentracing-go/log" @@ -367,7 +367,7 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, origin bo if errors.Is(err, topology.ErrNotFound) { if ps.skipList.PruneExpiresAfter(ch.Address(), overDraftRefresh) == 0 { //no overdraft peers, we have depleted ALL peers if inflight == 0 { - if ps.fullNode && ps.topologyDriver.IsReachable() { + if ps.fullNode { if cac.Valid(ch) { go ps.unwrap(ch) } diff --git a/pkg/pushsync/pushsync_test.go b/pkg/pushsync/pushsync_test.go index 7b6c958ef7b..24e9fb45c9b 100644 --- a/pkg/pushsync/pushsync_test.go +++ b/pkg/pushsync/pushsync_test.go @@ -14,22 +14,22 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/accounting" - accountingmock "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/crypto" - cryptomock "github.com/ethersphere/bee/pkg/crypto/mock" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - pricermock "github.com/ethersphere/bee/pkg/pricer/mock" - "github.com/ethersphere/bee/pkg/pushsync" - "github.com/ethersphere/bee/pkg/pushsync/pb" - storage "github.com/ethersphere/bee/pkg/storage" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/accounting" + accountingmock "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/crypto" + cryptomock "github.com/ethersphere/bee/v2/pkg/crypto/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + pricermock "github.com/ethersphere/bee/v2/pkg/pricer/mock" + "github.com/ethersphere/bee/v2/pkg/pushsync" + "github.com/ethersphere/bee/v2/pkg/pushsync/pb" + storage "github.com/ethersphere/bee/v2/pkg/storage" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/mock" ) const ( diff --git a/pkg/rate/rate_test.go b/pkg/rate/rate_test.go index 6c9ac2b28c7..55df75daff1 100644 --- a/pkg/rate/rate_test.go +++ b/pkg/rate/rate_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/rate" + "github.com/ethersphere/bee/v2/pkg/rate" ) func TestRateFirstBucket(t *testing.T) { diff --git a/pkg/ratelimit/ratelimit_test.go b/pkg/ratelimit/ratelimit_test.go index 8f87bfd8fc5..e31fe5722bc 100644 --- a/pkg/ratelimit/ratelimit_test.go +++ b/pkg/ratelimit/ratelimit_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/ratelimit" + "github.com/ethersphere/bee/v2/pkg/ratelimit" ) func TestRateLimit(t *testing.T) { diff --git a/pkg/replicas/export_test.go b/pkg/replicas/export_test.go index 6e029f302c6..271ad71ed0b 100644 --- a/pkg/replicas/export_test.go +++ b/pkg/replicas/export_test.go @@ -4,7 +4,7 @@ package replicas -import "github.com/ethersphere/bee/pkg/storage" +import "github.com/ethersphere/bee/v2/pkg/storage" var ( Signer = signer diff --git a/pkg/replicas/getter.go b/pkg/replicas/getter.go index 26345919958..5dc42cb7c82 100644 --- a/pkg/replicas/getter.go +++ b/pkg/replicas/getter.go @@ -12,10 +12,10 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // ErrSwarmageddon is returned in case of a vis mayor called Swarmageddon. diff --git a/pkg/replicas/getter_test.go b/pkg/replicas/getter_test.go index 7435b0574fd..057daa8e300 100644 --- a/pkg/replicas/getter_test.go +++ b/pkg/replicas/getter_test.go @@ -14,12 +14,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/replicas" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/replicas" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type testGetter struct { diff --git a/pkg/replicas/putter.go b/pkg/replicas/putter.go index 4aa55b638f0..e62478119a3 100644 --- a/pkg/replicas/putter.go +++ b/pkg/replicas/putter.go @@ -11,10 +11,10 @@ import ( "errors" "sync" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // putter is the private implementation of the public storage.Putter interface diff --git a/pkg/replicas/putter_test.go b/pkg/replicas/putter_test.go index 7d05624ebca..b4e379352bb 100644 --- a/pkg/replicas/putter_test.go +++ b/pkg/replicas/putter_test.go @@ -14,12 +14,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/replicas" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/replicas" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/replicas/replica_test.go b/pkg/replicas/replica_test.go index ce56401d987..3a253f24f5b 100644 --- a/pkg/replicas/replica_test.go +++ b/pkg/replicas/replica_test.go @@ -10,10 +10,10 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // dispersed verifies that a set of addresses are maximally dispersed without repetition diff --git a/pkg/replicas/replicas.go b/pkg/replicas/replicas.go index fd45b28a3b1..01b326b76c8 100644 --- a/pkg/replicas/replicas.go +++ b/pkg/replicas/replicas.go @@ -13,9 +13,9 @@ package replicas import ( "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/resolver/cidv1/cidv1.go b/pkg/resolver/cidv1/cidv1.go index ded3b701ffe..097f06d28aa 100644 --- a/pkg/resolver/cidv1/cidv1.go +++ b/pkg/resolver/cidv1/cidv1.go @@ -7,8 +7,8 @@ package cidv1 import ( "fmt" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/ipfs/go-cid" "github.com/multiformats/go-multihash" ) diff --git a/pkg/resolver/cidv1/cidv1_test.go b/pkg/resolver/cidv1/cidv1_test.go index 92100f73903..a0bcc675bc0 100644 --- a/pkg/resolver/cidv1/cidv1_test.go +++ b/pkg/resolver/cidv1/cidv1_test.go @@ -8,9 +8,9 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/cidv1" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/cidv1" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestCIDResolver(t *testing.T) { diff --git a/pkg/resolver/client/client.go b/pkg/resolver/client/client.go index 988606135d8..71d301fa74b 100644 --- a/pkg/resolver/client/client.go +++ b/pkg/resolver/client/client.go @@ -5,7 +5,7 @@ package client import ( - "github.com/ethersphere/bee/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver" ) // Interface is a resolver client that can connect/disconnect to an external diff --git a/pkg/resolver/client/ens/ens.go b/pkg/resolver/client/ens/ens.go index bd190fba7fb..38c7432e979 100644 --- a/pkg/resolver/client/ens/ens.go +++ b/pkg/resolver/client/ens/ens.go @@ -14,9 +14,9 @@ import ( "github.com/ethereum/go-ethereum/ethclient" goens "github.com/wealdtech/go-ens/v3" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/client" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/client" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/resolver/client/ens/ens_integration_test.go b/pkg/resolver/client/ens/ens_integration_test.go index 139347c2db8..f5aa9b1d9d7 100644 --- a/pkg/resolver/client/ens/ens_integration_test.go +++ b/pkg/resolver/client/ens/ens_integration_test.go @@ -10,8 +10,8 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/resolver/client/ens" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestENSIntegration(t *testing.T) { diff --git a/pkg/resolver/client/ens/ens_test.go b/pkg/resolver/client/ens/ens_test.go index 3ecd67be4ae..aa0d0c0cb64 100644 --- a/pkg/resolver/client/ens/ens_test.go +++ b/pkg/resolver/client/ens/ens_test.go @@ -13,9 +13,9 @@ import ( "github.com/ethereum/go-ethereum/rpc" goens "github.com/wealdtech/go-ens/v3" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/client/ens" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestNewENSClient(t *testing.T) { diff --git a/pkg/resolver/client/mock/mock.go b/pkg/resolver/client/mock/mock.go index d3b24fd8559..01bbdf0cf99 100644 --- a/pkg/resolver/client/mock/mock.go +++ b/pkg/resolver/client/mock/mock.go @@ -5,8 +5,8 @@ package mock import ( - "github.com/ethersphere/bee/pkg/resolver/client" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/resolver/client" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Ensure mock Client implements the Client interface. diff --git a/pkg/resolver/mock/resolver.go b/pkg/resolver/mock/resolver.go index 547abd6270b..bbae8ff2702 100644 --- a/pkg/resolver/mock/resolver.go +++ b/pkg/resolver/mock/resolver.go @@ -7,8 +7,8 @@ package mock import ( "fmt" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/client/ens" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" ) // Assure mock Resolver implements the Resolver interface. diff --git a/pkg/resolver/multiresolver/config_test.go b/pkg/resolver/multiresolver/config_test.go index 9ee417f6d3d..9b4c2d502c2 100644 --- a/pkg/resolver/multiresolver/config_test.go +++ b/pkg/resolver/multiresolver/config_test.go @@ -8,7 +8,7 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/resolver/multiresolver" + "github.com/ethersphere/bee/v2/pkg/resolver/multiresolver" ) func TestParseConnectionStrings(t *testing.T) { diff --git a/pkg/resolver/multiresolver/export_test.go b/pkg/resolver/multiresolver/export_test.go index 5e2624774c8..e3d260f74f9 100644 --- a/pkg/resolver/multiresolver/export_test.go +++ b/pkg/resolver/multiresolver/export_test.go @@ -4,7 +4,7 @@ package multiresolver -import "github.com/ethersphere/bee/pkg/log" +import "github.com/ethersphere/bee/v2/pkg/log" func GetLogger(mr *MultiResolver) log.Logger { return mr.logger diff --git a/pkg/resolver/multiresolver/multiresolver.go b/pkg/resolver/multiresolver/multiresolver.go index 97472d47807..31111931bb2 100644 --- a/pkg/resolver/multiresolver/multiresolver.go +++ b/pkg/resolver/multiresolver/multiresolver.go @@ -10,10 +10,10 @@ import ( "path" "strings" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/cidv1" - "github.com/ethersphere/bee/pkg/resolver/client/ens" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/cidv1" + "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" "github.com/hashicorp/go-multierror" ) diff --git a/pkg/resolver/multiresolver/multiresolver_test.go b/pkg/resolver/multiresolver/multiresolver_test.go index a6d31f796e7..326cbb69a04 100644 --- a/pkg/resolver/multiresolver/multiresolver_test.go +++ b/pkg/resolver/multiresolver/multiresolver_test.go @@ -10,11 +10,11 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/resolver" - "github.com/ethersphere/bee/pkg/resolver/mock" - "github.com/ethersphere/bee/pkg/resolver/multiresolver" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/resolver" + "github.com/ethersphere/bee/v2/pkg/resolver/mock" + "github.com/ethersphere/bee/v2/pkg/resolver/multiresolver" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Address = swarm.Address diff --git a/pkg/resolver/resolver.go b/pkg/resolver/resolver.go index 1d38e987165..043dcaf87e0 100644 --- a/pkg/resolver/resolver.go +++ b/pkg/resolver/resolver.go @@ -8,7 +8,7 @@ import ( "errors" "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Address is the swarm bzz address. diff --git a/pkg/retrieval/export_test.go b/pkg/retrieval/export_test.go index 4ba5bc1fdac..cc53399f636 100644 --- a/pkg/retrieval/export_test.go +++ b/pkg/retrieval/export_test.go @@ -7,8 +7,8 @@ package retrieval import ( "context" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func (s *Service) Handler(ctx context.Context, p p2p.Peer, stream p2p.Stream) error { diff --git a/pkg/retrieval/main_test.go b/pkg/retrieval/main_test.go index eec426389d0..8be3983b65d 100644 --- a/pkg/retrieval/main_test.go +++ b/pkg/retrieval/main_test.go @@ -14,7 +14,7 @@ func TestMain(m *testing.M) { goleak.VerifyTestMain( m, // pkg/p2p package has some leak issues, we ignore them here as they are not in current scope - goleak.IgnoreTopFunction("github.com/ethersphere/bee/pkg/p2p/protobuf.Reader.ReadMsgWithContext"), - goleak.IgnoreTopFunction("github.com/ethersphere/bee/pkg/p2p/streamtest.(*record).Read"), + goleak.IgnoreTopFunction("github.com/ethersphere/bee/v2/pkg/p2p/protobuf.Reader.ReadMsgWithContext"), + goleak.IgnoreTopFunction("github.com/ethersphere/bee/v2/pkg/p2p/streamtest.(*record).Read"), ) } diff --git a/pkg/retrieval/metrics.go b/pkg/retrieval/metrics.go index 30881b77361..f88f11d6c06 100644 --- a/pkg/retrieval/metrics.go +++ b/pkg/retrieval/metrics.go @@ -7,7 +7,7 @@ package retrieval import ( "github.com/prometheus/client_golang/prometheus" - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" ) type metrics struct { diff --git a/pkg/retrieval/retrieval.go b/pkg/retrieval/retrieval.go index cae78558df9..fc3a0092c69 100644 --- a/pkg/retrieval/retrieval.go +++ b/pkg/retrieval/retrieval.go @@ -14,19 +14,19 @@ import ( "fmt" "time" - "github.com/ethersphere/bee/pkg/accounting" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/pricer" - pb "github.com/ethersphere/bee/pkg/retrieval/pb" - "github.com/ethersphere/bee/pkg/skippeers" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/accounting" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/pricer" + pb "github.com/ethersphere/bee/v2/pkg/retrieval/pb" + "github.com/ethersphere/bee/v2/pkg/skippeers" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" olog "github.com/opentracing/opentracing-go/log" @@ -122,7 +122,7 @@ func (s *Service) Protocol() p2p.ProtocolSpec { } const ( - retrieveChunkTimeout = time.Second * 30 + RetrieveChunkTimeout = time.Second * 30 preemptiveInterval = time.Second overDraftRefresh = time.Millisecond * 600 skiplistDur = time.Minute @@ -320,7 +320,7 @@ func (s *Service) retrieveChunk(ctx context.Context, quit chan struct{}, chunkAd } }() - ctx, cancel := context.WithTimeout(ctx, retrieveChunkTimeout) + ctx, cancel := context.WithTimeout(ctx, RetrieveChunkTimeout) defer cancel() stream, err := s.streamer.NewStream(ctx, peer, nil, protocolName, protocolVersion, streamName) @@ -425,7 +425,7 @@ func (s *Service) closestPeer(addr swarm.Address, skipPeers []swarm.Address, all } func (s *Service) handler(p2pctx context.Context, p p2p.Peer, stream p2p.Stream) (err error) { - ctx, cancel := context.WithTimeout(p2pctx, retrieveChunkTimeout) + ctx, cancel := context.WithTimeout(p2pctx, RetrieveChunkTimeout) defer cancel() w, r := protobuf.NewWriterAndReader(stream) diff --git a/pkg/retrieval/retrieval_test.go b/pkg/retrieval/retrieval_test.go index c4156583cb2..05f44abeef8 100644 --- a/pkg/retrieval/retrieval_test.go +++ b/pkg/retrieval/retrieval_test.go @@ -15,26 +15,26 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/accounting" - accountingmock "github.com/ethersphere/bee/pkg/accounting/mock" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/pricer" - pricermock "github.com/ethersphere/bee/pkg/pricer/mock" - "github.com/ethersphere/bee/pkg/retrieval" - pb "github.com/ethersphere/bee/pkg/retrieval/pb" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - testingc "github.com/ethersphere/bee/pkg/storage/testing" - storemock "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" - - topologymock "github.com/ethersphere/bee/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/accounting" + accountingmock "github.com/ethersphere/bee/v2/pkg/accounting/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/pricer" + pricermock "github.com/ethersphere/bee/v2/pkg/pricer/mock" + "github.com/ethersphere/bee/v2/pkg/retrieval" + pb "github.com/ethersphere/bee/v2/pkg/retrieval/pb" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + testingc "github.com/ethersphere/bee/v2/pkg/storage/testing" + storemock "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" + + topologymock "github.com/ethersphere/bee/v2/pkg/topology/mock" ) var ( diff --git a/pkg/salud/metrics.go b/pkg/salud/metrics.go index db5309b9dad..c9a3b68a17f 100644 --- a/pkg/salud/metrics.go +++ b/pkg/salud/metrics.go @@ -5,7 +5,7 @@ package salud import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/salud/salud.go b/pkg/salud/salud.go index d9a661c40af..c6a46500cb0 100644 --- a/pkg/salud/salud.go +++ b/pkg/salud/salud.go @@ -12,11 +12,11 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" "go.uber.org/atomic" ) diff --git a/pkg/salud/salud_test.go b/pkg/salud/salud_test.go index 58a5ae38bb6..b408f06b95c 100644 --- a/pkg/salud/salud_test.go +++ b/pkg/salud/salud_test.go @@ -10,13 +10,13 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/salud" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/status" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - topMock "github.com/ethersphere/bee/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/salud" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/status" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + topMock "github.com/ethersphere/bee/v2/pkg/topology/mock" ) type peer struct { diff --git a/pkg/settlement/interface.go b/pkg/settlement/interface.go index 85daae6c212..f24ec60ce69 100644 --- a/pkg/settlement/interface.go +++ b/pkg/settlement/interface.go @@ -8,7 +8,7 @@ import ( "errors" "math/big" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/settlement/pseudosettle/export_test.go b/pkg/settlement/pseudosettle/export_test.go index 24cac963405..3748cbf03f6 100644 --- a/pkg/settlement/pseudosettle/export_test.go +++ b/pkg/settlement/pseudosettle/export_test.go @@ -8,7 +8,7 @@ import ( "context" "time" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) func (s *Service) SetTimeNow(f func() time.Time) { diff --git a/pkg/settlement/pseudosettle/metrics.go b/pkg/settlement/pseudosettle/metrics.go index b3530500be0..971795cb6a8 100644 --- a/pkg/settlement/pseudosettle/metrics.go +++ b/pkg/settlement/pseudosettle/metrics.go @@ -5,7 +5,7 @@ package pseudosettle import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/settlement/pseudosettle/pseudosettle.go b/pkg/settlement/pseudosettle/pseudosettle.go index 75fe647968f..24531b84641 100644 --- a/pkg/settlement/pseudosettle/pseudosettle.go +++ b/pkg/settlement/pseudosettle/pseudosettle.go @@ -13,13 +13,13 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/settlement" - pb "github.com/ethersphere/bee/pkg/settlement/pseudosettle/pb" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/settlement" + pb "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle/pb" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/settlement/pseudosettle/pseudosettle_test.go b/pkg/settlement/pseudosettle/pseudosettle_test.go index c12144623e3..397592e9d96 100644 --- a/pkg/settlement/pseudosettle/pseudosettle_test.go +++ b/pkg/settlement/pseudosettle/pseudosettle_test.go @@ -13,17 +13,17 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - mockp2p "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle" - "github.com/ethersphere/bee/pkg/settlement/pseudosettle/pb" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + mockp2p "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle" + "github.com/ethersphere/bee/v2/pkg/settlement/pseudosettle/pb" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) type testObserver struct { diff --git a/pkg/settlement/swap/addressbook.go b/pkg/settlement/swap/addressbook.go index 08d6c4ed778..5cf0aad45f8 100644 --- a/pkg/settlement/swap/addressbook.go +++ b/pkg/settlement/swap/addressbook.go @@ -9,8 +9,8 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/settlement/swap/chequebook/cashout.go b/pkg/settlement/swap/chequebook/cashout.go index 157af01ad56..245b16ca6aa 100644 --- a/pkg/settlement/swap/chequebook/cashout.go +++ b/pkg/settlement/swap/chequebook/cashout.go @@ -14,9 +14,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/transaction" ) var ( diff --git a/pkg/settlement/swap/chequebook/cashout_test.go b/pkg/settlement/swap/chequebook/cashout_test.go index 2aa3dc992c5..dc195e6a465 100644 --- a/pkg/settlement/swap/chequebook/cashout_test.go +++ b/pkg/settlement/swap/chequebook/cashout_test.go @@ -11,12 +11,12 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - chequestoremock "github.com/ethersphere/bee/pkg/settlement/swap/chequestore/mock" - storemock "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + chequestoremock "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequestore/mock" + storemock "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/settlement/swap/chequebook/cheque.go b/pkg/settlement/swap/chequebook/cheque.go index 01e282d5e1c..4ff118c22ec 100644 --- a/pkg/settlement/swap/chequebook/cheque.go +++ b/pkg/settlement/swap/chequebook/cheque.go @@ -11,8 +11,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/eip712" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" ) // Cheque represents a cheque for a SimpleSwap chequebook diff --git a/pkg/settlement/swap/chequebook/cheque_test.go b/pkg/settlement/swap/chequebook/cheque_test.go index dedcd055d14..f0aac83a43c 100644 --- a/pkg/settlement/swap/chequebook/cheque_test.go +++ b/pkg/settlement/swap/chequebook/cheque_test.go @@ -12,10 +12,10 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/crypto/eip712" - signermock "github.com/ethersphere/bee/pkg/crypto/mock" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/crypto/eip712" + signermock "github.com/ethersphere/bee/v2/pkg/crypto/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" ) func TestSignCheque(t *testing.T) { diff --git a/pkg/settlement/swap/chequebook/chequebook.go b/pkg/settlement/swap/chequebook/chequebook.go index 75d8e7876ca..ee04a818f93 100644 --- a/pkg/settlement/swap/chequebook/chequebook.go +++ b/pkg/settlement/swap/chequebook/chequebook.go @@ -13,11 +13,11 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/settlement/swap/chequebook/chequebook_test.go b/pkg/settlement/swap/chequebook/chequebook_test.go index ca3f705e80e..f9e656cd323 100644 --- a/pkg/settlement/swap/chequebook/chequebook_test.go +++ b/pkg/settlement/swap/chequebook/chequebook_test.go @@ -13,11 +13,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - storemock "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/transaction" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + storemock "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/transaction" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" ) func TestChequebookAddress(t *testing.T) { diff --git a/pkg/settlement/swap/chequebook/chequestore.go b/pkg/settlement/swap/chequebook/chequestore.go index 100e60774fb..8db2e6e3a28 100644 --- a/pkg/settlement/swap/chequebook/chequestore.go +++ b/pkg/settlement/swap/chequebook/chequestore.go @@ -13,9 +13,9 @@ import ( "sync" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/transaction" ) const ( diff --git a/pkg/settlement/swap/chequebook/chequestore_test.go b/pkg/settlement/swap/chequebook/chequestore_test.go index be636e67356..57cd138a4f1 100644 --- a/pkg/settlement/swap/chequebook/chequestore_test.go +++ b/pkg/settlement/swap/chequebook/chequestore_test.go @@ -11,9 +11,9 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - storemock "github.com/ethersphere/bee/pkg/statestore/mock" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + storemock "github.com/ethersphere/bee/v2/pkg/statestore/mock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" ) func TestReceiveCheque(t *testing.T) { diff --git a/pkg/settlement/swap/chequebook/common_test.go b/pkg/settlement/swap/chequebook/common_test.go index ef3b6988c25..717d205819f 100644 --- a/pkg/settlement/swap/chequebook/common_test.go +++ b/pkg/settlement/swap/chequebook/common_test.go @@ -9,7 +9,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" ) type chequeSignerMock struct { diff --git a/pkg/settlement/swap/chequebook/contract.go b/pkg/settlement/swap/chequebook/contract.go index 32ef2eba128..b655c511b84 100644 --- a/pkg/settlement/swap/chequebook/contract.go +++ b/pkg/settlement/swap/chequebook/contract.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) type chequebookContract struct { diff --git a/pkg/settlement/swap/chequebook/factory.go b/pkg/settlement/swap/chequebook/factory.go index 0f8bf3aea2f..27bd38db3b4 100644 --- a/pkg/settlement/swap/chequebook/factory.go +++ b/pkg/settlement/swap/chequebook/factory.go @@ -11,9 +11,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" "golang.org/x/net/context" ) diff --git a/pkg/settlement/swap/chequebook/factory_test.go b/pkg/settlement/swap/chequebook/factory_test.go index d7223330ea4..16667ec303c 100644 --- a/pkg/settlement/swap/chequebook/factory_test.go +++ b/pkg/settlement/swap/chequebook/factory_test.go @@ -12,11 +12,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/settlement/swap/chequebook/init.go b/pkg/settlement/swap/chequebook/init.go index 19bfc3c56b0..de643ecaaf2 100644 --- a/pkg/settlement/swap/chequebook/init.go +++ b/pkg/settlement/swap/chequebook/init.go @@ -13,12 +13,12 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/transaction" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/transaction" ) const ( diff --git a/pkg/settlement/swap/chequebook/mock/chequebook.go b/pkg/settlement/swap/chequebook/mock/chequebook.go index 79ce70a9a57..8950046c022 100644 --- a/pkg/settlement/swap/chequebook/mock/chequebook.go +++ b/pkg/settlement/swap/chequebook/mock/chequebook.go @@ -10,7 +10,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" ) // Service is the mock chequebook service. diff --git a/pkg/settlement/swap/chequestore/mock/chequestore.go b/pkg/settlement/swap/chequestore/mock/chequestore.go index 616063053aa..08215cecaf0 100644 --- a/pkg/settlement/swap/chequestore/mock/chequestore.go +++ b/pkg/settlement/swap/chequestore/mock/chequestore.go @@ -9,7 +9,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" ) // Service is the mock chequeStore service. diff --git a/pkg/settlement/swap/erc20/erc20.go b/pkg/settlement/swap/erc20/erc20.go index 510cc43769b..2733fa51887 100644 --- a/pkg/settlement/swap/erc20/erc20.go +++ b/pkg/settlement/swap/erc20/erc20.go @@ -11,9 +11,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/settlement/swap/erc20/erc20_test.go b/pkg/settlement/swap/erc20/erc20_test.go index a51652ccdd0..e5752aca5df 100644 --- a/pkg/settlement/swap/erc20/erc20_test.go +++ b/pkg/settlement/swap/erc20/erc20_test.go @@ -10,9 +10,9 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/settlement/swap/erc20/mock/erc20.go b/pkg/settlement/swap/erc20/mock/erc20.go index 8d7652d2fb3..d4f2ac1a5e5 100644 --- a/pkg/settlement/swap/erc20/mock/erc20.go +++ b/pkg/settlement/swap/erc20/mock/erc20.go @@ -10,7 +10,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" ) type Service struct { diff --git a/pkg/settlement/swap/headers/utilities.go b/pkg/settlement/swap/headers/utilities.go index ee9709147a0..a940c45b7c3 100644 --- a/pkg/settlement/swap/headers/utilities.go +++ b/pkg/settlement/swap/headers/utilities.go @@ -8,7 +8,7 @@ import ( "errors" "math/big" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) const ( diff --git a/pkg/settlement/swap/headers/utilities_test.go b/pkg/settlement/swap/headers/utilities_test.go index a16087646e6..0cb074ac00f 100644 --- a/pkg/settlement/swap/headers/utilities_test.go +++ b/pkg/settlement/swap/headers/utilities_test.go @@ -9,8 +9,8 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/p2p" - swap "github.com/ethersphere/bee/pkg/settlement/swap/headers" + "github.com/ethersphere/bee/v2/pkg/p2p" + swap "github.com/ethersphere/bee/v2/pkg/settlement/swap/headers" ) func TestParseSettlementResponseHeaders(t *testing.T) { diff --git a/pkg/settlement/swap/metrics.go b/pkg/settlement/swap/metrics.go index ca1870645d1..d3f50770d54 100644 --- a/pkg/settlement/swap/metrics.go +++ b/pkg/settlement/swap/metrics.go @@ -5,7 +5,7 @@ package swap import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/settlement/swap/mock/swap.go b/pkg/settlement/swap/mock/swap.go index 8007ddd0c3a..2318194f962 100644 --- a/pkg/settlement/swap/mock/swap.go +++ b/pkg/settlement/swap/mock/swap.go @@ -10,10 +10,10 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Service struct { diff --git a/pkg/settlement/swap/priceoracle/priceoracle.go b/pkg/settlement/swap/priceoracle/priceoracle.go index 06ab07d5e6c..0ba49e6eff2 100644 --- a/pkg/settlement/swap/priceoracle/priceoracle.go +++ b/pkg/settlement/swap/priceoracle/priceoracle.go @@ -13,9 +13,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-price-oracle-abi/priceoracleabi" ) diff --git a/pkg/settlement/swap/priceoracle/priceoracle_test.go b/pkg/settlement/swap/priceoracle/priceoracle_test.go index 2404d991058..58fa344b675 100644 --- a/pkg/settlement/swap/priceoracle/priceoracle_test.go +++ b/pkg/settlement/swap/priceoracle/priceoracle_test.go @@ -10,10 +10,10 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/settlement/swap/priceoracle" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-price-oracle-abi/priceoracleabi" ) diff --git a/pkg/settlement/swap/swap.go b/pkg/settlement/swap/swap.go index a47e70c0bee..4e7f99bd060 100644 --- a/pkg/settlement/swap/swap.go +++ b/pkg/settlement/swap/swap.go @@ -11,13 +11,13 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/settlement" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/settlement" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/settlement/swap/swap_test.go b/pkg/settlement/swap/swap_test.go index a7e55198dda..2f4d748740e 100644 --- a/pkg/settlement/swap/swap_test.go +++ b/pkg/settlement/swap/swap_test.go @@ -12,15 +12,15 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/settlement/swap" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - mockchequebook "github.com/ethersphere/bee/pkg/settlement/swap/chequebook/mock" - mockchequestore "github.com/ethersphere/bee/pkg/settlement/swap/chequestore/mock" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol" - mockstore "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/settlement/swap" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + mockchequebook "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock" + mockchequestore "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequestore/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol" + mockstore "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type swapProtocolMock struct { diff --git a/pkg/settlement/swap/swapprotocol/export_test.go b/pkg/settlement/swap/swapprotocol/export_test.go index 46b81c598b9..31fc9e6b79f 100644 --- a/pkg/settlement/swap/swapprotocol/export_test.go +++ b/pkg/settlement/swap/swapprotocol/export_test.go @@ -6,7 +6,7 @@ package swapprotocol import ( "context" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p" ) func (s *Service) Init(ctx context.Context, p p2p.Peer) error { diff --git a/pkg/settlement/swap/swapprotocol/swapprotocol.go b/pkg/settlement/swap/swapprotocol/swapprotocol.go index 58318826d23..45715621208 100644 --- a/pkg/settlement/swap/swapprotocol/swapprotocol.go +++ b/pkg/settlement/swap/swapprotocol/swapprotocol.go @@ -13,14 +13,14 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - swap "github.com/ethersphere/bee/pkg/settlement/swap/headers" - "github.com/ethersphere/bee/pkg/settlement/swap/priceoracle" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol/pb" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + swap "github.com/ethersphere/bee/v2/pkg/settlement/swap/headers" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/settlement/swap/swapprotocol/swapprotocol_test.go b/pkg/settlement/swap/swapprotocol/swapprotocol_test.go index 482de2e0796..45445132466 100644 --- a/pkg/settlement/swap/swapprotocol/swapprotocol_test.go +++ b/pkg/settlement/swap/swapprotocol/swapprotocol_test.go @@ -14,16 +14,16 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/settlement/swap/chequebook" - swapmock "github.com/ethersphere/bee/pkg/settlement/swap/mock" - priceoraclemock "github.com/ethersphere/bee/pkg/settlement/swap/priceoracle/mock" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol" - "github.com/ethersphere/bee/pkg/settlement/swap/swapprotocol/pb" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook" + swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock" + priceoraclemock "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle/mock" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/swapprotocol/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestEmitCheques(t *testing.T) { diff --git a/pkg/sharky/metrics.go b/pkg/sharky/metrics.go index 8da4ed99163..53db4675b06 100644 --- a/pkg/sharky/metrics.go +++ b/pkg/sharky/metrics.go @@ -5,7 +5,7 @@ package sharky import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/sharky/recovery_test.go b/pkg/sharky/recovery_test.go index 3cd96481231..1cc7ae3d55e 100644 --- a/pkg/sharky/recovery_test.go +++ b/pkg/sharky/recovery_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/sharky" ) func TestMissingShard(t *testing.T) { diff --git a/pkg/sharky/shard_test.go b/pkg/sharky/shard_test.go index cb85607d488..567a0cf9ad3 100644 --- a/pkg/sharky/shard_test.go +++ b/pkg/sharky/shard_test.go @@ -8,7 +8,7 @@ import ( "math" "testing" - "github.com/ethersphere/bee/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/sharky" ) func TestLocationSerialization(t *testing.T) { diff --git a/pkg/sharky/sharky_test.go b/pkg/sharky/sharky_test.go index 8ae75f5b9ca..1e3aadd78b4 100644 --- a/pkg/sharky/sharky_test.go +++ b/pkg/sharky/sharky_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/sharky" "golang.org/x/sync/errgroup" ) diff --git a/pkg/shed/db_test.go b/pkg/shed/db_test.go index 754f133a1a7..7bed4610504 100644 --- a/pkg/shed/db_test.go +++ b/pkg/shed/db_test.go @@ -19,7 +19,7 @@ package shed import ( "testing" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // TestNewDB constructs a new DB diff --git a/pkg/shed/example_store_test.go b/pkg/shed/example_store_test.go index fd8cae0f53a..911fe389d2a 100644 --- a/pkg/shed/example_store_test.go +++ b/pkg/shed/example_store_test.go @@ -25,10 +25,10 @@ import ( "log" "time" - shed2 "github.com/ethersphere/bee/pkg/shed" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" + shed2 "github.com/ethersphere/bee/v2/pkg/shed" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/syndtr/goleveldb/leveldb" ) diff --git a/pkg/shed/metrics.go b/pkg/shed/metrics.go index e922e39594e..58820407c9d 100644 --- a/pkg/shed/metrics.go +++ b/pkg/shed/metrics.go @@ -5,7 +5,7 @@ package shed import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/skippeers/skippeers.go b/pkg/skippeers/skippeers.go index c512e5e0ae8..f89a49364c4 100644 --- a/pkg/skippeers/skippeers.go +++ b/pkg/skippeers/skippeers.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const MaxDuration time.Duration = math.MaxInt64 diff --git a/pkg/skippeers/skippeers_test.go b/pkg/skippeers/skippeers_test.go index a6201deffc3..1f52636b91c 100644 --- a/pkg/skippeers/skippeers_test.go +++ b/pkg/skippeers/skippeers_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/skippeers" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/skippeers" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestPruneExpiresAfter(t *testing.T) { diff --git a/pkg/soc/soc.go b/pkg/soc/soc.go index 00e069f310e..65b44f2e66e 100644 --- a/pkg/soc/soc.go +++ b/pkg/soc/soc.go @@ -10,9 +10,9 @@ import ( "bytes" "errors" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/soc/soc_test.go b/pkg/soc/soc_test.go index e4f6fb4e199..6346242fa1b 100644 --- a/pkg/soc/soc_test.go +++ b/pkg/soc/soc_test.go @@ -12,10 +12,10 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestNew(t *testing.T) { @@ -47,6 +47,41 @@ func TestNew(t *testing.T) { } } +func TestReplica(t *testing.T) { + sig, err := hex.DecodeString("5acd384febc133b7b245e5ddc62d82d2cded9182d2716126cd8844509af65a053deb418208027f548e3e88343af6f84a8772fb3cebc0a1833a0ea7ec0c1348311b") + if err != nil { + t.Fatal(err) + } + + payload := []byte("foo") + ch, err := cac.New(payload) + if err != nil { + t.Fatal(err) + } + + id := make([]byte, swarm.HashSize) + s, err := soc.NewSigned(id, ch, swarm.ReplicasOwner, sig) + if err != nil { + t.Fatal(err) + } + + ch, err = s.Chunk() + if err != nil { + t.Fatal(err) + } + sch, err := soc.FromChunk(swarm.NewChunk(swarm.EmptyAddress, ch.Data())) + if err != nil { + t.Fatal(err) + } + ch, err = sch.Chunk() + if err != nil { + t.Fatal(err) + } + if !soc.Valid(ch) { + t.Fatal("invalid soc chunk") + } +} + func TestNewSigned(t *testing.T) { t.Parallel() diff --git a/pkg/soc/testing/soc.go b/pkg/soc/testing/soc.go index c8449e820ce..e5325f464b1 100644 --- a/pkg/soc/testing/soc.go +++ b/pkg/soc/testing/soc.go @@ -7,10 +7,10 @@ package testing import ( "testing" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // MockSOC defines a mocked SOC with exported fields for easy testing. diff --git a/pkg/soc/validator.go b/pkg/soc/validator.go index db0c388808e..06f2fb72e0a 100644 --- a/pkg/soc/validator.go +++ b/pkg/soc/validator.go @@ -7,7 +7,7 @@ package soc import ( "bytes" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Valid checks if the chunk is a valid single-owner chunk. diff --git a/pkg/soc/validator_test.go b/pkg/soc/validator_test.go index 695d43cc46f..e6913000149 100644 --- a/pkg/soc/validator_test.go +++ b/pkg/soc/validator_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestValid verifies that the validator can detect diff --git a/pkg/spinlock/wait_test.go b/pkg/spinlock/wait_test.go index e38aef2e650..090543723b1 100644 --- a/pkg/spinlock/wait_test.go +++ b/pkg/spinlock/wait_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/spinlock" ) func TestWait(t *testing.T) { diff --git a/pkg/statestore/leveldb/leveldb.go b/pkg/statestore/leveldb/leveldb.go index 65d2cc471ac..08d757ce288 100644 --- a/pkg/statestore/leveldb/leveldb.go +++ b/pkg/statestore/leveldb/leveldb.go @@ -10,8 +10,8 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" ldberr "github.com/syndtr/goleveldb/leveldb/errors" diff --git a/pkg/statestore/leveldb/leveldb_test.go b/pkg/statestore/leveldb/leveldb_test.go index 2e18b9f6b61..fffd43ac5f1 100644 --- a/pkg/statestore/leveldb/leveldb_test.go +++ b/pkg/statestore/leveldb/leveldb_test.go @@ -7,10 +7,10 @@ package leveldb_test import ( "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/statestore/leveldb" - "github.com/ethersphere/bee/pkg/statestore/test" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/statestore/leveldb" + "github.com/ethersphere/bee/v2/pkg/statestore/test" + "github.com/ethersphere/bee/v2/pkg/storage" ) func TestPersistentStateStore(t *testing.T) { diff --git a/pkg/statestore/mock/store.go b/pkg/statestore/mock/store.go index 964c5c4ef61..a3d34542f2c 100644 --- a/pkg/statestore/mock/store.go +++ b/pkg/statestore/mock/store.go @@ -10,7 +10,7 @@ import ( "strings" "sync" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) var _ storage.StateStorer = (*store)(nil) diff --git a/pkg/statestore/mock/store_test.go b/pkg/statestore/mock/store_test.go index fc891136376..330261dbba5 100644 --- a/pkg/statestore/mock/store_test.go +++ b/pkg/statestore/mock/store_test.go @@ -7,9 +7,9 @@ package mock_test import ( "testing" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/statestore/test" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/statestore/test" + "github.com/ethersphere/bee/v2/pkg/storage" ) func TestMockStateStore(t *testing.T) { diff --git a/pkg/statestore/storeadapter/migration.go b/pkg/statestore/storeadapter/migration.go index 171f31ccf57..ac5dbd457e2 100644 --- a/pkg/statestore/storeadapter/migration.go +++ b/pkg/statestore/storeadapter/migration.go @@ -7,8 +7,8 @@ package storeadapter import ( "strings" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/migration" ) func allSteps() migration.Steps { diff --git a/pkg/statestore/storeadapter/storeadapter.go b/pkg/statestore/storeadapter/storeadapter.go index 03327e83cdd..a923f60a0f8 100644 --- a/pkg/statestore/storeadapter/storeadapter.go +++ b/pkg/statestore/storeadapter/storeadapter.go @@ -10,9 +10,9 @@ import ( "fmt" "strings" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/migration" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" ) // stateStoreNamespace is the namespace used for state storage. diff --git a/pkg/statestore/storeadapter/storeadapter_test.go b/pkg/statestore/storeadapter/storeadapter_test.go index 5065a5158da..f90db7b7ce1 100644 --- a/pkg/statestore/storeadapter/storeadapter_test.go +++ b/pkg/statestore/storeadapter/storeadapter_test.go @@ -7,11 +7,11 @@ package storeadapter_test import ( "testing" - "github.com/ethersphere/bee/pkg/statestore/storeadapter" - "github.com/ethersphere/bee/pkg/statestore/test" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/statestore/storeadapter" + "github.com/ethersphere/bee/v2/pkg/statestore/test" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" ) func TestStateStoreAdapter(t *testing.T) { diff --git a/pkg/statestore/test/store.go b/pkg/statestore/test/store.go index ee5050b8633..10bc9c15c83 100644 --- a/pkg/statestore/test/store.go +++ b/pkg/statestore/test/store.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) const ( diff --git a/pkg/status/internal/pb/status.pb.go b/pkg/status/internal/pb/status.pb.go index a4f6ecf2ba5..868cc0f11e0 100644 --- a/pkg/status/internal/pb/status.pb.go +++ b/pkg/status/internal/pb/status.pb.go @@ -64,14 +64,15 @@ var xxx_messageInfo_Get proto.InternalMessageInfo // the appropriate values that are a snapshot of the current state // of the running node. type Snapshot struct { - ReserveSize uint64 `protobuf:"varint,1,opt,name=ReserveSize,proto3" json:"ReserveSize,omitempty"` - PullsyncRate float64 `protobuf:"fixed64,2,opt,name=PullsyncRate,proto3" json:"PullsyncRate,omitempty"` - StorageRadius uint32 `protobuf:"varint,3,opt,name=StorageRadius,proto3" json:"StorageRadius,omitempty"` - ConnectedPeers uint64 `protobuf:"varint,4,opt,name=ConnectedPeers,proto3" json:"ConnectedPeers,omitempty"` - NeighborhoodSize uint64 `protobuf:"varint,5,opt,name=NeighborhoodSize,proto3" json:"NeighborhoodSize,omitempty"` - BeeMode string `protobuf:"bytes,6,opt,name=BeeMode,proto3" json:"BeeMode,omitempty"` - BatchCommitment uint64 `protobuf:"varint,7,opt,name=BatchCommitment,proto3" json:"BatchCommitment,omitempty"` - IsReachable bool `protobuf:"varint,8,opt,name=IsReachable,proto3" json:"IsReachable,omitempty"` + ReserveSize uint64 `protobuf:"varint,1,opt,name=ReserveSize,proto3" json:"ReserveSize,omitempty"` + PullsyncRate float64 `protobuf:"fixed64,2,opt,name=PullsyncRate,proto3" json:"PullsyncRate,omitempty"` + StorageRadius uint32 `protobuf:"varint,3,opt,name=StorageRadius,proto3" json:"StorageRadius,omitempty"` + ConnectedPeers uint64 `protobuf:"varint,4,opt,name=ConnectedPeers,proto3" json:"ConnectedPeers,omitempty"` + NeighborhoodSize uint64 `protobuf:"varint,5,opt,name=NeighborhoodSize,proto3" json:"NeighborhoodSize,omitempty"` + BeeMode string `protobuf:"bytes,6,opt,name=BeeMode,proto3" json:"BeeMode,omitempty"` + BatchCommitment uint64 `protobuf:"varint,7,opt,name=BatchCommitment,proto3" json:"BatchCommitment,omitempty"` + IsReachable bool `protobuf:"varint,8,opt,name=IsReachable,proto3" json:"IsReachable,omitempty"` + ReserveSizeWithinRadius uint64 `protobuf:"varint,9,opt,name=ReserveSizeWithinRadius,proto3" json:"ReserveSizeWithinRadius,omitempty"` } func (m *Snapshot) Reset() { *m = Snapshot{} } @@ -163,6 +164,13 @@ func (m *Snapshot) GetIsReachable() bool { return false } +func (m *Snapshot) GetReserveSizeWithinRadius() uint64 { + if m != nil { + return m.ReserveSizeWithinRadius + } + return 0 +} + func init() { proto.RegisterType((*Get)(nil), "status.Get") proto.RegisterType((*Snapshot)(nil), "status.Snapshot") @@ -171,25 +179,26 @@ func init() { func init() { proto.RegisterFile("status.proto", fileDescriptor_dfe4fce6682daf5b) } var fileDescriptor_dfe4fce6682daf5b = []byte{ - // 279 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0xc1, 0x4a, 0xf3, 0x40, - 0x10, 0x07, 0xf0, 0x6e, 0xda, 0xa6, 0xf9, 0xf6, 0x6b, 0x55, 0xf6, 0xb4, 0x07, 0x59, 0x96, 0x20, - 0xb2, 0x78, 0xf0, 0xe2, 0x1b, 0xa4, 0x07, 0xf1, 0xa0, 0x94, 0xcd, 0xcd, 0xdb, 0x26, 0x19, 0x9a, - 0x40, 0x92, 0x0d, 0xd9, 0x89, 0xa0, 0x4f, 0xe1, 0xa3, 0xf8, 0x18, 0x1e, 0x7b, 0xf4, 0x28, 0xc9, - 0x8b, 0x88, 0x11, 0xa1, 0xad, 0xc7, 0xff, 0x8f, 0x61, 0x66, 0xf8, 0xd3, 0xa5, 0x43, 0x83, 0x9d, - 0xbb, 0x6e, 0x5a, 0x8b, 0x96, 0xf9, 0x3f, 0x29, 0x9c, 0xd3, 0xe9, 0x2d, 0x60, 0xf8, 0xe6, 0xd1, - 0x20, 0xae, 0x4d, 0xe3, 0x72, 0x8b, 0x4c, 0xd2, 0xff, 0x1a, 0x1c, 0xb4, 0x4f, 0x10, 0x17, 0x2f, - 0xc0, 0x89, 0x24, 0x6a, 0xa6, 0xf7, 0x89, 0x85, 0x74, 0xb9, 0xe9, 0xca, 0xd2, 0x3d, 0xd7, 0xa9, - 0x36, 0x08, 0xdc, 0x93, 0x44, 0x11, 0x7d, 0x60, 0xec, 0x82, 0xae, 0x62, 0xb4, 0xad, 0xd9, 0x82, - 0x36, 0x59, 0xd1, 0x39, 0x3e, 0x95, 0x44, 0xad, 0xf4, 0x21, 0xb2, 0x4b, 0x7a, 0xb2, 0xb6, 0x75, - 0x0d, 0x29, 0x42, 0xb6, 0x01, 0x68, 0x1d, 0x9f, 0x8d, 0xe7, 0x8e, 0x94, 0x5d, 0xd1, 0xb3, 0x07, - 0x28, 0xb6, 0x79, 0x62, 0xdb, 0xdc, 0xda, 0x6c, 0x7c, 0x6c, 0x3e, 0x4e, 0xfe, 0x71, 0xc6, 0xe9, - 0x22, 0x02, 0xb8, 0xb7, 0x19, 0x70, 0x5f, 0x12, 0xf5, 0x4f, 0xff, 0x46, 0xa6, 0xe8, 0x69, 0x64, - 0x30, 0xcd, 0xd7, 0xb6, 0xaa, 0x0a, 0xac, 0xa0, 0x46, 0xbe, 0x18, 0x97, 0x1c, 0xf3, 0x77, 0x07, - 0x77, 0x4e, 0x83, 0x49, 0x73, 0x93, 0x94, 0xc0, 0x03, 0x49, 0x54, 0xa0, 0xf7, 0x29, 0x3a, 0x7f, - 0xef, 0x05, 0xd9, 0xf5, 0x82, 0x7c, 0xf6, 0x82, 0xbc, 0x0e, 0x62, 0xb2, 0x1b, 0xc4, 0xe4, 0x63, - 0x10, 0x93, 0x47, 0xaf, 0x49, 0x12, 0x7f, 0xac, 0xf9, 0xe6, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x64, - 0x9a, 0xeb, 0xde, 0x76, 0x01, 0x00, 0x00, + // 298 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x3f, 0x4b, 0x73, 0x31, + 0x14, 0xc6, 0x9b, 0xfe, 0x6f, 0xde, 0xf6, 0x55, 0xb2, 0x98, 0x41, 0x42, 0x28, 0x22, 0xc1, 0xc1, + 0xc5, 0xc5, 0xb9, 0x1d, 0xc4, 0x41, 0x29, 0xe9, 0x20, 0xb8, 0xe5, 0xde, 0x7b, 0x68, 0x02, 0x6d, + 0x52, 0x6e, 0x4e, 0x05, 0xfd, 0x14, 0x7e, 0x2c, 0xc7, 0x8e, 0x8e, 0xd2, 0x6e, 0x7e, 0x0a, 0x31, + 0x2a, 0xdc, 0x56, 0x1c, 0x9f, 0xdf, 0x39, 0x3c, 0xe7, 0x9c, 0xe7, 0xd0, 0x7e, 0x44, 0x83, 0xab, + 0x78, 0xbe, 0x2c, 0x03, 0x06, 0xd6, 0xfe, 0x52, 0xc3, 0x16, 0x6d, 0x5c, 0x01, 0x0e, 0xdf, 0xeb, + 0xb4, 0x3b, 0xf5, 0x66, 0x19, 0x6d, 0x40, 0x26, 0xe9, 0x3f, 0x0d, 0x11, 0xca, 0x07, 0x98, 0xba, + 0x27, 0xe0, 0x44, 0x12, 0xd5, 0xd4, 0x55, 0xc4, 0x86, 0xb4, 0x3f, 0x59, 0xcd, 0xe7, 0xf1, 0xd1, + 0xe7, 0xda, 0x20, 0xf0, 0xba, 0x24, 0x8a, 0xe8, 0x1d, 0xc6, 0x4e, 0xe8, 0x60, 0x8a, 0xa1, 0x34, + 0x33, 0xd0, 0xa6, 0x70, 0xab, 0xc8, 0x1b, 0x92, 0xa8, 0x81, 0xde, 0x85, 0xec, 0x94, 0xfe, 0x1f, + 0x07, 0xef, 0x21, 0x47, 0x28, 0x26, 0x00, 0x65, 0xe4, 0xcd, 0x34, 0x6e, 0x8f, 0xb2, 0x33, 0x7a, + 0x78, 0x0b, 0x6e, 0x66, 0xb3, 0x50, 0xda, 0x10, 0x8a, 0xb4, 0x58, 0x2b, 0x75, 0xfe, 0xe2, 0x8c, + 0xd3, 0xce, 0x08, 0xe0, 0x26, 0x14, 0xc0, 0xdb, 0x92, 0xa8, 0x9e, 0xfe, 0x91, 0x4c, 0xd1, 0x83, + 0x91, 0xc1, 0xdc, 0x8e, 0xc3, 0x62, 0xe1, 0x70, 0x01, 0x1e, 0x79, 0x27, 0x99, 0xec, 0xe3, 0xcf, + 0x0c, 0xae, 0xa3, 0x06, 0x93, 0x5b, 0x93, 0xcd, 0x81, 0x77, 0x25, 0x51, 0x5d, 0x5d, 0x45, 0xec, + 0x92, 0x1e, 0x55, 0x22, 0xb9, 0x73, 0x68, 0x9d, 0xff, 0xbe, 0xb4, 0x97, 0x3c, 0xff, 0x2a, 0x8f, + 0x8e, 0x5f, 0x36, 0x82, 0xac, 0x37, 0x82, 0xbc, 0x6d, 0x04, 0x79, 0xde, 0x8a, 0xda, 0x7a, 0x2b, + 0x6a, 0xaf, 0x5b, 0x51, 0xbb, 0xaf, 0x2f, 0xb3, 0xac, 0x9d, 0x1e, 0x74, 0xf1, 0x11, 0x00, 0x00, + 0xff, 0xff, 0xb8, 0xde, 0xcb, 0x07, 0xb0, 0x01, 0x00, 0x00, } func (m *Get) Marshal() (dAtA []byte, err error) { @@ -235,6 +244,11 @@ func (m *Snapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ReserveSizeWithinRadius != 0 { + i = encodeVarintStatus(dAtA, i, uint64(m.ReserveSizeWithinRadius)) + i-- + dAtA[i] = 0x48 + } if m.IsReachable { i-- if m.IsReachable { @@ -337,6 +351,9 @@ func (m *Snapshot) Size() (n int) { if m.IsReachable { n += 2 } + if m.ReserveSizeWithinRadius != 0 { + n += 1 + sovStatus(uint64(m.ReserveSizeWithinRadius)) + } return n } @@ -586,6 +603,25 @@ func (m *Snapshot) Unmarshal(dAtA []byte) error { } } m.IsReachable = bool(v != 0) + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReserveSizeWithinRadius", wireType) + } + m.ReserveSizeWithinRadius = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowStatus + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ReserveSizeWithinRadius |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipStatus(dAtA[iNdEx:]) diff --git a/pkg/status/internal/pb/status.proto b/pkg/status/internal/pb/status.proto index f4cecd47088..a62eb327433 100644 --- a/pkg/status/internal/pb/status.proto +++ b/pkg/status/internal/pb/status.proto @@ -23,4 +23,5 @@ message Snapshot { string BeeMode = 6; uint64 BatchCommitment = 7; bool IsReachable = 8; + uint64 ReserveSizeWithinRadius = 9; } diff --git a/pkg/status/status.go b/pkg/status/status.go index 93a498bb20a..a8321dc98bc 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -8,13 +8,13 @@ import ( "context" "fmt" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/status/internal/pb" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/status/internal/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) // loggerName is the tree path name of the logger for this package. @@ -37,6 +37,7 @@ type SyncReporter interface { // Reserve defines the reserve storage related information required. type Reserve interface { ReserveSize() int + ReserveSizeWithinRadius() uint64 StorageRadius() uint8 } @@ -79,16 +80,18 @@ func NewService( // LocalSnapshot returns the current status snapshot of this node. func (s *Service) LocalSnapshot() (*Snapshot, error) { var ( - storageRadius uint8 - syncRate float64 - reserveSize uint64 - connectedPeers uint64 - neighborhoodSize uint64 + storageRadius uint8 + syncRate float64 + reserveSize uint64 + reserveSizeWithinRadius uint64 + connectedPeers uint64 + neighborhoodSize uint64 ) if s.reserve != nil { storageRadius = s.reserve.StorageRadius() reserveSize = uint64(s.reserve.ReserveSize()) + reserveSizeWithinRadius = s.reserve.ReserveSizeWithinRadius() } if s.sync != nil { @@ -115,14 +118,15 @@ func (s *Service) LocalSnapshot() (*Snapshot, error) { } return &Snapshot{ - BeeMode: s.beeMode, - ReserveSize: reserveSize, - PullsyncRate: syncRate, - StorageRadius: uint32(storageRadius), - ConnectedPeers: connectedPeers, - NeighborhoodSize: neighborhoodSize, - BatchCommitment: commitment, - IsReachable: s.topologyDriver.IsReachable(), + BeeMode: s.beeMode, + ReserveSize: reserveSize, + ReserveSizeWithinRadius: reserveSizeWithinRadius, + PullsyncRate: syncRate, + StorageRadius: uint32(storageRadius), + ConnectedPeers: connectedPeers, + NeighborhoodSize: neighborhoodSize, + BatchCommitment: commitment, + IsReachable: s.topologyDriver.IsReachable(), }, nil } diff --git a/pkg/status/status_test.go b/pkg/status/status_test.go index 0bca393ee7d..927ddb09ca5 100644 --- a/pkg/status/status_test.go +++ b/pkg/status/status_test.go @@ -9,14 +9,14 @@ import ( "context" "testing" - "github.com/ethersphere/bee/pkg/api" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p/protobuf" - "github.com/ethersphere/bee/pkg/p2p/streamtest" - "github.com/ethersphere/bee/pkg/status" - "github.com/ethersphere/bee/pkg/status/internal/pb" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/api" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p/protobuf" + "github.com/ethersphere/bee/v2/pkg/p2p/streamtest" + "github.com/ethersphere/bee/v2/pkg/status" + "github.com/ethersphere/bee/v2/pkg/status/internal/pb" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" "github.com/google/go-cmp/cmp" ) @@ -191,3 +191,6 @@ func (m *statusSnapshotMock) SyncRate() float64 { return m.Snapshot.Pu func (m *statusSnapshotMock) ReserveSize() int { return int(m.Snapshot.ReserveSize) } func (m *statusSnapshotMock) StorageRadius() uint8 { return uint8(m.Snapshot.StorageRadius) } func (m *statusSnapshotMock) Commitment() (uint64, error) { return m.Snapshot.BatchCommitment, nil } +func (m *statusSnapshotMock) ReserveSizeWithinRadius() uint64 { + return m.Snapshot.ReserveSizeWithinRadius +} diff --git a/pkg/steward/mock/steward.go b/pkg/steward/mock/steward.go index 4394ca301af..b8cee8b3588 100644 --- a/pkg/steward/mock/steward.go +++ b/pkg/steward/mock/steward.go @@ -7,8 +7,8 @@ package mock import ( "context" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Steward represents steward.Interface mock. diff --git a/pkg/steward/steward.go b/pkg/steward/steward.go index 73b3d17b87f..9c099dd3624 100644 --- a/pkg/steward/steward.go +++ b/pkg/steward/steward.go @@ -11,13 +11,13 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/retrieval" - "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/traversal" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/retrieval" + "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/traversal" ) type Interface interface { diff --git a/pkg/steward/steward_test.go b/pkg/steward/steward_test.go index fe3ccd05ba9..049fa581ae1 100644 --- a/pkg/steward/steward_test.go +++ b/pkg/steward/steward_test.go @@ -14,14 +14,14 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - postagetesting "github.com/ethersphere/bee/pkg/postage/mock" - "github.com/ethersphere/bee/pkg/steward" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/mock" + "github.com/ethersphere/bee/v2/pkg/steward" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type counter struct { diff --git a/pkg/storage/cache/cache.go b/pkg/storage/cache/cache.go index 880a408f7aa..1c659146f18 100644 --- a/pkg/storage/cache/cache.go +++ b/pkg/storage/cache/cache.go @@ -7,8 +7,8 @@ package cache import ( "errors" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" lru "github.com/hashicorp/golang-lru/v2" ) diff --git a/pkg/storage/cache/cache_test.go b/pkg/storage/cache/cache_test.go index 9220e93691d..6528f156785 100644 --- a/pkg/storage/cache/cache_test.go +++ b/pkg/storage/cache/cache_test.go @@ -7,9 +7,9 @@ package cache_test import ( "testing" - "github.com/ethersphere/bee/pkg/storage/cache" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/cache" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestCache(t *testing.T) { diff --git a/pkg/storage/cache/metrics.go b/pkg/storage/cache/metrics.go index 9492829ebc3..ec9a6051786 100644 --- a/pkg/storage/cache/metrics.go +++ b/pkg/storage/cache/metrics.go @@ -5,7 +5,7 @@ package cache import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/storage/chunkstore.go b/pkg/storage/chunkstore.go index aec30e6afc9..4d2e5d78d4a 100644 --- a/pkg/storage/chunkstore.go +++ b/pkg/storage/chunkstore.go @@ -9,7 +9,7 @@ import ( "fmt" "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Getter is the interface that wraps the basic Get method. diff --git a/pkg/storage/inmemchunkstore/inmemchunkstore.go b/pkg/storage/inmemchunkstore/inmemchunkstore.go index 0f225db0608..f1fd629db41 100644 --- a/pkg/storage/inmemchunkstore/inmemchunkstore.go +++ b/pkg/storage/inmemchunkstore/inmemchunkstore.go @@ -8,8 +8,8 @@ import ( "context" "sync" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type ChunkStore struct { diff --git a/pkg/storage/inmemchunkstore/inmemchunkstore_test.go b/pkg/storage/inmemchunkstore/inmemchunkstore_test.go index 1835fcc02a8..21d48b4687d 100644 --- a/pkg/storage/inmemchunkstore/inmemchunkstore_test.go +++ b/pkg/storage/inmemchunkstore/inmemchunkstore_test.go @@ -7,8 +7,8 @@ package inmemchunkstore_test import ( "testing" - inmem "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + inmem "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestChunkStore(t *testing.T) { diff --git a/pkg/storage/inmemchunkstore/transaction.go b/pkg/storage/inmemchunkstore/transaction.go index 5afaeef9386..f4ec18abc7e 100644 --- a/pkg/storage/inmemchunkstore/transaction.go +++ b/pkg/storage/inmemchunkstore/transaction.go @@ -9,8 +9,8 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var _ storage.TxChunkStore = (*TxChunkStore)(nil) diff --git a/pkg/storage/inmemchunkstore/transaction_test.go b/pkg/storage/inmemchunkstore/transaction_test.go index 646298075f7..20919731f51 100644 --- a/pkg/storage/inmemchunkstore/transaction_test.go +++ b/pkg/storage/inmemchunkstore/transaction_test.go @@ -7,8 +7,8 @@ package inmemchunkstore_test import ( "testing" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestTxChunkStore(t *testing.T) { diff --git a/pkg/storage/inmemstore/inmembatch.go b/pkg/storage/inmemstore/inmembatch.go index 309316e3c6f..7188f6d7e71 100644 --- a/pkg/storage/inmemstore/inmembatch.go +++ b/pkg/storage/inmemstore/inmembatch.go @@ -9,7 +9,7 @@ import ( "fmt" "sync" - storage "github.com/ethersphere/bee/pkg/storage" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) // batchOp represents a batch operations. diff --git a/pkg/storage/inmemstore/inmemstore.go b/pkg/storage/inmemstore/inmemstore.go index 38c34af60bd..b0052602aa1 100644 --- a/pkg/storage/inmemstore/inmemstore.go +++ b/pkg/storage/inmemstore/inmemstore.go @@ -11,7 +11,7 @@ import ( "sync" "github.com/armon/go-radix" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) const ( diff --git a/pkg/storage/inmemstore/inmemstore_test.go b/pkg/storage/inmemstore/inmemstore_test.go index cf79c9f2c7c..452daec1a55 100644 --- a/pkg/storage/inmemstore/inmemstore_test.go +++ b/pkg/storage/inmemstore/inmemstore_test.go @@ -7,8 +7,8 @@ package inmemstore_test import ( "testing" - inmem "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + inmem "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestStore(t *testing.T) { diff --git a/pkg/storage/inmemstore/transaction.go b/pkg/storage/inmemstore/transaction.go index b0d600444bc..1415143b41c 100644 --- a/pkg/storage/inmemstore/transaction.go +++ b/pkg/storage/inmemstore/transaction.go @@ -10,7 +10,7 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) var ( diff --git a/pkg/storage/inmemstore/transaction_test.go b/pkg/storage/inmemstore/transaction_test.go index 552088fa311..a9eabe36d56 100644 --- a/pkg/storage/inmemstore/transaction_test.go +++ b/pkg/storage/inmemstore/transaction_test.go @@ -7,8 +7,8 @@ package inmemstore_test import ( "testing" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestTxStore(t *testing.T) { diff --git a/pkg/storage/leveldbstore/batch.go b/pkg/storage/leveldbstore/batch.go index 96bbf2dbf49..64b72a97816 100644 --- a/pkg/storage/leveldbstore/batch.go +++ b/pkg/storage/leveldbstore/batch.go @@ -9,7 +9,7 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ldb "github.com/syndtr/goleveldb/leveldb" ) diff --git a/pkg/storage/leveldbstore/recovery.go b/pkg/storage/leveldbstore/recovery.go index f52701275f0..6d3e04ee91d 100644 --- a/pkg/storage/leveldbstore/recovery.go +++ b/pkg/storage/leveldbstore/recovery.go @@ -7,8 +7,8 @@ package leveldbstore import ( "fmt" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/opt" ) diff --git a/pkg/storage/leveldbstore/recovery_test.go b/pkg/storage/leveldbstore/recovery_test.go index f3d504f6e62..84bd9075d1a 100644 --- a/pkg/storage/leveldbstore/recovery_test.go +++ b/pkg/storage/leveldbstore/recovery_test.go @@ -11,9 +11,9 @@ import ( "slices" "testing" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storage/leveldbstore/store.go b/pkg/storage/leveldbstore/store.go index 30f203d3bfc..bf410d54c00 100644 --- a/pkg/storage/leveldbstore/store.go +++ b/pkg/storage/leveldbstore/store.go @@ -9,7 +9,7 @@ import ( "fmt" "strings" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" "github.com/syndtr/goleveldb/leveldb" ldbErrors "github.com/syndtr/goleveldb/leveldb/errors" "github.com/syndtr/goleveldb/leveldb/iterator" diff --git a/pkg/storage/leveldbstore/store_test.go b/pkg/storage/leveldbstore/store_test.go index 53fffc01a44..7e7bc809213 100644 --- a/pkg/storage/leveldbstore/store_test.go +++ b/pkg/storage/leveldbstore/store_test.go @@ -7,8 +7,8 @@ package leveldbstore_test import ( "testing" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" "github.com/syndtr/goleveldb/leveldb/opt" ) diff --git a/pkg/storage/leveldbstore/transaction.go b/pkg/storage/leveldbstore/transaction.go index 9a18b904ff2..c24259640a9 100644 --- a/pkg/storage/leveldbstore/transaction.go +++ b/pkg/storage/leveldbstore/transaction.go @@ -10,8 +10,8 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" "github.com/google/uuid" "github.com/syndtr/goleveldb/leveldb" ) diff --git a/pkg/storage/leveldbstore/transaction_test.go b/pkg/storage/leveldbstore/transaction_test.go index cc18e8f8632..e965ef0dc7a 100644 --- a/pkg/storage/leveldbstore/transaction_test.go +++ b/pkg/storage/leveldbstore/transaction_test.go @@ -7,8 +7,8 @@ package leveldbstore_test import ( "testing" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" ) func TestTxStore(t *testing.T) { diff --git a/pkg/storage/metrics.go b/pkg/storage/metrics.go index 00c90e8b361..f1a83b179d7 100644 --- a/pkg/storage/metrics.go +++ b/pkg/storage/metrics.go @@ -9,8 +9,8 @@ import ( "errors" "time" - m "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/swarm" + m "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/storage/migration/index.go b/pkg/storage/migration/index.go index bc08d6f2d2d..bb4df67f96f 100644 --- a/pkg/storage/migration/index.go +++ b/pkg/storage/migration/index.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - storage "github.com/ethersphere/bee/pkg/storage" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) var ErrItemIDShouldntChange = errors.New("item.ID shouldn't be changing after update") diff --git a/pkg/storage/migration/index_test.go b/pkg/storage/migration/index_test.go index cf2e0ab8ded..935a50b9b50 100644 --- a/pkg/storage/migration/index_test.go +++ b/pkg/storage/migration/index_test.go @@ -9,9 +9,9 @@ import ( "reflect" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/migration" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" ) func TestNewStepOnIndex(t *testing.T) { diff --git a/pkg/storage/migration/migration.go b/pkg/storage/migration/migration.go index 528831f0da8..fcbd154fb34 100644 --- a/pkg/storage/migration/migration.go +++ b/pkg/storage/migration/migration.go @@ -10,8 +10,8 @@ import ( "fmt" "sort" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" ) type ( diff --git a/pkg/storage/migration/migration_test.go b/pkg/storage/migration/migration_test.go index c1de785f7d3..5daa371fd39 100644 --- a/pkg/storage/migration/migration_test.go +++ b/pkg/storage/migration/migration_test.go @@ -12,11 +12,11 @@ import ( "strconv" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/migration" - "github.com/ethersphere/bee/pkg/storage/storagetest" - "github.com/ethersphere/bee/pkg/storage/storageutil" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" ) var ( diff --git a/pkg/storage/migration/steps_chain.go b/pkg/storage/migration/steps_chain.go index 96f8835b614..1b3ddc52301 100644 --- a/pkg/storage/migration/steps_chain.go +++ b/pkg/storage/migration/steps_chain.go @@ -4,7 +4,7 @@ package migration -import storage "github.com/ethersphere/bee/pkg/storage" +import storage "github.com/ethersphere/bee/v2/pkg/storage" // NewStepsChain returns new StepFn which combines all supplied StepFn // into single StepFn. diff --git a/pkg/storage/migration/steps_chain_test.go b/pkg/storage/migration/steps_chain_test.go index 4488d6805b0..f591440ac5a 100644 --- a/pkg/storage/migration/steps_chain_test.go +++ b/pkg/storage/migration/steps_chain_test.go @@ -7,9 +7,9 @@ package migration_test import ( "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/migration" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" ) func TestNewStepsChain(t *testing.T) { diff --git a/pkg/storage/repository.go b/pkg/storage/repository.go index f681ee76d88..c189cc3bfe4 100644 --- a/pkg/storage/repository.go +++ b/pkg/storage/repository.go @@ -9,8 +9,8 @@ import ( "errors" "time" - m "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/swarm" + m "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/storage/storagetest/batch.go b/pkg/storage/storagetest/batch.go index b144bc04908..c26986f42b5 100644 --- a/pkg/storage/storagetest/batch.go +++ b/pkg/storage/storagetest/batch.go @@ -9,7 +9,7 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storage/storagetest/benchmark.go b/pkg/storage/storagetest/benchmark.go index 09cd3241ecb..015392ff7c5 100644 --- a/pkg/storage/storagetest/benchmark.go +++ b/pkg/storage/storagetest/benchmark.go @@ -16,9 +16,9 @@ import ( "testing" "time" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/storage/storagetest/chunkstore.go b/pkg/storage/storagetest/chunkstore.go index 767c4a2a0c4..996d7977f06 100644 --- a/pkg/storage/storagetest/chunkstore.go +++ b/pkg/storage/storagetest/chunkstore.go @@ -9,10 +9,10 @@ import ( "errors" "testing" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - storage "github.com/ethersphere/bee/pkg/storage" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestChunkStore runs a correctness test suite on a given ChunkStore. diff --git a/pkg/storage/storagetest/storage.go b/pkg/storage/storagetest/storage.go index 55f21ad156e..d270bbfc357 100644 --- a/pkg/storage/storagetest/storage.go +++ b/pkg/storage/storagetest/storage.go @@ -18,10 +18,10 @@ import ( "sync" "testing" - "github.com/ethersphere/bee/pkg/encryption" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/encryption" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storage/storagetest/transaction.go b/pkg/storage/storagetest/transaction.go index 1275bedb7d9..8c8dde7cad0 100644 --- a/pkg/storage/storagetest/transaction.go +++ b/pkg/storage/storagetest/transaction.go @@ -12,10 +12,10 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storage/testing/chunk.go b/pkg/storage/testing/chunk.go index 51623f0b925..f51c1079974 100644 --- a/pkg/storage/testing/chunk.go +++ b/pkg/storage/testing/chunk.go @@ -21,12 +21,12 @@ import ( "crypto/rand" "testing" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // GenerateTestRandomChunk generates a valid content addressed chunk. diff --git a/pkg/storage/transaction.go b/pkg/storage/transaction.go index 1268e45da86..ad7d829d3c0 100644 --- a/pkg/storage/transaction.go +++ b/pkg/storage/transaction.go @@ -11,7 +11,7 @@ import ( "sync" "sync/atomic" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // ErrTxDone is returned by any operation that is performed on diff --git a/pkg/storage/transaction_test.go b/pkg/storage/transaction_test.go index a03df20a5dc..265e777bb68 100644 --- a/pkg/storage/transaction_test.go +++ b/pkg/storage/transaction_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage" ) func TestTxState(t *testing.T) { diff --git a/pkg/storageincentives/agent.go b/pkg/storageincentives/agent.go index 2bd0bf0ffb4..b71a77c3dff 100644 --- a/pkg/storageincentives/agent.go +++ b/pkg/storageincentives/agent.go @@ -16,17 +16,17 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/postage/postagecontract" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage/postagecontract" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" ) const loggerName = "storageincentives" diff --git a/pkg/storageincentives/agent_test.go b/pkg/storageincentives/agent_test.go index fe5bc6a937f..ae078f1a871 100644 --- a/pkg/storageincentives/agent_test.go +++ b/pkg/storageincentives/agent_test.go @@ -14,19 +14,19 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - contractMock "github.com/ethersphere/bee/pkg/postage/postagecontract/mock" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - statestore "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/storageincentives/staking/mock" - "github.com/ethersphere/bee/pkg/storer" - resMock "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + contractMock "github.com/ethersphere/bee/v2/pkg/postage/postagecontract/mock" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + statestore "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking/mock" + "github.com/ethersphere/bee/v2/pkg/storer" + resMock "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestAgent(t *testing.T) { diff --git a/pkg/storageincentives/events_test.go b/pkg/storageincentives/events_test.go index 6c40fe8fc2e..0ea4547a145 100644 --- a/pkg/storageincentives/events_test.go +++ b/pkg/storageincentives/events_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives" ) func TestClose(t *testing.T) { diff --git a/pkg/storageincentives/metrics.go b/pkg/storageincentives/metrics.go index 28c692cc3af..b376d9d20b2 100644 --- a/pkg/storageincentives/metrics.go +++ b/pkg/storageincentives/metrics.go @@ -5,7 +5,7 @@ package storageincentives import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/storageincentives/proof.go b/pkg/storageincentives/proof.go index ccc04cd935b..86dd115c67e 100644 --- a/pkg/storageincentives/proof.go +++ b/pkg/storageincentives/proof.go @@ -10,13 +10,13 @@ import ( "hash" "math/big" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/bmtpool" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/bmtpool" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var errProofCreation = errors.New("reserve commitment hasher: failure in proof creation") diff --git a/pkg/storageincentives/proof_test.go b/pkg/storageincentives/proof_test.go index 1d83309ba24..8b574cadf3d 100644 --- a/pkg/storageincentives/proof_test.go +++ b/pkg/storageincentives/proof_test.go @@ -12,16 +12,16 @@ import ( "math/big" "testing" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storageincentives" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storageincentives" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storageincentives/redistribution/inclusionproof.go b/pkg/storageincentives/redistribution/inclusionproof.go index b786d1d3001..41e319b9c63 100644 --- a/pkg/storageincentives/redistribution/inclusionproof.go +++ b/pkg/storageincentives/redistribution/inclusionproof.go @@ -8,10 +8,10 @@ import ( "encoding/binary" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type ChunkInclusionProofs struct { diff --git a/pkg/storageincentives/redistribution/redistribution.go b/pkg/storageincentives/redistribution/redistribution.go index 01ddb9195b0..42fa4ee6cf1 100644 --- a/pkg/storageincentives/redistribution/redistribution.go +++ b/pkg/storageincentives/redistribution/redistribution.go @@ -11,10 +11,10 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" ) const loggerName = "redistributionContract" diff --git a/pkg/storageincentives/redistribution/redistribution_test.go b/pkg/storageincentives/redistribution/redistribution_test.go index 4a8e84b421b..022e88fc3bf 100644 --- a/pkg/storageincentives/redistribution/redistribution_test.go +++ b/pkg/storageincentives/redistribution/redistribution_test.go @@ -15,15 +15,15 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/storageincentives/redistribution" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" - transactionMock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" - "github.com/ethersphere/bee/pkg/util/testutil" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/storageincentives/redistribution" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" + transactionMock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) var redistributionContractABI = abiutil.MustParseABI(chaincfg.Testnet.RedistributionABI) diff --git a/pkg/storageincentives/redistributionstate.go b/pkg/storageincentives/redistributionstate.go index b1f4b60dd03..9929a9e7831 100644 --- a/pkg/storageincentives/redistributionstate.go +++ b/pkg/storageincentives/redistributionstate.go @@ -12,12 +12,12 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/settlement/swap/erc20" - "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20" + "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" ) const loggerNameNode = "nodestatus" diff --git a/pkg/storageincentives/redistributionstate_test.go b/pkg/storageincentives/redistributionstate_test.go index 9c7f750d64c..063991c31d8 100644 --- a/pkg/storageincentives/redistributionstate_test.go +++ b/pkg/storageincentives/redistributionstate_test.go @@ -11,11 +11,11 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - erc20mock "github.com/ethersphere/bee/pkg/settlement/swap/erc20/mock" - "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" - transactionmock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + erc20mock "github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20/mock" + "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storageincentives/soc_mine_test.go b/pkg/storageincentives/soc_mine_test.go index d5b93241b21..bdece238f80 100644 --- a/pkg/storageincentives/soc_mine_test.go +++ b/pkg/storageincentives/soc_mine_test.go @@ -15,11 +15,11 @@ import ( "sync" "testing" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/sync/errgroup" ) diff --git a/pkg/storageincentives/staking/contract.go b/pkg/storageincentives/staking/contract.go index 128343824a2..f5a340b2b93 100644 --- a/pkg/storageincentives/staking/contract.go +++ b/pkg/storageincentives/staking/contract.go @@ -13,10 +13,10 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/storageincentives/staking/contract_test.go b/pkg/storageincentives/staking/contract_test.go index 27f9e31ccca..24133631b99 100644 --- a/pkg/storageincentives/staking/contract_test.go +++ b/pkg/storageincentives/staking/contract_test.go @@ -14,12 +14,12 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - chaincfg "github.com/ethersphere/bee/pkg/config" - "github.com/ethersphere/bee/pkg/storageincentives/staking" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/transaction" - transactionMock "github.com/ethersphere/bee/pkg/transaction/mock" - "github.com/ethersphere/bee/pkg/util/abiutil" + chaincfg "github.com/ethersphere/bee/v2/pkg/config" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/transaction" + transactionMock "github.com/ethersphere/bee/v2/pkg/transaction/mock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" ) var stakingContractABI = abiutil.MustParseABI(chaincfg.Testnet.StakingABI) diff --git a/pkg/storageincentives/staking/mock/contract.go b/pkg/storageincentives/staking/mock/contract.go index 09d8c03b4c2..e21e51964f9 100644 --- a/pkg/storageincentives/staking/mock/contract.go +++ b/pkg/storageincentives/staking/mock/contract.go @@ -9,7 +9,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/storageincentives/staking" + "github.com/ethersphere/bee/v2/pkg/storageincentives/staking" ) type stakingContractMock struct { diff --git a/pkg/storer/cachestore.go b/pkg/storer/cachestore.go index 1e7546c7c23..16c92cb7f25 100644 --- a/pkg/storer/cachestore.go +++ b/pkg/storer/cachestore.go @@ -10,9 +10,9 @@ import ( "fmt" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/storer/cachestore_test.go b/pkg/storer/cachestore_test.go index dc2264491e7..2c280dd3920 100644 --- a/pkg/storer/cachestore_test.go +++ b/pkg/storer/cachestore_test.go @@ -10,12 +10,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/spinlock" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/spinlock" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func testCacheStore(t *testing.T, newStorer func() (*storer.DB, error)) { diff --git a/pkg/storer/compact.go b/pkg/storer/compact.go index 3ecc623e98f..a2bea67176a 100644 --- a/pkg/storer/compact.go +++ b/pkg/storer/compact.go @@ -12,9 +12,9 @@ import ( "sort" "time" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Compact minimizes sharky disk usage by, using the current sharky locations from the storer, diff --git a/pkg/storer/compact_test.go b/pkg/storer/compact_test.go index 3606e7c8c9d..d18675ef33b 100644 --- a/pkg/storer/compact_test.go +++ b/pkg/storer/compact_test.go @@ -10,12 +10,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - pullerMock "github.com/ethersphere/bee/pkg/puller/mock" - chunk "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + pullerMock "github.com/ethersphere/bee/v2/pkg/puller/mock" + chunk "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // TestCompact creates two batches and puts chunks belonging to both batches. diff --git a/pkg/storer/debug.go b/pkg/storer/debug.go index 9128141a430..16f918d1ed6 100644 --- a/pkg/storer/debug.go +++ b/pkg/storer/debug.go @@ -7,11 +7,11 @@ package storer import ( "context" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/sync/errgroup" ) diff --git a/pkg/storer/debug_test.go b/pkg/storer/debug_test.go index d62a38aeb55..37325ce6cf8 100644 --- a/pkg/storer/debug_test.go +++ b/pkg/storer/debug_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/export_test.go b/pkg/storer/export_test.go index 0613e467831..47532f0c63d 100644 --- a/pkg/storer/export_test.go +++ b/pkg/storer/export_test.go @@ -7,9 +7,9 @@ package storer import ( "context" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/events" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/events" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" ) func (db *DB) Reserve() *reserve.Reserve { diff --git a/pkg/storer/internal/cache/cache.go b/pkg/storer/internal/cache/cache.go index 887f2a27ae9..a3e71f9cc70 100644 --- a/pkg/storer/internal/cache/cache.go +++ b/pkg/storer/internal/cache/cache.go @@ -14,9 +14,9 @@ import ( "sync/atomic" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/swarm" "resenje.org/multex" ) diff --git a/pkg/storer/internal/cache/cache_test.go b/pkg/storer/internal/cache/cache_test.go index c331853d352..337d47641df 100644 --- a/pkg/storer/internal/cache/cache_test.go +++ b/pkg/storer/internal/cache/cache_test.go @@ -14,12 +14,12 @@ import ( "testing" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/cache" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/cache" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/internal/cache/export_test.go b/pkg/storer/internal/cache/export_test.go index 9a8eda3afa3..dee5f9e6d09 100644 --- a/pkg/storer/internal/cache/export_test.go +++ b/pkg/storer/internal/cache/export_test.go @@ -9,9 +9,9 @@ import ( "fmt" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type ( diff --git a/pkg/storer/internal/chunkstamp/chunkstamp.go b/pkg/storer/internal/chunkstamp/chunkstamp.go index 4e8e8c91f22..83b6a4c236c 100644 --- a/pkg/storer/internal/chunkstamp/chunkstamp.go +++ b/pkg/storer/internal/chunkstamp/chunkstamp.go @@ -10,10 +10,10 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/storer/internal/chunkstamp/chunkstamp_test.go b/pkg/storer/internal/chunkstamp/chunkstamp_test.go index a09b1c111ac..44e1f8c3f78 100644 --- a/pkg/storer/internal/chunkstamp/chunkstamp_test.go +++ b/pkg/storer/internal/chunkstamp/chunkstamp_test.go @@ -9,13 +9,13 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/postage" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/internal/chunkstamp/export_test.go b/pkg/storer/internal/chunkstamp/export_test.go index 5e2640d094b..77e54330e66 100644 --- a/pkg/storer/internal/chunkstamp/export_test.go +++ b/pkg/storer/internal/chunkstamp/export_test.go @@ -4,7 +4,7 @@ package chunkstamp -import "github.com/ethersphere/bee/pkg/swarm" +import "github.com/ethersphere/bee/v2/pkg/swarm" type Item = item diff --git a/pkg/storer/internal/chunkstore/chunkstore.go b/pkg/storer/internal/chunkstore/chunkstore.go index f1af1098944..70279c6e320 100644 --- a/pkg/storer/internal/chunkstore/chunkstore.go +++ b/pkg/storer/internal/chunkstore/chunkstore.go @@ -11,10 +11,10 @@ import ( "fmt" "time" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/exp/slices" ) diff --git a/pkg/storer/internal/chunkstore/chunkstore_test.go b/pkg/storer/internal/chunkstore/chunkstore_test.go index ce135ebaceb..9515a8142e9 100644 --- a/pkg/storer/internal/chunkstore/chunkstore_test.go +++ b/pkg/storer/internal/chunkstore/chunkstore_test.go @@ -13,13 +13,13 @@ import ( "os" "testing" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/afero" ) diff --git a/pkg/storer/internal/chunkstore/helpers.go b/pkg/storer/internal/chunkstore/helpers.go index 8e0269144eb..782acc5788b 100644 --- a/pkg/storer/internal/chunkstore/helpers.go +++ b/pkg/storer/internal/chunkstore/helpers.go @@ -8,8 +8,8 @@ import ( "context" "fmt" - "github.com/ethersphere/bee/pkg/sharky" - storage "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/sharky" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) type LocationResult struct { diff --git a/pkg/storer/internal/chunkstore/helpers_test.go b/pkg/storer/internal/chunkstore/helpers_test.go index 5add6228f9e..2b5d37f2247 100644 --- a/pkg/storer/internal/chunkstore/helpers_test.go +++ b/pkg/storer/internal/chunkstore/helpers_test.go @@ -10,12 +10,12 @@ import ( "github.com/stretchr/testify/assert" - "github.com/ethersphere/bee/pkg/sharky" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/afero" ) diff --git a/pkg/storer/internal/chunkstore/recovery.go b/pkg/storer/internal/chunkstore/recovery.go index fad8d47e222..a628d60ff44 100644 --- a/pkg/storer/internal/chunkstore/recovery.go +++ b/pkg/storer/internal/chunkstore/recovery.go @@ -9,10 +9,10 @@ import ( "fmt" "slices" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" "github.com/vmihailenco/msgpack/v5" ) diff --git a/pkg/storer/internal/chunkstore/recovery_test.go b/pkg/storer/internal/chunkstore/recovery_test.go index 99c5b0f8c76..40d033df474 100644 --- a/pkg/storer/internal/chunkstore/recovery_test.go +++ b/pkg/storer/internal/chunkstore/recovery_test.go @@ -10,12 +10,12 @@ import ( "slices" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/afero" diff --git a/pkg/storer/internal/chunkstore/transaction.go b/pkg/storer/internal/chunkstore/transaction.go index 02927d6423a..82833fecd54 100644 --- a/pkg/storer/internal/chunkstore/transaction.go +++ b/pkg/storer/internal/chunkstore/transaction.go @@ -11,10 +11,10 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" "github.com/google/uuid" "github.com/vmihailenco/msgpack/v5" ) diff --git a/pkg/storer/internal/chunkstore/transaction_test.go b/pkg/storer/internal/chunkstore/transaction_test.go index 88dd98851ed..9c1092331f1 100644 --- a/pkg/storer/internal/chunkstore/transaction_test.go +++ b/pkg/storer/internal/chunkstore/transaction_test.go @@ -8,14 +8,14 @@ import ( "context" "testing" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/spf13/afero" ) diff --git a/pkg/storer/internal/events/subscribe_test.go b/pkg/storer/internal/events/subscribe_test.go index a2fb3088924..3e99494cd06 100644 --- a/pkg/storer/internal/events/subscribe_test.go +++ b/pkg/storer/internal/events/subscribe_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/storer/internal/events" + "github.com/ethersphere/bee/v2/pkg/storer/internal/events" ) func TestSubscriber(t *testing.T) { diff --git a/pkg/storer/internal/internal.go b/pkg/storer/internal/internal.go index 0433ad7a1c5..104d0a07fdd 100644 --- a/pkg/storer/internal/internal.go +++ b/pkg/storer/internal/internal.go @@ -9,10 +9,10 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Storage groups the storage.Store and storage.ChunkStore interfaces. diff --git a/pkg/storer/internal/pinning/export_test.go b/pkg/storer/internal/pinning/export_test.go index 79e5864dfba..ecce9d1b597 100644 --- a/pkg/storer/internal/pinning/export_test.go +++ b/pkg/storer/internal/pinning/export_test.go @@ -7,8 +7,8 @@ package pinstore import ( "fmt" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type ( diff --git a/pkg/storer/internal/pinning/pinning.go b/pkg/storer/internal/pinning/pinning.go index 8fb25ba92ad..de33f9ffd93 100644 --- a/pkg/storer/internal/pinning/pinning.go +++ b/pkg/storer/internal/pinning/pinning.go @@ -12,11 +12,11 @@ import ( "fmt" "sync" - "github.com/ethersphere/bee/pkg/encryption" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/encryption" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/uuid" ) diff --git a/pkg/storer/internal/pinning/pinning_test.go b/pkg/storer/internal/pinning/pinning_test.go index 017b135f6f8..431d04097be 100644 --- a/pkg/storer/internal/pinning/pinning_test.go +++ b/pkg/storer/internal/pinning/pinning_test.go @@ -11,12 +11,12 @@ import ( "math" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - storagetest "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storagetest "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type pinningCollection struct { diff --git a/pkg/storer/internal/reserve/items.go b/pkg/storer/internal/reserve/items.go index 0e98dc3bdb9..9380727b6ab 100644 --- a/pkg/storer/internal/reserve/items.go +++ b/pkg/storer/internal/reserve/items.go @@ -9,10 +9,10 @@ import ( "errors" "path" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/storer/internal/reserve/items_test.go b/pkg/storer/internal/reserve/items_test.go index 5ef0f5424ca..e5750626f9e 100644 --- a/pkg/storer/internal/reserve/items_test.go +++ b/pkg/storer/internal/reserve/items_test.go @@ -8,10 +8,10 @@ import ( "fmt" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestReserveItems(t *testing.T) { diff --git a/pkg/storer/internal/reserve/reserve.go b/pkg/storer/internal/reserve/reserve.go index 47c843e48b1..c640052609e 100644 --- a/pkg/storer/internal/reserve/reserve.go +++ b/pkg/storer/internal/reserve/reserve.go @@ -14,13 +14,13 @@ import ( "sync/atomic" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/storer/internal/stampindex" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/storer/internal/stampindex" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) // loggerName is the tree path name of the logger for this package. diff --git a/pkg/storer/internal/reserve/reserve_test.go b/pkg/storer/internal/reserve/reserve_test.go index 596552ad4dc..56a1ba4ee11 100644 --- a/pkg/storer/internal/reserve/reserve_test.go +++ b/pkg/storer/internal/reserve/reserve_test.go @@ -12,17 +12,17 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - storage "github.com/ethersphere/bee/pkg/storage" - chunk "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/storer/internal/stampindex" - "github.com/ethersphere/bee/pkg/swarm" - kademlia "github.com/ethersphere/bee/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunk "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/storer/internal/stampindex" + "github.com/ethersphere/bee/v2/pkg/swarm" + kademlia "github.com/ethersphere/bee/v2/pkg/topology/mock" ) func noopCacher(_ context.Context, _ internal.Storage, _ ...swarm.Address) error { diff --git a/pkg/storer/internal/stampindex/export_test.go b/pkg/storer/internal/stampindex/export_test.go index 50e75134b7c..b247fc06534 100644 --- a/pkg/storer/internal/stampindex/export_test.go +++ b/pkg/storer/internal/stampindex/export_test.go @@ -4,7 +4,7 @@ package stampindex -import "github.com/ethersphere/bee/pkg/swarm" +import "github.com/ethersphere/bee/v2/pkg/swarm" var ( ErrStampItemMarshalNamespaceInvalid = errStampItemMarshalNamespaceInvalid diff --git a/pkg/storer/internal/stampindex/stampindex.go b/pkg/storer/internal/stampindex/stampindex.go index 596c2af6af0..ff9c5e94318 100644 --- a/pkg/storer/internal/stampindex/stampindex.go +++ b/pkg/storer/internal/stampindex/stampindex.go @@ -9,10 +9,10 @@ import ( "errors" "fmt" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/storer/internal/stampindex/stampindex_test.go b/pkg/storer/internal/stampindex/stampindex_test.go index c95cdf0b682..b03aa390efb 100644 --- a/pkg/storer/internal/stampindex/stampindex_test.go +++ b/pkg/storer/internal/stampindex/stampindex_test.go @@ -9,12 +9,12 @@ import ( "fmt" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/stampindex" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/stampindex" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/internal/upload/uploadstore.go b/pkg/storer/internal/upload/uploadstore.go index 81fed2a8bcb..146995ecd7a 100644 --- a/pkg/storer/internal/upload/uploadstore.go +++ b/pkg/storer/internal/upload/uploadstore.go @@ -12,12 +12,12 @@ import ( "strconv" "time" - "github.com/ethersphere/bee/pkg/encryption" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/encryption" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // now returns the current time.Time; used in testing. diff --git a/pkg/storer/internal/upload/uploadstore_test.go b/pkg/storer/internal/upload/uploadstore_test.go index a2f7f931913..f8e46af258f 100644 --- a/pkg/storer/internal/upload/uploadstore_test.go +++ b/pkg/storer/internal/upload/uploadstore_test.go @@ -15,12 +15,12 @@ import ( "testing" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" ) diff --git a/pkg/storer/metrics.go b/pkg/storer/metrics.go index e132c4e931e..c416d222783 100644 --- a/pkg/storer/metrics.go +++ b/pkg/storer/metrics.go @@ -9,9 +9,9 @@ import ( "errors" "time" - m "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + m "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/storer/migration/all_steps.go b/pkg/storer/migration/all_steps.go index 69aa419747f..ea222c81181 100644 --- a/pkg/storer/migration/all_steps.go +++ b/pkg/storer/migration/all_steps.go @@ -5,9 +5,9 @@ package migration import ( - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/migration" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" ) // AfterInitSteps lists all migration steps for localstore IndexStore after the localstore is intiated. diff --git a/pkg/storer/migration/all_steps_test.go b/pkg/storer/migration/all_steps_test.go index 10a6fbce752..94e70fb251f 100644 --- a/pkg/storer/migration/all_steps_test.go +++ b/pkg/storer/migration/all_steps_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storage/migration" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" ) func TestPreSteps(t *testing.T) { diff --git a/pkg/storer/migration/refCntSize.go b/pkg/storer/migration/refCntSize.go index ccb4552b9a0..d13f5b8c354 100644 --- a/pkg/storer/migration/refCntSize.go +++ b/pkg/storer/migration/refCntSize.go @@ -10,12 +10,12 @@ import ( "errors" "os" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const oldRretrievalIndexItemSize = swarm.HashSize + 8 + sharky.LocationSize + 1 diff --git a/pkg/storer/migration/refCntSize_test.go b/pkg/storer/migration/refCntSize_test.go index a7869d31c31..c3310077ef2 100644 --- a/pkg/storer/migration/refCntSize_test.go +++ b/pkg/storer/migration/refCntSize_test.go @@ -8,11 +8,11 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/stretchr/testify/assert" ) diff --git a/pkg/storer/migration/step_01.go b/pkg/storer/migration/step_01.go index cc0b4fe8544..beaff83537d 100644 --- a/pkg/storer/migration/step_01.go +++ b/pkg/storer/migration/step_01.go @@ -5,7 +5,7 @@ package migration import ( - storage "github.com/ethersphere/bee/pkg/storage" + storage "github.com/ethersphere/bee/v2/pkg/storage" ) // step_01 serves as example for setting up migration step. diff --git a/pkg/storer/migration/step_01_test.go b/pkg/storer/migration/step_01_test.go index 8b89d556745..7e4e6ee5df1 100644 --- a/pkg/storer/migration/step_01_test.go +++ b/pkg/storer/migration/step_01_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" ) func Test_Step_01(t *testing.T) { diff --git a/pkg/storer/migration/step_02.go b/pkg/storer/migration/step_02.go index 2da6963a35f..b60ce42cc43 100644 --- a/pkg/storer/migration/step_02.go +++ b/pkg/storer/migration/step_02.go @@ -7,9 +7,9 @@ package migration import ( "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/cache" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/cache" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // step_02 migrates the cache to the new format. diff --git a/pkg/storer/migration/step_02_test.go b/pkg/storer/migration/step_02_test.go index 85180ce134b..6275790093e 100644 --- a/pkg/storer/migration/step_02_test.go +++ b/pkg/storer/migration/step_02_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/assert" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - "github.com/ethersphere/bee/pkg/storer/internal/cache" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + "github.com/ethersphere/bee/v2/pkg/storer/internal/cache" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type testEntry struct { diff --git a/pkg/storer/migration/step_03.go b/pkg/storer/migration/step_03.go index 8f52ba11547..317f4290aea 100644 --- a/pkg/storer/migration/step_03.go +++ b/pkg/storer/migration/step_03.go @@ -9,10 +9,10 @@ import ( "errors" "os" - "github.com/ethersphere/bee/pkg/log" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // step_03 is a migration step that removes all BinItem entries and migrates diff --git a/pkg/storer/migration/step_03_test.go b/pkg/storer/migration/step_03_test.go index 180cc16aa10..4df69dec6c7 100644 --- a/pkg/storer/migration/step_03_test.go +++ b/pkg/storer/migration/step_03_test.go @@ -9,13 +9,13 @@ import ( "errors" "testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/stretchr/testify/assert" ) diff --git a/pkg/storer/migration/step_04.go b/pkg/storer/migration/step_04.go index e621ae3458a..fa316f8393b 100644 --- a/pkg/storer/migration/step_04.go +++ b/pkg/storer/migration/step_04.go @@ -8,11 +8,11 @@ import ( "context" "os" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // step_04 is the fourth step of the migration. It forces a sharky recovery to diff --git a/pkg/storer/migration/step_04_test.go b/pkg/storer/migration/step_04_test.go index 6b70d69d5e7..ec3f4cb87e8 100644 --- a/pkg/storer/migration/step_04_test.go +++ b/pkg/storer/migration/step_04_test.go @@ -11,12 +11,12 @@ import ( "path/filepath" "testing" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage/inmemstore" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage/inmemstore" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/stretchr/testify/assert" ) diff --git a/pkg/storer/migration/step_05.go b/pkg/storer/migration/step_05.go index f9aa75b2b00..0061920fb6c 100644 --- a/pkg/storer/migration/step_05.go +++ b/pkg/storer/migration/step_05.go @@ -8,9 +8,9 @@ import ( "fmt" "os" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/upload" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" ) // step_05 is a migration step that removes all upload items from the store. diff --git a/pkg/storer/migration/step_05_test.go b/pkg/storer/migration/step_05_test.go index cc7a88214a8..e363c0b71b2 100644 --- a/pkg/storer/migration/step_05_test.go +++ b/pkg/storer/migration/step_05_test.go @@ -8,17 +8,17 @@ import ( "context" "testing" - "github.com/ethersphere/bee/pkg/node" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" - chunktest "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" - kademlia "github.com/ethersphere/bee/pkg/topology/mock" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/node" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" + chunktest "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" + kademlia "github.com/ethersphere/bee/v2/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func Test_Step_05(t *testing.T) { diff --git a/pkg/storer/mock/forgetting.go b/pkg/storer/mock/forgetting.go index 5588b5c263e..e91560c60fb 100644 --- a/pkg/storer/mock/forgetting.go +++ b/pkg/storer/mock/forgetting.go @@ -10,8 +10,8 @@ import ( "sync/atomic" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type DelayedStore struct { diff --git a/pkg/storer/mock/mockreserve.go b/pkg/storer/mock/mockreserve.go index d6d70390242..7cd3cb8fd6a 100644 --- a/pkg/storer/mock/mockreserve.go +++ b/pkg/storer/mock/mockreserve.go @@ -9,9 +9,9 @@ import ( "math/big" "sync" - storage "github.com/ethersphere/bee/pkg/storage" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type chunksResponse struct { diff --git a/pkg/storer/mock/mockstorer.go b/pkg/storer/mock/mockstorer.go index fa08445d0ec..083b1c5a95b 100644 --- a/pkg/storer/mock/mockstorer.go +++ b/pkg/storer/mock/mockstorer.go @@ -9,12 +9,12 @@ import ( "sync" "time" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - "github.com/ethersphere/bee/pkg/pusher" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + "github.com/ethersphere/bee/v2/pkg/pusher" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "go.uber.org/atomic" ) diff --git a/pkg/storer/mock/mockstorer_test.go b/pkg/storer/mock/mockstorer_test.go index 40f08a4d852..6fbee300c24 100644 --- a/pkg/storer/mock/mockstorer_test.go +++ b/pkg/storer/mock/mockstorer_test.go @@ -12,11 +12,11 @@ import ( "testing" "time" - storage "github.com/ethersphere/bee/pkg/storage" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/netstore.go b/pkg/storer/netstore.go index 3d5a0c01057..1b13ef5908e 100644 --- a/pkg/storer/netstore.go +++ b/pkg/storer/netstore.go @@ -8,10 +8,10 @@ import ( "context" "errors" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" "github.com/opentracing/opentracing-go/ext" olog "github.com/opentracing/opentracing-go/log" "golang.org/x/sync/errgroup" diff --git a/pkg/storer/netstore_test.go b/pkg/storer/netstore_test.go index b15cd2cfed8..3feac383898 100644 --- a/pkg/storer/netstore_test.go +++ b/pkg/storer/netstore_test.go @@ -11,12 +11,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/retrieval" - storage "github.com/ethersphere/bee/pkg/storage" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/retrieval" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type testRetrieval struct { diff --git a/pkg/storer/pinstore.go b/pkg/storer/pinstore.go index 58cc2ef2cc2..dd9cfc3b51d 100644 --- a/pkg/storer/pinstore.go +++ b/pkg/storer/pinstore.go @@ -9,10 +9,10 @@ import ( "fmt" "time" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // NewCollection is the implementation of the PinStore.NewCollection method. diff --git a/pkg/storer/pinstore_test.go b/pkg/storer/pinstore_test.go index 43676f6ce61..4719f4baaf5 100644 --- a/pkg/storer/pinstore_test.go +++ b/pkg/storer/pinstore_test.go @@ -11,10 +11,10 @@ import ( "testing" "time" - storage "github.com/ethersphere/bee/pkg/storage" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func testPinStore(t *testing.T, newStorer func() (*storer.DB, error)) { diff --git a/pkg/storer/recover.go b/pkg/storer/recover.go index 7fa48ec2112..a6500ea7828 100644 --- a/pkg/storer/recover.go +++ b/pkg/storer/recover.go @@ -12,10 +12,10 @@ import ( "path/filepath" "time" - "github.com/ethersphere/bee/pkg/sharky" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/sharky" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/storer/reserve.go b/pkg/storer/reserve.go index 66a8fd0c464..589a0f853a1 100644 --- a/pkg/storer/reserve.go +++ b/pkg/storer/reserve.go @@ -14,12 +14,12 @@ import ( "sync/atomic" "time" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storageutil" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storageutil" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( @@ -35,6 +35,7 @@ func reserveUpdateBatchLockKey(batchID []byte) string { } var errMaxRadius = errors.New("max radius reached") +var reserveSizeWithinRadius atomic.Uint64 type Syncer interface { // Number of active historical syncing jobs. @@ -137,6 +138,7 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) { if err != nil { db.logger.Error(err, "reserve count within radius") } + reserveSizeWithinRadius.Store(uint64(count)) for batch := range evictBatches { db.logger.Debug("reserve size worker, invalid batch id", "batch_id", hex.EncodeToString([]byte(batch))) @@ -474,6 +476,10 @@ func (db *DB) ReserveSize() int { return db.reserve.Size() } +func (db *DB) ReserveSizeWithinRadius() uint64 { + return reserveSizeWithinRadius.Load() +} + func (db *DB) IsWithinStorageRadius(addr swarm.Address) bool { if db.reserve == nil { return false diff --git a/pkg/storer/reserve_test.go b/pkg/storer/reserve_test.go index aa5f79a6737..9537f230c49 100644 --- a/pkg/storer/reserve_test.go +++ b/pkg/storer/reserve_test.go @@ -12,19 +12,19 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/postage" - batchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - pullerMock "github.com/ethersphere/bee/pkg/puller/mock" - "github.com/ethersphere/bee/pkg/spinlock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/storagetest" - chunk "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/storer/internal/stampindex" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/postage" + batchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + pullerMock "github.com/ethersphere/bee/v2/pkg/puller/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/storagetest" + chunk "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/storer/internal/stampindex" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestIndexCollision(t *testing.T) { diff --git a/pkg/storer/sample.go b/pkg/storer/sample.go index 7fd5cc2ad4a..d3cb1ecec99 100644 --- a/pkg/storer/sample.go +++ b/pkg/storer/sample.go @@ -16,13 +16,13 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/bmt" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/soc" - chunk "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstamp" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/bmt" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/soc" + chunk "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstamp" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/sync/errgroup" ) @@ -337,7 +337,7 @@ func transformedAddress(hasher *bmt.Hasher, chunk swarm.Chunk, chType swarm.Chun case swarm.ChunkTypeSingleOwner: return transformedAddressSOC(hasher, chunk) default: - return swarm.ZeroAddress, fmt.Errorf("chunk type [%v] is is not valid", chType) + return swarm.ZeroAddress, fmt.Errorf("chunk type [%v] is not valid", chType) } } diff --git a/pkg/storer/sample_test.go b/pkg/storer/sample_test.go index 215b190fc1a..cf10d59894b 100644 --- a/pkg/storer/sample_test.go +++ b/pkg/storer/sample_test.go @@ -6,15 +6,15 @@ package storer_test import ( "context" - "github.com/ethersphere/bee/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/postage" "math/rand" "testing" "time" - postagetesting "github.com/ethersphere/bee/pkg/postage/testing" - chunk "github.com/ethersphere/bee/pkg/storage/testing" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + postagetesting "github.com/ethersphere/bee/v2/pkg/postage/testing" + chunk "github.com/ethersphere/bee/v2/pkg/storage/testing" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/storer.go b/pkg/storer/storer.go index 3ebb3a025d7..c6987a54554 100644 --- a/pkg/storer/storer.go +++ b/pkg/storer/storer.go @@ -18,27 +18,27 @@ import ( "sync/atomic" "time" - "github.com/ethersphere/bee/pkg/log" - m "github.com/ethersphere/bee/pkg/metrics" - "github.com/ethersphere/bee/pkg/postage" - "github.com/ethersphere/bee/pkg/pusher" - "github.com/ethersphere/bee/pkg/retrieval" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/leveldbstore" - "github.com/ethersphere/bee/pkg/storage/migration" - "github.com/ethersphere/bee/pkg/storer/internal" - "github.com/ethersphere/bee/pkg/storer/internal/cache" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - "github.com/ethersphere/bee/pkg/storer/internal/events" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/storer/internal/reserve" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/util/syncutil" + "github.com/ethersphere/bee/v2/pkg/log" + m "github.com/ethersphere/bee/v2/pkg/metrics" + "github.com/ethersphere/bee/v2/pkg/postage" + "github.com/ethersphere/bee/v2/pkg/pusher" + "github.com/ethersphere/bee/v2/pkg/retrieval" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/leveldbstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + "github.com/ethersphere/bee/v2/pkg/storer/internal/cache" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + "github.com/ethersphere/bee/v2/pkg/storer/internal/events" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/storer/internal/reserve" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/util/syncutil" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/afero" "github.com/syndtr/goleveldb/leveldb" @@ -278,15 +278,15 @@ func initDiskRepository( basePath string, locker storage.ChunkLocker, opts *Options, -) (storage.Repository, io.Closer, error) { +) (storage.Repository, *PinIntegrity, io.Closer, error) { store, err := initStore(basePath, opts) if err != nil { - return nil, nil, fmt.Errorf("failed creating levelDB index store: %w", err) + return nil, nil, nil, fmt.Errorf("failed creating levelDB index store: %w", err) } err = migration.Migrate(store, "core-migration", localmigration.BeforeIinitSteps()) if err != nil { - return nil, nil, fmt.Errorf("failed core migration: %w", err) + return nil, nil, nil, fmt.Errorf("failed core migration: %w", err) } if opts.LdbStats.Load() != nil { @@ -338,13 +338,13 @@ func initDiskRepository( if _, err := os.Stat(sharkyBasePath); os.IsNotExist(err) { err := os.Mkdir(sharkyBasePath, 0777) if err != nil { - return nil, nil, err + return nil, nil, nil, err } } recoveryCloser, err := sharkyRecovery(ctx, sharkyBasePath, store, opts) if err != nil { - return nil, nil, fmt.Errorf("failed to recover sharky: %w", err) + return nil, nil, nil, fmt.Errorf("failed to recover sharky: %w", err) } sharky, err := sharky.New( @@ -353,20 +353,25 @@ func initDiskRepository( swarm.SocMaxChunkSize, ) if err != nil { - return nil, nil, fmt.Errorf("failed creating sharky instance: %w", err) + return nil, nil, nil, fmt.Errorf("failed creating sharky instance: %w", err) } txStore := leveldbstore.NewTxStore(store) if err := txStore.Recover(); err != nil { - return nil, nil, fmt.Errorf("failed to recover index store: %w", err) + return nil, nil, nil, fmt.Errorf("failed to recover index store: %w", err) } txChunkStore := chunkstore.NewTxChunkStore(txStore, sharky) if err := txChunkStore.Recover(); err != nil { - return nil, nil, fmt.Errorf("failed to recover chunk store: %w", err) + return nil, nil, nil, fmt.Errorf("failed to recover chunk store: %w", err) } - return storage.NewRepository(txStore, txChunkStore, locker), closer(store, sharky, recoveryCloser), nil + pinIntegrity := &PinIntegrity{ + Store: store, + Sharky: sharky, + } + + return storage.NewRepository(txStore, txChunkStore, locker), pinIntegrity, closer(store, sharky, recoveryCloser), nil } func initCache(ctx context.Context, capacity uint64, repo storage.Repository) (*cache.Cache, error) { @@ -457,6 +462,8 @@ type DB struct { setSyncerOnce sync.Once syncer Syncer opts workerOpts + + pinIntegrity *PinIntegrity } type workerOpts struct { @@ -468,9 +475,10 @@ type workerOpts struct { // component stores. func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) { var ( - repo storage.Repository - err error - dbCloser io.Closer + repo storage.Repository + err error + dbCloser io.Closer + pinIntegrity *PinIntegrity ) if opts == nil { opts = defaultOptions() @@ -497,7 +505,7 @@ func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) { return nil, err } } else { - repo, dbCloser, err = initDiskRepository(ctx, dirPath, locker, opts) + repo, pinIntegrity, dbCloser, err = initDiskRepository(ctx, dirPath, locker, opts) if err != nil { return nil, err } @@ -550,6 +558,7 @@ func New(ctx context.Context, dirPath string, opts *Options) (*DB, error) { wakeupDuration: opts.ReserveWakeUpDuration, }, directUploadLimiter: make(chan struct{}, pusher.ConcurrentPushes), + pinIntegrity: pinIntegrity, } if db.validStamp == nil { @@ -665,6 +674,10 @@ func (db *DB) ChunkStore() storage.ReadOnlyChunkStore { return db.repo.ChunkStore() } +func (db *DB) PinIntegrity() *PinIntegrity { + return db.pinIntegrity +} + // Execute implements the internal.TxExecutor interface. func (db *DB) Execute(ctx context.Context, do func(internal.Storage) error) error { tx, commit, rollback := db.repo.NewTx(ctx) diff --git a/pkg/storer/storer_test.go b/pkg/storer/storer_test.go index ce2d7eb72cf..43ea78d889e 100644 --- a/pkg/storer/storer_test.go +++ b/pkg/storer/storer_test.go @@ -11,20 +11,20 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/postage" - batchstore "github.com/ethersphere/bee/pkg/postage/batchstore/mock" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/storage/migration" - "github.com/ethersphere/bee/pkg/storer" - cs "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - localmigration "github.com/ethersphere/bee/pkg/storer/migration" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - kademlia "github.com/ethersphere/bee/pkg/topology/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/postage" + batchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/storage/migration" + "github.com/ethersphere/bee/v2/pkg/storer" + cs "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + localmigration "github.com/ethersphere/bee/v2/pkg/storer/migration" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + kademlia "github.com/ethersphere/bee/v2/pkg/topology/mock" ) func verifyChunks( diff --git a/pkg/storer/subscribe_push.go b/pkg/storer/subscribe_push.go index d9c37abce28..a82c0db46db 100644 --- a/pkg/storer/subscribe_push.go +++ b/pkg/storer/subscribe_push.go @@ -9,8 +9,8 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const subscribePushEventKey = "subscribe-push" diff --git a/pkg/storer/subscribe_push_test.go b/pkg/storer/subscribe_push_test.go index 851dd060580..17d7c46e486 100644 --- a/pkg/storer/subscribe_push_test.go +++ b/pkg/storer/subscribe_push_test.go @@ -11,9 +11,9 @@ import ( "testing" "time" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestPushSubscriber(t *testing.T) { diff --git a/pkg/storer/uploadstore.go b/pkg/storer/uploadstore.go index 9b5aeca4bbc..d3596dbede0 100644 --- a/pkg/storer/uploadstore.go +++ b/pkg/storer/uploadstore.go @@ -10,11 +10,11 @@ import ( "fmt" "sort" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/storer/internal/upload" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/storer/internal/upload" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const uploadStoreKey = "uploadstore" diff --git a/pkg/storer/uploadstore_test.go b/pkg/storer/uploadstore_test.go index fa267728e6e..04b1016027a 100644 --- a/pkg/storer/uploadstore_test.go +++ b/pkg/storer/uploadstore_test.go @@ -11,10 +11,10 @@ import ( "testing" "time" - storage "github.com/ethersphere/bee/pkg/storage" - chunktesting "github.com/ethersphere/bee/pkg/storage/testing" - storer "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + storage "github.com/ethersphere/bee/v2/pkg/storage" + chunktesting "github.com/ethersphere/bee/v2/pkg/storage/testing" + storer "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/storer/validate.go b/pkg/storer/validate.go index ccad569455d..894f12a0651 100644 --- a/pkg/storer/validate.go +++ b/pkg/storer/validate.go @@ -14,14 +14,14 @@ import ( "sync/atomic" - "github.com/ethersphere/bee/pkg/cac" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sharky" - "github.com/ethersphere/bee/pkg/soc" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storer/internal/chunkstore" - pinstore "github.com/ethersphere/bee/pkg/storer/internal/pinning" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/cac" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sharky" + "github.com/ethersphere/bee/v2/pkg/soc" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storer/internal/chunkstore" + pinstore "github.com/ethersphere/bee/v2/pkg/storer/internal/pinning" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Validate ensures that all retrievalIndex chunks are correctly stored in sharky. @@ -173,27 +173,81 @@ func ValidatePinCollectionChunks(ctx context.Context, basePath, pin, location st }() logger.Info("performing chunk validation") - validatePins(logger, store, pin, location, sharky.Read) + + pv := PinIntegrity{ + Store: store, + Sharky: sharky, + } + + var ( + fileName = "address.csv" + fileLoc = "." + ) + + if location != "" { + if path.Ext(location) != "" { + fileName = path.Base(location) + } + fileLoc = path.Dir(location) + } + + logger.Info("saving stats", "location", fileLoc, "name", fileName) + + location = path.Join(fileLoc, fileName) + + f, err := os.OpenFile(location, os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + return fmt.Errorf("open output file for writing: %w", err) + } + + if _, err := f.WriteString("invalid\tmissing\ttotal\taddress\n"); err != nil { + return fmt.Errorf("write title: %w", err) + } + + defer f.Close() + + var ch = make(chan PinStat) + go pv.Check(ctx, logger, pin, ch) + + for st := range ch { + report := fmt.Sprintf("%d\t%d\t%d\t%s\n", st.Invalid, st.Missing, st.Total, st.Ref) + + if _, err := f.WriteString(report); err != nil { + logger.Error(err, "write report line") + break + } + } return nil } -func validatePins(logger log.Logger, store storage.Store, pin, location string, readFn func(context.Context, sharky.Location, []byte) error) { +type PinIntegrity struct { + Store storage.Store + Sharky *sharky.Store +} + +type PinStat struct { + Ref swarm.Address + Total, Missing, Invalid int +} + +func (p *PinIntegrity) Check(ctx context.Context, logger log.Logger, pin string, out chan PinStat) { var stats struct { total, read, invalid atomic.Int32 } n := time.Now() defer func() { + close(out) logger.Info("done", "duration", time.Since(n), "read", stats.read.Load(), "invalid", stats.invalid.Load(), "total", stats.total.Load()) }() validChunk := func(item *chunkstore.RetrievalIndexItem, buf []byte) bool { stats.total.Add(1) - if err := readFn(context.Background(), item.Location, buf); err != nil { + if err := p.Sharky.Read(ctx, item.Location, buf); err != nil { stats.read.Add(1) - return true + return false } ch := swarm.NewChunk(item.Address, buf) @@ -221,7 +275,7 @@ func validatePins(logger log.Logger, store storage.Store, pin, location string, pins = append(pins, addr) } else { var err error - pins, err = pinstore.Pins(store) + pins, err = pinstore.Pins(p.Store) if err != nil { logger.Error(err, "get pins") return @@ -230,34 +284,11 @@ func validatePins(logger log.Logger, store storage.Store, pin, location string, logger.Info("got a total number of pins", "size", len(pins)) - var ( - fileName = "address.csv" - fileLoc = "." - ) - - if location != "" { - if path.Ext(location) != "" { - fileName = path.Base(location) - } - fileLoc = path.Dir(location) - } - - logger.Info("saving stats to", "location", fileLoc, "name", fileName) - - location = path.Join(fileLoc, fileName) - - f, err := os.OpenFile(location, os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - logger.Error(err, "open output file for writing") - return - } - - if _, err := f.WriteString("invalid\tmissing\ttotal\taddress\n"); err != nil { - logger.Error(err, "write title") - return - } - - defer f.Close() + var tcount, tmicrs int64 + defer func() { + dur := float64(tmicrs) / float64(tcount) + logger.Info("done iterating pins", "duration", dur) + }() for _, pin := range pins { var wg sync.WaitGroup @@ -273,6 +304,9 @@ func validatePins(logger log.Logger, store storage.Store, pin, location string, defer wg.Done() buf := make([]byte, swarm.SocMaxChunkSize) for item := range iteratateItemsC { + if ctx.Err() != nil { + break + } if !validChunk(item, buf[:item.Location.Length]) { invalid.Add(1) } @@ -280,28 +314,56 @@ func validatePins(logger log.Logger, store storage.Store, pin, location string, }() } - logger.Info("start iteration", "pin", pin) + var count, micrs int64 + + err := pinstore.IterateCollection(p.Store, pin, func(addr swarm.Address) (bool, error) { + n := time.Now() + + defer func() { + count++ + micrs += time.Since(n).Microseconds() + }() - _ = pinstore.IterateCollection(store, pin, func(addr swarm.Address) (bool, error) { total.Add(1) + rIdx := &chunkstore.RetrievalIndexItem{Address: addr} - if err := store.Get(rIdx); err != nil { + if err := p.Store.Get(rIdx); err != nil { missing.Add(1) } else { - iteratateItemsC <- rIdx + select { + case <-ctx.Done(): + return true, nil + case iteratateItemsC <- rIdx: + } } + return false, nil }) + dur := float64(micrs) / float64(count) + + if err != nil { + logger.Error(err, "new iteration", "pin", pin, "duration", dur) + } else { + logger.Info("new iteration", "pin", pin, "duration", dur) + } + + tcount++ + tmicrs += int64(dur) + close(iteratateItemsC) wg.Wait() - report := fmt.Sprintf("%d\t%d\t%d\t%s\n", invalid.Load(), missing.Load(), total.Load(), pin) - - if _, err := f.WriteString(report); err != nil { - logger.Error(err, "write report line") + select { + case <-ctx.Done(): + logger.Info("context done") return + case out <- PinStat{ + Ref: pin, + Total: int(total.Load()), + Missing: int(missing.Load()), + Invalid: int(invalid.Load())}: } } } diff --git a/pkg/swarm/distance_test.go b/pkg/swarm/distance_test.go index f06641a0ed2..0adf2430919 100644 --- a/pkg/swarm/distance_test.go +++ b/pkg/swarm/distance_test.go @@ -7,7 +7,7 @@ package swarm_test import ( "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type distanceTest struct { diff --git a/pkg/swarm/hasher_test.go b/pkg/swarm/hasher_test.go index 3811e09605a..f08e2f28f42 100644 --- a/pkg/swarm/hasher_test.go +++ b/pkg/swarm/hasher_test.go @@ -8,7 +8,7 @@ import ( "bytes" "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestNewHasher(t *testing.T) { diff --git a/pkg/swarm/swarm_test.go b/pkg/swarm/swarm_test.go index 7555ac5bf4d..fdde62625be 100644 --- a/pkg/swarm/swarm_test.go +++ b/pkg/swarm/swarm_test.go @@ -10,7 +10,7 @@ import ( "errors" "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func TestAddress(t *testing.T) { diff --git a/pkg/swarm/test_helpers.go b/pkg/swarm/test_helpers.go index e3d6cb27ac9..b043e1bb17d 100644 --- a/pkg/swarm/test_helpers.go +++ b/pkg/swarm/test_helpers.go @@ -8,7 +8,7 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) // RandAddress generates a random address. diff --git a/pkg/swarm/test_helpers_test.go b/pkg/swarm/test_helpers_test.go index e7c21e9e633..a4184dfedc2 100644 --- a/pkg/swarm/test_helpers_test.go +++ b/pkg/swarm/test_helpers_test.go @@ -8,7 +8,7 @@ import ( "encoding/binary" "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func Test_RandAddress(t *testing.T) { diff --git a/pkg/swarm/utilities_test.go b/pkg/swarm/utilities_test.go index 17ade1aaa28..6cd75a89a32 100644 --- a/pkg/swarm/utilities_test.go +++ b/pkg/swarm/utilities_test.go @@ -7,7 +7,7 @@ package swarm_test import ( "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func Test_ContainsAddress(t *testing.T) { diff --git a/pkg/topology/kademlia/binprefix.go b/pkg/topology/kademlia/binprefix.go index f9d92ff429e..94e2550ea2d 100644 --- a/pkg/topology/kademlia/binprefix.go +++ b/pkg/topology/kademlia/binprefix.go @@ -8,7 +8,7 @@ import ( "math" "math/bits" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // generateCommonBinPrefixes generates the common bin prefixes diff --git a/pkg/topology/kademlia/export_test.go b/pkg/topology/kademlia/export_test.go index b005dd92c93..96b8b3191fc 100644 --- a/pkg/topology/kademlia/export_test.go +++ b/pkg/topology/kademlia/export_test.go @@ -5,9 +5,9 @@ package kademlia import ( - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/pslice" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/pslice" ) var ( diff --git a/pkg/topology/kademlia/internal/metrics/metrics.go b/pkg/topology/kademlia/internal/metrics/metrics.go index a161b2ec014..d6ce41e3a73 100644 --- a/pkg/topology/kademlia/internal/metrics/metrics.go +++ b/pkg/topology/kademlia/internal/metrics/metrics.go @@ -13,9 +13,9 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/shed" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/shed" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/syndtr/goleveldb/leveldb" ) diff --git a/pkg/topology/kademlia/internal/metrics/metrics_test.go b/pkg/topology/kademlia/internal/metrics/metrics_test.go index 3373dc4b7b8..2aae2a68c4e 100644 --- a/pkg/topology/kademlia/internal/metrics/metrics_test.go +++ b/pkg/topology/kademlia/internal/metrics/metrics_test.go @@ -8,11 +8,11 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/shed" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/kademlia/internal/metrics" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/shed" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia/internal/metrics" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/google/go-cmp/cmp" ) diff --git a/pkg/topology/kademlia/internal/waitnext/waitnext.go b/pkg/topology/kademlia/internal/waitnext/waitnext.go index 744622d93b8..9a93f274eba 100644 --- a/pkg/topology/kademlia/internal/waitnext/waitnext.go +++ b/pkg/topology/kademlia/internal/waitnext/waitnext.go @@ -10,7 +10,7 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type next struct { diff --git a/pkg/topology/kademlia/internal/waitnext/waitnext_test.go b/pkg/topology/kademlia/internal/waitnext/waitnext_test.go index 35f3062bd38..3b67a785f3e 100644 --- a/pkg/topology/kademlia/internal/waitnext/waitnext_test.go +++ b/pkg/topology/kademlia/internal/waitnext/waitnext_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/kademlia/internal/waitnext" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia/internal/waitnext" ) func TestSet(t *testing.T) { diff --git a/pkg/topology/kademlia/kademlia.go b/pkg/topology/kademlia/kademlia.go index 277eeba331a..5fe6f7f2f4d 100644 --- a/pkg/topology/kademlia/kademlia.go +++ b/pkg/topology/kademlia/kademlia.go @@ -16,16 +16,16 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/discovery" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/shed" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - im "github.com/ethersphere/bee/pkg/topology/kademlia/internal/metrics" - "github.com/ethersphere/bee/pkg/topology/kademlia/internal/waitnext" - "github.com/ethersphere/bee/pkg/topology/pslice" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/discovery" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/shed" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + im "github.com/ethersphere/bee/v2/pkg/topology/kademlia/internal/metrics" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia/internal/waitnext" + "github.com/ethersphere/bee/v2/pkg/topology/pslice" ma "github.com/multiformats/go-multiaddr" "golang.org/x/sync/errgroup" ) @@ -913,7 +913,7 @@ func (k *Kad) recalcDepth() { } // connect connects to a peer and gossips its address to our connected peers, -// as well as sends the peers we are connected to to the newly connected peer +// as well as sends the peers we are connected to the newly connected peer func (k *Kad) connect(ctx context.Context, peer swarm.Address, ma ma.Multiaddr) error { k.logger.Debug("attempting connect to peer", "peer_address", peer) diff --git a/pkg/topology/kademlia/kademlia_test.go b/pkg/topology/kademlia/kademlia_test.go index 48e0c20ecb7..e3cd6912ebc 100644 --- a/pkg/topology/kademlia/kademlia_test.go +++ b/pkg/topology/kademlia/kademlia_test.go @@ -18,21 +18,21 @@ import ( ma "github.com/multiformats/go-multiaddr" - "github.com/ethersphere/bee/pkg/addressbook" - "github.com/ethersphere/bee/pkg/bzz" - beeCrypto "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/discovery/mock" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - p2pmock "github.com/ethersphere/bee/pkg/p2p/mock" - "github.com/ethersphere/bee/pkg/spinlock" - mockstate "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/kademlia" - im "github.com/ethersphere/bee/pkg/topology/kademlia/internal/metrics" - "github.com/ethersphere/bee/pkg/topology/pslice" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/addressbook" + "github.com/ethersphere/bee/v2/pkg/bzz" + beeCrypto "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/discovery/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + p2pmock "github.com/ethersphere/bee/v2/pkg/p2p/mock" + "github.com/ethersphere/bee/v2/pkg/spinlock" + mockstate "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/kademlia" + im "github.com/ethersphere/bee/v2/pkg/topology/kademlia/internal/metrics" + "github.com/ethersphere/bee/v2/pkg/topology/pslice" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) const spinLockWaitTime = time.Second * 5 diff --git a/pkg/topology/kademlia/metrics.go b/pkg/topology/kademlia/metrics.go index 3640ca7fd54..42e1d6c294a 100644 --- a/pkg/topology/kademlia/metrics.go +++ b/pkg/topology/kademlia/metrics.go @@ -5,7 +5,7 @@ package kademlia import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/topology/kademlia/mock/kademlia.go b/pkg/topology/kademlia/mock/kademlia.go index 23713a129c6..cd115bf7186 100644 --- a/pkg/topology/kademlia/mock/kademlia.go +++ b/pkg/topology/kademlia/mock/kademlia.go @@ -9,9 +9,9 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) type AddrTuple struct { diff --git a/pkg/topology/lightnode/container.go b/pkg/topology/lightnode/container.go index 5f2285a06a4..0e4f6c3967c 100644 --- a/pkg/topology/lightnode/container.go +++ b/pkg/topology/lightnode/container.go @@ -10,10 +10,10 @@ import ( "math/big" "sync" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/pslice" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/pslice" ) type Container struct { diff --git a/pkg/topology/lightnode/container_test.go b/pkg/topology/lightnode/container_test.go index 3533dcc089f..20a7664adc5 100644 --- a/pkg/topology/lightnode/container_test.go +++ b/pkg/topology/lightnode/container_test.go @@ -10,10 +10,10 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" - "github.com/ethersphere/bee/pkg/topology/lightnode" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/topology/lightnode" ) func TestContainer(t *testing.T) { diff --git a/pkg/topology/lightnode/metrics.go b/pkg/topology/lightnode/metrics.go index f6c6ff2bbc1..cea1504f8a9 100644 --- a/pkg/topology/lightnode/metrics.go +++ b/pkg/topology/lightnode/metrics.go @@ -5,7 +5,7 @@ package lightnode import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/topology/mock/mock.go b/pkg/topology/mock/mock.go index f052045920b..f545bfee858 100644 --- a/pkg/topology/mock/mock.go +++ b/pkg/topology/mock/mock.go @@ -10,9 +10,9 @@ import ( "sync" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) type mock struct { diff --git a/pkg/topology/pslice/pslice.go b/pkg/topology/pslice/pslice.go index 0337fa0125d..ca1b8e5c4c3 100644 --- a/pkg/topology/pslice/pslice.go +++ b/pkg/topology/pslice/pslice.go @@ -7,8 +7,8 @@ package pslice import ( "sync" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/topology" ) // PSlice maintains a list of addresses, indexing them by their different proximity orders. diff --git a/pkg/topology/pslice/pslice_test.go b/pkg/topology/pslice/pslice_test.go index 37e454871ce..9bcdf1312e2 100644 --- a/pkg/topology/pslice/pslice_test.go +++ b/pkg/topology/pslice/pslice_test.go @@ -9,9 +9,9 @@ import ( "sort" "testing" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" - "github.com/ethersphere/bee/pkg/topology/pslice" + "github.com/ethersphere/bee/v2/pkg/topology/pslice" ) // TestShallowestEmpty tests that ShallowestEmpty functionality works correctly. diff --git a/pkg/topology/topology.go b/pkg/topology/topology.go index ebc7bcf8670..63747a912c6 100644 --- a/pkg/topology/topology.go +++ b/pkg/topology/topology.go @@ -11,8 +11,8 @@ import ( "io" "time" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var ( diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 14ccdb9ab43..e9c563464fa 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -13,8 +13,8 @@ import ( "net/http" "time" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" "github.com/opentracing/opentracing-go" "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" diff --git a/pkg/tracing/tracing_test.go b/pkg/tracing/tracing_test.go index 8a2f871dc45..9c0baa2f685 100644 --- a/pkg/tracing/tracing_test.go +++ b/pkg/tracing/tracing_test.go @@ -11,10 +11,10 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/p2p" - "github.com/ethersphere/bee/pkg/tracing" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/p2p" + "github.com/ethersphere/bee/v2/pkg/tracing" + "github.com/ethersphere/bee/v2/pkg/util/testutil" "github.com/uber/jaeger-client-go" ) diff --git a/pkg/transaction/backend.go b/pkg/transaction/backend.go index df479d55829..be1f958b317 100644 --- a/pkg/transaction/backend.go +++ b/pkg/transaction/backend.go @@ -13,7 +13,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" ) // Backend is the minimum of blockchain backend functions we need. diff --git a/pkg/transaction/backend_test.go b/pkg/transaction/backend_test.go index 8ca76fec823..d9d09e55b3c 100644 --- a/pkg/transaction/backend_test.go +++ b/pkg/transaction/backend_test.go @@ -12,8 +12,8 @@ import ( "time" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendmock" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" ) func TestIsSynced(t *testing.T) { diff --git a/pkg/transaction/backendmock/backend.go b/pkg/transaction/backendmock/backend.go index 7f787fe3d60..3a78f325c0c 100644 --- a/pkg/transaction/backendmock/backend.go +++ b/pkg/transaction/backendmock/backend.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) type backendMock struct { diff --git a/pkg/transaction/backendsimulation/backend.go b/pkg/transaction/backendsimulation/backend.go index 2b3a3946864..57965abe7ea 100644 --- a/pkg/transaction/backendsimulation/backend.go +++ b/pkg/transaction/backendsimulation/backend.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) type AccountAtKey struct { diff --git a/pkg/transaction/event_test.go b/pkg/transaction/event_test.go index 4d6dd47193e..e286796d248 100644 --- a/pkg/transaction/event_test.go +++ b/pkg/transaction/event_test.go @@ -11,8 +11,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" "github.com/ethersphere/go-sw3-abi/sw3abi" ) diff --git a/pkg/transaction/mock/transaction.go b/pkg/transaction/mock/transaction.go index 7478daa63e6..d987fd52249 100644 --- a/pkg/transaction/mock/transaction.go +++ b/pkg/transaction/mock/transaction.go @@ -14,7 +14,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) type transactionServiceMock struct { diff --git a/pkg/transaction/monitor.go b/pkg/transaction/monitor.go index 64d58be7c5c..f4ebcd3be92 100644 --- a/pkg/transaction/monitor.go +++ b/pkg/transaction/monitor.go @@ -15,7 +15,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/log" + "github.com/ethersphere/bee/v2/pkg/log" ) var ErrTransactionCancelled = errors.New("transaction cancelled") diff --git a/pkg/transaction/monitor_test.go b/pkg/transaction/monitor_test.go index 5887848ac2c..7b88e84629f 100644 --- a/pkg/transaction/monitor_test.go +++ b/pkg/transaction/monitor_test.go @@ -11,9 +11,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendsimulation" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendsimulation" ) func TestMonitorWatchTransaction(t *testing.T) { diff --git a/pkg/transaction/monitormock/monitor.go b/pkg/transaction/monitormock/monitor.go index a0334469873..1662751aa74 100644 --- a/pkg/transaction/monitormock/monitor.go +++ b/pkg/transaction/monitormock/monitor.go @@ -11,7 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) type transactionMonitorMock struct { diff --git a/pkg/transaction/transaction.go b/pkg/transaction/transaction.go index 592af68a566..2774aad95af 100644 --- a/pkg/transaction/transaction.go +++ b/pkg/transaction/transaction.go @@ -19,10 +19,10 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sctx" - "github.com/ethersphere/bee/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sctx" + "github.com/ethersphere/bee/v2/pkg/storage" "golang.org/x/net/context" ) diff --git a/pkg/transaction/transaction_test.go b/pkg/transaction/transaction_test.go index 0bc8be4f361..41cf94f0112 100644 --- a/pkg/transaction/transaction_test.go +++ b/pkg/transaction/transaction_test.go @@ -18,16 +18,16 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" - "github.com/ethersphere/bee/pkg/crypto" - signermock "github.com/ethersphere/bee/pkg/crypto/mock" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/sctx" - storemock "github.com/ethersphere/bee/pkg/statestore/mock" - "github.com/ethersphere/bee/pkg/transaction" - "github.com/ethersphere/bee/pkg/transaction/backendmock" - "github.com/ethersphere/bee/pkg/transaction/monitormock" - "github.com/ethersphere/bee/pkg/util/abiutil" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/crypto" + signermock "github.com/ethersphere/bee/v2/pkg/crypto/mock" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/sctx" + storemock "github.com/ethersphere/bee/v2/pkg/statestore/mock" + "github.com/ethersphere/bee/v2/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction/backendmock" + "github.com/ethersphere/bee/v2/pkg/transaction/monitormock" + "github.com/ethersphere/bee/v2/pkg/util/abiutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func nonceKey(sender common.Address) string { diff --git a/pkg/transaction/wrapped/metrics.go b/pkg/transaction/wrapped/metrics.go index bc555032fdf..eeb255c3d3b 100644 --- a/pkg/transaction/wrapped/metrics.go +++ b/pkg/transaction/wrapped/metrics.go @@ -5,7 +5,7 @@ package wrapped import ( - m "github.com/ethersphere/bee/pkg/metrics" + m "github.com/ethersphere/bee/v2/pkg/metrics" "github.com/prometheus/client_golang/prometheus" ) diff --git a/pkg/transaction/wrapped/wrapped.go b/pkg/transaction/wrapped/wrapped.go index 24d8e3d5a0c..f810ee2ebab 100644 --- a/pkg/transaction/wrapped/wrapped.go +++ b/pkg/transaction/wrapped/wrapped.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/bee/pkg/transaction" + "github.com/ethersphere/bee/v2/pkg/transaction" ) var ( diff --git a/pkg/traversal/traversal.go b/pkg/traversal/traversal.go index dbdb5603e82..98029f925d9 100644 --- a/pkg/traversal/traversal.go +++ b/pkg/traversal/traversal.go @@ -13,13 +13,13 @@ import ( "errors" "fmt" - "github.com/ethersphere/bee/pkg/file/joiner" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/manifest/mantaray" - "github.com/ethersphere/bee/pkg/soc" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file/joiner" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/manifest/mantaray" + "github.com/ethersphere/bee/v2/pkg/soc" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Traverser represents service which traverse through address dependent chunks. diff --git a/pkg/traversal/traversal_test.go b/pkg/traversal/traversal_test.go index 7d9d473e1e4..04f0068c6de 100644 --- a/pkg/traversal/traversal_test.go +++ b/pkg/traversal/traversal_test.go @@ -14,15 +14,15 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/manifest" - testingsoc "github.com/ethersphere/bee/pkg/soc/testing" - storage "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/storage/inmemchunkstore" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/traversal" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/manifest" + testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing" + storage "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/traversal" ) const ( diff --git a/pkg/util/nbhdutil/miner.go b/pkg/util/nbhdutil/miner.go index 4d6f38a6f1d..83a51a8eeb7 100644 --- a/pkg/util/nbhdutil/miner.go +++ b/pkg/util/nbhdutil/miner.go @@ -10,8 +10,8 @@ import ( "encoding/binary" "fmt" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/swarm" ) func MineOverlay(ctx context.Context, p ecdsa.PublicKey, networkID uint64, targetNeighborhood string) (swarm.Address, []byte, error) { diff --git a/pkg/util/nbhdutil/miner_test.go b/pkg/util/nbhdutil/miner_test.go index 2b630af3c19..bcf72128bb9 100644 --- a/pkg/util/nbhdutil/miner_test.go +++ b/pkg/util/nbhdutil/miner_test.go @@ -9,9 +9,9 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/swarm" - "github.com/ethersphere/bee/pkg/util/nbhdutil" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/util/nbhdutil" ) func TestMiner(t *testing.T) { diff --git a/pkg/util/nbhdutil/neighborhoodsuggestion.go b/pkg/util/nbhdutil/neighborhoodsuggestion.go new file mode 100644 index 00000000000..699bc37505b --- /dev/null +++ b/pkg/util/nbhdutil/neighborhoodsuggestion.go @@ -0,0 +1,53 @@ +// Copyright 2024 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 nbhdutil + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + + "github.com/ethersphere/bee/v2/pkg/swarm" +) + +type httpClient interface { + Get(url string) (*http.Response, error) +} + +func FetchNeighborhood(client httpClient, suggester string) (string, error) { + if suggester == "" { + return "", nil + } + + _, err := url.ParseRequestURI(suggester) + if err != nil { + return "", err + } + + type suggestionRes struct { + Neighborhood string `json:"neighborhood"` + } + res, err := client.Get(suggester) + if err != nil { + return "", err + } + defer res.Body.Close() + var suggestion suggestionRes + d, err := io.ReadAll(res.Body) + if err != nil { + return "", err + } + err = json.Unmarshal(d, &suggestion) + if err != nil { + return "", err + } + _, err = swarm.ParseBitStrAddress(suggestion.Neighborhood) + if err != nil { + return "", fmt.Errorf("invalid neighborhood. %s", suggestion.Neighborhood) + } + return suggestion.Neighborhood, nil +} diff --git a/pkg/util/nbhdutil/neighborhoodsuggestion_test.go b/pkg/util/nbhdutil/neighborhoodsuggestion_test.go new file mode 100644 index 00000000000..cf477800882 --- /dev/null +++ b/pkg/util/nbhdutil/neighborhoodsuggestion_test.go @@ -0,0 +1,86 @@ +// Copyright 2024 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 nbhdutil_test + +import ( + "io" + "net/http" + "strings" + "testing" + + "github.com/ethersphere/bee/v2/pkg/util/nbhdutil" +) + +type mockHttpClient struct { + res string +} + +func (c *mockHttpClient) Get(_ string) (*http.Response, error) { + return &http.Response{ + Body: io.NopCloser(strings.NewReader(c.res)), + }, nil +} + +func Test_FetchNeighborhood(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + neighborhood string + suggester string + httpRes string + wantNeighborhood string + wantError bool + }{ + { + name: "no suggester", + suggester: "", + wantNeighborhood: "", + wantError: false, + }, + { + name: "inavlid suggester url", + suggester: "abc", + wantNeighborhood: "", + wantError: true, + }, + { + name: "missing neighborhood in res", + suggester: "http://test.com", + wantNeighborhood: "", + wantError: false, + httpRes: `{"abc":"abc"}`, + }, + { + name: "invalid neighborhood", + suggester: "http://test.com", + wantNeighborhood: "", + wantError: true, + httpRes: `{"neighborhood":"abc"}`, + }, + { + name: "valid neighborhood", + suggester: "http://test.com", + wantNeighborhood: "11011101000", + wantError: false, + httpRes: `{"neighborhood":"11011101000"}`, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + neighborhood, err := nbhdutil.FetchNeighborhood(&mockHttpClient{res: test.httpRes}, test.suggester) + if test.wantNeighborhood != neighborhood { + t.Fatalf("invalid neighborhood. want %s, got %s", test.wantNeighborhood, neighborhood) + } + if test.wantError && err == nil { + t.Fatalf("expected error. got no error") + } + if !test.wantError && err != nil { + t.Fatalf("expected no error. got %v", err) + } + }) + } +} diff --git a/pkg/util/testutil/helpers.go b/pkg/util/testutil/helpers.go index da9488e0987..1726e33d020 100644 --- a/pkg/util/testutil/helpers.go +++ b/pkg/util/testutil/helpers.go @@ -11,8 +11,8 @@ import ( "reflect" "testing" - "github.com/ethersphere/bee/pkg/log" - "github.com/ethersphere/bee/pkg/util/ioutil" + "github.com/ethersphere/bee/v2/pkg/log" + "github.com/ethersphere/bee/v2/pkg/util/ioutil" ) // RandBytes returns bytes slice of specified size filled with random values. diff --git a/pkg/util/testutil/helpers_test.go b/pkg/util/testutil/helpers_test.go index d74c8ad4bca..7ad37a272f9 100644 --- a/pkg/util/testutil/helpers_test.go +++ b/pkg/util/testutil/helpers_test.go @@ -8,7 +8,7 @@ import ( "bytes" "testing" - "github.com/ethersphere/bee/pkg/util/testutil" + "github.com/ethersphere/bee/v2/pkg/util/testutil" ) func TestRandBytes(t *testing.T) { diff --git a/pkg/util/testutil/pseudorand/reader.go b/pkg/util/testutil/pseudorand/reader.go index d7fcf0c3646..bccb8900d7e 100644 --- a/pkg/util/testutil/pseudorand/reader.go +++ b/pkg/util/testutil/pseudorand/reader.go @@ -16,7 +16,7 @@ import ( "fmt" "io" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const bufSize = 4096 diff --git a/pkg/util/testutil/pseudorand/reader_test.go b/pkg/util/testutil/pseudorand/reader_test.go index 4ec85a90d73..2abd6aaf382 100644 --- a/pkg/util/testutil/pseudorand/reader_test.go +++ b/pkg/util/testutil/pseudorand/reader_test.go @@ -12,7 +12,7 @@ import ( "math/rand" "testing" - "github.com/ethersphere/bee/pkg/util/testutil/pseudorand" + "github.com/ethersphere/bee/v2/pkg/util/testutil/pseudorand" ) func TestReader(t *testing.T) { From 9e366b76b84dff530baf31fdcbb3b24bacf21d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20S=C3=A1rai?= Date: Thu, 4 Apr 2024 11:41:44 +0200 Subject: [PATCH 22/22] Update package imports to use the v2 version of the modules (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ferenc Sárai --- pkg/dynamicaccess/accesslogic.go | 6 +++--- pkg/dynamicaccess/accesslogic_test.go | 8 ++++---- pkg/dynamicaccess/controller.go | 4 ++-- pkg/dynamicaccess/controller_test.go | 12 ++++++------ pkg/dynamicaccess/grantee.go | 6 +++--- pkg/dynamicaccess/grantee_manager.go | 6 +++--- pkg/dynamicaccess/grantee_manager_test.go | 4 ++-- pkg/dynamicaccess/grantee_test.go | 18 +++++++++--------- pkg/dynamicaccess/history.go | 2 +- pkg/dynamicaccess/history_test.go | 6 +++--- pkg/dynamicaccess/mock/grantee.go | 2 +- pkg/dynamicaccess/mock/history.go | 10 +++++----- pkg/dynamicaccess/mock/session.go | 4 ++-- pkg/dynamicaccess/session.go | 4 ++-- pkg/dynamicaccess/session_test.go | 8 ++++---- pkg/kvs/kvs.go | 8 ++++---- pkg/kvs/kvs_test.go | 18 +++++++++--------- pkg/kvs/mock/kvs.go | 4 ++-- 18 files changed, 65 insertions(+), 65 deletions(-) diff --git a/pkg/dynamicaccess/accesslogic.go b/pkg/dynamicaccess/accesslogic.go index 593e02d630c..a2a6fbdce24 100644 --- a/pkg/dynamicaccess/accesslogic.go +++ b/pkg/dynamicaccess/accesslogic.go @@ -3,9 +3,9 @@ package dynamicaccess import ( "crypto/ecdsa" - encryption "github.com/ethersphere/bee/pkg/encryption" - "github.com/ethersphere/bee/pkg/kvs" - "github.com/ethersphere/bee/pkg/swarm" + encryption "github.com/ethersphere/bee/v2/pkg/encryption" + "github.com/ethersphere/bee/v2/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/crypto/sha3" ) diff --git a/pkg/dynamicaccess/accesslogic_test.go b/pkg/dynamicaccess/accesslogic_test.go index 8c2f2a6489f..be115f424d1 100644 --- a/pkg/dynamicaccess/accesslogic_test.go +++ b/pkg/dynamicaccess/accesslogic_test.go @@ -7,10 +7,10 @@ import ( "encoding/hex" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/dynamicaccess" - kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) // Generates a new test environment with a fix private key diff --git a/pkg/dynamicaccess/controller.go b/pkg/dynamicaccess/controller.go index df39fa23c32..ccdc8c2d7f4 100644 --- a/pkg/dynamicaccess/controller.go +++ b/pkg/dynamicaccess/controller.go @@ -3,8 +3,8 @@ package dynamicaccess import ( "crypto/ecdsa" - kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" - "github.com/ethersphere/bee/pkg/swarm" + kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type Controller interface { diff --git a/pkg/dynamicaccess/controller_test.go b/pkg/dynamicaccess/controller_test.go index 24107123ab5..efbfc8d4e42 100644 --- a/pkg/dynamicaccess/controller_test.go +++ b/pkg/dynamicaccess/controller_test.go @@ -8,12 +8,12 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/dynamicaccess/mock" - "github.com/ethersphere/bee/pkg/encryption" - kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess/mock" + "github.com/ethersphere/bee/v2/pkg/encryption" + kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "golang.org/x/crypto/sha3" ) diff --git a/pkg/dynamicaccess/grantee.go b/pkg/dynamicaccess/grantee.go index afbe5349818..d850fc047cc 100644 --- a/pkg/dynamicaccess/grantee.go +++ b/pkg/dynamicaccess/grantee.go @@ -6,9 +6,9 @@ import ( "crypto/elliptic" "fmt" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) const ( diff --git a/pkg/dynamicaccess/grantee_manager.go b/pkg/dynamicaccess/grantee_manager.go index eaa9cc9ffd9..1fac35a38bd 100644 --- a/pkg/dynamicaccess/grantee_manager.go +++ b/pkg/dynamicaccess/grantee_manager.go @@ -3,9 +3,9 @@ package dynamicaccess import ( "crypto/ecdsa" - "github.com/ethersphere/bee/pkg/dynamicaccess/mock" - "github.com/ethersphere/bee/pkg/kvs" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess/mock" + "github.com/ethersphere/bee/v2/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type GranteeManager interface { diff --git a/pkg/dynamicaccess/grantee_manager_test.go b/pkg/dynamicaccess/grantee_manager_test.go index d458e007088..bb01c13cd85 100644 --- a/pkg/dynamicaccess/grantee_manager_test.go +++ b/pkg/dynamicaccess/grantee_manager_test.go @@ -7,8 +7,8 @@ import ( "fmt" "testing" - "github.com/ethersphere/bee/pkg/dynamicaccess" - kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock" ) func setupAccessLogic(privateKey *ecdsa.PrivateKey) dynamicaccess.ActLogic { diff --git a/pkg/dynamicaccess/grantee_test.go b/pkg/dynamicaccess/grantee_test.go index 5b7a9bc5402..b644f5896c5 100644 --- a/pkg/dynamicaccess/grantee_test.go +++ b/pkg/dynamicaccess/grantee_test.go @@ -7,15 +7,15 @@ import ( "crypto/rand" "testing" - "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/storage" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/storage" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/stretchr/testify/assert" ) diff --git a/pkg/dynamicaccess/history.go b/pkg/dynamicaccess/history.go index 63ec00847a6..82d18f5ef8a 100644 --- a/pkg/dynamicaccess/history.go +++ b/pkg/dynamicaccess/history.go @@ -2,7 +2,7 @@ package dynamicaccess import ( "github.com/ethereum/go-ethereum/common" - "github.com/ethersphere/bee/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/kvs" ) type History interface { diff --git a/pkg/dynamicaccess/history_test.go b/pkg/dynamicaccess/history_test.go index c2164df7d39..6c0a48a4fd6 100644 --- a/pkg/dynamicaccess/history_test.go +++ b/pkg/dynamicaccess/history_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/dynamicaccess/mock" - kvsmock "github.com/ethersphere/bee/pkg/kvs/mock" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess/mock" + kvsmock "github.com/ethersphere/bee/v2/pkg/kvs/mock" "github.com/stretchr/testify/assert" ) diff --git a/pkg/dynamicaccess/mock/grantee.go b/pkg/dynamicaccess/mock/grantee.go index f4bd90740ab..50689ade08f 100644 --- a/pkg/dynamicaccess/mock/grantee.go +++ b/pkg/dynamicaccess/mock/grantee.go @@ -3,7 +3,7 @@ package mock import ( "crypto/ecdsa" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type GranteeListMock interface { diff --git a/pkg/dynamicaccess/mock/history.go b/pkg/dynamicaccess/mock/history.go index 91b544a0760..e7747434d59 100644 --- a/pkg/dynamicaccess/mock/history.go +++ b/pkg/dynamicaccess/mock/history.go @@ -5,11 +5,11 @@ import ( "sort" "time" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/feeds" - "github.com/ethersphere/bee/pkg/kvs" - "github.com/ethersphere/bee/pkg/storage" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/feeds" + "github.com/ethersphere/bee/v2/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/storage" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type historyMock struct { diff --git a/pkg/dynamicaccess/mock/session.go b/pkg/dynamicaccess/mock/session.go index ba3e3f8c8f2..9613aacedfa 100644 --- a/pkg/dynamicaccess/mock/session.go +++ b/pkg/dynamicaccess/mock/session.go @@ -3,8 +3,8 @@ package mock import ( "crypto/ecdsa" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/keystore" ) type SessionMock struct { diff --git a/pkg/dynamicaccess/session.go b/pkg/dynamicaccess/session.go index b2718aedd67..0b58c1aa3dd 100644 --- a/pkg/dynamicaccess/session.go +++ b/pkg/dynamicaccess/session.go @@ -4,8 +4,8 @@ import ( "crypto/ecdsa" "errors" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/keystore" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/keystore" ) // Session represents an interface for a Diffie-Helmann key derivation diff --git a/pkg/dynamicaccess/session_test.go b/pkg/dynamicaccess/session_test.go index 501d1abd2b6..493b998a805 100644 --- a/pkg/dynamicaccess/session_test.go +++ b/pkg/dynamicaccess/session_test.go @@ -8,10 +8,10 @@ import ( "io" "testing" - "github.com/ethersphere/bee/pkg/crypto" - "github.com/ethersphere/bee/pkg/dynamicaccess" - "github.com/ethersphere/bee/pkg/dynamicaccess/mock" - memkeystore "github.com/ethersphere/bee/pkg/keystore/mem" + "github.com/ethersphere/bee/v2/pkg/crypto" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess" + "github.com/ethersphere/bee/v2/pkg/dynamicaccess/mock" + memkeystore "github.com/ethersphere/bee/v2/pkg/keystore/mem" ) func mockKeyFunc(publicKey *ecdsa.PublicKey, nonces [][]byte) ([][]byte, error) { diff --git a/pkg/kvs/kvs.go b/pkg/kvs/kvs.go index 1106f2ceee8..fcb5fc668bb 100644 --- a/pkg/kvs/kvs.go +++ b/pkg/kvs/kvs.go @@ -9,10 +9,10 @@ import ( "encoding/hex" "errors" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/manifest" - "github.com/ethersphere/bee/pkg/storer" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/manifest" + "github.com/ethersphere/bee/v2/pkg/storer" + "github.com/ethersphere/bee/v2/pkg/swarm" ) type KeyValueStore interface { diff --git a/pkg/kvs/kvs_test.go b/pkg/kvs/kvs_test.go index 309250dacff..9edfe48062c 100644 --- a/pkg/kvs/kvs_test.go +++ b/pkg/kvs/kvs_test.go @@ -8,15 +8,15 @@ import ( "context" "testing" - "github.com/ethersphere/bee/pkg/file" - "github.com/ethersphere/bee/pkg/file/loadsave" - "github.com/ethersphere/bee/pkg/file/pipeline" - "github.com/ethersphere/bee/pkg/file/pipeline/builder" - "github.com/ethersphere/bee/pkg/file/redundancy" - "github.com/ethersphere/bee/pkg/kvs" - "github.com/ethersphere/bee/pkg/storage" - mockstorer "github.com/ethersphere/bee/pkg/storer/mock" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/file" + "github.com/ethersphere/bee/v2/pkg/file/loadsave" + "github.com/ethersphere/bee/v2/pkg/file/pipeline" + "github.com/ethersphere/bee/v2/pkg/file/pipeline/builder" + "github.com/ethersphere/bee/v2/pkg/file/redundancy" + "github.com/ethersphere/bee/v2/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/storage" + mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock" + "github.com/ethersphere/bee/v2/pkg/swarm" "github.com/stretchr/testify/assert" ) diff --git a/pkg/kvs/mock/kvs.go b/pkg/kvs/mock/kvs.go index fc091a88417..78282934bf2 100644 --- a/pkg/kvs/mock/kvs.go +++ b/pkg/kvs/mock/kvs.go @@ -4,8 +4,8 @@ import ( "encoding/hex" "sync" - "github.com/ethersphere/bee/pkg/kvs" - "github.com/ethersphere/bee/pkg/swarm" + "github.com/ethersphere/bee/v2/pkg/kvs" + "github.com/ethersphere/bee/v2/pkg/swarm" ) var lock = &sync.Mutex{}