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 | Bin 65607 -> 66049 bytes 5 files changed, 140 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 4b62e23e163012b09f0b8b1f221649f0d0ef1166..5f3644aee78be3d8b23487b6dc6161ef94bb0e10 100644 GIT binary patch delta 373 zcmX@!z|z>lvSC%hWUm4qUqf93JtG4n0|N^q14Bb2OG5))3(Hh<%haS)bE6~!g$zTh z#6%az3WJK&sx;@S0vB_?qTEEU5FZzhVpEF}Q!ihWs4(M_l1g8%%;d=%i=-yM%@+tI zV5)w4zFuyA3dnG?)Y6FJB#V+@12cciD&x#jUlU8WBJWiH3=e-ZvmhgvaElNNSHtkM z9E-_}dE%2}3xzgsEBLQHdEG2wOEWz~WTV^)E%JksgG`N!iYhG)461w!y|RLWGAoM8 zBaFQxEX|DcGxWpDvr1CaC;yzIy!q4|*@VdffB2(}70QhD4D<|i!2w}xXlw`!5K}{4 z%QPc1v(!XjaF{0}+2d_eTA6KLW$xtc8c- S?V9fDJ9+