2020-12-17 16:13:34 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
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"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "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-05-31 17:00:41 +00:00
|
|
|
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID) (*storagegroup.StorageGroup, error) {
|
2020-12-17 16:13:34 +00:00
|
|
|
var (
|
|
|
|
sumPhySize uint64
|
2022-05-31 17:00:41 +00:00
|
|
|
phyMembers []oid.ID
|
2020-12-17 16:13:34 +00:00
|
|
|
phyHashes [][]byte
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2022-05-13 09:25:13 +00:00
|
|
|
sg storagegroup.StorageGroup
|
2020-12-17 16:13:34 +00:00
|
|
|
)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.SetContainer(cnr)
|
2020-12-17 16:13:34 +00:00
|
|
|
|
|
|
|
for i := range members {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.SetObject(members[i])
|
2020-12-17 16:13:34 +00:00
|
|
|
|
|
|
|
if err := objutil.IterateAllSplitLeaves(r, addr, func(leaf *object.Object) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, ok := leaf.ID()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
phyMembers = append(phyMembers, id)
|
2020-12-17 16:13:34 +00:00
|
|
|
sumPhySize += leaf.PayloadSize()
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := leaf.PayloadHomomorphicHash()
|
|
|
|
phyHashes = append(phyHashes, cs.Value())
|
2020-12-17 16:13:34 +00:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sumHash, err := tz.Concat(phyHashes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
var cs checksum.Checksum
|
2022-02-25 09:20:49 +00:00
|
|
|
tzHash := [64]byte{}
|
2020-12-17 16:13:34 +00:00
|
|
|
copy(tzHash[:], sumHash)
|
|
|
|
cs.SetTillichZemor(tzHash)
|
|
|
|
|
|
|
|
sg.SetMembers(phyMembers)
|
|
|
|
sg.SetValidationDataSize(sumPhySize)
|
|
|
|
sg.SetValidationDataHash(cs)
|
|
|
|
|
2022-05-13 09:25:13 +00:00
|
|
|
return &sg, nil
|
2020-12-17 16:13:34 +00:00
|
|
|
}
|