From 2f020dcb308ddbc806c06b8a7dfb879f13cde58e Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 17 Feb 2022 23:11:45 -0800 Subject: [PATCH] Update to use the latest protobuf package to build pb (#5193) * Update to use the latest protobuf package to build pb The pb package was generated some time ago with old version of https://github.com/golang/protobuf which was deprecated and in favor of google.golang.org/protobuf (see deprecation notice in https://pkg.go.dev/github.com/golang/protobuf) This PR updates the generation of pb package with v1.27.1 of google.golang.org/protobuf. Signed-off-by: Yong Tang * Exclude pb from import test Signed-off-by: Yong Tang --- core/dnsserver/server_grpc.go | 1 + pb/Makefile | 9 +- pb/dns.pb.go | 243 ++++++++++++++++------------------ pb/dns.proto | 2 +- pb/dns_grpc.pb.go | 105 +++++++++++++++ test/presubmit_test.go | 4 + 6 files changed, 236 insertions(+), 128 deletions(-) create mode 100644 pb/dns_grpc.pb.go diff --git a/core/dnsserver/server_grpc.go b/core/dnsserver/server_grpc.go index d5726e8a6..766c27e36 100644 --- a/core/dnsserver/server_grpc.go +++ b/core/dnsserver/server_grpc.go @@ -22,6 +22,7 @@ import ( // ServergRPC represents an instance of a DNS-over-gRPC server. type ServergRPC struct { *Server + *pb.UnimplementedDnsServiceServer grpcServer *grpc.Server listenAddr net.Addr tlsConfig *tls.Config diff --git a/pb/Makefile b/pb/Makefile index a666d6c15..7e8cdaf26 100644 --- a/pb/Makefile +++ b/pb/Makefile @@ -2,11 +2,18 @@ # from: https://github.com/golang/protobuf to make this work. # The generate dns.pb.go is checked into git, so for normal builds we don't need # to run this generation step. +# Note: The following has been used when regenerate pb: +# curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip +# go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 +# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0 +# export PATH="$PATH:$(go env GOPATH)/bin" +# rm pb/dns.pb.go pb/dns_grpc.pb.go +# make pb all: dns.pb.go dns.pb.go: dns.proto - protoc --go_out=plugins=grpc:. dns.proto + protoc --go_out=. --go-grpc_out=. dns.proto .PHONY: clean clean: diff --git a/pb/dns.pb.go b/pb/dns.pb.go index 919f0e7d7..e2a311cc1 100644 --- a/pb/dns.pb.go +++ b/pb/dns.pb.go @@ -1,156 +1,147 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.4 // source: dns.proto package pb import ( - context "context" - fmt "fmt" - math "math" - - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -/* Miek: disabled this manually, because I don't know what the heck */ -/* -// 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 -*/ +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) +) type DnsPacket struct { - Msg []byte `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Msg []byte `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` } -func (m *DnsPacket) Reset() { *m = DnsPacket{} } -func (m *DnsPacket) String() string { return proto.CompactTextString(m) } -func (*DnsPacket) ProtoMessage() {} +func (x *DnsPacket) Reset() { + *x = DnsPacket{} + if protoimpl.UnsafeEnabled { + mi := &file_dns_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DnsPacket) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DnsPacket) ProtoMessage() {} + +func (x *DnsPacket) ProtoReflect() protoreflect.Message { + mi := &file_dns_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 DnsPacket.ProtoReflect.Descriptor instead. func (*DnsPacket) Descriptor() ([]byte, []int) { - return fileDescriptor_638ff8d8aaf3d8ae, []int{0} + return file_dns_proto_rawDescGZIP(), []int{0} } -func (m *DnsPacket) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_DnsPacket.Unmarshal(m, b) -} -func (m *DnsPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_DnsPacket.Marshal(b, m, deterministic) -} -func (m *DnsPacket) XXX_Merge(src proto.Message) { - xxx_messageInfo_DnsPacket.Merge(m, src) -} -func (m *DnsPacket) XXX_Size() int { - return xxx_messageInfo_DnsPacket.Size(m) -} -func (m *DnsPacket) XXX_DiscardUnknown() { - xxx_messageInfo_DnsPacket.DiscardUnknown(m) -} - -var xxx_messageInfo_DnsPacket proto.InternalMessageInfo - -func (m *DnsPacket) GetMsg() []byte { - if m != nil { - return m.Msg +func (x *DnsPacket) GetMsg() []byte { + if x != nil { + return x.Msg } return nil } -func init() { - proto.RegisterType((*DnsPacket)(nil), "coredns.dns.DnsPacket") +var File_dns_proto protoreflect.FileDescriptor + +var file_dns_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x64, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x63, 0x6f, 0x72, + 0x65, 0x64, 0x6e, 0x73, 0x2e, 0x64, 0x6e, 0x73, 0x22, 0x1d, 0x0a, 0x09, 0x44, 0x6e, 0x73, 0x50, + 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x45, 0x0a, 0x0a, 0x44, 0x6e, 0x73, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x37, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16, + 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x64, 0x6e, 0x73, 0x2e, 0x64, 0x6e, 0x73, 0x2e, 0x44, 0x6e, 0x73, + 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x16, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x64, 0x6e, 0x73, + 0x2e, 0x64, 0x6e, 0x73, 0x2e, 0x44, 0x6e, 0x73, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } -func init() { proto.RegisterFile("dns.proto", fileDescriptor_638ff8d8aaf3d8ae) } +var ( + file_dns_proto_rawDescOnce sync.Once + file_dns_proto_rawDescData = file_dns_proto_rawDesc +) -var fileDescriptor_638ff8d8aaf3d8ae = []byte{ - // 120 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0xc9, 0x2b, 0xd6, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4e, 0xce, 0x2f, 0x4a, 0x05, 0x71, 0x53, 0xf2, 0x8a, - 0x95, 0x64, 0xb9, 0x38, 0x5d, 0xf2, 0x8a, 0x03, 0x12, 0x93, 0xb3, 0x53, 0x4b, 0x84, 0x04, 0xb8, - 0x98, 0x73, 0x8b, 0xd3, 0x25, 0x18, 0x15, 0x18, 0x35, 0x78, 0x82, 0x40, 0x4c, 0x23, 0x57, 0x2e, - 0x2e, 0x97, 0xbc, 0xe2, 0xe0, 0xd4, 0xa2, 0xb2, 0xcc, 0xe4, 0x54, 0x21, 0x73, 0x2e, 0xd6, 0xc0, - 0xd2, 0xd4, 0xa2, 0x4a, 0x21, 0x31, 0x3d, 0x24, 0x33, 0xf4, 0xe0, 0x06, 0x48, 0xe1, 0x10, 0x77, - 0x62, 0x89, 0x62, 0x2a, 0x48, 0x4a, 0x62, 0x03, 0xdb, 0x6f, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, - 0xf5, 0xd1, 0x3f, 0x26, 0x8c, 0x00, 0x00, 0x00, +func file_dns_proto_rawDescGZIP() []byte { + file_dns_proto_rawDescOnce.Do(func() { + file_dns_proto_rawDescData = protoimpl.X.CompressGZIP(file_dns_proto_rawDescData) + }) + return file_dns_proto_rawDescData } -// 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 - -// DnsServiceClient is the client API for DnsService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type DnsServiceClient interface { - Query(ctx context.Context, in *DnsPacket, opts ...grpc.CallOption) (*DnsPacket, error) +var file_dns_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_dns_proto_goTypes = []interface{}{ + (*DnsPacket)(nil), // 0: coredns.dns.DnsPacket +} +var file_dns_proto_depIdxs = []int32{ + 0, // 0: coredns.dns.DnsService.Query:input_type -> coredns.dns.DnsPacket + 0, // 1: coredns.dns.DnsService.Query:output_type -> coredns.dns.DnsPacket + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] 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 } -type dnsServiceClient struct { - cc *grpc.ClientConn -} - -func NewDnsServiceClient(cc *grpc.ClientConn) DnsServiceClient { - return &dnsServiceClient{cc} -} - -func (c *dnsServiceClient) Query(ctx context.Context, in *DnsPacket, opts ...grpc.CallOption) (*DnsPacket, error) { - out := new(DnsPacket) - err := c.cc.Invoke(ctx, "/coredns.dns.DnsService/Query", in, out, opts...) - if err != nil { - return nil, err +func init() { file_dns_proto_init() } +func file_dns_proto_init() { + if File_dns_proto != nil { + return } - return out, nil -} - -// DnsServiceServer is the server API for DnsService service. -type DnsServiceServer interface { - Query(context.Context, *DnsPacket) (*DnsPacket, error) -} - -func RegisterDnsServiceServer(s *grpc.Server, srv DnsServiceServer) { - s.RegisterService(&_DnsService_serviceDesc, srv) -} - -func _DnsService_Query_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DnsPacket) - if err := dec(in); err != nil { - return nil, err + if !protoimpl.UnsafeEnabled { + file_dns_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DnsPacket); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } - if interceptor == nil { - return srv.(DnsServiceServer).Query(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/coredns.dns.DnsService/Query", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DnsServiceServer).Query(ctx, req.(*DnsPacket)) - } - return interceptor(ctx, in, info, handler) -} - -var _DnsService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "coredns.dns.DnsService", - HandlerType: (*DnsServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Query", - Handler: _DnsService_Query_Handler, + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_dns_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "dns.proto", + GoTypes: file_dns_proto_goTypes, + DependencyIndexes: file_dns_proto_depIdxs, + MessageInfos: file_dns_proto_msgTypes, + }.Build() + File_dns_proto = out.File + file_dns_proto_rawDesc = nil + file_dns_proto_goTypes = nil + file_dns_proto_depIdxs = nil } diff --git a/pb/dns.proto b/pb/dns.proto index 8461f01e6..ee24cb0bb 100644 --- a/pb/dns.proto +++ b/pb/dns.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package coredns.dns; -option go_package = "pb"; +option go_package = ".;pb"; message DnsPacket { bytes msg = 1; diff --git a/pb/dns_grpc.pb.go b/pb/dns_grpc.pb.go new file mode 100644 index 000000000..6ff3faf11 --- /dev/null +++ b/pb/dns_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.4 +// source: dns.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// DnsServiceClient is the client API for DnsService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type DnsServiceClient interface { + Query(ctx context.Context, in *DnsPacket, opts ...grpc.CallOption) (*DnsPacket, error) +} + +type dnsServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewDnsServiceClient(cc grpc.ClientConnInterface) DnsServiceClient { + return &dnsServiceClient{cc} +} + +func (c *dnsServiceClient) Query(ctx context.Context, in *DnsPacket, opts ...grpc.CallOption) (*DnsPacket, error) { + out := new(DnsPacket) + err := c.cc.Invoke(ctx, "/coredns.dns.DnsService/Query", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// DnsServiceServer is the server API for DnsService service. +// All implementations must embed UnimplementedDnsServiceServer +// for forward compatibility +type DnsServiceServer interface { + Query(context.Context, *DnsPacket) (*DnsPacket, error) + mustEmbedUnimplementedDnsServiceServer() +} + +// UnimplementedDnsServiceServer must be embedded to have forward compatible implementations. +type UnimplementedDnsServiceServer struct { +} + +func (UnimplementedDnsServiceServer) Query(context.Context, *DnsPacket) (*DnsPacket, error) { + return nil, status.Errorf(codes.Unimplemented, "method Query not implemented") +} +func (UnimplementedDnsServiceServer) mustEmbedUnimplementedDnsServiceServer() {} + +// UnsafeDnsServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to DnsServiceServer will +// result in compilation errors. +type UnsafeDnsServiceServer interface { + mustEmbedUnimplementedDnsServiceServer() +} + +func RegisterDnsServiceServer(s grpc.ServiceRegistrar, srv DnsServiceServer) { + s.RegisterService(&DnsService_ServiceDesc, srv) +} + +func _DnsService_Query_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DnsPacket) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DnsServiceServer).Query(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/coredns.dns.DnsService/Query", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DnsServiceServer).Query(ctx, req.(*DnsPacket)) + } + return interceptor(ctx, in, info, handler) +} + +// DnsService_ServiceDesc is the grpc.ServiceDesc for DnsService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var DnsService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "coredns.dns.DnsService", + HandlerType: (*DnsServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Query", + Handler: _DnsService_Query_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "dns.proto", +} diff --git a/test/presubmit_test.go b/test/presubmit_test.go index 903661ba0..b94beb31b 100644 --- a/test/presubmit_test.go +++ b/test/presubmit_test.go @@ -250,6 +250,10 @@ func (w *testImportOrderingWalker) walk(path string, info os.FileInfo, _ error) if filepath.Ext(path) != ".go" { return nil } + // pb files are autogenerated by protoc + if strings.HasPrefix(path, "../pb/") { + return nil + } fs := token.NewFileSet() f, err := parser.ParseFile(fs, path, nil, parser.AllErrors)