Skip to content

Commit

Permalink
refactor(act): chunk download and granteelist handling (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bosi95 authored and aranyia committed Jun 7, 2024
1 parent 50604e1 commit a4b7ca8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
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")
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
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

0 comments on commit a4b7ca8

Please sign in to comment.