diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go new file mode 100644 index 0000000000..0acde3f8e9 --- /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 0000000000..fec514595d --- /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 ea939f56bf..f904f33b39 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 1c1628ae3c..1993ed041f 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 4b62e23e16..5f3644aee7 100644 Binary files a/go.sum and b/go.sum differ