2020-08-21 15:01:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-22 11:03:45 +00:00
|
|
|
"fmt"
|
2020-08-25 13:37:10 +00:00
|
|
|
"io"
|
2020-08-21 15:01:59 +00:00
|
|
|
"net"
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container"
|
2020-08-25 13:37:10 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2020-08-21 15:01:59 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
type containerSvc struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
type objectSvc struct{}
|
2020-08-21 15:01:59 +00:00
|
|
|
|
|
|
|
func unimplementedErr(srv, call string) error {
|
2020-08-22 11:03:45 +00:00
|
|
|
return errors.Errorf("unimplemented API service call %s.%s", srv, call)
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Put(context.Context, *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Delete(context.Context, *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Delete")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) Get(context.Context, *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "Get")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) List(context.Context, *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "List")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) SetExtendedACL(context.Context, *containerGRPC.SetExtendedACLRequest) (*containerGRPC.SetExtendedACLResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "SetExtendedACL")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-22 11:03:45 +00:00
|
|
|
func (s *containerSvc) GetExtendedACL(context.Context, *containerGRPC.GetExtendedACLRequest) (*containerGRPC.GetExtendedACLResponse, error) {
|
|
|
|
return nil, unimplementedErr("Container", "GetExtendedACL")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *objectSvc) Get(context.Context, *object.GetRequest) (object.GetObjectStreamer, error) {
|
2020-08-22 11:03:45 +00:00
|
|
|
return nil, unimplementedErr("Object", "Get")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *objectSvc) Put(context.Context) (object.PutObjectStreamer, error) {
|
2020-08-22 11:03:45 +00:00
|
|
|
return nil, unimplementedErr("Object", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *objectSvc) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) {
|
2020-08-22 11:03:45 +00:00
|
|
|
return nil, unimplementedErr("Object", "Put")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
type simpleSearchStreamer struct {
|
|
|
|
count int
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *simpleSearchStreamer) Recv() (*object.SearchResponse, error) {
|
|
|
|
resp := new(object.SearchResponse)
|
|
|
|
|
|
|
|
body := new(object.SearchResponseBody)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
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 resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *objectSvc) Search(context.Context, *object.SearchRequest) (object.SearchObjectStreamer, error) {
|
|
|
|
return new(simpleSearchStreamer), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *objectSvc) Delete(context.Context, *object.DeleteRequest) (*object.DeleteResponse, error) {
|
2020-08-22 11:03:45 +00:00
|
|
|
return nil, unimplementedErr("Object", "Delete")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *objectSvc) GetRange(context.Context, *object.GetRangeRequest) (object.GetRangeObjectStreamer, error) {
|
2020-08-22 11:03:45 +00:00
|
|
|
return nil, unimplementedErr("Object", "GetRange")
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:37:10 +00:00
|
|
|
func (s *objectSvc) GetRangeHash(context.Context, *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
2020-08-21 15:01:59 +00:00
|
|
|
return nil, unimplementedErr("Object", "GetRangeHash")
|
|
|
|
}
|
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
func initGRPC(c *cfg) {
|
|
|
|
var err error
|
2020-08-21 15:01:59 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
c.cfgGRPC.listener, err = net.Listen("tcp", c.cfgGRPC.endpoint)
|
|
|
|
fatalOnErr(err)
|
2020-08-22 15:20:47 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
c.cfgGRPC.server = grpc.NewServer()
|
|
|
|
}
|
2020-08-22 11:03:45 +00:00
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
func serveGRPC(c *cfg) {
|
2020-08-22 11:03:45 +00:00
|
|
|
go func() {
|
|
|
|
c.wg.Add(1)
|
|
|
|
defer func() {
|
|
|
|
c.wg.Done()
|
|
|
|
}()
|
|
|
|
|
2020-08-24 09:40:32 +00:00
|
|
|
if err := c.cfgGRPC.server.Serve(c.cfgGRPC.listener); err != nil {
|
2020-08-22 11:03:45 +00:00
|
|
|
fmt.Println("gRPC server error", err)
|
|
|
|
}
|
|
|
|
}()
|
2020-08-21 15:01:59 +00:00
|
|
|
}
|