2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-09 08:02:27 +00:00
|
|
|
"context"
|
2022-12-21 16:32:08 +00:00
|
|
|
"crypto/ecdsa"
|
2020-12-08 16:18:24 +00:00
|
|
|
"hash"
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
coreclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2023-04-24 09:09:43 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-09-26 07:54:03 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// Prm groups parameters of Get service call.
|
2020-09-26 07:54:03 +00:00
|
|
|
type Prm struct {
|
2020-12-07 17:49:47 +00:00
|
|
|
commonPrm
|
|
|
|
}
|
|
|
|
|
|
|
|
// RangePrm groups parameters of GetRange service call.
|
|
|
|
type RangePrm struct {
|
|
|
|
commonPrm
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
rng *objectSDK.Range
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:28:50 +00:00
|
|
|
// Validate pre-validates `OBJECTRANGE` request's parameters content
|
|
|
|
// without access to the requested object's payload.
|
|
|
|
func (p RangePrm) Validate() error {
|
|
|
|
if p.rng != nil {
|
|
|
|
off := p.rng.GetOffset()
|
|
|
|
l := p.rng.GetLength()
|
|
|
|
|
|
|
|
if l == 0 {
|
|
|
|
return errRangeZeroLength
|
|
|
|
}
|
|
|
|
|
|
|
|
if off+l <= off {
|
|
|
|
return errRangeOverflow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-08 16:18:24 +00:00
|
|
|
// RangeHashPrm groups parameters of GetRange service call.
|
|
|
|
type RangeHashPrm struct {
|
|
|
|
commonPrm
|
|
|
|
|
|
|
|
hashGen func() hash.Hash
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
rngs []objectSDK.Range
|
2021-01-11 13:50:04 +00:00
|
|
|
|
|
|
|
salt []byte
|
2020-12-08 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 09:09:43 +00:00
|
|
|
type RequestParameters struct {
|
|
|
|
commonPrm
|
|
|
|
head bool
|
|
|
|
rng *objectSDK.Range
|
|
|
|
}
|
|
|
|
|
|
|
|
type RequestForwarder func(context.Context, coreclient.NodeInfo, coreclient.MultiAddressClient) (*objectSDK.Object, error)
|
2021-04-29 12:18:29 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
// HeadPrm groups parameters of Head service call.
|
|
|
|
type HeadPrm struct {
|
|
|
|
commonPrm
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
type commonPrm struct {
|
2020-12-02 23:45:25 +00:00
|
|
|
objWriter ObjectWriter
|
|
|
|
|
2020-09-29 15:05:22 +00:00
|
|
|
common *util.CommonPrm
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr oid.Address
|
2021-11-01 08:35:33 +00:00
|
|
|
|
|
|
|
raw bool
|
2021-04-29 12:18:29 +00:00
|
|
|
|
|
|
|
forwarder RequestForwarder
|
2022-12-21 16:32:08 +00:00
|
|
|
|
|
|
|
// signerKey is a cached key that should be used for spawned
|
|
|
|
// requests (if any), could be nil if incoming request handling
|
|
|
|
// routine does not include any key fetching operations
|
|
|
|
signerKey *ecdsa.PrivateKey
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
// SetObjectWriter sets target component to write the object.
|
|
|
|
func (p *Prm) SetObjectWriter(w ObjectWriter) {
|
|
|
|
p.objWriter = w
|
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
// SetChunkWriter sets target component to write the object payload range.
|
2023-04-24 07:33:12 +00:00
|
|
|
func (p *commonPrm) SetChunkWriter(w ChunkWriter) {
|
2020-12-09 10:32:33 +00:00
|
|
|
p.objWriter = &partWriter{
|
2020-12-07 17:49:47 +00:00
|
|
|
chunkWriter: w,
|
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
// SetRange sets range of the requested payload data.
|
2023-04-24 09:09:43 +00:00
|
|
|
func (p *RangePrm) SetRange(rng *objectSDK.Range) {
|
2020-12-07 17:49:47 +00:00
|
|
|
p.rng = rng
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
2020-12-08 16:18:24 +00:00
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetRangeList sets a list of object payload ranges.
|
2023-04-24 09:09:43 +00:00
|
|
|
func (p *RangeHashPrm) SetRangeList(rngs []objectSDK.Range) {
|
2020-12-08 16:18:24 +00:00
|
|
|
p.rngs = rngs
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHashGenerator sets constructor of hashing algorithm.
|
|
|
|
func (p *RangeHashPrm) SetHashGenerator(v func() hash.Hash) {
|
|
|
|
p.hashGen = v
|
|
|
|
}
|
2020-12-08 16:26:34 +00:00
|
|
|
|
2021-01-11 13:50:04 +00:00
|
|
|
// SetSalt sets binary salt to XOR object's payload ranges before hash calculation.
|
|
|
|
func (p *RangeHashPrm) SetSalt(salt []byte) {
|
|
|
|
p.salt = salt
|
|
|
|
}
|
|
|
|
|
2020-12-08 16:26:34 +00:00
|
|
|
// SetCommonParameters sets common parameters of the operation.
|
|
|
|
func (p *commonPrm) SetCommonParameters(common *util.CommonPrm) {
|
|
|
|
p.common = common
|
|
|
|
}
|
2020-12-09 10:32:33 +00:00
|
|
|
|
2021-04-29 12:18:29 +00:00
|
|
|
func (p *commonPrm) SetRequestForwarder(f RequestForwarder) {
|
|
|
|
p.forwarder = f
|
|
|
|
}
|
|
|
|
|
2024-08-12 14:11:10 +00:00
|
|
|
func (p *commonPrm) SetSignerKey(signerKey *ecdsa.PrivateKey) {
|
|
|
|
p.signerKey = signerKey
|
|
|
|
}
|
|
|
|
|
2021-11-01 08:35:33 +00:00
|
|
|
// WithAddress sets object address to be read.
|
2022-05-31 17:00:41 +00:00
|
|
|
func (p *commonPrm) WithAddress(addr oid.Address) {
|
2021-11-01 08:35:33 +00:00
|
|
|
p.addr = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRawFlag sets flag of raw reading.
|
|
|
|
func (p *commonPrm) WithRawFlag(raw bool) {
|
|
|
|
p.raw = raw
|
|
|
|
}
|
|
|
|
|
2022-12-21 16:32:08 +00:00
|
|
|
// WithCachedSignerKey sets optional key for all further requests.
|
|
|
|
func (p *commonPrm) WithCachedSignerKey(signerKey *ecdsa.PrivateKey) {
|
|
|
|
p.signerKey = signerKey
|
|
|
|
}
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
// SetHeaderWriter sets target component to write the object header.
|
2023-04-24 08:36:15 +00:00
|
|
|
func (p *commonPrm) SetHeaderWriter(w HeaderWriter) {
|
2020-12-09 10:32:33 +00:00
|
|
|
p.objWriter = &partWriter{
|
|
|
|
headWriter: w,
|
|
|
|
}
|
|
|
|
}
|