diff --git a/api/v0/finder/client/libp2p/client.go b/api/v0/finder/client/libp2p/client.go index acdfa7928..3eca94749 100644 --- a/api/v0/finder/client/libp2p/client.go +++ b/api/v0/finder/client/libp2p/client.go @@ -13,6 +13,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multihash" + "google.golang.org/protobuf/proto" ) type Client struct { @@ -123,9 +124,9 @@ func (c *Client) GetStats(ctx context.Context) (*model.Stats, error) { } func (c *Client) sendRecv(ctx context.Context, req *pb.FinderMessage, expectRspType pb.FinderMessage_MessageType) ([]byte, error) { - resp := new(pb.FinderMessage) + var resp pb.FinderMessage err := c.p2pc.SendRequest(ctx, req, func(data []byte) error { - return resp.Unmarshal(data) + return proto.Unmarshal(data, &resp) }) if err != nil { return nil, fmt.Errorf("failed to send request to indexer: %s", err) diff --git a/api/v0/finder/pb/Makefile b/api/v0/finder/pb/Makefile index e2a5bd0f8..a89f6a878 100644 --- a/api/v0/finder/pb/Makefile +++ b/api/v0/finder/pb/Makefile @@ -4,7 +4,7 @@ GO = $(PB:.proto=.pb.go) all: $(GO) %.pb.go: %.proto - protoc --proto_path=$(GOPATH)/pkg/mod:. --proto_path=/usr/include --gogofaster_out=. $< + docker run -v $(CURDIR):/defs -w /defs namely/protoc-all -d . -l go --go-module-prefix github.com/ipni/storetheindex/api/v0/finder/pb -o . clean: rm -f *.pb.go diff --git a/api/v0/finder/pb/finder.pb.go b/api/v0/finder/pb/finder.pb.go index a70bfe0dc..2ca3684c0 100644 --- a/api/v0/finder/pb/finder.pb.go +++ b/api/v0/finder/pb/finder.pb.go @@ -1,26 +1,24 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.6 // source: finder.proto -package reqresp_pb +package pb import ( - fmt "fmt" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" + 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 - -// 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.GoGoProtoPackageIsVersion3 // 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 FinderMessage_MessageType int32 @@ -36,372 +34,208 @@ const ( FinderMessage_GET_STATS_RESPONSE FinderMessage_MessageType = 8 ) -var FinderMessage_MessageType_name = map[int32]string{ - 0: "ERROR_RESPONSE", - 1: "FIND", - 2: "FIND_RESPONSE", - 3: "LIST_PROVIDERS", - 4: "LIST_PROVIDERS_RESPONSE", - 5: "GET_PROVIDER", - 6: "GET_PROVIDER_RESPONSE", - 7: "GET_STATS", - 8: "GET_STATS_RESPONSE", -} +// Enum value maps for FinderMessage_MessageType. +var ( + FinderMessage_MessageType_name = map[int32]string{ + 0: "ERROR_RESPONSE", + 1: "FIND", + 2: "FIND_RESPONSE", + 3: "LIST_PROVIDERS", + 4: "LIST_PROVIDERS_RESPONSE", + 5: "GET_PROVIDER", + 6: "GET_PROVIDER_RESPONSE", + 7: "GET_STATS", + 8: "GET_STATS_RESPONSE", + } + FinderMessage_MessageType_value = map[string]int32{ + "ERROR_RESPONSE": 0, + "FIND": 1, + "FIND_RESPONSE": 2, + "LIST_PROVIDERS": 3, + "LIST_PROVIDERS_RESPONSE": 4, + "GET_PROVIDER": 5, + "GET_PROVIDER_RESPONSE": 6, + "GET_STATS": 7, + "GET_STATS_RESPONSE": 8, + } +) -var FinderMessage_MessageType_value = map[string]int32{ - "ERROR_RESPONSE": 0, - "FIND": 1, - "FIND_RESPONSE": 2, - "LIST_PROVIDERS": 3, - "LIST_PROVIDERS_RESPONSE": 4, - "GET_PROVIDER": 5, - "GET_PROVIDER_RESPONSE": 6, - "GET_STATS": 7, - "GET_STATS_RESPONSE": 8, +func (x FinderMessage_MessageType) Enum() *FinderMessage_MessageType { + p := new(FinderMessage_MessageType) + *p = x + return p } func (x FinderMessage_MessageType) String() string { - return proto.EnumName(FinderMessage_MessageType_name, int32(x)) + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FinderMessage_MessageType) Descriptor() protoreflect.EnumDescriptor { + return file_finder_proto_enumTypes[0].Descriptor() } +func (FinderMessage_MessageType) Type() protoreflect.EnumType { + return &file_finder_proto_enumTypes[0] +} + +func (x FinderMessage_MessageType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FinderMessage_MessageType.Descriptor instead. func (FinderMessage_MessageType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_02dfec63316bfb34, []int{0, 0} + return file_finder_proto_rawDescGZIP(), []int{0, 0} } type FinderMessage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + // defines what type of message it is. Type FinderMessage_MessageType `protobuf:"varint,1,opt,name=type,proto3,enum=reqresp.pb.FinderMessage_MessageType" json:"type,omitempty"` // Value for the message Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } -func (m *FinderMessage) Reset() { *m = FinderMessage{} } -func (m *FinderMessage) String() string { return proto.CompactTextString(m) } -func (*FinderMessage) ProtoMessage() {} -func (*FinderMessage) Descriptor() ([]byte, []int) { - return fileDescriptor_02dfec63316bfb34, []int{0} -} -func (m *FinderMessage) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *FinderMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_FinderMessage.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 (x *FinderMessage) Reset() { + *x = FinderMessage{} + if protoimpl.UnsafeEnabled { + mi := &file_finder_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } } -func (m *FinderMessage) XXX_Merge(src proto.Message) { - xxx_messageInfo_FinderMessage.Merge(m, src) -} -func (m *FinderMessage) XXX_Size() int { - return m.Size() -} -func (m *FinderMessage) XXX_DiscardUnknown() { - xxx_messageInfo_FinderMessage.DiscardUnknown(m) -} -var xxx_messageInfo_FinderMessage proto.InternalMessageInfo - -func (m *FinderMessage) GetType() FinderMessage_MessageType { - if m != nil { - return m.Type - } - return FinderMessage_ERROR_RESPONSE +func (x *FinderMessage) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *FinderMessage) GetData() []byte { - if m != nil { - return m.Data +func (*FinderMessage) ProtoMessage() {} + +func (x *FinderMessage) ProtoReflect() protoreflect.Message { + mi := &file_finder_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 nil + return mi.MessageOf(x) } -func init() { - proto.RegisterEnum("reqresp.pb.FinderMessage_MessageType", FinderMessage_MessageType_name, FinderMessage_MessageType_value) - proto.RegisterType((*FinderMessage)(nil), "reqresp.pb.FinderMessage") +// Deprecated: Use FinderMessage.ProtoReflect.Descriptor instead. +func (*FinderMessage) Descriptor() ([]byte, []int) { + return file_finder_proto_rawDescGZIP(), []int{0} } -func init() { proto.RegisterFile("finder.proto", fileDescriptor_02dfec63316bfb34) } - -var fileDescriptor_02dfec63316bfb34 = []byte{ - // 260 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xcb, 0xcc, 0x4b, - 0x49, 0x2d, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x2a, 0x4a, 0x2d, 0x2c, 0x4a, 0x2d, - 0x2e, 0xd0, 0x2b, 0x48, 0x52, 0x5a, 0xc2, 0xc4, 0xc5, 0xeb, 0x06, 0x96, 0xf4, 0x4d, 0x2d, 0x2e, - 0x4e, 0x4c, 0x4f, 0x15, 0xb2, 0xe4, 0x62, 0x29, 0xa9, 0x2c, 0x48, 0x95, 0x60, 0x54, 0x60, 0xd4, - 0xe0, 0x33, 0x52, 0xd5, 0x43, 0x28, 0xd6, 0x43, 0x51, 0xa8, 0x07, 0xa5, 0x43, 0x2a, 0x0b, 0x52, - 0x83, 0xc0, 0x5a, 0x84, 0x84, 0xb8, 0x58, 0x52, 0x12, 0x4b, 0x12, 0x25, 0x98, 0x14, 0x18, 0x35, - 0x78, 0x82, 0xc0, 0x6c, 0xa5, 0xc3, 0x8c, 0x5c, 0xdc, 0x48, 0x2a, 0x85, 0x84, 0xb8, 0xf8, 0x5c, - 0x83, 0x82, 0xfc, 0x83, 0xe2, 0x83, 0x5c, 0x83, 0x03, 0xfc, 0xfd, 0x82, 0x5d, 0x05, 0x18, 0x84, - 0x38, 0xb8, 0x58, 0xdc, 0x3c, 0xfd, 0x5c, 0x04, 0x18, 0x85, 0x04, 0xb9, 0x78, 0x41, 0x2c, 0x84, - 0x24, 0x13, 0x48, 0x83, 0x8f, 0x67, 0x70, 0x48, 0x7c, 0x40, 0x90, 0x7f, 0x98, 0xa7, 0x8b, 0x6b, - 0x50, 0xb0, 0x00, 0xb3, 0x90, 0x34, 0x97, 0x38, 0xaa, 0x18, 0x42, 0x03, 0x8b, 0x90, 0x00, 0x17, - 0x8f, 0xbb, 0x2b, 0x42, 0x4e, 0x80, 0x55, 0x48, 0x92, 0x4b, 0x14, 0x59, 0x04, 0xa1, 0x98, 0x4d, - 0x88, 0x97, 0x8b, 0x13, 0x24, 0x15, 0x1c, 0xe2, 0x18, 0x12, 0x2c, 0xc0, 0x2e, 0x24, 0xc6, 0x25, - 0x04, 0xe7, 0x22, 0x94, 0x71, 0x38, 0x49, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, - 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, - 0x43, 0x12, 0x1b, 0x38, 0x4c, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdd, 0x03, 0x37, 0x1d, - 0x63, 0x01, 0x00, 0x00, +func (x *FinderMessage) GetType() FinderMessage_MessageType { + if x != nil { + return x.Type + } + return FinderMessage_ERROR_RESPONSE } -func (m *FinderMessage) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (x *FinderMessage) GetData() []byte { + if x != nil { + return x.Data } - return dAtA[:n], nil + return nil } -func (m *FinderMessage) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) +var File_finder_proto protoreflect.FileDescriptor + +var file_finder_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x66, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, + 0x72, 0x65, 0x71, 0x72, 0x65, 0x73, 0x70, 0x2e, 0x70, 0x62, 0x22, 0xa4, 0x02, 0x0a, 0x0d, 0x46, + 0x69, 0x6e, 0x64, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x39, 0x0a, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x25, 0x2e, 0x72, 0x65, 0x71, + 0x72, 0x65, 0x73, 0x70, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xc3, 0x01, 0x0a, 0x0b, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x0e, 0x45, + 0x52, 0x52, 0x4f, 0x52, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x00, 0x12, + 0x08, 0x0a, 0x04, 0x46, 0x49, 0x4e, 0x44, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x46, 0x49, 0x4e, + 0x44, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, + 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x44, 0x45, 0x52, 0x53, 0x10, 0x03, + 0x12, 0x1b, 0x0a, 0x17, 0x4c, 0x49, 0x53, 0x54, 0x5f, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x44, 0x45, + 0x52, 0x53, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x04, 0x12, 0x10, 0x0a, + 0x0c, 0x47, 0x45, 0x54, 0x5f, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x44, 0x45, 0x52, 0x10, 0x05, 0x12, + 0x19, 0x0a, 0x15, 0x47, 0x45, 0x54, 0x5f, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x44, 0x45, 0x52, 0x5f, + 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, 0x06, 0x12, 0x0d, 0x0a, 0x09, 0x47, 0x45, + 0x54, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x53, 0x10, 0x07, 0x12, 0x16, 0x0a, 0x12, 0x47, 0x45, 0x54, + 0x5f, 0x53, 0x54, 0x41, 0x54, 0x53, 0x5f, 0x52, 0x45, 0x53, 0x50, 0x4f, 0x4e, 0x53, 0x45, 0x10, + 0x08, 0x42, 0x30, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x69, 0x70, 0x6e, 0x69, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x74, 0x68, 0x65, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x30, 0x2f, 0x66, 0x69, 0x6e, 0x64, 0x65, 0x72, + 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } -func (m *FinderMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintFinder(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x12 - } - if m.Type != 0 { - i = encodeVarintFinder(dAtA, i, uint64(m.Type)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} +var ( + file_finder_proto_rawDescOnce sync.Once + file_finder_proto_rawDescData = file_finder_proto_rawDesc +) -func encodeVarintFinder(dAtA []byte, offset int, v uint64) int { - offset -= sovFinder(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *FinderMessage) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Type != 0 { - n += 1 + sovFinder(uint64(m.Type)) - } - l = len(m.Data) - if l > 0 { - n += 1 + l + sovFinder(uint64(l)) - } - return n +func file_finder_proto_rawDescGZIP() []byte { + file_finder_proto_rawDescOnce.Do(func() { + file_finder_proto_rawDescData = protoimpl.X.CompressGZIP(file_finder_proto_rawDescData) + }) + return file_finder_proto_rawDescData } -func sovFinder(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 +var file_finder_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_finder_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_finder_proto_goTypes = []interface{}{ + (FinderMessage_MessageType)(0), // 0: reqresp.pb.FinderMessage.MessageType + (*FinderMessage)(nil), // 1: reqresp.pb.FinderMessage } -func sozFinder(x uint64) (n int) { - return sovFinder(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +var file_finder_proto_depIdxs = []int32{ + 0, // 0: reqresp.pb.FinderMessage.type:type_name -> reqresp.pb.FinderMessage.MessageType + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } -func (m *FinderMessage) 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 ErrIntOverflowFinder - } - 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: FinderMessage: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: FinderMessage: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) - } - m.Type = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFinder - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Type |= FinderMessage_MessageType(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFinder - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthFinder - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthFinder - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFinder(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFinder - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF +func init() { file_finder_proto_init() } +func file_finder_proto_init() { + if File_finder_proto != nil { + return } - return nil -} -func skipFinder(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, ErrIntOverflowFinder - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break + if !protoimpl.UnsafeEnabled { + file_finder_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FinderMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil } } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowFinder - } - 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, ErrIntOverflowFinder - } - 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, ErrInvalidLengthFinder - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupFinder - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthFinder - } - if depth == 0 { - return iNdEx, nil - } } - return 0, io.ErrUnexpectedEOF + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_finder_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_finder_proto_goTypes, + DependencyIndexes: file_finder_proto_depIdxs, + EnumInfos: file_finder_proto_enumTypes, + MessageInfos: file_finder_proto_msgTypes, + }.Build() + File_finder_proto = out.File + file_finder_proto_rawDesc = nil + file_finder_proto_goTypes = nil + file_finder_proto_depIdxs = nil } - -var ( - ErrInvalidLengthFinder = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowFinder = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupFinder = fmt.Errorf("proto: unexpected end of group") -) diff --git a/api/v0/finder/pb/finder.proto b/api/v0/finder/pb/finder.proto index 6b59f99fb..91d1b1bc7 100644 --- a/api/v0/finder/pb/finder.proto +++ b/api/v0/finder/pb/finder.proto @@ -1,28 +1,24 @@ -// In order to re-generate the golang packages for `Message` you will need... -// 1. Protobuf binary (tested with protoc 3.0.0). - https://github.com/gogo/protobuf/releases -// 2. Gogo Protobuf (tested with gogo 0.3). - https://github.com/gogo/protobuf -// Now from `libp2p//pb` you can run... -// `protoc --gogo_out=. --proto_path=../..//pb/ --proto_path=./ --proto_path=/usr/include pb.proto` - syntax = "proto3"; package reqresp.pb; +option go_package = "github.com/ipni/storetheindex/api/v0/finder/pb"; + message FinderMessage { - enum MessageType { - ERROR_RESPONSE = 0; - FIND = 1; - FIND_RESPONSE = 2; - LIST_PROVIDERS = 3; - LIST_PROVIDERS_RESPONSE = 4; - GET_PROVIDER = 5; - GET_PROVIDER_RESPONSE = 6; - GET_STATS = 7; - GET_STATS_RESPONSE = 8; - } + enum MessageType { + ERROR_RESPONSE = 0; + FIND = 1; + FIND_RESPONSE = 2; + LIST_PROVIDERS = 3; + LIST_PROVIDERS_RESPONSE = 4; + GET_PROVIDER = 5; + GET_PROVIDER_RESPONSE = 6; + GET_STATS = 7; + GET_STATS_RESPONSE = 8; + } - // defines what type of message it is. - MessageType type = 1; + // defines what type of message it is. + MessageType type = 1; - // Value for the message - bytes data = 2; + // Value for the message + bytes data = 2; } diff --git a/api/v0/libp2pclient/client.go b/api/v0/libp2pclient/client.go index 1c401925e..19b63b0a3 100644 --- a/api/v0/libp2pclient/client.go +++ b/api/v0/libp2pclient/client.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/gogo/protobuf/proto" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" @@ -16,6 +15,7 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-msgio" "github.com/multiformats/go-multiaddr" + "google.golang.org/protobuf/proto" ) // Client is responsible for sending requests and receiving responses to and diff --git a/api/v0/libp2pclient/message_writer.go b/api/v0/libp2pclient/message_writer.go index 0a50ddf5e..faa849064 100644 --- a/api/v0/libp2pclient/message_writer.go +++ b/api/v0/libp2pclient/message_writer.go @@ -6,8 +6,8 @@ import ( "io" "sync" - "github.com/gogo/protobuf/proto" - "github.com/libp2p/go-msgio/protoio" + "github.com/libp2p/go-msgio/pbio" + "google.golang.org/protobuf/proto" ) // The Protobuf writer performs multiple small writes when writing a message. @@ -15,7 +15,7 @@ import ( // packet for every single write. type bufferedDelimitedWriter struct { *bufio.Writer - protoio.WriteCloser + pbio.WriteCloser } var writerPool = sync.Pool{ @@ -23,7 +23,7 @@ var writerPool = sync.Pool{ w := bufio.NewWriter(nil) return &bufferedDelimitedWriter{ Writer: w, - WriteCloser: protoio.NewDelimitedWriter(w), + WriteCloser: pbio.NewDelimitedWriter(w), } }, } diff --git a/go.mod b/go.mod index ee0bbedbe..65cd5ef84 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/filecoin-project/go-dagaggregator-unixfs v0.3.0 github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc4 github.com/gammazero/deque v0.2.0 - github.com/gogo/protobuf v1.3.2 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-retryablehttp v0.7.1 github.com/ipfs/go-cid v0.3.2 @@ -56,6 +55,7 @@ require ( golang.org/x/sys v0.5.0 golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 + google.golang.org/protobuf v1.28.1 ) require ( @@ -113,6 +113,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -223,7 +224,6 @@ require ( golang.org/x/sync v0.1.0 // indirect golang.org/x/text v0.7.0 // indirect golang.org/x/tools v0.3.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect diff --git a/internal/libp2pserver/message_writer.go b/internal/libp2pserver/message_writer.go index 90c01b291..63f3ba3fa 100644 --- a/internal/libp2pserver/message_writer.go +++ b/internal/libp2pserver/message_writer.go @@ -6,8 +6,8 @@ import ( "io" "sync" - "github.com/gogo/protobuf/proto" - "github.com/libp2p/go-msgio/protoio" + "github.com/libp2p/go-msgio/pbio" + "google.golang.org/protobuf/proto" ) // The Protobuf writer performs multiple small writes when writing a message. @@ -15,7 +15,7 @@ import ( // packet for every single write. type bufferedDelimitedWriter struct { *bufio.Writer - protoio.WriteCloser + pbio.WriteCloser } var writerPool = sync.Pool{ @@ -23,7 +23,7 @@ var writerPool = sync.Pool{ w := bufio.NewWriter(nil) return &bufferedDelimitedWriter{ Writer: w, - WriteCloser: protoio.NewDelimitedWriter(w), + WriteCloser: pbio.NewDelimitedWriter(w), } }, } diff --git a/internal/libp2pserver/server.go b/internal/libp2pserver/server.go index 6cbc3f361..783bf3f18 100644 --- a/internal/libp2pserver/server.go +++ b/internal/libp2pserver/server.go @@ -8,7 +8,6 @@ import ( "net/http" "time" - "github.com/gogo/protobuf/proto" logging "github.com/ipfs/go-log/v2" "github.com/ipni/storetheindex/api/v0" "github.com/libp2p/go-libp2p/core/host" @@ -16,6 +15,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" "github.com/libp2p/go-msgio" + "google.golang.org/protobuf/proto" ) // Idle time before the stream is closed diff --git a/server/finder/libp2p/handler.go b/server/finder/libp2p/handler.go index 03d0bc16b..1be8c8b3f 100644 --- a/server/finder/libp2p/handler.go +++ b/server/finder/libp2p/handler.go @@ -8,7 +8,6 @@ import ( "net/http" "time" - "github.com/gogo/protobuf/proto" logging "github.com/ipfs/go-log/v2" indexer "github.com/ipni/go-indexer-core" coremetrics "github.com/ipni/go-indexer-core/metrics" @@ -24,6 +23,7 @@ import ( "github.com/libp2p/go-libp2p/core/protocol" "go.opencensus.io/stats" "go.opencensus.io/tag" + "google.golang.org/protobuf/proto" ) var log = logging.Logger("indexer/finder") @@ -48,7 +48,7 @@ func (h *libp2pHandler) ProtocolID() protocol.ID { func (h *libp2pHandler) HandleMessage(ctx context.Context, msgPeer peer.ID, msgbytes []byte) (proto.Message, error) { var req pb.FinderMessage - err := req.Unmarshal(msgbytes) + err := proto.Unmarshal(msgbytes, &req) if err != nil { return nil, err }