[#1377] oid, cid: Upgrade SDK package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-05-12 19:37:46 +03:00 committed by LeL
parent f65898a354
commit f15e6e888f
118 changed files with 1455 additions and 886 deletions

View file

@ -2,6 +2,7 @@ package audit
import (
"context"
"crypto/sha256"
"encoding/hex"
clientcore "github.com/nspcc-dev/neofs-node/pkg/core/client"
@ -46,6 +47,8 @@ func (ap *Processor) processStartAudit(epoch uint64) {
var auditCtx context.Context
auditCtx, ap.prevAuditCanceler = context.WithCancel(context.Background())
pivot := make([]byte, sha256.Size)
for i := range containers {
cnr, err := cntClient.Get(ap.containerClient, containers[i]) // get container structure
if err != nil {
@ -56,7 +59,7 @@ func (ap *Processor) processStartAudit(epoch uint64) {
continue
}
pivot := containers[i].ToV2().GetValue()
containers[i].Encode(pivot)
// find all container nodes for current epoch
nodes, err := nm.GetContainerNodes(cnr.PlacementPolicy(), pivot)

View file

@ -79,7 +79,8 @@ func generateContainers(n int) []*cid.ID {
result := make([]*cid.ID, 0, n)
for i := 0; i < n; i++ {
result = append(result, cidtest.ID())
v := cidtest.ID()
result = append(result, &v)
}
return result

View file

@ -137,14 +137,14 @@ func checkTokenContext(tok *session.Token, verbAssert verbAssert) error {
return err
}
func checkTokenContextWithCID(tok *session.Token, id *cid.ID, verbAssert verbAssert) error {
func checkTokenContextWithCID(tok *session.Token, id cid.ID, verbAssert verbAssert) error {
c, err := contextWithVerifiedVerb(tok, verbAssert)
if err != nil {
return err
}
tokCID := c.Container()
if tokCID != nil && !tokCID.Equal(id) {
if tokCID != nil && !tokCID.Equals(id) {
return errWrongCID
}

View file

@ -8,7 +8,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
@ -192,10 +191,12 @@ func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error {
if token != nil {
// check token context
// TODO: #1147 think how to avoid version casts
idV2 := new(refs.ContainerID)
idV2.SetValue(binCID)
var id cid.ID
id := cid.NewFromV2(idV2)
err = id.Decode(binCID)
if err != nil {
return fmt.Errorf("decode container ID: %w", err)
}
err = checkTokenContextWithCID(token, id, func(c *session.ContainerContext) bool {
return c.IsForDelete()

View file

@ -56,8 +56,13 @@ func (cp *Processor) checkSetEACL(e container.SetEACL) error {
return fmt.Errorf("invalid binary table: %w", err)
}
idCnr, ok := table.CID()
if !ok {
return errors.New("missing container ID in eACL table")
}
// receive owner of the related container
cnr, err := cntClient.Get(cp.cnrClient, table.CID())
cnr, err := cntClient.Get(cp.cnrClient, &idCnr)
if err != nil {
return fmt.Errorf("could not receive the container: %w", err)
}
@ -70,7 +75,7 @@ func (cp *Processor) checkSetEACL(e container.SetEACL) error {
if tok != nil {
// check token context
err = checkTokenContextWithCID(tok, table.CID(), func(c *session.ContainerContext) bool {
err = checkTokenContextWithCID(tok, idCnr, func(c *session.ContainerContext) bool {
return c.IsForSetEACL()
})
if err != nil {

View file

@ -32,8 +32,6 @@ type singleResultCtx struct {
log *logger.Logger
cid *cid.ID
txTable *common.TransferTable
cnrInfo common.ContainerInfo
@ -146,9 +144,15 @@ func (c *Calculator) processResult(ctx *singleResultCtx) {
}
func (c *Calculator) readContainerInfo(ctx *singleResultCtx) bool {
cnr, ok := ctx.auditResult.Container()
if !ok {
ctx.log.Error("missing container in audit result")
return false
}
var err error
ctx.cnrInfo, err = c.prm.ContainerStorage.ContainerInfo(ctx.auditResult.Container())
ctx.cnrInfo, err = c.prm.ContainerStorage.ContainerInfo(&cnr)
if err != nil {
ctx.log.Error("could not get container info",
zap.String("error", err.Error()),
@ -214,10 +218,10 @@ func (c *Calculator) sumSGSizes(ctx *singleResultCtx) bool {
fail := false
addr := addressSDK.NewAddress()
addr.SetContainerID(ctx.containerID())
addr.SetContainerID(*ctx.containerID())
ctx.auditResult.IteratePassedStorageGroups(func(id oid.ID) bool {
addr.SetObjectID(&id)
addr.SetObjectID(id)
sgInfo, err := c.prm.SGStorage.SGInfo(addr)
if err != nil {
@ -307,11 +311,8 @@ func (c *Calculator) fillTransferTable(ctx *singleResultCtx) bool {
}
func (c *singleResultCtx) containerID() *cid.ID {
if c.cid == nil {
c.cid = c.auditResult.Container()
}
return c.cid
cnr, _ := c.auditResult.Container()
return &cnr
}
func (c *singleResultCtx) auditEpoch() uint64 {