Skip to content

Commit

Permalink
refactor(act): typos & docs (#40)
Browse files Browse the repository at this point in the history
refactor(act): typos, docs, removed unused import aliases
  • Loading branch information
aranyia committed Jun 6, 2024
1 parent 943b219 commit 272ffcb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
5 changes: 2 additions & 3 deletions pkg/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"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/storage"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/ethersphere/bee/v2/pkg/tracing"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -124,8 +124,7 @@ func (s *Service) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
// TODO: what should be the root_address ? (eref vs ref)
span.SetTag("root_address", reference)
span.SetTag("root_address", encryptedReference)

err = putter.Done(reference)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
"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/storage"
"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"
Expand Down Expand Up @@ -281,17 +281,16 @@ func (s *Service) fileUploadHandler(
ext.LogError(span, err, olog.String("action", "putter.Done"))
return
}
// TODO: what should be the root_address ? (eref vs ref)
span.LogFields(olog.Bool("success", true))
span.SetTag("root_address", manifestReference)
span.SetTag("root_address", encryptedReference)

if tagID != 0 {
w.Header().Set(SwarmTagHeader, fmt.Sprint(tagID))
span.SetTag("tagID", tagID)
}
w.Header().Set(ETagHeader, fmt.Sprintf("%q", encryptedReference.String()))
w.Header().Set("Access-Control-Expose-Headers", SwarmTagHeader)
// TODO: do we need to return reference as well ?

jsonhttp.Created(w, bzzUploadResponse{
Reference: encryptedReference,
})
Expand Down
18 changes: 10 additions & 8 deletions pkg/api/dynamicaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"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"
storer "github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
)
Expand All @@ -40,7 +40,7 @@ func getAddressFromContext(ctx context.Context) swarm.Address {
return swarm.ZeroAddress
}

// setAddress sets the swarm address in the context
// setAddressInContext sets the swarm address in the context
func setAddressInContext(ctx context.Context, address swarm.Address) context.Context {
return context.WithValue(ctx, addressKey{}, address)
}
Expand Down Expand Up @@ -121,8 +121,8 @@ func (s *Service) actDecryptionHandler() func(h http.Handler) http.Handler {
}
}

// actEncryptionHandler is a middleware that encrypts the given address using the publisher's public key
// Uploads the encrypted reference, history and kvs to the store
// actEncryptionHandler is a middleware that encrypts the given address using the publisher's public key,
// uploads the encrypted reference, history and kvs to the store
func (s *Service) actEncryptionHandler(
ctx context.Context,
w http.ResponseWriter,
Expand All @@ -140,7 +140,7 @@ func (s *Service) actEncryptionHandler(
return swarm.ZeroAddress, fmt.Errorf("act failed to encrypt reference: %w", err)
}
// only need to upload history and kvs if a new history is created,
// meaning that the publsher uploaded to the history for the first time
// meaning that the publisher uploaded to the history for the first time
if !historyReference.Equal(historyRootHash) {
err = putter.Done(storageReference)
if err != nil {
Expand Down Expand Up @@ -199,7 +199,8 @@ func (s *Service) actListGranteesHandler(w http.ResponseWriter, r *http.Request)
jsonhttp.OK(w, granteeSlice)
}

// TODO: actGrantRevokeHandler doc.
// actGrantRevokeHandler is a middleware that makes updates to the list of grantees,
// only the publisher is authorized to perform this action
func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request) {
logger := s.logger.WithName("act_grant_revoke_handler").Build()

Expand Down Expand Up @@ -363,7 +364,8 @@ func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request)
})
}

// TODO: actCreateGranteesHandler doc.
// actCreateGranteesHandler is a middleware that creates a new list of grantees,
// only the publisher is authorized to perform this action
func (s *Service) actCreateGranteesHandler(w http.ResponseWriter, r *http.Request) {
logger := s.logger.WithName("acthandler").Build()

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"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/storage"
"github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
)
Expand Down
5 changes: 1 addition & 4 deletions pkg/dynamicaccess/accesslogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"crypto/ecdsa"
"fmt"

