2020-12-17 16:13:34 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
|
|
|
oidSDK "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/storagegroup"
|
2020-12-17 16:13:34 +00:00
|
|
|
"github.com/nspcc-dev/tzhash/tz"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CollectMembers creates new storage group structure and fills it
|
|
|
|
// with information about members collected via HeadReceiver.
|
|
|
|
//
|
|
|
|
// Resulting storage group consists of physically stored objects only.
|
2022-01-26 12:11:13 +00:00
|
|
|
func CollectMembers(r objutil.HeadReceiver, cid *cid.ID, members []*oidSDK.ID) (*storagegroup.StorageGroup, error) {
|
2020-12-17 16:13:34 +00:00
|
|
|
var (
|
|
|
|
sumPhySize uint64
|
2022-01-26 12:11:13 +00:00
|
|
|
phyMembers []*oidSDK.ID
|
2020-12-17 16:13:34 +00:00
|
|
|
phyHashes [][]byte
|
2022-01-26 12:11:13 +00:00
|
|
|
addr = addressSDK.NewAddress()
|
2020-12-17 16:13:34 +00:00
|
|
|
sg = storagegroup.New()
|
|
|
|
)
|
|
|
|
|
|
|
|
addr.SetContainerID(cid)
|
|
|
|
|
|
|
|
for i := range members {
|
|
|
|
addr.SetObjectID(members[i])
|
|
|
|
|
|
|
|
if err := objutil.IterateAllSplitLeaves(r, addr, func(leaf *object.Object) {
|
|
|
|
phyMembers = append(phyMembers, leaf.ID())
|
|
|
|
sumPhySize += leaf.PayloadSize()
|
|
|
|
phyHashes = append(phyHashes, leaf.PayloadHomomorphicHash().Sum())
|
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sumHash, err := tz.Concat(phyHashes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
cs := checksum.New()
|
2020-12-17 16:13:34 +00:00
|
|
|
tzHash := [client.TZSize]byte{}
|
|
|
|
copy(tzHash[:], sumHash)
|
|
|
|
cs.SetTillichZemor(tzHash)
|
|
|
|
|
|
|
|
sg.SetMembers(phyMembers)
|
|
|
|
sg.SetValidationDataSize(sumPhySize)
|
|
|
|
sg.SetValidationDataHash(cs)
|
|
|
|
|
|
|
|
return sg, nil
|
|
|
|
}
|