From 265c26150d7be9406e311b32625809669c490556 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 21 Aug 2020 18:01:59 +0300 Subject: [PATCH] [#11] Build simple neofs-node application Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 11 ++++ cmd/neofs-node/grpc.go | 113 +++++++++++++++++++++++++++++++++++++++ cmd/neofs-node/main.go | 12 +++++ go.mod | 7 +-- go.sum | 4 ++ 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 cmd/neofs-node/config.go create mode 100644 cmd/neofs-node/grpc.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go new file mode 100644 index 000000000..0acde3f8e --- /dev/null +++ b/cmd/neofs-node/config.go @@ -0,0 +1,11 @@ +package main + +type cfg struct { + grpcAddr string +} + +func defaultCfg() *cfg { + return &cfg{ + grpcAddr: ":50501", + } +} diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go new file mode 100644 index 000000000..fec514595 --- /dev/null +++ b/cmd/neofs-node/grpc.go @@ -0,0 +1,113 @@ +package main + +import ( + "context" + "net" + + accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc" + container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" + object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc" + session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc" + "github.com/pkg/errors" + "google.golang.org/grpc" +) + +type unimplementedServer struct { + accServer + cnrServer + objServer +} + +type accServer struct{} + +type sesServer struct{} + +type cnrServer struct{} + +type objServer struct{} + +func unimplementedErr(srv, call string) error { + return errors.Errorf("unimplemented service call %s.%s", srv, call) +} + +func (*accServer) Balance(context.Context, *accounting.BalanceRequest) (*accounting.BalanceResponse, error) { + return nil, unimplementedErr("Accounting", "Balance") +} + +func (*sesServer) Create(context.Context, *session.CreateRequest) (*session.CreateResponse, error) { + return nil, unimplementedErr("Session", "Create") +} + +func (*cnrServer) Put(context.Context, *container.PutRequest) (*container.PutResponse, error) { + return nil, unimplementedErr("Contianer", "Put") +} + +func (*cnrServer) Delete(context.Context, *container.DeleteRequest) (*container.DeleteResponse, error) { + return nil, unimplementedErr("Contianer", "Delete") +} + +func (*cnrServer) Get(context.Context, *container.GetRequest) (*container.GetResponse, error) { + return nil, unimplementedErr("Contianer", "Get") +} + +func (*cnrServer) List(context.Context, *container.ListRequest) (*container.ListResponse, error) { + return nil, unimplementedErr("Contianer", "List") +} + +func (*cnrServer) SetExtendedACL(context.Context, *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) { + return nil, unimplementedErr("Contianer", "SetExtendedACL") +} + +func (*cnrServer) GetExtendedACL(context.Context, *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) { + return nil, unimplementedErr("Contianer", "GetExtendedACL") +} + +func (*objServer) Get(*object.GetRequest, object.ObjectService_GetServer) error { + return unimplementedErr("Object", "Get") +} + +func (*objServer) Put(object.ObjectService_PutServer) error { + return unimplementedErr("Object", "Put") +} + +func (*objServer) Delete(context.Context, *object.DeleteRequest) (*object.DeleteResponse, error) { + return nil, unimplementedErr("Object", "Delete") +} + +func (*objServer) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) { + return nil, unimplementedErr("Object", "Head") +} + +func (*objServer) Search(*object.SearchRequest, object.ObjectService_SearchServer) error { + return unimplementedErr("Object", "Search") +} + +func (*objServer) GetRange(*object.GetRangeRequest, object.ObjectService_GetRangeServer) error { + return unimplementedErr("Object", "GetRange") +} + +func (*objServer) GetRangeHash(context.Context, *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) { + return nil, unimplementedErr("Object", "GetRangeHash") +} + +func serveGRPC(c *cfg) error { + lis, err := net.Listen("tcp", c.grpcAddr) + fatalOnErr(err) + + srv := grpc.NewServer() + + s := new(unimplementedServer) + + accounting.RegisterAccountingServiceServer(srv, s) + container.RegisterContainerServiceServer(srv, s) + session.RegisterSessionServiceServer(srv, s) + object.RegisterObjectServiceServer(srv, s) + + if err := srv.Serve(lis); err != nil { + return err + } + + lis.Close() + + return nil +} diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index ea939f56b..f904f33b3 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -1,10 +1,22 @@ package main import ( + "log" + "github.com/nspcc-dev/neofs-node/pkg/util/grace" ) +func fatalOnErr(err error) { + if err != nil { + log.Fatal(err) + } +} + func main() { + c := defaultCfg() + + fatalOnErr(serveGRPC(c)) + ctx := grace.NewGracefulContext(nil) <-ctx.Done() diff --git a/go.mod b/go.mod index 1c1628ae3..1993ed041 100644 --- a/go.mod +++ b/go.mod @@ -16,9 +16,10 @@ require ( github.com/multiformats/go-multihash v0.0.13 github.com/nspcc-dev/hrw v1.0.9 github.com/nspcc-dev/neo-go v0.90.0 - github.com/nspcc-dev/neofs-api-go v1.3.0 + github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200820112910-89e79ebe72b0 github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/netmap v1.7.0 + github.com/nspcc-dev/tzhash v1.4.0 // indirect github.com/panjf2000/ants/v2 v2.3.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.6.0 @@ -26,7 +27,7 @@ require ( github.com/spaolacci/murmur3 v1.1.0 github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.7.0 - github.com/stretchr/testify v1.5.1 + github.com/stretchr/testify v1.6.1 github.com/valyala/fasthttp v1.9.0 go.etcd.io/bbolt v1.3.4 go.uber.org/atomic v1.5.1 @@ -41,4 +42,4 @@ require ( ) // Used for debug reasons -// replace github.com/nspcc-dev/neofs-api-go => ../neofs-api-go +replace github.com/nspcc-dev/neofs-api-go => ../neofs-api-go diff --git a/go.sum b/go.sum index 4b62e23e1..5f3644aee 100644 --- a/go.sum +++ b/go.sum @@ -297,6 +297,8 @@ github.com/nspcc-dev/neo-go v0.90.0 h1:ABNDrJuF9C1XuLQu0q9DKSVMlg9eQn/g6rX8Jbr31 github.com/nspcc-dev/neo-go v0.90.0/go.mod h1:pPFdnApJwUSRAnpdiPBZl7I7jv0doDg5naecpSPK4+Q= github.com/nspcc-dev/neofs-api-go v1.3.0 h1:w0wYIXzPJIElwhqahnQw/1NKiHxjRZKJhDUMSbEHmdk= github.com/nspcc-dev/neofs-api-go v1.3.0/go.mod h1:NlCjqm//ZRXBNlxtrilLM1GgkRz0mv4V3pdX8OcGoLw= +github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200820112910-89e79ebe72b0 h1:aaDAx0xezfCzpD7NrmaJTLDHs58t5JM4ZV3ttyMJicY= +github.com/nspcc-dev/neofs-api-go v1.3.1-0.20200820112910-89e79ebe72b0/go.mod h1:6euXsb8tS06O9z3iuM49FrKeOhHO66R2DW8T8E1Wfl8= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.3 h1:aca3X2aly92ENRbFK+kH6Hd+J9EQ4Eu6XMVoITSIKtc= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= @@ -419,6 +421,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73 h1:I2drr5K0tykBofr74ZEGliE/Hf6fNkEbcPyFvsy7wZk= @@ -665,6 +668,7 @@ gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=