Merge pull request #12 from nspcc-dev/update-object-utils

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:
Evgeniy Kulikov 2019-11-22 17:17:50 +03:00 committed by GitHub
commit 2f81b52e80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 42 deletions

2
go.mod
View file

@ -8,7 +8,7 @@ require (
github.com/golang/protobuf v1.3.2 github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1 github.com/google/uuid v1.1.1
github.com/mr-tron/base58 v1.1.2 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/netmap v1.6.1
github.com/nspcc-dev/tzhash v1.3.0 github.com/nspcc-dev/tzhash v1.3.0
github.com/onsi/ginkgo v1.10.2 // indirect github.com/onsi/ginkgo v1.10.2 // indirect

1
go.sum
View file

@ -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/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 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.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 h1:Pigqpqi6QSdRiusbq5XlO20A18k6Eyu7j9MzOfAE3CM=
github.com/nspcc-dev/netmap v1.6.1/go.mod h1:mhV3UOg9ljQmu0teQShD6+JYX09XY5gu2I4hIByCH9M= github.com/nspcc-dev/netmap v1.6.1/go.mod h1:mhV3UOg9ljQmu0teQShD6+JYX09XY5gu2I4hIByCH9M=
github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c= github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ6c=

View file

@ -4,53 +4,14 @@ import (
"io" "io"
"code.cloudfoundry.org/bytefmt" "code.cloudfoundry.org/bytefmt"
"github.com/nspcc-dev/neofs-proto/service"
"github.com/nspcc-dev/neofs-proto/session" "github.com/nspcc-dev/neofs-proto/session"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const maxGetPayloadSize = 3584 * 1024 // 3.5 MiB // MakePutRequestHeader combines object and session token value
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
// into header of object put request. // 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{ return &PutRequest{
RequestMetaHeader: service.RequestMetaHeader{TTL: ttl, Epoch: epoch},
R: &PutRequest_Header{Header: &PutRequest_PutHeader{ R: &PutRequest_Header{Header: &PutRequest_PutHeader{
Object: obj, Object: obj,
Token: token, Token: token,