diff --git a/pkg/network/muxer/listener.go b/pkg/network/muxer/listener.go deleted file mode 100644 index 9ba669951..000000000 --- a/pkg/network/muxer/listener.go +++ /dev/null @@ -1,51 +0,0 @@ -package muxer - -import ( - "net" - - manet "github.com/multiformats/go-multiaddr-net" - "github.com/pkg/errors" -) - -type netListenerAdapter struct { - manet.Listener -} - -var errNothingAccept = errors.New("nothing to accept") - -// Accept waits for and returns the next connection to the listener. -func (l *netListenerAdapter) Accept() (net.Conn, error) { - if l.Listener == nil { - return nil, errNothingAccept - } - - return l.Listener.Accept() -} - -// Close closes the listener. -// Any blocked Accept operations will be unblocked and return errors. -func (l *netListenerAdapter) Close() error { - if l.Listener == nil { - return nil - } - - return l.Listener.Close() -} - -// Addr returns the net.Listener's network address. -func (l *netListenerAdapter) Addr() net.Addr { - if l.Listener == nil { - return (*net.TCPAddr)(nil) - } - - return l.Listener.Addr() -} - -// NetListener turns this Listener into a net.Listener. -// -// * Connections returned from Accept implement multiaddr-net Conn. -// * Calling WrapNetListener on the net.Listener returned by this function will -// return the original (underlying) multiaddr-net Listener. -func NetListener(l manet.Listener) net.Listener { - return &netListenerAdapter{Listener: l} -} diff --git a/pkg/network/muxer/muxer.go b/pkg/network/muxer/muxer.go deleted file mode 100644 index 3f8640382..000000000 --- a/pkg/network/muxer/muxer.go +++ /dev/null @@ -1,239 +0,0 @@ -package muxer - -import ( - "context" - "net" - "strings" - "sync/atomic" - "time" - - "github.com/multiformats/go-multiaddr" - "github.com/nspcc-dev/neofs-node/pkg/network" - "github.com/soheilhy/cmux" - "github.com/valyala/fasthttp" - "go.uber.org/zap" - "google.golang.org/grpc" -) - -type ( - // StoreParams groups the parameters of network connections muxer constructor. - Params struct { - Logger *zap.Logger - API *fasthttp.Server - Address multiaddr.Multiaddr - ShutdownTTL time.Duration - P2P *grpc.Server - } - - // Mux is an interface of network connections muxer. - Mux interface { - Start(ctx context.Context) - Stop() - } - - muxer struct { - maddr multiaddr.Multiaddr - run *int32 - lis net.Listener - log *zap.Logger - ttl time.Duration - - p2p *grpc.Server - api *fasthttp.Server - - done chan struct{} - } -) - -const ( - // we close listener, that's why we ignore this errors - errClosedConnection = "use of closed network connection" - errMuxListenerClose = "mux: listener closed" - errHTTPServerClosed = "http: Server closed" -) - -var ( - ignoredErrors = []string{ - errClosedConnection, - errMuxListenerClose, - errHTTPServerClosed, - } -) - -// New constructs network connections muxer and returns Mux interface. -func New(p Params) Mux { - return &muxer{ - maddr: p.Address, - ttl: p.ShutdownTTL, - run: new(int32), - api: p.API, - p2p: p.P2P, - log: p.Logger, - - done: make(chan struct{}), - } -} - -func needCatch(err error) bool { - if err == nil || containsErr(err) { - return false - } - - return true -} - -func containsErr(err error) bool { - for _, msg := range ignoredErrors { - if strings.Contains(err.Error(), msg) { - return true - } - } - - return false -} - -func (m *muxer) Start(ctx context.Context) { - var err error - - // if already started - ignore - if !atomic.CompareAndSwapInt32(m.run, 0, 1) { - m.log.Warn("already started") - return - } else if m.lis != nil { - m.log.Info("try close old listener") - if err = m.lis.Close(); err != nil { - m.log.Fatal("could not close old listener", - zap.Error(err)) - } - } - - if m.lis, err = network.Listen(m.maddr); err != nil { - m.log.Fatal("could not close old listener", - zap.Error(err)) - } - - mux := cmux.New(m.lis) - mux.HandleError(func(e error) bool { - if needCatch(e) { - m.log.Error("error-handler: something went wrong", - zap.Error(e)) - } - return true - }) - - // trpcL := mux.Match(cmux.Any()) // Any means anything that is not yet matched. - hLis := mux.Match(cmux.HTTP1Fast()) - gLis := mux.Match(cmux.HTTP2()) - pLis := mux.Match(cmux.Any()) - - m.log.Debug("delay context worker") - - go func() { - <-ctx.Done() - m.Stop() - }() - - m.log.Debug("delay tcp") - - go func() { - m.log.Debug("tcp: serve") - loop: - for { - select { - case <-ctx.Done(): - break loop - default: - } - - con, err := pLis.Accept() - if err != nil { - break loop - } - - _ = con.Close() - } - - m.log.Debug("tcp: stopped") - }() - - m.log.Debug("delay p2p") - - go func() { - if m.p2p == nil { - m.log.Info("p2p: service is empty") - return - } - - m.log.Debug("p2p: serve") - - if err := m.p2p.Serve(gLis); needCatch(err) { - m.log.Error("p2p: something went wrong", - zap.Error(err)) - } - - m.log.Debug("p2p: stopped") - }() - - m.log.Debug("delay api") - - go func() { - if m.api == nil { - m.log.Info("api: service is empty") - return - } - - m.log.Debug("api: serve") - - if err := m.api.Serve(hLis); needCatch(err) { - m.log.Error("rpc: something went wrong", - zap.Error(err)) - } - - m.log.Debug("rpc: stopped") - }() - - m.log.Debug("delay serve") - - go func() { - defer func() { close(m.done) }() - - m.log.Debug("mux: serve") - - if err := mux.Serve(); needCatch(err) { - m.log.Fatal("mux: something went wrong", - zap.Error(err)) - } - - m.log.Debug("mux: stopped") - }() -} - -func (m *muxer) Stop() { - if !atomic.CompareAndSwapInt32(m.run, 1, 0) { - m.log.Warn("already stopped") - return - } - - if err := m.lis.Close(); err != nil { - m.log.Error("could not close connection", - zap.Error(err)) - } - - m.log.Debug("lis: close ok") - - <-m.done // muxer stopped - - if m.api != nil { - if err := m.api.Shutdown(); needCatch(err) { - m.log.Error("api: could not shutdown", - zap.Error(err)) - } - - m.log.Debug("api: shutdown ok") - } - - if m.p2p != nil { - m.p2p.GracefulStop() - m.log.Debug("p2p: shutdown ok") - } -} diff --git a/pkg/network/muxer/muxer_test.go b/pkg/network/muxer/muxer_test.go deleted file mode 100644 index 79a7e1f32..000000000 --- a/pkg/network/muxer/muxer_test.go +++ /dev/null @@ -1,396 +0,0 @@ -package muxer - -import ( - "context" - "net" - "net/http" - "os" - "reflect" - "strings" - "sync" - "testing" - "time" - - "bou.ke/monkey" - "github.com/multiformats/go-multiaddr" - manet "github.com/multiformats/go-multiaddr-net" - "github.com/pkg/errors" - "github.com/soheilhy/cmux" - "github.com/spf13/viper" - "github.com/stretchr/testify/require" - "github.com/valyala/fasthttp" - "go.uber.org/atomic" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "google.golang.org/grpc" -) - -type ( - errListener struct { - net.TCPListener - } - - syncListener struct { - sync.Mutex - net.Listener - } - - errMuxer struct { - handleError func(error) bool - } - - testWriter struct{} - - // service is used to implement GreaterServer. - service struct{} -) - -const MIMEApplicationJSON = "application/json" - -// Hello is simple handler -func (*service) Hello(ctx context.Context, req *HelloRequest) (*HelloResponse, error) { - return &HelloResponse{ - Message: "Hello " + req.Name, - }, nil -} - -func (testWriter) Sync() error { return nil } -func (testWriter) Write(p []byte) (n int, err error) { return len(p), nil } - -func (errMuxer) Match(...cmux.Matcher) net.Listener { - return &errListener{} -} - -func (errMuxer) MatchWithWriters(...cmux.MatchWriter) net.Listener { - return &errListener{} -} - -func (errMuxer) Serve() error { - return errors.New("cmux.Serve error") -} - -func (e *errMuxer) HandleError(h cmux.ErrorHandler) { - e.handleError = h -} - -func (errMuxer) SetReadTimeout(time.Duration) { - panic("implement me") -} - -func (l *syncListener) Close() error { - l.Lock() - err := l.Listener.Close() - l.Unlock() - return err -} - -func (errListener) Close() error { return errors.New("close error") } - -func testMultiAddr(is *require.Assertions) multiaddr.Multiaddr { - mAddr, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/0") - is.NoError(err) - return mAddr -} - -func testLogger() *zap.Logger { - encoderCfg := zapcore.EncoderConfig{ - MessageKey: "msg", - LevelKey: "level", - NameKey: "logger", - EncodeLevel: zapcore.LowercaseLevelEncoder, - EncodeTime: zapcore.ISO8601TimeEncoder, - EncodeDuration: zapcore.StringDurationEncoder, - } - core := zapcore.NewCore(zapcore.NewJSONEncoder(encoderCfg), testWriter{}, zap.DPanicLevel) - return zap.New(core).WithOptions() -} - -func testHTTPServer() *fasthttp.Server { - return &fasthttp.Server{Handler: func(ctx *fasthttp.RequestCtx) {}} -} - -func TestSuite(t *testing.T) { - t.Run("it should run, stop and not panic", func(t *testing.T) { - var ( - is = require.New(t) - v = viper.New() - g = grpc.NewServer() - l = testLogger() - a = testMultiAddr(is) - s = time.Second - err error - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - v.SetDefault("api.address", "/ip4/0.0.0.0/tcp/0") - v.SetDefault("api.shutdown_timeout", time.Second) - - m := New(Params{ - Logger: l, - Address: a, - ShutdownTTL: s, - API: testHTTPServer(), - P2P: g, - }) - - is.NotPanics(func() { - m.Start(ctx) - }) - - res, err := http.Post("http://"+m.(*muxer).lis.Addr().String(), MIMEApplicationJSON, strings.NewReader(`{ - "jsonrpc": "2.0", - "id": 1 - "method": "get_version", - "params": [], - }`)) - is.NoError(err) - defer res.Body.Close() - - time.Sleep(100 * time.Millisecond) - - is.NotPanics(m.Stop) - }) - - t.Run("it should work with gRPC", func(t *testing.T) { - var ( - is = require.New(t) - g = grpc.NewServer() - l = testLogger() - s = time.Second - err error - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - addr, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/63090") - is.NoError(err) - - RegisterGreeterServer(g, &service{}) - - m := New(Params{ - Logger: l, - Address: addr, - ShutdownTTL: s, - P2P: g, - }) - - is.NotPanics(func() { - m.Start(ctx) - }) - - a, err := manet.ToNetAddr(addr) - require.NoError(t, err) - - con, err := grpc.DialContext(ctx, a.String(), grpc.WithInsecure()) - require.NoError(t, err) - - res, err := NewGreeterClient(con).Hello(ctx, &HelloRequest{Name: "test"}) - is.NoError(err) - is.Contains(res.Message, "test") - - time.Sleep(100 * time.Millisecond) - - is.NotPanics(m.Stop) - }) - - t.Run("it should not start if already started", func(t *testing.T) { - var ( - is = require.New(t) - g = grpc.NewServer() - l = testLogger() - a = testMultiAddr(is) - s = time.Second - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - m := New(Params{ - Logger: l, - Address: a, - ShutdownTTL: s, - API: testHTTPServer(), - P2P: g, - }) - is.NotNil(m) - - mux, ok := m.(*muxer) - is.True(ok) - is.NotNil(mux) - - *mux.run = 1 - - is.NotPanics(func() { - mux.Start(ctx) - }) - - *mux.run = 0 - - is.NotPanics(mux.Stop) - }) - - t.Run("it should fail on close listener", func(t *testing.T) { - var ( - is = require.New(t) - g = grpc.NewServer() - l = testLogger() - a = testMultiAddr(is) - s = time.Second - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - m := New(Params{ - Logger: l, - Address: a, - ShutdownTTL: s, - API: testHTTPServer(), - P2P: g, - }) - is.NotNil(m) - - mux, ok := m.(*muxer) - is.True(ok) - is.NotNil(mux) - - mux.lis = &errListener{} - - exit := atomic.NewInt32(0) - - monkey.Patch(os.Exit, func(v int) { exit.Store(int32(v)) }) - - is.NotPanics(func() { - mux.Start(ctx) - }) - is.Equal(int32(1), exit.Load()) - }) - - t.Run("it should fail on create/close Listener without handlers", func(t *testing.T) { - var ( - is = require.New(t) - l = testLogger() - err error - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - mux := new(muxer) - mux.log = l - mux.run = new(int32) - mux.done = make(chan struct{}) - mux.maddr, err = multiaddr.NewMultiaddr("/ip4/1.1.1.1/tcp/2") - is.NoError(err) - - mux.lis, err = net.ListenTCP("tcp", nil) - is.NoError(err) - - exit := atomic.NewInt32(0) - monkey.Patch(os.Exit, func(v int) { - exit.Store(int32(v)) - }) - - m := &errMuxer{handleError: func(e error) bool { return true }} - monkey.Patch(cmux.New, func(net.Listener) cmux.CMux { - // prevent panic: - mux.lis, err = net.ListenTCP("tcp", nil) - return m - }) - - mux.Start(ctx) - // c.So(mux.Start, ShouldNotPanic) - - m.handleError(errors.New("test")) - - is.Equal(int32(1), exit.Load()) - - mux.lis = &errListener{} - *mux.run = 1 - - is.NotPanics(mux.Stop) - }) - - t.Run("it should fail on create/close Listener with handlers", func(t *testing.T) { - var ( - is = require.New(t) - g = grpc.NewServer() - l = testLogger() - err error - ) - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - mux := new(muxer) - mux.api = testHTTPServer() - mux.p2p = g - mux.log = l - mux.run = new(int32) - mux.done = make(chan struct{}) - mux.maddr, err = multiaddr.NewMultiaddr("/ip4/1.1.1.1/tcp/2") - is.NoError(err) - - mu := new(sync.Mutex) - - exit := atomic.NewInt32(0) - monkey.Patch(os.Exit, func(v int) { - exit.Store(int32(v)) - - mu.Lock() - if l, ok := mux.lis.(*syncListener); ok { - l.Lock() - l.Listener, _ = net.ListenTCP("tcp", nil) - l.Unlock() - } - mu.Unlock() - }) - - m := &errMuxer{handleError: func(e error) bool { return true }} - monkey.Patch(cmux.New, func(net.Listener) cmux.CMux { - // prevent panic: - return m - }) - - is.NotPanics(func() { - mux.Start(ctx) - }) - - m.handleError(errors.New("test")) - - is.Equal(int32(1), exit.Load()) - - mu.Lock() - mux.lis = &syncListener{Listener: &errListener{}} - mu.Unlock() - *mux.run = 1 - - monkey.PatchInstanceMethod(reflect.TypeOf(&http.Server{}), "Shutdown", func(*http.Server, context.Context) error { - return errors.New("http.Shutdown error") - }) - - is.NotPanics(mux.Stop) - }) - - t.Run("should not panic when work with nil listener", func(t *testing.T) { - var ( - is = require.New(t) - err error - ) - - lis := NetListener(nil) - is.NotPanics(func() { - is.NoError(lis.Close()) - }) - is.NotPanics(func() { - lis.Addr() - }) - is.NotPanics(func() { - _, err = lis.Accept() - is.EqualError(err, errNothingAccept.Error()) - }) - }) -} diff --git a/pkg/network/muxer/muxer_test.pb.go b/pkg/network/muxer/muxer_test.pb.go deleted file mode 100644 index a7a905a37..000000000 --- a/pkg/network/muxer/muxer_test.pb.go +++ /dev/null @@ -1,601 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: pkg/network/muxer/muxer_test.proto - -package muxer - -import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Request message example -type HelloRequest struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *HelloRequest) Reset() { *m = HelloRequest{} } -func (m *HelloRequest) String() string { return proto.CompactTextString(m) } -func (*HelloRequest) ProtoMessage() {} -func (*HelloRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_df7fe4d8473d3601, []int{0} -} -func (m *HelloRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HelloRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HelloRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HelloRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_HelloRequest.Merge(m, src) -} -func (m *HelloRequest) XXX_Size() int { - return m.Size() -} -func (m *HelloRequest) XXX_DiscardUnknown() { - xxx_messageInfo_HelloRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_HelloRequest proto.InternalMessageInfo - -func (m *HelloRequest) GetName() string { - if m != nil { - return m.Name - } - return "" -} - -type HelloResponse struct { - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *HelloResponse) Reset() { *m = HelloResponse{} } -func (m *HelloResponse) String() string { return proto.CompactTextString(m) } -func (*HelloResponse) ProtoMessage() {} -func (*HelloResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_df7fe4d8473d3601, []int{1} -} -func (m *HelloResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HelloResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HelloResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HelloResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_HelloResponse.Merge(m, src) -} -func (m *HelloResponse) XXX_Size() int { - return m.Size() -} -func (m *HelloResponse) XXX_DiscardUnknown() { - xxx_messageInfo_HelloResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_HelloResponse proto.InternalMessageInfo - -func (m *HelloResponse) GetMessage() string { - if m != nil { - return m.Message - } - return "" -} - -func init() { - proto.RegisterType((*HelloRequest)(nil), "muxer.HelloRequest") - proto.RegisterType((*HelloResponse)(nil), "muxer.HelloResponse") -} - -func init() { proto.RegisterFile("pkg/network/muxer/muxer_test.proto", fileDescriptor_df7fe4d8473d3601) } - -var fileDescriptor_df7fe4d8473d3601 = []byte{ - // 210 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2a, 0xc8, 0x4e, 0xd7, - 0xcf, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, 0x2d, 0xad, 0x48, 0x2d, 0x82, 0x90, 0xf1, - 0x25, 0xa9, 0xc5, 0x25, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xac, 0x60, 0x11, 0x25, 0x25, - 0x2e, 0x1e, 0x8f, 0xd4, 0x9c, 0x9c, 0xfc, 0xa0, 0xd4, 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x21, 0x21, - 0x2e, 0x96, 0xbc, 0xc4, 0xdc, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x30, 0x5b, 0x49, - 0x93, 0x8b, 0x17, 0xaa, 0xa6, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x82, 0x8b, 0x3d, 0x37, - 0xb5, 0xb8, 0x38, 0x31, 0x1d, 0xa6, 0x0e, 0xc6, 0x35, 0xb2, 0xe5, 0x62, 0x77, 0x2f, 0x4a, 0x4d, - 0x2d, 0x49, 0x2d, 0x12, 0x32, 0xe2, 0x62, 0x05, 0xeb, 0x12, 0x12, 0xd6, 0x03, 0x5b, 0xa5, 0x87, - 0x6c, 0x8f, 0x94, 0x08, 0xaa, 0x20, 0xc4, 0x60, 0x27, 0xe7, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, - 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xc3, 0xf4, 0xcc, 0x92, - 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xbc, 0xe2, 0x82, 0xe4, 0x64, 0xdd, 0x94, 0xd4, - 0x32, 0xfd, 0xbc, 0xd4, 0xfc, 0xb4, 0x62, 0xdd, 0xbc, 0xfc, 0x94, 0x54, 0x7d, 0x0c, 0xaf, 0x26, - 0xb1, 0x81, 0x3d, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x6d, 0x4f, 0x57, 0x17, 0x06, 0x01, - 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// GreeterClient is the client API for Greeter service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type GreeterClient interface { - Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) -} - -type greeterClient struct { - cc *grpc.ClientConn -} - -func NewGreeterClient(cc *grpc.ClientConn) GreeterClient { - return &greeterClient{cc} -} - -func (c *greeterClient) Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) { - out := new(HelloResponse) - err := c.cc.Invoke(ctx, "/muxer.Greeter/Hello", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// GreeterServer is the server API for Greeter service. -type GreeterServer interface { - Hello(context.Context, *HelloRequest) (*HelloResponse, error) -} - -// UnimplementedGreeterServer can be embedded to have forward compatible implementations. -type UnimplementedGreeterServer struct { -} - -func (*UnimplementedGreeterServer) Hello(ctx context.Context, req *HelloRequest) (*HelloResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Hello not implemented") -} - -func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { - s.RegisterService(&_Greeter_serviceDesc, srv) -} - -func _Greeter_Hello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HelloRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GreeterServer).Hello(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/muxer.Greeter/Hello", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GreeterServer).Hello(ctx, req.(*HelloRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _Greeter_serviceDesc = grpc.ServiceDesc{ - ServiceName: "muxer.Greeter", - HandlerType: (*GreeterServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Hello", - Handler: _Greeter_Hello_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "pkg/network/muxer/muxer_test.proto", -} - -func (m *HelloRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HelloRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HelloRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Name) > 0 { - i -= len(m.Name) - copy(dAtA[i:], m.Name) - i = encodeVarintMuxerTest(dAtA, i, uint64(len(m.Name))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *HelloResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HelloResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HelloResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Message) > 0 { - i -= len(m.Message) - copy(dAtA[i:], m.Message) - i = encodeVarintMuxerTest(dAtA, i, uint64(len(m.Message))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintMuxerTest(dAtA []byte, offset int, v uint64) int { - offset -= sovMuxerTest(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *HelloRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Name) - if l > 0 { - n += 1 + l + sovMuxerTest(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func (m *HelloResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Message) - if l > 0 { - n += 1 + l + sovMuxerTest(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n -} - -func sovMuxerTest(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozMuxerTest(x uint64) (n int) { - return sovMuxerTest(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *HelloRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HelloRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HelloRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthMuxerTest - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthMuxerTest - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Name = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMuxerTest(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMuxerTest - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMuxerTest - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *HelloResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HelloResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HelloResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthMuxerTest - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthMuxerTest - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Message = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipMuxerTest(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthMuxerTest - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthMuxerTest - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipMuxerTest(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowMuxerTest - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthMuxerTest - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupMuxerTest - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthMuxerTest - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthMuxerTest = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowMuxerTest = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupMuxerTest = fmt.Errorf("proto: unexpected end of group") -) diff --git a/pkg/network/muxer/muxer_test.proto b/pkg/network/muxer/muxer_test.proto deleted file mode 100644 index 3079865c8..000000000 --- a/pkg/network/muxer/muxer_test.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; -option go_package = "github.com/nspcc-dev/neofs-node/pkg/network/muxer"; - -package muxer; - -// The Greater service definition. -service Greeter { - rpc Hello(HelloRequest) returns (HelloResponse); -} - -// Request message example -message HelloRequest { - string name = 1; -} - -message HelloResponse { - string message = 1; -}