forked from TrueCloudLab/frostfs-api-go
Remove SendPutRequest and update MakePutRequestHeader
- SendPutRequest unused and work not like expected - MakePutRequestHeader should not set epoch / ttl - remove unused internal functions and consts - update to latest neofs-crypto
This commit is contained in:
parent
f5b18eac94
commit
3b2ea6b8f4
3 changed files with 4 additions and 42 deletions
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/golang/protobuf v1.3.2
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/mr-tron/base58 v1.1.2
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.1
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.2
|
||||
github.com/nspcc-dev/netmap v1.6.1
|
||||
github.com/nspcc-dev/tzhash v1.3.0
|
||||
github.com/onsi/ginkgo v1.10.2 // indirect
|
||||
|
|
1
go.sum
1
go.sum
|
@ -73,6 +73,7 @@ github.com/nspcc-dev/hrw v1.0.8 h1:vwRuJXZXgkMvf473vFzeWGCfY1WBVeSHAEHvR4u3/Cg=
|
|||
github.com/nspcc-dev/hrw v1.0.8/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.1 h1:NxKexcW88vlHO/u7EYjx5Q1UaOQ7XhYrCsLSVgOcCxw=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.1/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/neofs-crypto v0.2.2/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
|
||||
github.com/nspcc-dev/netmap v1.6.1 h1:Pigqpqi6QSdRiusbq5XlO20A18k6Eyu7j9MzOfAE3CM=
|
||||
github.com/nspcc-dev/netmap v1.6.1/go.mod h1:mhV3UOg9ljQmu0teQShD6+JYX09XY5gu2I4hIByCH9M=
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c=
|
||||
|
|
|
@ -4,53 +4,14 @@ import (
|
|||
"io"
|
||||
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
"github.com/nspcc-dev/neofs-proto/service"
|
||||
"github.com/nspcc-dev/neofs-proto/session"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const maxGetPayloadSize = 3584 * 1024 // 3.5 MiB
|
||||
|
||||
func splitBytes(data []byte, maxSize int) (result [][]byte) {
|
||||
l := len(data)
|
||||
if l == 0 {
|
||||
return [][]byte{data}
|
||||
}
|
||||
for i := 0; i < l; i += maxSize {
|
||||
last := i + maxSize
|
||||
if last > l {
|
||||
last = l
|
||||
}
|
||||
result = append(result, data[i:last])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SendPutRequest prepares object and sends it in chunks through protobuf stream.
|
||||
func SendPutRequest(s Service_PutClient, obj *Object, epoch uint64, ttl uint32) (*PutResponse, error) {
|
||||
// TODO split must take into account size of the marshalled Object
|
||||
chunks := splitBytes(obj.Payload, maxGetPayloadSize)
|
||||
obj.Payload = chunks[0]
|
||||
if err := s.Send(MakePutRequestHeader(obj, epoch, ttl, nil)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range chunks[1:] {
|
||||
if err := s.Send(MakePutRequestChunk(chunks[i+1])); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
resp, err := s.CloseAndRecv()
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// MakePutRequestHeader combines object, epoch, ttl and session token value
|
||||
// MakePutRequestHeader combines object and session token value
|
||||
// into header of object put request.
|
||||
func MakePutRequestHeader(obj *Object, epoch uint64, ttl uint32, token *session.Token) *PutRequest {
|
||||
func MakePutRequestHeader(obj *Object, token *session.Token) *PutRequest {
|
||||
return &PutRequest{
|
||||
RequestMetaHeader: service.RequestMetaHeader{TTL: ttl, Epoch: epoch},
|
||||
R: &PutRequest_Header{Header: &PutRequest_PutHeader{
|
||||
Object: obj,
|
||||
Token: token,
|
||||
|
|
Loading…
Reference in a new issue