2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2020-12-08 16:18:24 +00:00
|
|
|
"hash"
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-09-29 15:05:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
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
|
|
|
|
|
|
|
|
rng *objectSDK.Range
|
|
|
|
}
|
|
|
|
|
2020-12-08 16:18:24 +00:00
|
|
|
// RangeHashPrm groups parameters of GetRange service call.
|
|
|
|
type RangeHashPrm struct {
|
|
|
|
commonPrm
|
|
|
|
|
|
|
|
hashGen func() hash.Hash
|
|
|
|
|
|
|
|
rngs []*objectSDK.Range
|
2021-01-11 13:50:04 +00:00
|
|
|
|
|
|
|
salt []byte
|
2020-12-08 16:18:24 +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
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
client.GetObjectParams
|
|
|
|
}
|
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 {
|
|
|
|
WriteChunk([]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 {
|
|
|
|
WriteHeader(*object.Object) error
|
|
|
|
}
|
|
|
|
|
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.
|
2020-12-07 17:49:47 +00:00
|
|
|
func (p *RangePrm) 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.
|
|
|
|
func (p *RangePrm) SetRange(rng *objectSDK.Range) {
|
|
|
|
p.rng = rng
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
2020-12-08 16:18:24 +00:00
|
|
|
|
|
|
|
// SetRangeList sets list of object payload ranges.
|
|
|
|
func (p *RangeHashPrm) SetRangeList(rngs []*objectSDK.Range) {
|
|
|
|
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
|
|
|
|
|
|
|
// SetHeaderWriter sets target component to write the object header.
|
|
|
|
func (p *HeadPrm) SetHeaderWriter(w HeaderWriter) {
|
|
|
|
p.objWriter = &partWriter{
|
|
|
|
headWriter: w,
|
|
|
|
}
|
|
|
|
}
|