encryption "github.com/ethersphere/bee/v2/pkg/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"
Expand All @@ -26,13 +26,11 @@ var (
type Decryptor interface {
// DecryptRef will return a decrypted reference, for given encrypted reference and grantee
DecryptRef(ctx context.Context, storage kvs.KeyValueStore, encryptedRef 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
// AddGrantee adds a new grantee to the ACT
AddGrantee(ctx context.Context, storage kvs.KeyValueStore, publisherPubKey, granteePubKey *ecdsa.PublicKey, accessKey *encryption.Key) error
Expand Down Expand Up @@ -122,7 +120,6 @@ func (al *ActLogic) getAccessKey(ctx context.Context, storage kvs.KeyValueStore,
// Generate lookup key and access key decryption key for a given public key
func (al *ActLogic) getKeys(publicKey *ecdsa.PublicKey) ([]byte, []byte, error) {
nonces := [][]byte{zeroByteArray, oneByteArray}
// keys := make([][]byte, 0, len(nonces))
keys, err := al.Session.Key(publicKey, nonces)
if keys == nil {
return nil, nil, err
Expand Down
14 changes: 7 additions & 7 deletions pkg/dynamicaccess/accesslogic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ func TestDecryptRef_Success(t *testing.T) {
t.Error(err)
}

acutalRef, err := al.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey)
actualRef, err := al.DecryptRef(ctx, 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!")
if expectedRef.Compare(actualRef) != 0 {
t.Errorf("Get returned a wrong Swarm reference!")
}
}

Expand Down Expand Up @@ -120,14 +120,14 @@ func TestDecryptRefWithGrantee_Success(t *testing.T) {

diffieHellman2 := dynamicaccess.NewDefaultSession(id1)
granteeAccessLogic := dynamicaccess.NewLogic(diffieHellman2)
acutalRef, err := granteeAccessLogic.DecryptRef(ctx, s, encryptedRef, &id0.PublicKey)
actualRef, err := granteeAccessLogic.DecryptRef(ctx, 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!")
if expectedRef.Compare(actualRef) != 0 {
t.Errorf("Get returned a wrong Swarm reference!")
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ func TestAddPublisher(t *testing.T) {

decodedEncryptedAccessKey := hex.EncodeToString(encryptedAccessKey)

// A random value is returned so it is only possibly to check the length of the returned value
// A random value is returned, so it is only possible 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))
Expand Down
23 changes: 7 additions & 16 deletions pkg/dynamicaccess/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ import (
"io"
"time"

encryption "github.com/ethersphere/bee/v2/pkg/encryption"
"github.com/ethersphere/bee/v2/pkg/encryption"
"github.com/ethersphere/bee/v2/pkg/file"
"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"
"github.com/ethersphere/bee/v2/pkg/swarm"
)

type GranteeManager interface {
// TODO: doc
// HandleGrantees manages the grantees for the given publisher, updating the list based on provided public keys to add or remove.
// Only the publisher can make changes to the grantee list.
HandleGrantees(ctx context.Context, ls file.LoadSaver, gls file.LoadSaver, granteeref swarm.Address, historyref swarm.Address, publisher *ecdsa.PublicKey, addList, removeList []*ecdsa.PublicKey) (swarm.Address, swarm.Address, swarm.Address, swarm.Address, error)
// GetGrantees returns the list of grantees for the given publisher.
// The list is accessible only by the publisher.
Expand Down Expand Up @@ -70,7 +67,7 @@ func (c *ControllerStruct) DownloadHandler(
func (c *ControllerStruct) UploadHandler(
ctx context.Context,
ls file.LoadSaver,
refrefence swarm.Address,
reference swarm.Address,
publisher *ecdsa.PublicKey,
historyRootHash swarm.Address,
) (swarm.Address, swarm.Address, swarm.Address, error) {
Expand Down Expand Up @@ -121,7 +118,7 @@ func (c *ControllerStruct) UploadHandler(
}
}

encryptedRef, err := c.accessLogic.EncryptRef(ctx, storage, publisher, refrefence)
encryptedRef, err := c.accessLogic.EncryptRef(ctx, storage, publisher, reference)
return actRef, historyRef, encryptedRef, err
}

Expand Down Expand Up @@ -265,7 +262,7 @@ func (c *ControllerStruct) HandleGrantees(
return glref, eglref, href, actref, nil
}

func (c *ControllerStruct) GetGrantees(ctx context.Context, ls file.LoadSaver, publisher *ecdsa.PublicKey, encryptedglref swarm.Address) ([]*ecdsa.PublicKey, error) {
func (c *ControllerStruct) GetGrantees(_ context.Context, ls file.LoadSaver, publisher *ecdsa.PublicKey, encryptedglref swarm.Address) ([]*ecdsa.PublicKey, error) {
granteeRef, err := c.decryptRefForPublisher(publisher, encryptedglref)
if err != nil {
return nil, err
Expand Down Expand Up @@ -305,13 +302,7 @@ func (c *ControllerStruct) decryptRefForPublisher(publisherPubKey *ecdsa.PublicK
return swarm.NewAddress(ref), 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)
}
}

// TODO: what to do in close ?
func (s *ControllerStruct) Close() error {
func (c *ControllerStruct) Close() error {
return nil
}

0 comments on commit 272ffcb

Please sign in to comment.