diff --git a/pkg/services/control/ir/convert.go b/pkg/services/control/ir/convert.go new file mode 100644 index 000000000..3536951f4 --- /dev/null +++ b/pkg/services/control/ir/convert.go @@ -0,0 +1,34 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/rpc/grpc" + "github.com/nspcc-dev/neofs-api-go/rpc/message" +) + +type requestWrapper struct { + message.Message + m grpc.Message +} + +func (w *requestWrapper) ToGRPCMessage() grpc.Message { + return w.m +} + +type healthCheckResponseWrapper struct { + m *HealthCheckResponse +} + +func (w *healthCheckResponseWrapper) ToGRPCMessage() grpc.Message { + return w.m +} + +func (w *healthCheckResponseWrapper) FromGRPCMessage(m grpc.Message) error { + var ok bool + + w.m, ok = m.(*HealthCheckResponse) + if !ok { + return message.NewUnexpectedMessageType(m, w.m) + } + + return nil +} diff --git a/pkg/services/control/ir/rpc.go b/pkg/services/control/ir/rpc.go new file mode 100644 index 000000000..8ed7cf44e --- /dev/null +++ b/pkg/services/control/ir/rpc.go @@ -0,0 +1,34 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/rpc/client" + "github.com/nspcc-dev/neofs-api-go/rpc/common" +) + +const serviceName = "ircontrol.ControlService" + +const ( + rpcHealthCheck = "HealthCheck" +) + +// HealthCheck executes ControlService.HealthCheck RPC. +func HealthCheck( + cli *client.Client, + req *HealthCheckRequest, + opts ...client.CallOption, +) (*HealthCheckResponse, error) { + wResp := &healthCheckResponseWrapper{ + m: new(HealthCheckResponse), + } + + wReq := &requestWrapper{ + m: req, + } + + err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcHealthCheck), wReq, wResp, opts...) + if err != nil { + return nil, err + } + + return wResp.m, nil +} diff --git a/pkg/services/control/ir/service.go b/pkg/services/control/ir/service.go new file mode 100644 index 000000000..8f7705c98 --- /dev/null +++ b/pkg/services/control/ir/service.go @@ -0,0 +1,148 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/util/proto" +) + +// StableMarshal reads binary representation of health check request body +// in protobuf binary format. +// +// If buffer length is less than x.StableSize(), new buffer is allocated. +// +// Returns any error encountered which did not allow writing the data completely. +// Otherwise, returns the buffer in which the data is written. +// +// Structures with the same field values have the same binary format. +func (x *HealthCheckRequest_Body) StableMarshal(buf []byte) ([]byte, error) { + return buf, nil +} + +// StableSize returns binary size of health check request body +// in protobuf binary format. +// +// Structures with the same field values have the same binary size. +func (x *HealthCheckRequest_Body) StableSize() int { + return 0 +} + +// SetBody sets health check request body. +func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) { + if x != nil { + x.Body = v + } +} + +// SetSignature sets signature of the health check request body. +func (x *HealthCheckRequest) SetSignature(body *Signature) { + if x != nil { + x.Signature = body + } +} + +// ReadSignedData reads signed data of health check request to buf. +// +// If buffer length is less than x.SignedDataSize(), new buffer is allocated. +// +// Returns any error encountered which did not allow writing the data completely. +// Otherwise, returns the buffer in which the data is written. +// +// Structures with the same field values have the same signed data. +func (x *HealthCheckRequest) ReadSignedData(buf []byte) ([]byte, error) { + return x.GetBody().StableMarshal(buf) +} + +// SignedDataSize returns binary size of the signed data +// of health check request. +// +// Structures with the same field values have the same signed data size. +func (x *HealthCheckRequest) SignedDataSize() int { + return x.GetBody().StableSize() +} + +// SetHealthStatus sets health status of the IR application. +func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) { + if x != nil { + x.HealthStatus = v + } +} + +const ( + _ = iota + healthRespBodyHealthStatusFNum +) + +// StableMarshal reads binary representation of health check response body +// in protobuf binary format. +// +// If buffer length is less than x.StableSize(), new buffer is allocated. +// +// Returns any error encountered which did not allow writing the data completely. +// Otherwise, returns the buffer in which the data is written. +// +// Structures with the same field values have the same binary format. +func (x *HealthCheckResponse_Body) StableMarshal(buf []byte) ([]byte, error) { + if x == nil { + return []byte{}, nil + } + + if sz := x.StableSize(); len(buf) < sz { + buf = make([]byte, sz) + } + + _, err := proto.EnumMarshal(healthRespBodyHealthStatusFNum, buf, int32(x.HealthStatus)) + if err != nil { + return nil, err + } + + return buf, nil +} + +// StableSize returns binary size of health check response body +// in protobuf binary format. +// +// Structures with the same field values have the same binary size. +func (x *HealthCheckResponse_Body) StableSize() int { + if x == nil { + return 0 + } + + size := 0 + + size += proto.EnumSize(healthRespBodyHealthStatusFNum, int32(x.HealthStatus)) + + return size +} + +// SetBody sets health check response body. +func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) { + if x != nil { + x.Body = v + } +} + +// SetSignature sets signature of the health check response body. +func (x *HealthCheckResponse) SetSignature(v *Signature) { + if x != nil { + x.Signature = v + } +} + +// ReadSignedData reads signed data of health check response to buf. +// +// If buffer length is less than x.SignedDataSize(), new buffer is allocated. +// +// Returns any error encountered which did not allow writing the data completely. +// Otherwise, returns the buffer in which the data is written. +// +// Structures with the same field values have the same signed data. +func (x *HealthCheckResponse) ReadSignedData(buf []byte) ([]byte, error) { + return x.GetBody().StableMarshal(buf) +} + +// SignedDataSize returns binary size of the signed data +// of health check response. +// +// Structures with the same field values have the same signed data size. +func (x *HealthCheckResponse) SignedDataSize() int { + return x.GetBody().StableSize() +} diff --git a/pkg/services/control/ir/service.pb.go b/pkg/services/control/ir/service.pb.go new file mode 100644 index 000000000..0b60effb8 --- /dev/null +++ b/pkg/services/control/ir/service.pb.go @@ -0,0 +1,472 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.25.0 +// protoc v3.14.0 +// source: pkg/services/control/ir/service.proto + +package control + +import ( + context "context" + proto "github.com/golang/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 + +// Health check request. +type HealthCheckRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Body of health check request message. + Body *HealthCheckRequest_Body `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + // Body signature. + // Should be signed by node key or one of + // the keys configured by the node. + Signature *Signature `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (x *HealthCheckRequest) Reset() { + *x = HealthCheckRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HealthCheckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HealthCheckRequest) ProtoMessage() {} + +func (x *HealthCheckRequest) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HealthCheckRequest.ProtoReflect.Descriptor instead. +func (*HealthCheckRequest) Descriptor() ([]byte, []int) { + return file_pkg_services_control_ir_service_proto_rawDescGZIP(), []int{0} +} + +func (x *HealthCheckRequest) GetBody() *HealthCheckRequest_Body { + if x != nil { + return x.Body + } + return nil +} + +func (x *HealthCheckRequest) GetSignature() *Signature { + if x != nil { + return x.Signature + } + return nil +} + +// Health check response. +type HealthCheckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Body of health check response message. + Body *HealthCheckResponse_Body `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` + // Body signature. + Signature *Signature `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (x *HealthCheckResponse) Reset() { + *x = HealthCheckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HealthCheckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HealthCheckResponse) ProtoMessage() {} + +func (x *HealthCheckResponse) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HealthCheckResponse.ProtoReflect.Descriptor instead. +func (*HealthCheckResponse) Descriptor() ([]byte, []int) { + return file_pkg_services_control_ir_service_proto_rawDescGZIP(), []int{1} +} + +func (x *HealthCheckResponse) GetBody() *HealthCheckResponse_Body { + if x != nil { + return x.Body + } + return nil +} + +func (x *HealthCheckResponse) GetSignature() *Signature { + if x != nil { + return x.Signature + } + return nil +} + +// Health check request body. +type HealthCheckRequest_Body struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *HealthCheckRequest_Body) Reset() { + *x = HealthCheckRequest_Body{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HealthCheckRequest_Body) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HealthCheckRequest_Body) ProtoMessage() {} + +func (x *HealthCheckRequest_Body) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HealthCheckRequest_Body.ProtoReflect.Descriptor instead. +func (*HealthCheckRequest_Body) Descriptor() ([]byte, []int) { + return file_pkg_services_control_ir_service_proto_rawDescGZIP(), []int{0, 0} +} + +// Health check response body +type HealthCheckResponse_Body struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Health status of IR node application. + HealthStatus HealthStatus `protobuf:"varint,1,opt,name=health_status,json=healthStatus,proto3,enum=ircontrol.HealthStatus" json:"health_status,omitempty"` +} + +func (x *HealthCheckResponse_Body) Reset() { + *x = HealthCheckResponse_Body{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HealthCheckResponse_Body) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HealthCheckResponse_Body) ProtoMessage() {} + +func (x *HealthCheckResponse_Body) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_control_ir_service_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HealthCheckResponse_Body.ProtoReflect.Descriptor instead. +func (*HealthCheckResponse_Body) Descriptor() ([]byte, []int) { + return file_pkg_services_control_ir_service_proto_rawDescGZIP(), []int{1, 0} +} + +func (x *HealthCheckResponse_Body) GetHealthStatus() HealthStatus { + if x != nil { + return x.HealthStatus + } + return HealthStatus_HEALTH_STATUS_UNDEFINED +} + +var File_pkg_services_control_ir_service_proto protoreflect.FileDescriptor + +var file_pkg_services_control_ir_service_proto_rawDesc = []byte{ + 0x0a, 0x25, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x69, 0x72, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x1a, 0x23, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, + 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x69, 0x72, 0x2f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x88, 0x01, 0x0a, 0x12, 0x48, 0x65, 0x61, 0x6c, + 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x36, + 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x69, + 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, + 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x42, 0x6f, 0x64, 0x79, + 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x12, 0x32, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, + 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x69, 0x72, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, + 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x06, 0x0a, 0x04, 0x42, 0x6f, + 0x64, 0x79, 0x22, 0xc8, 0x01, 0x0a, 0x13, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x04, 0x62, 0x6f, + 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x69, 0x72, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x52, 0x04, 0x62, + 0x6f, 0x64, 0x79, 0x12, 0x32, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x44, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, + 0x3c, 0x0a, 0x0d, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, + 0x0c, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x32, 0x5e, 0x0a, + 0x0e, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x4c, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x1d, + 0x2e, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, + 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, + 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x39, 0x5a, + 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x73, 0x70, 0x63, + 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, 0x6e, 0x6f, 0x64, 0x65, + 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x69, 0x72, + 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pkg_services_control_ir_service_proto_rawDescOnce sync.Once + file_pkg_services_control_ir_service_proto_rawDescData = file_pkg_services_control_ir_service_proto_rawDesc +) + +func file_pkg_services_control_ir_service_proto_rawDescGZIP() []byte { + file_pkg_services_control_ir_service_proto_rawDescOnce.Do(func() { + file_pkg_services_control_ir_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_services_control_ir_service_proto_rawDescData) + }) + return file_pkg_services_control_ir_service_proto_rawDescData +} + +var file_pkg_services_control_ir_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_pkg_services_control_ir_service_proto_goTypes = []interface{}{ + (*HealthCheckRequest)(nil), // 0: ircontrol.HealthCheckRequest + (*HealthCheckResponse)(nil), // 1: ircontrol.HealthCheckResponse + (*HealthCheckRequest_Body)(nil), // 2: ircontrol.HealthCheckRequest.Body + (*HealthCheckResponse_Body)(nil), // 3: ircontrol.HealthCheckResponse.Body + (*Signature)(nil), // 4: ircontrol.Signature + (HealthStatus)(0), // 5: ircontrol.HealthStatus +} +var file_pkg_services_control_ir_service_proto_depIdxs = []int32{ + 2, // 0: ircontrol.HealthCheckRequest.body:type_name -> ircontrol.HealthCheckRequest.Body + 4, // 1: ircontrol.HealthCheckRequest.signature:type_name -> ircontrol.Signature + 3, // 2: ircontrol.HealthCheckResponse.body:type_name -> ircontrol.HealthCheckResponse.Body + 4, // 3: ircontrol.HealthCheckResponse.signature:type_name -> ircontrol.Signature + 5, // 4: ircontrol.HealthCheckResponse.Body.health_status:type_name -> ircontrol.HealthStatus + 0, // 5: ircontrol.ControlService.HealthCheck:input_type -> ircontrol.HealthCheckRequest + 1, // 6: ircontrol.ControlService.HealthCheck:output_type -> ircontrol.HealthCheckResponse + 6, // [6:7] is the sub-list for method output_type + 5, // [5:6] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_pkg_services_control_ir_service_proto_init() } +func file_pkg_services_control_ir_service_proto_init() { + if File_pkg_services_control_ir_service_proto != nil { + return + } + file_pkg_services_control_ir_types_proto_init() + if !protoimpl.UnsafeEnabled { + file_pkg_services_control_ir_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthCheckRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pkg_services_control_ir_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthCheckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pkg_services_control_ir_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthCheckRequest_Body); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pkg_services_control_ir_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthCheckResponse_Body); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pkg_services_control_ir_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_pkg_services_control_ir_service_proto_goTypes, + DependencyIndexes: file_pkg_services_control_ir_service_proto_depIdxs, + MessageInfos: file_pkg_services_control_ir_service_proto_msgTypes, + }.Build() + File_pkg_services_control_ir_service_proto = out.File + file_pkg_services_control_ir_service_proto_rawDesc = nil + file_pkg_services_control_ir_service_proto_goTypes = nil + file_pkg_services_control_ir_service_proto_depIdxs = nil +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// 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.SupportPackageIsVersion6 + +// ControlServiceClient is the client API for ControlService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ControlServiceClient interface { + // Performs health check of the IR node. + HealthCheck(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) +} + +type controlServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewControlServiceClient(cc grpc.ClientConnInterface) ControlServiceClient { + return &controlServiceClient{cc} +} + +func (c *controlServiceClient) HealthCheck(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error) { + out := new(HealthCheckResponse) + err := c.cc.Invoke(ctx, "/ircontrol.ControlService/HealthCheck", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ControlServiceServer is the server API for ControlService service. +type ControlServiceServer interface { + // Performs health check of the IR node. + HealthCheck(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) +} + +// UnimplementedControlServiceServer can be embedded to have forward compatible implementations. +type UnimplementedControlServiceServer struct { +} + +func (*UnimplementedControlServiceServer) HealthCheck(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method HealthCheck not implemented") +} + +func RegisterControlServiceServer(s *grpc.Server, srv ControlServiceServer) { + s.RegisterService(&_ControlService_serviceDesc, srv) +} + +func _ControlService_HealthCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HealthCheckRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ControlServiceServer).HealthCheck(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ircontrol.ControlService/HealthCheck", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ControlServiceServer).HealthCheck(ctx, req.(*HealthCheckRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _ControlService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ircontrol.ControlService", + HandlerType: (*ControlServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "HealthCheck", + Handler: _ControlService_HealthCheck_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "pkg/services/control/ir/service.proto", +} diff --git a/pkg/services/control/ir/service.proto b/pkg/services/control/ir/service.proto new file mode 100644 index 000000000..e330d0fcf --- /dev/null +++ b/pkg/services/control/ir/service.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package ircontrol; + +import "pkg/services/control/ir/types.proto"; + +option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/ir/control"; + +// `ControlService` provides an interface for internal work with the Inner Ring node. +service ControlService { + // Performs health check of the IR node. + rpc HealthCheck (HealthCheckRequest) returns (HealthCheckResponse); +} + +// Health check request. +message HealthCheckRequest { + // Health check request body. + message Body { + } + + // Body of health check request message. + Body body = 1; + + // Body signature. + // Should be signed by node key or one of + // the keys configured by the node. + Signature signature = 2; +} + +// Health check response. +message HealthCheckResponse { + // Health check response body + message Body { + // Health status of IR node application. + HealthStatus health_status = 1; + } + + // Body of health check response message. + Body body = 1; + + // Body signature. + Signature signature = 2; +} diff --git a/pkg/services/control/ir/service_test.go b/pkg/services/control/ir/service_test.go new file mode 100644 index 000000000..9958e0a56 --- /dev/null +++ b/pkg/services/control/ir/service_test.go @@ -0,0 +1,47 @@ +package control_test + +import ( + "testing" + + control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +type protoMessage interface { + StableMarshal([]byte) ([]byte, error) + proto.Message +} + +func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) { + data, err := m1.StableMarshal(nil) + require.NoError(t, err) + + require.NoError(t, proto.Unmarshal(data, m2)) + + require.True(t, cmp(m1, m2)) +} + +func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) { + testStableMarshal(t, + generateHealthCheckResponseBody(), + new(control.HealthCheckResponse_Body), + func(m1, m2 protoMessage) bool { + return equalHealthCheckResponseBodies( + m1.(*control.HealthCheckResponse_Body), + m2.(*control.HealthCheckResponse_Body), + ) + }, + ) +} + +func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body { + body := new(control.HealthCheckResponse_Body) + body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN) + + return body +} + +func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool { + return b1.GetHealthStatus() == b2.GetHealthStatus() +} diff --git a/pkg/services/control/ir/types.go b/pkg/services/control/ir/types.go new file mode 100644 index 000000000..97ffd3ce3 --- /dev/null +++ b/pkg/services/control/ir/types.go @@ -0,0 +1,15 @@ +package control + +// SetKey sets public key used for signing. +func (x *Signature) SetKey(v []byte) { + if x != nil { + x.Key = v + } +} + +// SetSign sets binary signature. +func (x *Signature) SetSign(v []byte) { + if x != nil { + x.Sign = v + } +} diff --git a/pkg/services/control/ir/types.pb.go b/pkg/services/control/ir/types.pb.go new file mode 100644 index 000000000..07daaef73 --- /dev/null +++ b/pkg/services/control/ir/types.pb.go @@ -0,0 +1,229 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.25.0 +// protoc v3.14.0 +// source: pkg/services/control/ir/types.proto + +package control + +import ( + proto "github.com/golang/protobuf/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 + +// Health status of the IR application. +type HealthStatus int32 + +const ( + // Undefined status, default value. + HealthStatus_HEALTH_STATUS_UNDEFINED HealthStatus = 0 + // IR application is starting. + HealthStatus_STARTING HealthStatus = 1 + // IR application is started and serves all services. + HealthStatus_READY HealthStatus = 2 + // IR application is shutting down. + HealthStatus_SHUTTING_DOWN HealthStatus = 3 +) + +// Enum value maps for HealthStatus. +var ( + HealthStatus_name = map[int32]string{ + 0: "HEALTH_STATUS_UNDEFINED", + 1: "STARTING", + 2: "READY", + 3: "SHUTTING_DOWN", + } + HealthStatus_value = map[string]int32{ + "HEALTH_STATUS_UNDEFINED": 0, + "STARTING": 1, + "READY": 2, + "SHUTTING_DOWN": 3, + } +) + +func (x HealthStatus) Enum() *HealthStatus { + p := new(HealthStatus) + *p = x + return p +} + +func (x HealthStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (HealthStatus) Descriptor() protoreflect.EnumDescriptor { + return file_pkg_services_control_ir_types_proto_enumTypes[0].Descriptor() +} + +func (HealthStatus) Type() protoreflect.EnumType { + return &file_pkg_services_control_ir_types_proto_enumTypes[0] +} + +func (x HealthStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use HealthStatus.Descriptor instead. +func (HealthStatus) EnumDescriptor() ([]byte, []int) { + return file_pkg_services_control_ir_types_proto_rawDescGZIP(), []int{0} +} + +// Signature of some message. +type Signature struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Public key used for signing. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Binary signature. + Sign []byte `protobuf:"bytes,2,opt,name=sign,json=signature,proto3" json:"sign,omitempty"` +} + +func (x *Signature) Reset() { + *x = Signature{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_services_control_ir_types_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Signature) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Signature) ProtoMessage() {} + +func (x *Signature) ProtoReflect() protoreflect.Message { + mi := &file_pkg_services_control_ir_types_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Signature.ProtoReflect.Descriptor instead. +func (*Signature) Descriptor() ([]byte, []int) { + return file_pkg_services_control_ir_types_proto_rawDescGZIP(), []int{0} +} + +func (x *Signature) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +func (x *Signature) GetSign() []byte { + if x != nil { + return x.Sign + } + return nil +} + +var File_pkg_services_control_ir_types_proto protoreflect.FileDescriptor + +var file_pkg_services_control_ir_types_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2f, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x69, 0x72, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x69, 0x72, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x22, 0x36, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x17, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, + 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x2a, 0x57, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x6c, + 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1b, 0x0a, 0x17, 0x48, 0x45, 0x41, 0x4c, + 0x54, 0x48, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, + 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x54, 0x41, 0x52, 0x54, 0x49, 0x4e, + 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x52, 0x45, 0x41, 0x44, 0x59, 0x10, 0x02, 0x12, 0x11, + 0x0a, 0x0d, 0x53, 0x48, 0x55, 0x54, 0x54, 0x49, 0x4e, 0x47, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x10, + 0x03, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x6e, 0x73, 0x70, 0x63, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6e, 0x65, 0x6f, 0x66, 0x73, 0x2d, + 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x73, 0x2f, 0x69, 0x72, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pkg_services_control_ir_types_proto_rawDescOnce sync.Once + file_pkg_services_control_ir_types_proto_rawDescData = file_pkg_services_control_ir_types_proto_rawDesc +) + +func file_pkg_services_control_ir_types_proto_rawDescGZIP() []byte { + file_pkg_services_control_ir_types_proto_rawDescOnce.Do(func() { + file_pkg_services_control_ir_types_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_services_control_ir_types_proto_rawDescData) + }) + return file_pkg_services_control_ir_types_proto_rawDescData +} + +var file_pkg_services_control_ir_types_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_pkg_services_control_ir_types_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_pkg_services_control_ir_types_proto_goTypes = []interface{}{ + (HealthStatus)(0), // 0: ircontrol.HealthStatus + (*Signature)(nil), // 1: ircontrol.Signature +} +var file_pkg_services_control_ir_types_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_pkg_services_control_ir_types_proto_init() } +func file_pkg_services_control_ir_types_proto_init() { + if File_pkg_services_control_ir_types_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_pkg_services_control_ir_types_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Signature); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pkg_services_control_ir_types_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pkg_services_control_ir_types_proto_goTypes, + DependencyIndexes: file_pkg_services_control_ir_types_proto_depIdxs, + EnumInfos: file_pkg_services_control_ir_types_proto_enumTypes, + MessageInfos: file_pkg_services_control_ir_types_proto_msgTypes, + }.Build() + File_pkg_services_control_ir_types_proto = out.File + file_pkg_services_control_ir_types_proto_rawDesc = nil + file_pkg_services_control_ir_types_proto_goTypes = nil + file_pkg_services_control_ir_types_proto_depIdxs = nil +} diff --git a/pkg/services/control/ir/types.proto b/pkg/services/control/ir/types.proto new file mode 100644 index 000000000..3a7791874 --- /dev/null +++ b/pkg/services/control/ir/types.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package ircontrol; + +option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/ir/control"; + +// Signature of some message. +message Signature { + // Public key used for signing. + bytes key = 1 [json_name = "key"]; + + // Binary signature. + bytes sign = 2 [json_name = "signature"]; +} + +// Health status of the IR application. +enum HealthStatus { + // Undefined status, default value. + HEALTH_STATUS_UNDEFINED = 0; + + // IR application is starting. + STARTING = 1; + + // IR application is started and serves all services. + READY = 2; + + // IR application is shutting down. + SHUTTING_DOWN = 3; +}