3805b0f638
There is a need to generalize single-address client to group-address client. To do this, we can re-implement `Client` interface from NeoFS API Go library and still use it in the application code. There is a problem with method `Raw` which must return single-address raw client. So as not to make changes to API library we need to overload Client interface in order to support `Raw` method in group-address client implementation. Define `Client` interface in new `pkg/core/client` package. Completely inherit API `Client` interface. Add `RawForAddress` method to build raw client for the single node address. Adopt the application code that used Raw method to work with new `Client`. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
118 lines
2.6 KiB
Go
118 lines
2.6 KiB
Go
package getsvc
|
|
|
|
import (
|
|
"hash"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
|
)
|
|
|
|
// Prm groups parameters of Get service call.
|
|
type Prm struct {
|
|
commonPrm
|
|
}
|
|
|
|
// RangePrm groups parameters of GetRange service call.
|
|
type RangePrm struct {
|
|
commonPrm
|
|
|
|
rng *objectSDK.Range
|
|
}
|
|
|
|
// RangeHashPrm groups parameters of GetRange service call.
|
|
type RangeHashPrm struct {
|
|
commonPrm
|
|
|
|
hashGen func() hash.Hash
|
|
|
|
rngs []*objectSDK.Range
|
|
|
|
salt []byte
|
|
}
|
|
|
|
type RequestForwarder func(network.Address, coreclient.Client) (*objectSDK.Object, error)
|
|
|
|
// HeadPrm groups parameters of Head service call.
|
|
type HeadPrm struct {
|
|
commonPrm
|
|
}
|
|
|
|
type commonPrm struct {
|
|
objWriter ObjectWriter
|
|
|
|
common *util.CommonPrm
|
|
|
|
client.GetObjectParams
|
|
|
|
forwarder RequestForwarder
|
|
}
|
|
|
|
// ChunkWriter is an interface of target component
|
|
// to write payload chunk.
|
|
type ChunkWriter interface {
|
|
WriteChunk([]byte) error
|
|
}
|
|
|
|
// HeaderWriter is an interface of target component
|
|
// to write object header.
|
|
type HeaderWriter interface {
|
|
WriteHeader(*object.Object) error
|
|
}
|
|
|
|
// ObjectWriter is an interface of target component to write object.
|
|
type ObjectWriter interface {
|
|
HeaderWriter
|
|
ChunkWriter
|
|
}
|
|
|
|
// SetObjectWriter sets target component to write the object.
|
|
func (p *Prm) SetObjectWriter(w ObjectWriter) {
|
|
p.objWriter = w
|
|
}
|
|
|
|
// SetChunkWriter sets target component to write the object payload range.
|
|
func (p *RangePrm) SetChunkWriter(w ChunkWriter) {
|
|
p.objWriter = &partWriter{
|
|
chunkWriter: w,
|
|
}
|
|
}
|
|
|
|
// SetRange sets range of the requested payload data.
|
|
func (p *RangePrm) SetRange(rng *objectSDK.Range) {
|
|
p.rng = rng
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetSalt sets binary salt to XOR object's payload ranges before hash calculation.
|
|
func (p *RangeHashPrm) SetSalt(salt []byte) {
|
|
p.salt = salt
|
|
}
|
|
|
|
// SetCommonParameters sets common parameters of the operation.
|
|
func (p *commonPrm) SetCommonParameters(common *util.CommonPrm) {
|
|
p.common = common
|
|
}
|
|
|
|
func (p *commonPrm) SetRequestForwarder(f RequestForwarder) {
|
|
p.forwarder = f
|
|
}
|
|
|
|
// SetHeaderWriter sets target component to write the object header.
|
|
func (p *HeadPrm) SetHeaderWriter(w HeaderWriter) {
|
|
p.objWriter = &partWriter{
|
|
headWriter: w,
|
|
}
|
|
}
|