Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(act): chunk download and granteelist handling #46

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/api/dynamicaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ func (s *Service) actDecryptionHandler() func(h http.Handler) http.Handler {
ls := loadsave.NewReadonly(s.storer.Download(cache))
reference, err := s.dac.DownloadHandler(ctx, ls, paths.Address, headers.Publisher, *headers.HistoryAddress, timestamp)
if err != nil {
logger.Debug("act failed to decrypt reference", "error", err)
logger.Error(nil, "act failed to decrypt reference")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it logging nil to error level and log the error to debug?

Copy link
Author

@bosi95 bosi95 May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern is used in other endpoints (I agree it is strange)

jsonhttp.InternalServerError(w, errActDownload)
return
}
Expand All @@ -132,7 +134,7 @@ func (s *Service) actEncryptionHandler(
) (swarm.Address, error) {
logger := s.logger.WithName("act_encryption_handler").Build()
publisherPublicKey := &s.publicKey
ls := loadsave.New(s.storer.ChunkStore(), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
storageReference, historyReference, encryptedReference, err := s.dac.UploadHandler(ctx, ls, reference, publisherPublicKey, historyRootHash)
if err != nil {
logger.Debug("act failed to encrypt reference", "error", err)
Expand Down Expand Up @@ -324,8 +326,8 @@ func (s *Service) actGrantRevokeHandler(w http.ResponseWriter, r *http.Request)

granteeref := paths.GranteesAddress
publisher := &s.publicKey
ls := loadsave.New(s.storer.ChunkStore(), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
gls := loadsave.New(s.storer.ChunkStore(), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
granteeref, encryptedglref, historyref, actref, err := s.dac.UpdateHandler(ctx, ls, gls, granteeref, historyAddress, publisher, grantees.Addlist, grantees.Revokelist)
if err != nil {
logger.Debug("failed to update grantee list", "error", err)
Expand Down Expand Up @@ -469,8 +471,8 @@ func (s *Service) actCreateGranteesHandler(w http.ResponseWriter, r *http.Reques
}

publisher := &s.publicKey
ls := loadsave.New(s.storer.ChunkStore(), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
gls := loadsave.New(s.storer.ChunkStore(), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
ls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, false, redundancy.NONE))
gls := loadsave.New(s.storer.Download(true), s.storer.Cache(), requestPipelineFactory(ctx, putter, granteeListEncrypt, redundancy.NONE))
granteeref, encryptedglref, historyref, actref, err := s.dac.UpdateHandler(ctx, ls, gls, swarm.ZeroAddress, historyAddress, publisher, list, nil)
if err != nil {
logger.Debug("failed to update grantee list", "error", err)
Expand Down
15 changes: 4 additions & 11 deletions pkg/dynamicaccess/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func (c *ControllerStruct) UploadHandler(
storage kvs.KeyValueStore
actRef swarm.Address
)
now := time.Now().Unix()
if historyRef.IsZero() {
history, err := NewHistory(ls)
if err != nil {
Expand All @@ -94,7 +93,7 @@ func (c *ControllerStruct) UploadHandler(
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
err = history.Add(ctx, actRef, &now, nil)
err = history.Add(ctx, actRef, nil, nil)
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
Expand All @@ -107,12 +106,11 @@ func (c *ControllerStruct) UploadHandler(
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
entry, err := history.Lookup(ctx, now)
actRef = entry.Reference()
entry, err := history.Lookup(ctx, time.Now().Unix())
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
storage, err = kvs.NewReference(ls, actRef)
storage, err = kvs.NewReference(ls, entry.Reference())
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
Expand Down Expand Up @@ -197,15 +195,12 @@ func (c *ControllerStruct) UpdateHandler(
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
}
granteesToAdd := addList

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of granteesToAdd? Why not just use addList?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

granteesToAdd can change due to remove(), if removelist is non-empty, then granteesToAdd = gl.Get()

if len(removeList) != 0 {
err = gl.Remove(removeList)
if err != nil {
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
}

var granteesToAdd []*ecdsa.PublicKey
if len(removeList) != 0 || encryptedglref.IsZero() {
// generate new access key and new act
act, err = kvs.New(ls)
if err != nil {
Expand All @@ -216,8 +211,6 @@ func (c *ControllerStruct) UpdateHandler(
return swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, swarm.ZeroAddress, err
}
granteesToAdd = gl.Get()
} else {
granteesToAdd = addList
}

for _, grantee := range granteesToAdd {
Expand Down
Loading