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-04-29 17:02:52 +00:00
|
|
|
func CollectMembers(r objutil.HeadReceiver, cnr cid.ID, members []oid.ID, calcHomoHash bool) (*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()
|
2022-04-29 17:02:52 +00:00
|
|
|
|
|
|
|
if calcHomoHash {
|
|
|
|
phyHashes = append(phyHashes, cs.Value())
|
|
|
|
}
|
2020-12-17 16:13:34 +00:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sg.SetMembers(phyMembers)
|
|
|
|
sg.SetValidationDataSize(sumPhySize)
|
2022-04-29 17:02:52 +00:00
|
|
|
|
|
|
|
if calcHomoHash {
|
|
|
|
sumHash, err := tz.Concat(phyHashes)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var cs checksum.Checksum
|
|
|
|
tzHash := [64]byte{}
|
|
|
|
copy(tzHash[:], sumHash)
|
|
|
|
cs.SetTillichZemor(tzHash)
|
|
|
|
|
|
|
|
sg.SetValidationDataHash(cs)
|
|
|
|
}
|
2020-12-17 16:13:34 +00:00
|
|
|
|
2022-05-13 09:25:13 +00:00
|
|
|
return &sg, nil
|
2020-12-17 16:13:34 +00:00
|
|
|
}
|