2020-08-25 13:37:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-08-25 14:44:41 +00:00
|
|
|
"context"
|
2020-08-25 15:45:36 +00:00
|
|
|
"fmt"
|
2020-08-25 14:44:41 +00:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-08-25 13:37:10 +00:00
|
|
|
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
2020-08-25 14:44:41 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2020-08-25 13:37:10 +00:00
|
|
|
objectTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
|
|
|
|
objectService "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
|
|
|
)
|
|
|
|
|
2020-08-25 14:44:41 +00:00
|
|
|
type simpleSearchBodyStreamer struct {
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:08:58 +00:00
|
|
|
type simpleGetBodyStreamer struct {
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:45:36 +00:00
|
|
|
type simplePutBodyStreamer struct{}
|
|
|
|
|
2020-08-25 15:58:31 +00:00
|
|
|
type simpleRangeBodyStreamer struct {
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
2020-08-25 15:45:36 +00:00
|
|
|
type objectExecutor struct{}
|
2020-08-25 14:44:41 +00:00
|
|
|
|
2020-08-25 15:08:58 +00:00
|
|
|
func (s *simpleGetBodyStreamer) Recv() (*object.GetResponseBody, error) {
|
|
|
|
body := new(object.GetResponseBody)
|
|
|
|
|
|
|
|
id := new(refs.ObjectID)
|
|
|
|
id.SetValue([]byte{1, 2, 3})
|
|
|
|
|
|
|
|
if s.count == 0 {
|
|
|
|
in := new(object.GetObjectPartInit)
|
|
|
|
in.SetObjectID(id)
|
|
|
|
|
|
|
|
body.SetObjectPart(in)
|
|
|
|
} else if s.count == 1 {
|
|
|
|
c := new(object.GetObjectPartChunk)
|
|
|
|
c.SetChunk([]byte{8, 8, 0, 0, 5, 5, 5, 3, 5, 3, 5})
|
|
|
|
|
|
|
|
body.SetObjectPart(c)
|
|
|
|
} else {
|
|
|
|
return nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
s.count++
|
|
|
|
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:44:41 +00:00
|
|
|
func (*objectExecutor) Get(context.Context, *object.GetRequestBody) (objectService.GetObjectBodyStreamer, error) {
|
2020-08-25 15:08:58 +00:00
|
|
|
return new(simpleGetBodyStreamer), nil
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 15:45:36 +00:00
|
|
|
func (s *simplePutBodyStreamer) Send(body *object.PutRequestBody) error {
|
|
|
|
fmt.Printf("object part received %T\n", body.GetObjectPart())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simplePutBodyStreamer) CloseAndRecv() (*object.PutResponseBody, error) {
|
|
|
|
body := new(object.PutResponseBody)
|
|
|
|
oid := new(refs.ObjectID)
|
|
|
|
|
|
|
|
body.SetObjectID(oid)
|
|
|
|
|
|
|
|
oid.SetValue([]byte{6, 7, 8})
|
|
|
|
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*objectExecutor) Put(context.Context) (objectService.PutObjectBodyStreamer, error) {
|
|
|
|
return new(simplePutBodyStreamer), nil
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 16:08:16 +00:00
|
|
|
func (*objectExecutor) Head(_ context.Context, body *object.HeadRequestBody) (*object.HeadResponseBody, error) {
|
|
|
|
res := new(object.HeadResponseBody)
|
|
|
|
|
|
|
|
hdrPart := new(object.GetHeaderPartShort)
|
|
|
|
shHdr := new(object.ShortHeader)
|
|
|
|
hdrPart.SetShortHeader(shHdr)
|
|
|
|
|
|
|
|
shHdr.SetPayloadLength(100)
|
|
|
|
|
|
|
|
res.SetHeaderPart(hdrPart)
|
|
|
|
|
|
|
|
return res, nil
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *objectExecutor) Search(ctx context.Context, body *object.SearchRequestBody) (objectService.SearchObjectBodyStreamer, error) {
|
|
|
|
return new(simpleSearchBodyStreamer), nil
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:12:54 +00:00
|
|
|
func (*objectExecutor) Delete(_ context.Context, body *object.DeleteRequestBody) (*object.DeleteResponseBody, error) {
|
|
|
|
return new(object.DeleteResponseBody), nil
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 15:58:31 +00:00
|
|
|
func (s *simpleRangeBodyStreamer) Recv() (*object.GetRangeResponseBody, error) {
|
|
|
|
body := new(object.GetRangeResponseBody)
|
|
|
|
|
|
|
|
if s.count == 0 {
|
|
|
|
body.SetChunk([]byte{1, 2, 2, 1})
|
|
|
|
} else if s.count == 1 {
|
|
|
|
body.SetChunk([]byte{4, 2, 4, 2})
|
|
|
|
} else {
|
|
|
|
return nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
s.count++
|
|
|
|
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*objectExecutor) GetRange(_ context.Context, body *object.GetRangeRequestBody) (objectService.GetRangeObjectBodyStreamer, error) {
|
|
|
|
return new(simpleRangeBodyStreamer), nil
|
2020-08-25 14:44:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*objectExecutor) GetRangeHash(context.Context, *object.GetRangeHashRequestBody) (*object.GetRangeHashResponseBody, error) {
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *simpleSearchBodyStreamer) Recv() (*object.SearchResponseBody, error) {
|
|
|
|
body := new(object.SearchResponseBody)
|
|
|
|
|
|
|
|
id := new(refs.ObjectID)
|
|
|
|
body.SetIDList([]*refs.ObjectID{id})
|
|
|
|
|
|
|
|
if s.count == 0 {
|
|
|
|
id.SetValue([]byte{1})
|
|
|
|
} else if s.count == 1 {
|
|
|
|
id.SetValue([]byte{2})
|
|
|
|
} else {
|
|
|
|
return nil, io.EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
s.count++
|
|
|
|
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func initObjectService(c *cfg) {
|
2020-08-25 14:44:41 +00:00
|
|
|
metaHdr := new(session.ResponseMetaHeader)
|
|
|
|
xHdr := new(session.XHeader)
|
|
|
|
xHdr.SetKey("test X-Header key for Object service")
|
|
|
|
xHdr.SetValue("test X-Header value for Object service")
|
|
|
|
metaHdr.SetXHeaders([]*session.XHeader{xHdr})
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
objectGRPC.RegisterObjectServiceServer(c.cfgGRPC.server,
|
|
|
|
objectTransportGRPC.New(
|
|
|
|
objectService.NewSignService(
|
|
|
|
c.key,
|
2020-08-25 14:44:41 +00:00
|
|
|
objectService.NewExecutionService(
|
|
|
|
new(objectExecutor),
|
|
|
|
metaHdr,
|
|
|
|
),
|
2020-08-25 13:37:10 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|