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"
|
2022-11-24 14:28:50 +00:00
|
|
|
"errors"
|
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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
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
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
rng *object.Range
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-24 14:28:50 +00:00
|
|
|
var (
|
|
|
|
errRangeZeroLength = errors.New("zero range length")
|
|
|
|
errRangeOverflow = errors.New("range overflow")
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2022-03-15 12:11:35 +00:00
|
|
|
rngs []object.Range
|
2021-01-11 13:50:04 +00:00
|
|
|
|
|
|
|
salt []byte
|
2020-12-08 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 08:17:59 +00:00
|
|
|
type RequestForwarder func(context.Context, coreclient.NodeInfo, coreclient.MultiAddressClient) (*object.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
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
// ChunkWriter is an interface of target component
|
|
|
|
// to write payload chunk.
|
|
|
|
type ChunkWriter interface {
|
2023-03-09 08:02:27 +00:00
|
|
|
WriteChunk(context.Context, []byte) error
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
// HeaderWriter is an interface of target component
|
|
|
|
// to write object header.
|
|
|
|
type HeaderWriter interface {
|
2023-03-09 08:02:27 +00:00
|
|
|
WriteHeader(context.Context, *object.Object) error
|
2020-12-09 10:32:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// ObjectWriter is an interface of target component to write object.
|
|
|
|
type ObjectWriter interface {
|
2020-12-09 10:32:33 +00:00
|
|
|
HeaderWriter
|
2020-12-07 17:49:47 +00:00
|
|
|
ChunkWriter
|
2020-09-26 07:54:03 +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.
|
2022-03-03 14:19:05 +00:00
|
|
|
func (p *RangePrm) SetRange(rng *object.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.
|
2022-03-15 12:11:35 +00:00
|
|
|
func (p *RangeHashPrm) SetRangeList(rngs []object.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
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
func (p *HeadPrm) SetHeaderWriter(w HeaderWriter) {
|
|
|
|
p.objWriter = &partWriter{
|
|
|
|
headWriter: w,
|
|
|
|
}
|
|
|
|
}
|