diff --git a/commonfile/fileproto/file.pb.go b/commonfile/fileproto/file.pb.go index a13658fc..96e1e303 100644 --- a/commonfile/fileproto/file.pb.go +++ b/commonfile/fileproto/file.pb.go @@ -298,94 +298,6 @@ func (m *BlockPushResponse) XXX_DiscardUnknown() { var xxx_messageInfo_BlockPushResponse proto.InternalMessageInfo -type BlocksDeleteRequest struct { - SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - Cids [][]byte `protobuf:"bytes,2,rep,name=cids,proto3" json:"cids,omitempty"` -} - -func (m *BlocksDeleteRequest) Reset() { *m = BlocksDeleteRequest{} } -func (m *BlocksDeleteRequest) String() string { return proto.CompactTextString(m) } -func (*BlocksDeleteRequest) ProtoMessage() {} -func (*BlocksDeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{4} -} -func (m *BlocksDeleteRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlocksDeleteRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlocksDeleteRequest.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 *BlocksDeleteRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlocksDeleteRequest.Merge(m, src) -} -func (m *BlocksDeleteRequest) XXX_Size() int { - return m.Size() -} -func (m *BlocksDeleteRequest) XXX_DiscardUnknown() { - xxx_messageInfo_BlocksDeleteRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_BlocksDeleteRequest proto.InternalMessageInfo - -func (m *BlocksDeleteRequest) GetSpaceId() string { - if m != nil { - return m.SpaceId - } - return "" -} - -func (m *BlocksDeleteRequest) GetCids() [][]byte { - if m != nil { - return m.Cids - } - return nil -} - -type BlocksDeleteResponse struct { -} - -func (m *BlocksDeleteResponse) Reset() { *m = BlocksDeleteResponse{} } -func (m *BlocksDeleteResponse) String() string { return proto.CompactTextString(m) } -func (*BlocksDeleteResponse) ProtoMessage() {} -func (*BlocksDeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{5} -} -func (m *BlocksDeleteResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *BlocksDeleteResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_BlocksDeleteResponse.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 *BlocksDeleteResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_BlocksDeleteResponse.Merge(m, src) -} -func (m *BlocksDeleteResponse) XXX_Size() int { - return m.Size() -} -func (m *BlocksDeleteResponse) XXX_DiscardUnknown() { - xxx_messageInfo_BlocksDeleteResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_BlocksDeleteResponse proto.InternalMessageInfo - type BlocksCheckRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` Cids [][]byte `protobuf:"bytes,2,rep,name=cids,proto3" json:"cids,omitempty"` @@ -395,7 +307,7 @@ func (m *BlocksCheckRequest) Reset() { *m = BlocksCheckRequest{} } func (m *BlocksCheckRequest) String() string { return proto.CompactTextString(m) } func (*BlocksCheckRequest) ProtoMessage() {} func (*BlocksCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{6} + return fileDescriptor_fd665a7e11c833d5, []int{4} } func (m *BlocksCheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -446,7 +358,7 @@ func (m *BlocksCheckResponse) Reset() { *m = BlocksCheckResponse{} } func (m *BlocksCheckResponse) String() string { return proto.CompactTextString(m) } func (*BlocksCheckResponse) ProtoMessage() {} func (*BlocksCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{7} + return fileDescriptor_fd665a7e11c833d5, []int{5} } func (m *BlocksCheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -491,7 +403,7 @@ func (m *BlockAvailability) Reset() { *m = BlockAvailability{} } func (m *BlockAvailability) String() string { return proto.CompactTextString(m) } func (*BlockAvailability) ProtoMessage() {} func (*BlockAvailability) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{8} + return fileDescriptor_fd665a7e11c833d5, []int{6} } func (m *BlockAvailability) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -544,7 +456,7 @@ func (m *BlocksBindRequest) Reset() { *m = BlocksBindRequest{} } func (m *BlocksBindRequest) String() string { return proto.CompactTextString(m) } func (*BlocksBindRequest) ProtoMessage() {} func (*BlocksBindRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{9} + return fileDescriptor_fd665a7e11c833d5, []int{7} } func (m *BlocksBindRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -601,7 +513,7 @@ func (m *BlocksBindResponse) Reset() { *m = BlocksBindResponse{} } func (m *BlocksBindResponse) String() string { return proto.CompactTextString(m) } func (*BlocksBindResponse) ProtoMessage() {} func (*BlocksBindResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{10} + return fileDescriptor_fd665a7e11c833d5, []int{8} } func (m *BlocksBindResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -639,7 +551,7 @@ func (m *FilesDeleteRequest) Reset() { *m = FilesDeleteRequest{} } func (m *FilesDeleteRequest) String() string { return proto.CompactTextString(m) } func (*FilesDeleteRequest) ProtoMessage() {} func (*FilesDeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{11} + return fileDescriptor_fd665a7e11c833d5, []int{9} } func (m *FilesDeleteRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -689,7 +601,7 @@ func (m *FilesDeleteResponse) Reset() { *m = FilesDeleteResponse{} } func (m *FilesDeleteResponse) String() string { return proto.CompactTextString(m) } func (*FilesDeleteResponse) ProtoMessage() {} func (*FilesDeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{12} + return fileDescriptor_fd665a7e11c833d5, []int{10} } func (m *FilesDeleteResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -727,7 +639,7 @@ func (m *FilesInfoRequest) Reset() { *m = FilesInfoRequest{} } func (m *FilesInfoRequest) String() string { return proto.CompactTextString(m) } func (*FilesInfoRequest) ProtoMessage() {} func (*FilesInfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{13} + return fileDescriptor_fd665a7e11c833d5, []int{11} } func (m *FilesInfoRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -778,7 +690,7 @@ func (m *FilesInfoResponse) Reset() { *m = FilesInfoResponse{} } func (m *FilesInfoResponse) String() string { return proto.CompactTextString(m) } func (*FilesInfoResponse) ProtoMessage() {} func (*FilesInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{14} + return fileDescriptor_fd665a7e11c833d5, []int{12} } func (m *FilesInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -824,7 +736,7 @@ func (m *FileInfo) Reset() { *m = FileInfo{} } func (m *FileInfo) String() string { return proto.CompactTextString(m) } func (*FileInfo) ProtoMessage() {} func (*FileInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{15} + return fileDescriptor_fd665a7e11c833d5, []int{13} } func (m *FileInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -881,7 +793,7 @@ func (m *CheckRequest) Reset() { *m = CheckRequest{} } func (m *CheckRequest) String() string { return proto.CompactTextString(m) } func (*CheckRequest) ProtoMessage() {} func (*CheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{16} + return fileDescriptor_fd665a7e11c833d5, []int{14} } func (m *CheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -919,7 +831,7 @@ func (m *CheckResponse) Reset() { *m = CheckResponse{} } func (m *CheckResponse) String() string { return proto.CompactTextString(m) } func (*CheckResponse) ProtoMessage() {} func (*CheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{17} + return fileDescriptor_fd665a7e11c833d5, []int{15} } func (m *CheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -970,7 +882,7 @@ func (m *SpaceInfoRequest) Reset() { *m = SpaceInfoRequest{} } func (m *SpaceInfoRequest) String() string { return proto.CompactTextString(m) } func (*SpaceInfoRequest) ProtoMessage() {} func (*SpaceInfoRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{18} + return fileDescriptor_fd665a7e11c833d5, []int{16} } func (m *SpaceInfoRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1017,7 +929,7 @@ func (m *SpaceInfoResponse) Reset() { *m = SpaceInfoResponse{} } func (m *SpaceInfoResponse) String() string { return proto.CompactTextString(m) } func (*SpaceInfoResponse) ProtoMessage() {} func (*SpaceInfoResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_fd665a7e11c833d5, []int{19} + return fileDescriptor_fd665a7e11c833d5, []int{17} } func (m *SpaceInfoResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1081,8 +993,6 @@ func init() { proto.RegisterType((*BlockGetResponse)(nil), "filesync.BlockGetResponse") proto.RegisterType((*BlockPushRequest)(nil), "filesync.BlockPushRequest") proto.RegisterType((*BlockPushResponse)(nil), "filesync.BlockPushResponse") - proto.RegisterType((*BlocksDeleteRequest)(nil), "filesync.BlocksDeleteRequest") - proto.RegisterType((*BlocksDeleteResponse)(nil), "filesync.BlocksDeleteResponse") proto.RegisterType((*BlocksCheckRequest)(nil), "filesync.BlocksCheckRequest") proto.RegisterType((*BlocksCheckResponse)(nil), "filesync.BlocksCheckResponse") proto.RegisterType((*BlockAvailability)(nil), "filesync.BlockAvailability") @@ -1104,59 +1014,58 @@ func init() { } var fileDescriptor_fd665a7e11c833d5 = []byte{ - // 817 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x4f, 0x53, 0xfb, 0x44, - 0x18, 0x6e, 0xda, 0xfc, 0x4a, 0xf3, 0x96, 0x42, 0xba, 0x40, 0xad, 0xa5, 0x66, 0x3a, 0x39, 0x38, - 0x0c, 0xe3, 0x14, 0x07, 0x3d, 0x70, 0xf1, 0x40, 0x4b, 0x0b, 0x15, 0x07, 0x35, 0x8c, 0xc3, 0xa8, - 0x17, 0xd3, 0x64, 0x0b, 0x91, 0x90, 0xad, 0xd9, 0xad, 0x52, 0x3f, 0x82, 0x27, 0xfd, 0x32, 0x7e, - 0x06, 0x8e, 0x1c, 0x3d, 0x3a, 0xf0, 0x45, 0x9c, 0xdd, 0x6c, 0x9a, 0xed, 0x1f, 0x07, 0xc4, 0x4b, - 0xd8, 0x3c, 0xfb, 0xbe, 0xef, 0xf3, 0xee, 0xf3, 0x66, 0x1f, 0x0a, 0x1f, 0x7a, 0xe4, 0xee, 0x8e, - 0x44, 0xa3, 0x20, 0xc4, 0x07, 0xfc, 0x31, 0x8e, 0x09, 0x23, 0x07, 0xe2, 0x49, 0x05, 0xd0, 0x16, - 0x6b, 0x54, 0xe2, 0x6b, 0x3a, 0x8d, 0x3c, 0xfb, 0x33, 0xd8, 0xec, 0x84, 0xc4, 0xbb, 0x3d, 0xc5, - 0xcc, 0xc1, 0x3f, 0x4d, 0x30, 0x65, 0xa8, 0x0e, 0x6b, 0x74, 0xec, 0x7a, 0x78, 0xe0, 0xd7, 0xb5, - 0x96, 0xb6, 0x67, 0x38, 0xe9, 0x2b, 0x32,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x6f, 0x9f, 0x71, 0xaa, 0x4d, - 0x41, 0xd1, 0x66, 0x3b, 0xd5, 0x37, 0x29, 0x2d, 0x55, 0x3f, 0x03, 0xd4, 0xe7, 0x7d, 0xbd, 0x76, - 0xa2, 0x75, 0x58, 0x4b, 0x38, 0x12, 0xe1, 0x0d, 0x27, 0x7d, 0xb5, 0x77, 0x60, 0x6b, 0xae, 0x92, - 0x24, 0xe8, 0x83, 0x29, 0xe0, 0x41, 0x34, 0x22, 0xff, 0xa7, 0x7c, 0x0f, 0xaa, 0x4a, 0x1d, 0x39, - 0xd8, 0x8f, 0xc1, 0x18, 0xa5, 0xa0, 0x9c, 0x27, 0xca, 0x74, 0xe6, 0xf1, 0x22, 0x3c, 0x0b, 0xb2, - 0x7f, 0x80, 0x52, 0x0a, 0x2b, 0xea, 0x69, 0x73, 0xea, 0x59, 0x00, 0x13, 0xea, 0x5e, 0xe3, 0xce, - 0x94, 0xe1, 0x64, 0x7c, 0xba, 0xa3, 0x20, 0xa8, 0x09, 0x06, 0x57, 0xb4, 0x4b, 0x26, 0x11, 0x13, - 0xf7, 0xa8, 0xe2, 0x64, 0x80, 0xbd, 0x01, 0xeb, 0xea, 0x17, 0x6c, 0x9f, 0x43, 0x65, 0xfe, 0x6b, - 0x6c, 0x40, 0x49, 0x1e, 0x97, 0x8a, 0x9e, 0x0d, 0x67, 0xf6, 0xce, 0xa9, 0xdd, 0x30, 0x24, 0xbf, - 0x5c, 0xc5, 0x01, 0xc3, 0x82, 0xba, 0xe4, 0x28, 0x88, 0xfd, 0x11, 0x98, 0x97, 0x22, 0xf6, 0x35, - 0x6a, 0xda, 0x7f, 0x68, 0x50, 0x55, 0xc2, 0x25, 0xbf, 0x05, 0x10, 0x06, 0x77, 0x01, 0x4b, 0x8e, - 0xa7, 0x25, 0xc7, 0xcb, 0x90, 0xff, 0x7e, 0x7c, 0x5d, 0x39, 0x3e, 0xcf, 0x16, 0x6a, 0x27, 0xdb, - 0x7a, 0x92, 0x9d, 0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, 0xc1, 0xbf, 0xec, 0xca, 0x5a, - 0xa7, 0x00, 0x99, 0x6b, 0xa0, 0x45, 0x5a, 0xd5, 0xa6, 0x1a, 0xcd, 0xd5, 0x9b, 0x59, 0x53, 0x8a, - 0x3d, 0xa8, 0x4d, 0x2d, 0xfb, 0x8f, 0xda, 0xd4, 0x0a, 0x4f, 0xe1, 0x32, 0xcd, 0xbc, 0x40, 0x95, - 0x69, 0xd1, 0x68, 0x54, 0x99, 0x96, 0xcd, 0xe3, 0x08, 0xde, 0x25, 0x02, 0xd5, 0xb2, 0xa8, 0x39, - 0x69, 0xde, 0x5b, 0xc2, 0x33, 0xfe, 0xd9, 0xb5, 0x52, 0xf9, 0x17, 0xaf, 0xa6, 0xca, 0xbf, 0x74, - 0x0f, 0x3b, 0xed, 0x87, 0x27, 0x4b, 0x7b, 0x7c, 0xb2, 0xb4, 0xbf, 0x9f, 0x2c, 0xed, 0xf7, 0x67, - 0x2b, 0xf7, 0xf8, 0x6c, 0xe5, 0xfe, 0x7a, 0xb6, 0x72, 0xdf, 0x6d, 0xaf, 0xfa, 0x4d, 0x32, 0x2c, - 0x8a, 0x3f, 0x9f, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0x26, 0x23, 0x7f, 0x83, 0xb2, 0x08, 0x00, - 0x00, + // 805 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x52, 0xeb, 0x36, + 0x14, 0x8e, 0x13, 0x13, 0xe2, 0x13, 0x02, 0x8e, 0xf8, 0x69, 0x1a, 0x52, 0x4f, 0xc6, 0x8b, 0x0e, + 0xc3, 0x74, 0x42, 0x87, 0x76, 0xc1, 0xa6, 0x0b, 0x12, 0x12, 0x48, 0xe9, 0xd0, 0xd6, 0x4c, 0x87, + 0x69, 0xbb, 0xa9, 0x63, 0x2b, 0xe0, 0x62, 0xac, 0xd4, 0x52, 0x5a, 0x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xf3, 0xd5, 0x9b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x45, 0x87, 0x27, + 0x98, 0x55, 0x08, 0x00, 0x00, } func (m *BlockGetRequest) Marshal() (dAtA []byte, err error) { @@ -1307,68 +1216,6 @@ func (m *BlockPushResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *BlocksDeleteRequest) 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 *BlocksDeleteRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlocksDeleteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Cids) > 0 { - for iNdEx := len(m.Cids) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Cids[iNdEx]) - copy(dAtA[i:], m.Cids[iNdEx]) - i = encodeVarintFile(dAtA, i, uint64(len(m.Cids[iNdEx]))) - i-- - dAtA[i] = 0x12 - } - } - if len(m.SpaceId) > 0 { - i -= len(m.SpaceId) - copy(dAtA[i:], m.SpaceId) - i = encodeVarintFile(dAtA, i, uint64(len(m.SpaceId))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *BlocksDeleteResponse) 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 *BlocksDeleteResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *BlocksDeleteResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func (m *BlocksCheckRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1944,34 +1791,6 @@ func (m *BlockPushResponse) Size() (n int) { return n } -func (m *BlocksDeleteRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.SpaceId) - if l > 0 { - n += 1 + l + sovFile(uint64(l)) - } - if len(m.Cids) > 0 { - for _, b := range m.Cids { - l = len(b) - n += 1 + l + sovFile(uint64(l)) - } - } - return n -} - -func (m *BlocksDeleteResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func (m *BlocksCheckRequest) Size() (n int) { if m == nil { return 0 @@ -2668,170 +2487,6 @@ func (m *BlockPushResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *BlocksDeleteRequest) 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 ErrIntOverflowFile - } - 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: BlocksDeleteRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlocksDeleteRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SpaceId", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFile - } - 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 ErrInvalidLengthFile - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthFile - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.SpaceId = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Cids", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowFile - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthFile - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthFile - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Cids = append(m.Cids, make([]byte, postIndex-iNdEx)) - copy(m.Cids[len(m.Cids)-1], dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipFile(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFile - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *BlocksDeleteResponse) 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 ErrIntOverflowFile - } - 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: BlocksDeleteResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: BlocksDeleteResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipFile(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthFile - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *BlocksCheckRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/commonfile/fileproto/protos/file.proto b/commonfile/fileproto/protos/file.proto index 5ebbb91f..3a79543b 100644 --- a/commonfile/fileproto/protos/file.proto +++ b/commonfile/fileproto/protos/file.proto @@ -51,13 +51,6 @@ message BlockPushRequest { message BlockPushResponse {} -message BlocksDeleteRequest { - string spaceId = 1; - repeated bytes cids = 2; -} - -message BlocksDeleteResponse {} - message BlocksCheckRequest { string spaceId = 1; diff --git a/commonspace/headsync/headsync.go b/commonspace/headsync/headsync.go index 08d6d9e3..27a62733 100644 --- a/commonspace/headsync/headsync.go +++ b/commonspace/headsync/headsync.go @@ -46,7 +46,7 @@ type headSync struct { diff ldiff.Diff log logger.CtxLogger syncer DiffSyncer - configuration nodeconf.Configuration + configuration nodeconf.NodeConf spaceIsDeleted *atomic.Bool syncPeriod int @@ -56,7 +56,7 @@ func NewHeadSync( spaceId string, spaceIsDeleted *atomic.Bool, syncPeriod int, - configuration nodeconf.Configuration, + configuration nodeconf.NodeConf, storage spacestorage.SpaceStorage, peerManager peermanager.PeerManager, cache treegetter.TreeGetter, diff --git a/commonspace/object/tree/synctree/syncclient.go b/commonspace/object/tree/synctree/syncclient.go index 6ad98c7c..5a62c632 100644 --- a/commonspace/object/tree/synctree/syncclient.go +++ b/commonspace/object/tree/synctree/syncclient.go @@ -19,14 +19,14 @@ type syncClient struct { objectsync.MessagePool RequestFactory spaceId string - configuration nodeconf.Configuration + configuration nodeconf.NodeConf } func newSyncClient( spaceId string, pool objectsync.MessagePool, factory RequestFactory, - configuration nodeconf.Configuration) SyncClient { + configuration nodeconf.NodeConf) SyncClient { return &syncClient{ MessagePool: pool, RequestFactory: factory, diff --git a/commonspace/object/tree/synctree/synctree.go b/commonspace/object/tree/synctree/synctree.go index 56d07c1c..69d077e5 100644 --- a/commonspace/object/tree/synctree/synctree.go +++ b/commonspace/object/tree/synctree/synctree.go @@ -64,7 +64,7 @@ type ResponsiblePeersGetter interface { type BuildDeps struct { SpaceId string ObjectSync objectsync.ObjectSync - Configuration nodeconf.Configuration + Configuration nodeconf.NodeConf HeadNotifiable HeadNotifiable Listener updatelistener.UpdateListener AclList list.AclList diff --git a/commonspace/object/tree/synctree/synctree_test.go b/commonspace/object/tree/synctree/synctree_test.go index 8854a702..7b1b804d 100644 --- a/commonspace/object/tree/synctree/synctree_test.go +++ b/commonspace/object/tree/synctree/synctree_test.go @@ -34,8 +34,8 @@ func (s syncTreeMatcher) String() string { return "" } -func syncClientFuncCreator(client SyncClient) func(spaceId string, factory RequestFactory, objectSync objectsync.ObjectSync, configuration nodeconf.Configuration) SyncClient { - return func(spaceId string, factory RequestFactory, objectSync objectsync.ObjectSync, configuration nodeconf.Configuration) SyncClient { +func syncClientFuncCreator(client SyncClient) func(spaceId string, factory RequestFactory, objectSync objectsync.ObjectSync, configuration nodeconf.NodeConf) SyncClient { + return func(spaceId string, factory RequestFactory, objectSync objectsync.ObjectSync, configuration nodeconf.NodeConf) SyncClient { return client } } diff --git a/commonspace/objectsync/objectsync.go b/commonspace/objectsync/objectsync.go index 74b3f7fa..06127d0c 100644 --- a/commonspace/objectsync/objectsync.go +++ b/commonspace/objectsync/objectsync.go @@ -32,7 +32,7 @@ type objectSync struct { messagePool MessagePool objectGetter syncobjectgetter.SyncObjectGetter - configuration nodeconf.Configuration + configuration nodeconf.NodeConf spaceStorage spacestorage.SpaceStorage syncCtx context.Context @@ -43,7 +43,7 @@ type objectSync struct { func NewObjectSync( spaceId string, spaceIsDeleted *atomic.Bool, - configuration nodeconf.Configuration, + configuration nodeconf.NodeConf, peerManager peermanager.PeerManager, objectGetter syncobjectgetter.SyncObjectGetter, storage spacestorage.SpaceStorage) ObjectSync { @@ -64,7 +64,7 @@ func NewObjectSync( func newObjectSync( spaceId string, spaceIsDeleted *atomic.Bool, - configuration nodeconf.Configuration, + configuration nodeconf.NodeConf, objectGetter syncobjectgetter.SyncObjectGetter, spaceStorage spacestorage.SpaceStorage, syncCtx context.Context, diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 1455faff..8ad55eac 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -49,7 +49,7 @@ type Deps struct { Account accountservice.Service TreeGetter treegetter.TreeGetter Store spacestorage.SpaceStorage - Configuration nodeconf.Configuration + Configuration nodeconf.NodeConf DeletionState settingsstate.ObjectDeletionState Provider SpaceIdsProvider OnSpaceDelete func() diff --git a/commonspace/space.go b/commonspace/space.go index 8b4375fb..cdb00e18 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -121,7 +121,7 @@ type space struct { cache *commonGetter account accountservice.Service aclList *syncacl.SyncAcl - configuration nodeconf.Configuration + configuration nodeconf.NodeConf settingsObject settings.SettingsObject peerManager peermanager.PeerManager diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index cf4a2710..0d2168c7 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -135,7 +135,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { } } - lastConfiguration := s.configurationService.GetLast() + lastConfiguration := s.configurationService var ( spaceIsClosed = &atomic.Bool{} spaceIsDeleted = &atomic.Bool{} @@ -202,7 +202,7 @@ func (s *spaceService) addSpaceStorage(ctx context.Context, spaceDescription Spa func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string) (st spacestorage.SpaceStorage, err error) { var p peer.Peer - lastConfiguration := s.configurationService.GetLast() + lastConfiguration := s.configurationService // we can't connect to client if it is a node if lastConfiguration.IsResponsible(id) { err = spacesyncproto.ErrSpaceMissing diff --git a/commonspace/syncstatus/syncstatus.go b/commonspace/syncstatus/syncstatus.go index 091988f5..e9c99275 100644 --- a/commonspace/syncstatus/syncstatus.go +++ b/commonspace/syncstatus/syncstatus.go @@ -72,7 +72,7 @@ type treeStatus struct { type syncStatusProvider struct { sync.Mutex - configuration nodeconf.Configuration + configuration nodeconf.NodeConf periodicSync periodicsync.PeriodicSync updateReceiver UpdateReceiver storage spacestorage.SpaceStorage @@ -92,11 +92,11 @@ type syncStatusProvider struct { type SyncStatusDeps struct { UpdateIntervalSecs int UpdateTimeout time.Duration - Configuration nodeconf.Configuration + Configuration nodeconf.NodeConf Storage spacestorage.SpaceStorage } -func DefaultDeps(configuration nodeconf.Configuration, store spacestorage.SpaceStorage) SyncStatusDeps { +func DefaultDeps(configuration nodeconf.NodeConf, store spacestorage.SpaceStorage) SyncStatusDeps { return SyncStatusDeps{ UpdateIntervalSecs: syncUpdateInterval, UpdateTimeout: syncTimeout, diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index fc3c2dc2..5dc58c64 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -23,6 +23,7 @@ type CoordinatorClient interface { StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) SpaceSign(ctx context.Context, payload SpaceSignPayload) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) + NetworkConfiguration(ctx context.Context, currentId string) (*coordinatorproto.NetworkConfigurationResponse, error) app.Component } @@ -128,8 +129,23 @@ func (c *coordinatorClient) FileLimitCheck(ctx context.Context, spaceId string, return resp.Limit, nil } +func (c *coordinatorClient) NetworkConfiguration(ctx context.Context, currentId string) (resp *coordinatorproto.NetworkConfigurationResponse, err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + resp, err = cl.NetworkConfiguration(ctx, &coordinatorproto.NetworkConfigurationRequest{ + CurrentId: currentId, + }) + if err != nil { + err = rpcerr.Unwrap(err) + return + } + return +} + func (c *coordinatorClient) client(ctx context.Context) (coordinatorproto.DRPCCoordinatorClient, error) { - p, err := c.pool.GetOneOf(ctx, c.nodeConf.GetLast().CoordinatorPeers()) + p, err := c.pool.GetOneOf(ctx, c.nodeConf.CoordinatorPeers()) if err != nil { return nil, err } diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index ab31996b..1dee3da3 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -96,6 +96,21 @@ func (mr *MockCoordinatorClientMockRecorder) Name() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockCoordinatorClient)(nil).Name)) } +// NetworkConfiguration mocks base method. +func (m *MockCoordinatorClient) NetworkConfiguration(arg0 context.Context, arg1 string) (*coordinatorproto.NetworkConfigurationResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NetworkConfiguration", arg0, arg1) + ret0, _ := ret[0].(*coordinatorproto.NetworkConfigurationResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// NetworkConfiguration indicates an expected call of NetworkConfiguration. +func (mr *MockCoordinatorClientMockRecorder) NetworkConfiguration(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NetworkConfiguration", reflect.TypeOf((*MockCoordinatorClient)(nil).NetworkConfiguration), arg0, arg1) +} + // SpaceSign mocks base method. func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 coordinatorclient.SpaceSignPayload) (*coordinatorproto.SpaceReceiptWithSignature, error) { m.ctrl.T.Helper() diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index ef911967..a08e0891 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -90,6 +90,38 @@ func (SpaceStatus) EnumDescriptor() ([]byte, []int) { return fileDescriptor_d94f6f99586adae2, []int{1} } +// NodeType determines the type of API that a node supports +type NodeType int32 + +const ( + // TreeAPI supports space/tree sync api + NodeType_TreeAPI NodeType = 0 + // FileAPI support file api + NodeType_FileAPI NodeType = 1 + // CoordinatorAPI supports coordinator api + NodeType_CoordinatorAPI NodeType = 2 +) + +var NodeType_name = map[int32]string{ + 0: "TreeAPI", + 1: "FileAPI", + 2: "CoordinatorAPI", +} + +var NodeType_value = map[string]int32{ + "TreeAPI": 0, + "FileAPI": 1, + "CoordinatorAPI": 2, +} + +func (x NodeType) String() string { + return proto.EnumName(NodeType_name, int32(x)) +} + +func (NodeType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{2} +} + type SpaceSignRequest struct { // SpaceId is the id of the signed space SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` @@ -688,9 +720,194 @@ func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { return nil } +// NetworkConfigurationRequest contains currenId of the client configuration, it can be empty +type NetworkConfigurationRequest struct { + // currenId of the client configuration + // if the currentId is equal to the latest configuration id then the response will not contain a nodes list + CurrentId string `protobuf:"bytes,1,opt,name=currentId,proto3" json:"currentId,omitempty"` +} + +func (m *NetworkConfigurationRequest) Reset() { *m = NetworkConfigurationRequest{} } +func (m *NetworkConfigurationRequest) String() string { return proto.CompactTextString(m) } +func (*NetworkConfigurationRequest) ProtoMessage() {} +func (*NetworkConfigurationRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{11} +} +func (m *NetworkConfigurationRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NetworkConfigurationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_NetworkConfigurationRequest.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 *NetworkConfigurationRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_NetworkConfigurationRequest.Merge(m, src) +} +func (m *NetworkConfigurationRequest) XXX_Size() int { + return m.Size() +} +func (m *NetworkConfigurationRequest) XXX_DiscardUnknown() { + xxx_messageInfo_NetworkConfigurationRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_NetworkConfigurationRequest proto.InternalMessageInfo + +func (m *NetworkConfigurationRequest) GetCurrentId() string { + if m != nil { + return m.CurrentId + } + return "" +} + +// NetworkConfigurationResponse contains list of nodes +type NetworkConfigurationResponse struct { + // id of current configuration + ConfigurationId string `protobuf:"bytes,1,opt,name=configurationId,proto3" json:"configurationId,omitempty"` + // network id + NetworkId string `protobuf:"bytes,2,opt,name=networkId,proto3" json:"networkId,omitempty"` + // nodes list - it will be empty if the client's currentId is equal configurationId + Nodes []*Node `protobuf:"bytes,3,rep,name=nodes,proto3" json:"nodes,omitempty"` + // unix timestamp of the creation time of configuration + CreationTimeUnix uint64 `protobuf:"varint,4,opt,name=creationTimeUnix,proto3" json:"creationTimeUnix,omitempty"` +} + +func (m *NetworkConfigurationResponse) Reset() { *m = NetworkConfigurationResponse{} } +func (m *NetworkConfigurationResponse) String() string { return proto.CompactTextString(m) } +func (*NetworkConfigurationResponse) ProtoMessage() {} +func (*NetworkConfigurationResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{12} +} +func (m *NetworkConfigurationResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NetworkConfigurationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_NetworkConfigurationResponse.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 *NetworkConfigurationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_NetworkConfigurationResponse.Merge(m, src) +} +func (m *NetworkConfigurationResponse) XXX_Size() int { + return m.Size() +} +func (m *NetworkConfigurationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_NetworkConfigurationResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_NetworkConfigurationResponse proto.InternalMessageInfo + +func (m *NetworkConfigurationResponse) GetConfigurationId() string { + if m != nil { + return m.ConfigurationId + } + return "" +} + +func (m *NetworkConfigurationResponse) GetNetworkId() string { + if m != nil { + return m.NetworkId + } + return "" +} + +func (m *NetworkConfigurationResponse) GetNodes() []*Node { + if m != nil { + return m.Nodes + } + return nil +} + +func (m *NetworkConfigurationResponse) GetCreationTimeUnix() uint64 { + if m != nil { + return m.CreationTimeUnix + } + return 0 +} + +// Node describes one node in the network +type Node struct { + // peerId - it's a peer identifier (libp2p format string) so it's an encoded publicKey + PeerId string `protobuf:"bytes,1,opt,name=peerId,proto3" json:"peerId,omitempty"` + // list of node addresses + Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"` + // list of supported APIs + Types []NodeType `protobuf:"varint,3,rep,packed,name=types,proto3,enum=coordinator.NodeType" json:"types,omitempty"` +} + +func (m *Node) Reset() { *m = Node{} } +func (m *Node) String() string { return proto.CompactTextString(m) } +func (*Node) ProtoMessage() {} +func (*Node) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{13} +} +func (m *Node) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Node) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Node.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 *Node) XXX_Merge(src proto.Message) { + xxx_messageInfo_Node.Merge(m, src) +} +func (m *Node) XXX_Size() int { + return m.Size() +} +func (m *Node) XXX_DiscardUnknown() { + xxx_messageInfo_Node.DiscardUnknown(m) +} + +var xxx_messageInfo_Node proto.InternalMessageInfo + +func (m *Node) GetPeerId() string { + if m != nil { + return m.PeerId + } + return "" +} + +func (m *Node) GetAddresses() []string { + if m != nil { + return m.Addresses + } + return nil +} + +func (m *Node) GetTypes() []NodeType { + if m != nil { + return m.Types + } + return nil +} + func init() { proto.RegisterEnum("coordinator.ErrorCodes", ErrorCodes_name, ErrorCodes_value) proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) + proto.RegisterEnum("coordinator.NodeType", NodeType_name, NodeType_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") proto.RegisterType((*SpaceStatusPayload)(nil), "coordinator.SpaceStatusPayload") proto.RegisterType((*SpaceSignResponse)(nil), "coordinator.SpaceSignResponse") @@ -702,6 +919,9 @@ func init() { proto.RegisterType((*SpaceStatusCheckResponse)(nil), "coordinator.SpaceStatusCheckResponse") proto.RegisterType((*SpaceStatusChangeRequest)(nil), "coordinator.SpaceStatusChangeRequest") proto.RegisterType((*SpaceStatusChangeResponse)(nil), "coordinator.SpaceStatusChangeResponse") + proto.RegisterType((*NetworkConfigurationRequest)(nil), "coordinator.NetworkConfigurationRequest") + proto.RegisterType((*NetworkConfigurationResponse)(nil), "coordinator.NetworkConfigurationResponse") + proto.RegisterType((*Node)(nil), "coordinator.Node") } func init() { @@ -709,53 +929,65 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 728 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcf, 0x4e, 0x13, 0x41, - 0x18, 0xef, 0xb6, 0x05, 0xd2, 0xaf, 0xa4, 0x2e, 0x23, 0xe0, 0xda, 0xe0, 0xda, 0xac, 0x4a, 0x1a, - 0x62, 0x80, 0x14, 0x35, 0xf1, 0x66, 0xac, 0x98, 0x60, 0x0c, 0x92, 0xc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 0x4f, - 0x0d, 0xbb, 0xc2, 0x89, 0x7a, 0xfe, 0xc5, 0xa1, 0xb8, 0x69, 0x43, 0xa5, 0xd6, 0xdf, 0x22, 0x54, - 0xdb, 0x83, 0x69, 0x91, 0x67, 0x50, 0xe9, 0x3f, 0x4f, 0xe4, 0x46, 0xce, 0x20, 0x07, 0x0f, 0x79, - 0xdd, 0x1c, 0x67, 0x4e, 0x84, 0x79, 0x03, 0xb5, 0xec, 0x55, 0x20, 0x56, 0xc6, 0x23, 0xf7, 0x12, - 0xd6, 0x6f, 0x4d, 0xe4, 0x24, 0xa1, 0xdf, 0xa7, 0xdf, 0x95, 0xc1, 0x05, 0x20, 0xb7, 0xc7, 0xc9, - 0x9e, 0x09, 0x7f, 0xe7, 0x12, 0x56, 0x92, 0x60, 0x2f, 0x7d, 0xa6, 0x95, 0x8d, 0x23, 0x13, 0x7c, - 0x95, 0x9b, 0x52, 0x5f, 0xbe, 0x8c, 0x16, 0xe7, 0x78, 0xfc, 0xe0, 0xd7, 0xb9, 0xa9, 0x9d, 0x9d, - 0x9b, 0xda, 0x9f, 0x73, 0x53, 0xfb, 0x7a, 0x61, 0x16, 0xce, 0x2e, 0xcc, 0xc2, 0xef, 0x0b, 0xb3, - 0xf0, 0x76, 0x69, 0xd2, 0xb7, 0x77, 0x6f, 0x5a, 0xfe, 0xdb, 0xf8, 0x17, 0x00, 0x00, 0xff, 0xff, - 0x86, 0x2f, 0x30, 0xee, 0xa2, 0x07, 0x00, 0x00, + // 918 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x6e, 0x23, 0x45, + 0x10, 0xf6, 0xd8, 0x4e, 0x82, 0xcb, 0x91, 0x77, 0xd2, 0x24, 0x61, 0x30, 0x66, 0xb0, 0x06, 0x58, + 0x4c, 0x40, 0xd9, 0x95, 0x17, 0x10, 0x88, 0x0b, 0x60, 0x16, 0x29, 0x08, 0x85, 0x68, 0x12, 0x83, + 0x80, 0x03, 0x9a, 0x9d, 0xa9, 0x24, 0xad, 0x38, 0xdd, 0x43, 0x77, 0x9b, 0x4d, 0x0e, 0x48, 0x3c, + 0x02, 0x27, 0x0e, 0x3c, 0x03, 0x6f, 0x00, 0x0f, 0xc0, 0x31, 0x47, 0x8e, 0x28, 0x91, 0x78, 0x0e, + 0xd4, 0xf3, 0xe7, 0x1e, 0x7b, 0x9c, 0x20, 0xed, 0xc5, 0x76, 0x7f, 0xf5, 0xfb, 0x55, 0x55, 0x57, + 0x1b, 0xde, 0x0d, 0x39, 0x17, 0x11, 0x65, 0x81, 0xe2, 0xe2, 0x81, 0xf1, 0x3b, 0x16, 0x5c, 0xf1, + 0x07, 0xc9, 0xa7, 0x34, 0xf1, 0xdd, 0x04, 0x22, 0x6d, 0x03, 0xf2, 0x7e, 0xb3, 0xc0, 0x3e, 0x8c, + 0x83, 0x10, 0x0f, 0xe9, 0x09, 0xf3, 0xf1, 0x87, 0x29, 0x4a, 0x45, 0x1c, 0x58, 0x93, 0x1a, 0xdb, + 0x8b, 0x1c, 0xab, 0x6f, 0x0d, 0x5a, 0x7e, 0x7e, 0x24, 0xdb, 0xb0, 0x7a, 0x8a, 0x41, 0x84, 0xc2, + 0xa9, 0xf7, 0xad, 0xc1, 0xba, 0x9f, 0x9d, 0x48, 0x1f, 0xda, 0x7c, 0x12, 0xed, 0x45, 0xc8, 0x14, + 0x55, 0x97, 0x4e, 0x23, 0x11, 0x9a, 0x10, 0x19, 0xc2, 0x26, 0xc3, 0xa7, 0xf9, 0x51, 0x47, 0x0b, + 0xd4, 0x54, 0xa0, 0xd3, 0x4c, 0x54, 0x2b, 0x65, 0x9e, 0x02, 0x92, 0xe6, 0xa6, 0x02, 0x35, 0x95, + 0x07, 0xc1, 0xe5, 0x84, 0x07, 0x11, 0x79, 0x08, 0xab, 0x32, 0x01, 0x92, 0xe4, 0x3a, 0x43, 0x67, + 0xd7, 0xe4, 0x68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, 0xd4, 0xb8, + 0xa0, 0x56, 0xe9, 0x82, 0xf6, 0xa0, 0x15, 0x44, 0x91, 0x40, 0x29, 0x51, 0x3a, 0xf5, 0x7e, 0x43, + 0xa7, 0x54, 0x00, 0xe4, 0x2d, 0x58, 0x51, 0x97, 0x71, 0x96, 0x52, 0x67, 0xb8, 0xb5, 0x90, 0xd2, + 0xd1, 0x65, 0x8c, 0x7e, 0xaa, 0xb3, 0xf3, 0xb3, 0x05, 0xf0, 0x58, 0x08, 0x2e, 0x46, 0x49, 0x96, + 0x1d, 0x80, 0x31, 0xc3, 0x8b, 0x18, 0x43, 0x85, 0x91, 0x5d, 0x23, 0x76, 0xb6, 0x4c, 0x3e, 0xd5, + 0xad, 0xc7, 0xc8, 0xb6, 0x88, 0x03, 0x9b, 0x33, 0x84, 0x72, 0x76, 0x80, 0x2c, 0xa2, 0xec, 0xc4, + 0xae, 0x17, 0xba, 0x23, 0x4d, 0x07, 0x23, 0xbb, 0x41, 0x08, 0x74, 0x12, 0x64, 0x9f, 0xab, 0xc7, + 0x17, 0x54, 0x2a, 0x69, 0x37, 0x89, 0x0d, 0xed, 0x24, 0xde, 0x97, 0xc7, 0xc7, 0x12, 0x95, 0xfd, + 0x7b, 0x7d, 0xe7, 0x27, 0x68, 0x1b, 0x73, 0x40, 0xb6, 0x4b, 0xab, 0x3f, 0x77, 0x56, 0x23, 0x2e, + 0x74, 0xcd, 0x71, 0x49, 0xc3, 0xe6, 0x59, 0xd8, 0xd6, 0x9c, 0x3c, 0x17, 0x1c, 0xaa, 0x40, 0x68, + 0xfb, 0xfa, 0x9c, 0xdf, 0x9c, 0x50, 0x63, 0xe7, 0x7d, 0x78, 0x2e, 0x2f, 0x0a, 0x69, 0xc3, 0xda, + 0x91, 0x40, 0xfc, 0xf8, 0x60, 0xcf, 0xae, 0xe9, 0x83, 0xde, 0x16, 0xfa, 0x60, 0x69, 0x2a, 0xa3, + 0x59, 0x19, 0x35, 0x56, 0x1f, 0xfe, 0xdb, 0x80, 0xb6, 0x01, 0x92, 0xcf, 0xa1, 0x55, 0x3c, 0x1f, + 0xe4, 0xe5, 0x8a, 0x41, 0x9f, 0x3d, 0xb4, 0x5d, 0x77, 0x99, 0x38, 0x9b, 0xcf, 0x6f, 0xa0, 0x53, + 0x5e, 0x55, 0xc4, 0x2b, 0x59, 0x54, 0x2e, 0xc9, 0xee, 0xab, 0xb7, 0xea, 0x64, 0xae, 0xbf, 0xcf, + 0xdf, 0xfd, 0xd9, 0x82, 0x22, 0xaf, 0x2d, 0xbb, 0x96, 0x25, 0xf7, 0xaf, 0xdf, 0xa1, 0x95, 0x05, + 0x78, 0x92, 0x3f, 0xa3, 0xc6, 0x46, 0x20, 0xb7, 0xd8, 0x1a, 0x9b, 0xac, 0x7b, 0xff, 0x2e, 0xb5, + 0x2c, 0xc6, 0x19, 0x6c, 0x56, 0xdd, 0x6f, 0x32, 0x28, 0x4f, 0xfb, 0xf2, 0x05, 0xd2, 0x7d, 0xf3, + 0x7f, 0x68, 0xa6, 0xc1, 0x3e, 0x79, 0xef, 0xaf, 0x6b, 0xd7, 0xba, 0xba, 0x76, 0xad, 0x7f, 0xae, + 0x5d, 0xeb, 0x97, 0x1b, 0xb7, 0x76, 0x75, 0xe3, 0xd6, 0xfe, 0xbe, 0x71, 0x6b, 0xdf, 0xf6, 0x6e, + 0xfb, 0x23, 0xf6, 0x64, 0x35, 0xf9, 0x7a, 0xf4, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x5e, + 0x22, 0xba, 0xaf, 0x09, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -1179,6 +1411,149 @@ func (m *SpaceStatusChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *NetworkConfigurationRequest) 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 *NetworkConfigurationRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NetworkConfigurationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CurrentId) > 0 { + i -= len(m.CurrentId) + copy(dAtA[i:], m.CurrentId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.CurrentId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *NetworkConfigurationResponse) 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 *NetworkConfigurationResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NetworkConfigurationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CreationTimeUnix != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.CreationTimeUnix)) + i-- + dAtA[i] = 0x20 + } + if len(m.Nodes) > 0 { + for iNdEx := len(m.Nodes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Nodes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.NetworkId) > 0 { + i -= len(m.NetworkId) + copy(dAtA[i:], m.NetworkId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.NetworkId))) + i-- + dAtA[i] = 0x12 + } + if len(m.ConfigurationId) > 0 { + i -= len(m.ConfigurationId) + copy(dAtA[i:], m.ConfigurationId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.ConfigurationId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Node) 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 *Node) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Node) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Types) > 0 { + dAtA5 := make([]byte, len(m.Types)*10) + var j4 int + for _, num := range m.Types { + for num >= 1<<7 { + dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j4++ + } + dAtA5[j4] = uint8(num) + j4++ + } + i -= j4 + copy(dAtA[i:], dAtA5[:j4]) + i = encodeVarintCoordinator(dAtA, i, uint64(j4)) + i-- + dAtA[i] = 0x1a + } + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(m.PeerId) > 0 { + i -= len(m.PeerId) + copy(dAtA[i:], m.PeerId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.PeerId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintCoordinator(dAtA []byte, offset int, v uint64) int { offset -= sovCoordinator(v) base := offset @@ -1377,6 +1752,71 @@ func (m *SpaceStatusChangeResponse) Size() (n int) { return n } +func (m *NetworkConfigurationRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CurrentId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *NetworkConfigurationResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ConfigurationId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.NetworkId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + if len(m.Nodes) > 0 { + for _, e := range m.Nodes { + l = e.Size() + n += 1 + l + sovCoordinator(uint64(l)) + } + } + if m.CreationTimeUnix != 0 { + n += 1 + sovCoordinator(uint64(m.CreationTimeUnix)) + } + return n +} + +func (m *Node) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PeerId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovCoordinator(uint64(l)) + } + } + if len(m.Types) > 0 { + l = 0 + for _, e := range m.Types { + l += sovCoordinator(uint64(e)) + } + n += 1 + sovCoordinator(uint64(l)) + l + } + return n +} + func sovCoordinator(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2647,6 +3087,438 @@ func (m *SpaceStatusChangeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *NetworkConfigurationRequest) 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 ErrIntOverflowCoordinator + } + 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: NetworkConfigurationRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NetworkConfigurationRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NetworkConfigurationResponse) 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 ErrIntOverflowCoordinator + } + 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: NetworkConfigurationResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NetworkConfigurationResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConfigurationId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConfigurationId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NetworkId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NetworkId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Nodes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Nodes = append(m.Nodes, &Node{}) + if err := m.Nodes[len(m.Nodes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CreationTimeUnix", wireType) + } + m.CreationTimeUnix = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CreationTimeUnix |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Node) 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 ErrIntOverflowCoordinator + } + 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: Node: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Node: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PeerId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PeerId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + 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 ErrInvalidLengthCoordinator + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 3: + if wireType == 0 { + var v NodeType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= NodeType(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Types = append(m.Types, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + var elementCount int + if elementCount != 0 && len(m.Types) == 0 { + m.Types = make([]NodeType, 0, elementCount) + } + for iNdEx < postIndex { + var v NodeType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= NodeType(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Types = append(m.Types, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field Types", wireType) + } + default: + iNdEx = preIndex + skippy, err := skipCoordinator(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCoordinator + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCoordinator(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/coordinator/coordinatorproto/coordinator_drpc.pb.go b/coordinator/coordinatorproto/coordinator_drpc.pb.go index 3fd4e199..75e73a7b 100644 --- a/coordinator/coordinatorproto/coordinator_drpc.pb.go +++ b/coordinator/coordinatorproto/coordinator_drpc.pb.go @@ -44,6 +44,7 @@ type DRPCCoordinatorClient interface { FileLimitCheck(ctx context.Context, in *FileLimitCheckRequest) (*FileLimitCheckResponse, error) SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) + NetworkConfiguration(ctx context.Context, in *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) } type drpcCoordinatorClient struct { @@ -92,11 +93,21 @@ func (c *drpcCoordinatorClient) SpaceStatusChange(ctx context.Context, in *Space return out, nil } +func (c *drpcCoordinatorClient) NetworkConfiguration(ctx context.Context, in *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) { + out := new(NetworkConfigurationResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/NetworkConfiguration", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + type DRPCCoordinatorServer interface { SpaceSign(context.Context, *SpaceSignRequest) (*SpaceSignResponse, error) FileLimitCheck(context.Context, *FileLimitCheckRequest) (*FileLimitCheckResponse, error) SpaceStatusCheck(context.Context, *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) SpaceStatusChange(context.Context, *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) + NetworkConfiguration(context.Context, *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) } type DRPCCoordinatorUnimplementedServer struct{} @@ -117,9 +128,13 @@ func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusChange(context.Context, return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } +func (s *DRPCCoordinatorUnimplementedServer) NetworkConfiguration(context.Context, *NetworkConfigurationRequest) (*NetworkConfigurationResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + type DRPCCoordinatorDescription struct{} -func (DRPCCoordinatorDescription) NumMethods() int { return 4 } +func (DRPCCoordinatorDescription) NumMethods() int { return 5 } func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { switch n { @@ -159,6 +174,15 @@ func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Rec in1.(*SpaceStatusChangeRequest), ) }, DRPCCoordinatorServer.SpaceStatusChange, true + case 4: + return "/coordinator.Coordinator/NetworkConfiguration", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + NetworkConfiguration( + ctx, + in1.(*NetworkConfigurationRequest), + ) + }, DRPCCoordinatorServer.NetworkConfiguration, true default: return "", nil, nil, nil, false } @@ -231,3 +255,19 @@ func (x *drpcCoordinator_SpaceStatusChangeStream) SendAndClose(m *SpaceStatusCha } return x.CloseSend() } + +type DRPCCoordinator_NetworkConfigurationStream interface { + drpc.Stream + SendAndClose(*NetworkConfigurationResponse) error +} + +type drpcCoordinator_NetworkConfigurationStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_NetworkConfigurationStream) SendAndClose(m *NetworkConfigurationResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}); err != nil { + return err + } + return x.CloseSend() +} diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 1075a1d6..804957a1 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -18,6 +18,9 @@ service Coordinator { // SpaceStatusChange changes the status of space rpc SpaceStatusChange(SpaceStatusChangeRequest) returns (SpaceStatusChangeResponse); + + // NetworkConfiguration retrieves the latest network configuration + rpc NetworkConfiguration(NetworkConfigurationRequest) returns (NetworkConfigurationResponse); } message SpaceSignRequest { @@ -109,3 +112,42 @@ message SpaceStatusChangeRequest { message SpaceStatusChangeResponse { SpaceStatusPayload payload = 1; } + +// NetworkConfigurationRequest contains currenId of the client configuration, it can be empty +message NetworkConfigurationRequest { + // currenId of the client configuration + // if the currentId is equal to the latest configuration id then the response will not contain a nodes list + string currentId = 1; +} + +// NetworkConfigurationResponse contains list of nodes +message NetworkConfigurationResponse { + // id of current configuration + string configurationId = 1; + // network id + string networkId = 2; + // nodes list - it will be empty if the client's currentId is equal configurationId + repeated Node nodes = 3; + // unix timestamp of the creation time of configuration + uint64 creationTimeUnix = 4; +} + +// NodeType determines the type of API that a node supports +enum NodeType { + // TreeAPI supports space/tree sync api + TreeAPI = 0; + // FileAPI support file api + FileAPI = 1; + // CoordinatorAPI supports coordinator api + CoordinatorAPI = 2; +} + +// Node describes one node in the network +message Node { + // peerId - it's a peer identifier (libp2p format string) so it's an encoded publicKey + string peerId = 1; + // list of node addresses + repeated string addresses = 2; + // list of supported APIs + repeated NodeType types = 3; +} diff --git a/coordinator/nodeconfsource/nodeconfsource.go b/coordinator/nodeconfsource/nodeconfsource.go new file mode 100644 index 00000000..f66dcafb --- /dev/null +++ b/coordinator/nodeconfsource/nodeconfsource.go @@ -0,0 +1,68 @@ +package nodeconfsource + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/coordinator/coordinatorclient" + "github.com/anytypeio/any-sync/coordinator/coordinatorproto" + "github.com/anytypeio/any-sync/nodeconf" + "time" +) + +type NodeConfSource interface { + app.Component + nodeconf.Source +} + +func New() NodeConfSource { + return new(nodeConfSource) +} + +type nodeConfSource struct { + cl coordinatorclient.CoordinatorClient +} + +func (n *nodeConfSource) Init(a *app.App) (err error) { + n.cl = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) + return nil +} + +func (n *nodeConfSource) Name() (name string) { + return nodeconf.CNameSource +} + +func (n *nodeConfSource) GetLast(ctx context.Context, currentId string) (c nodeconf.Configuration, err error) { + res, err := n.cl.NetworkConfiguration(ctx, currentId) + if err != nil { + return + } + if res.ConfigurationId == currentId { + err = nodeconf.ErrConfigurationNotChanged + return + } + nodes := make([]nodeconf.Node, len(res.Nodes)) + for i, node := range res.Nodes { + types := make([]nodeconf.NodeType, 0, len(node.Types)) + for _, nt := range node.Types { + switch nt { + case coordinatorproto.NodeType_FileAPI: + types = append(types, nodeconf.NodeTypeFile) + case coordinatorproto.NodeType_CoordinatorAPI: + types = append(types, nodeconf.NodeTypeCoordinator) + case coordinatorproto.NodeType_TreeAPI: + types = append(types, nodeconf.NodeTypeTree) + } + } + nodes[i] = nodeconf.Node{ + PeerId: node.PeerId, + Addresses: node.Addresses, + Types: types, + } + } + return nodeconf.Configuration{ + Id: res.ConfigurationId, + NetworkId: res.NetworkId, + Nodes: nodes, + CreationTime: time.Unix(int64(res.CreationTimeUnix), 0), + }, nil +} diff --git a/go.mod b/go.mod index bbb0de70..17e557c3 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-merkledag v0.10.0 github.com/ipfs/go-unixfs v0.4.5 - github.com/libp2p/go-libp2p v0.24.1 + github.com/libp2p/go-libp2p v0.25.1 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multihash v0.2.1 @@ -59,11 +59,12 @@ require ( github.com/ipfs/go-bitfield v1.1.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect - github.com/ipfs/go-ipfs-files v0.2.0 // indirect + github.com/ipfs/go-ipfs-files v0.3.0 // indirect github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect github.com/ipfs/go-ipfs-util v0.0.2 // indirect github.com/ipfs/go-ipld-cbor v0.0.6 // indirect github.com/ipfs/go-ipld-legacy v0.1.1 // indirect + github.com/ipfs/go-libipfs v0.7.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect @@ -72,18 +73,16 @@ require ( github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.2 // indirect + github.com/klauspost/cpuid/v2 v2.2.3 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect - github.com/libp2p/go-openssl v0.1.0 // indirect github.com/mattn/go-isatty v0.0.17 // indirect - github.com/mattn/go-pointer v0.0.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/minio/sha256-simd v1.0.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect github.com/multiformats/go-multiaddr v0.8.0 // indirect github.com/multiformats/go-multicodec v0.8.0 // indirect - github.com/multiformats/go-multistream v0.3.3 // indirect + github.com/multiformats/go-multistream v0.4.1 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -92,9 +91,8 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.39.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect - github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 // indirect + github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect go.opentelemetry.io/otel v1.11.2 // indirect go.opentelemetry.io/otel/trace v1.11.2 // indirect diff --git a/go.sum b/go.sum index 762c3cb8..8e765b40 100644 --- a/go.sum +++ b/go.sum @@ -117,11 +117,11 @@ github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNo github.com/ipfs/go-ipfs-exchange-interface v0.2.0 h1:8lMSJmKogZYNo2jjhUs0izT+dck05pqUw4mWNW9Pw6Y= github.com/ipfs/go-ipfs-exchange-interface v0.2.0/go.mod h1:z6+RhJuDQbqKguVyslSOuVDhqF9JtTrO3eptSAiW2/Y= github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA= -github.com/ipfs/go-ipfs-files v0.2.0 h1:z6MCYHQSZpDWpUSK59Kf0ajP1fi4gLCf6fIulVsp8A8= -github.com/ipfs/go-ipfs-files v0.2.0/go.mod h1:vT7uaQfIsprKktzbTPLnIsd+NGw9ZbYwSq0g3N74u0M= +github.com/ipfs/go-ipfs-files v0.3.0 h1:fallckyc5PYjuMEitPNrjRfpwl7YFt69heCOUhsbGxQ= +github.com/ipfs/go-ipfs-files v0.3.0/go.mod h1:xAUtYMwB+iu/dtf6+muHNSFQCJG2dSiStR2P6sn9tIM= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= -github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= +github.com/ipfs/go-ipfs-pq v0.0.3 h1:YpoHVJB+jzK15mr/xsWC574tyDLkezVrDNeaalQBsTE= github.com/ipfs/go-ipfs-routing v0.3.0 h1:9W/W3N+g+y4ZDeffSgqhgo7BsBSJwPMcyssET9OWevc= github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= @@ -134,6 +134,8 @@ github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSg github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc= github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg= +github.com/ipfs/go-libipfs v0.7.0 h1:Mi54WJTODaOL2/ZSm5loi3SwI3jI2OuFWUrQIkJ5cpM= +github.com/ipfs/go-libipfs v0.7.0/go.mod h1:KsIf/03CqhICzyRGyGo68tooiBE2iFbI/rXW7FhAYr0= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= @@ -144,7 +146,7 @@ github.com/ipfs/go-merkledag v0.10.0 h1:IUQhj/kzTZfam4e+LnaEpoiZ9vZF6ldimVlby+6O github.com/ipfs/go-merkledag v0.10.0/go.mod h1:zkVav8KiYlmbzUzNM6kENzkdP5+qR7+2mCwxkQ6GIj8= github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= -github.com/ipfs/go-peertaskqueue v0.8.0 h1:JyNO144tfu9bx6Hpo119zvbEL9iQ760FHOiJYsUjqaU= +github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg= github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU= github.com/ipfs/go-unixfs v0.4.5/go.mod h1:BIznJNvt/gEx/ooRMI4Us9K8+qeGO7vx1ohnbk8gjFg= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= @@ -169,8 +171,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/klauspost/cpuid/v2 v2.2.2 h1:xPMwiykqNK9VK0NYC3+jTMYv9I6Vl3YdjZgPZKG3zO0= -github.com/klauspost/cpuid/v2 v2.2.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU= +github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/koron/go-ssdp v0.0.3 h1:JivLMY45N76b4p/vsWGOKewBQu6uf39y8l+AQ7sDKx8= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -183,24 +185,20 @@ github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoR github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= -github.com/libp2p/go-libp2p v0.24.1 h1:+lS4fqj7RF9egcPq9Yo3iqdRTcDMApzoBbQMhxtwOVw= -github.com/libp2p/go-libp2p v0.24.1/go.mod h1:5LJqbrqFsUzWrq70JHCYqjATlX4ey8Klpct3OEe8hSI= +github.com/libp2p/go-libp2p v0.25.1 h1:YK+YDCHpYyTvitKWVxa5PfElgIpOONU01X5UcLEwJGA= +github.com/libp2p/go-libp2p v0.25.1/go.mod h1:xnK9/1d9+jeQCVvi/f1g12KqtVi/jP/SijtKV1hML3g= github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= -github.com/libp2p/go-msgio v0.2.0 h1:W6shmB+FeynDrUVl2dgFQvzfBZcXiyqY4VmpQLu9FqU= +github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0= github.com/libp2p/go-nat v0.1.0 h1:MfVsH6DLcpa04Xr+p8hmVRG4juse0s3J8HyNWYHffXg= github.com/libp2p/go-netroute v0.2.1 h1:V8kVrpD8GK0Riv15/7VN6RbUQ3URNZVosw7H2v9tksU= -github.com/libp2p/go-openssl v0.1.0 h1:LBkKEcUv6vtZIQLVTegAil8jbNpJErQ9AnT+bWV+Ooo= -github.com/libp2p/go-openssl v0.1.0/go.mod h1:OiOxwPpL3n4xlenjx2h7AwSGaFSC/KZvf6gNdOBQMtc= github.com/libp2p/go-yamux/v4 v4.0.0 h1:+Y80dV2Yx/kv7Y7JKu0LECyVdMXm1VUoko+VQ9rBfZQ= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0= -github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= @@ -237,8 +235,8 @@ github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUj github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108= github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= -github.com/multiformats/go-multistream v0.3.3 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o= -github.com/multiformats/go-multistream v0.3.3/go.mod h1:ODRoqamLUsETKS9BNcII4gcRsJBU5VAwRIv7O39cEXg= +github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3de4741sbiSdfo= +github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= @@ -275,8 +273,6 @@ github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg= github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= -github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= -github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -299,8 +295,8 @@ github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvS github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ= github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= -github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 h1:obKzQ1ey5AJg5NKjgtTo/CKwLImVP4ETLRcsmzFJ4Qw= -github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa h1:EyA027ZAkuaCLoxVX4r1TZMPy1d31fM6hbfQ4OU4I5o= +github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= diff --git a/net/dialer/dialer.go b/net/dialer/dialer.go index 7252a4f3..00cdb996 100644 --- a/net/dialer/dialer.go +++ b/net/dialer/dialer.go @@ -42,6 +42,7 @@ type Dialer interface { type dialer struct { transport secureservice.SecureService config net2.Config + nodeConf nodeconf.NodeConf peerAddrs map[string][]string mu sync.RWMutex @@ -49,7 +50,7 @@ type dialer struct { func (d *dialer) Init(a *app.App) (err error) { d.transport = a.MustComponent(secureservice.CName).(secureservice.SecureService) - d.peerAddrs = a.MustComponent(nodeconf.CName).(nodeconf.Service).GetLast().Addresses() + d.nodeConf = a.MustComponent(nodeconf.CName).(nodeconf.NodeConf) d.config = a.MustComponent("config").(net2.ConfigGetter).GetNet() return } @@ -73,6 +74,17 @@ func (d *dialer) SetPeerAddrs(peerId string, addrs []string) { d.peerAddrs[peerId] = addrs } +func (d *dialer) getPeerAddrs(peerId string) ([]string, error) { + if addrs, ok := d.nodeConf.PeerAddresses(peerId); ok { + return addrs, nil + } + addrs, ok := d.peerAddrs[peerId] + if !ok || len(addrs) == 0 { + return nil, ErrArrdsNotFound + } + return addrs, nil +} + func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err error) { var ctxCancel context.CancelFunc ctx, ctxCancel = context.WithTimeout(ctx, time.Second*10) @@ -80,10 +92,11 @@ func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err erro d.mu.RLock() defer d.mu.RUnlock() - addrs, ok := d.peerAddrs[peerId] - if !ok || len(addrs) == 0 { - return nil, ErrArrdsNotFound + addrs, err := d.getPeerAddrs(peerId) + if err != nil { + return } + var ( conn drpc.Conn sc sec.SecureConn diff --git a/net/pool/pool.go b/net/pool/pool.go index b2e4ae22..b7e391c6 100644 --- a/net/pool/pool.go +++ b/net/pool/pool.go @@ -6,6 +6,7 @@ import ( "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/net/dialer" "github.com/anytypeio/any-sync/net/peer" + "go.uber.org/zap" "math/rand" ) @@ -78,6 +79,8 @@ func (p *pool) GetOneOf(ctx context.Context, peerIds []string) (peer.Peer, error for _, peerId := range peerIds { if v, err := p.cache.Get(ctx, peerId); err == nil { return v.(peer.Peer), nil + } else { + log.Debug("unable to connect", zap.String("peerId", peerId), zap.Error(err)) } } return nil, ErrUnableToConnect @@ -92,6 +95,8 @@ func (p *pool) DialOneOf(ctx context.Context, peerIds []string) (peer.Peer, erro for _, peerId := range peerIds { if v, err := p.dialer.Dial(ctx, peerId); err == nil { return v.(peer.Peer), nil + } else { + log.Debug("unable to connect", zap.String("peerId", peerId), zap.Error(err)) } } return nil, ErrUnableToConnect diff --git a/net/secureservice/secureservice.go b/net/secureservice/secureservice.go index 4bbb8dee..918c1987 100644 --- a/net/secureservice/secureservice.go +++ b/net/secureservice/secureservice.go @@ -70,7 +70,7 @@ func (s *secureService) Init(a *app.App) (err error) { s.nodeconf = a.MustComponent(nodeconf.CName).(nodeconf.Service) s.inboundChecker = s.noVerifyChecker - confTypes := s.nodeconf.GetLast().NodeTypes(account.Account().PeerId) + confTypes := s.nodeconf.NodeTypes(account.Account().PeerId) if len(confTypes) > 0 { // require identity verification if we are node s.inboundChecker = s.peerSignVerifier @@ -116,7 +116,7 @@ func (s *secureService) SecureOutbound(ctx context.Context, conn net.Conn) (sec. return nil, HandshakeError{err: err, remoteAddr: conn.RemoteAddr().String()} } peerId := sc.RemotePeer().String() - confTypes := s.nodeconf.GetLast().NodeTypes(peerId) + confTypes := s.nodeconf.NodeTypes(peerId) var checker handshake.CredentialChecker if len(confTypes) > 0 { checker = s.peerSignVerifier diff --git a/net/secureservice/secureservice_test.go b/net/secureservice/secureservice_test.go index b1dc7e6a..e5d4e5d9 100644 --- a/net/secureservice/secureservice_test.go +++ b/net/secureservice/secureservice_test.go @@ -6,7 +6,9 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/net/peer" "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/mock_nodeconf" "github.com/anytypeio/any-sync/testutil/testnodeconf" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "net" @@ -19,7 +21,6 @@ func TestHandshake(t *testing.T) { nc := testnodeconf.GenNodeConfig(2) fxS := newFixture(t, nc, nc.GetAccountService(0)) defer fxS.Finish(t) - sc, cc := net.Pipe() type acceptRes struct { @@ -53,20 +54,28 @@ func TestHandshake(t *testing.T) { func newFixture(t *testing.T, nc *testnodeconf.Config, acc accountservice.Service) *fixture { fx := &fixture{ + ctrl: gomock.NewController(t), secureService: New().(*secureService), acc: acc, a: new(app.App), } - - fx.a.Register(fx.acc).Register(nc).Register(nodeconf.New()).Register(fx.secureService) + fx.mockNodeConf = mock_nodeconf.NewMockService(fx.ctrl) + fx.mockNodeConf.EXPECT().Init(gomock.Any()) + fx.mockNodeConf.EXPECT().Name().Return(nodeconf.CName).AnyTimes() + fx.mockNodeConf.EXPECT().Run(ctx) + fx.mockNodeConf.EXPECT().Close(ctx) + fx.mockNodeConf.EXPECT().NodeTypes(gomock.Any()).Return([]nodeconf.NodeType{nodeconf.NodeTypeTree}).AnyTimes() + fx.a.Register(fx.acc).Register(nc).Register(fx.mockNodeConf).Register(fx.secureService) require.NoError(t, fx.a.Start(ctx)) return fx } type fixture struct { *secureService - a *app.App - acc accountservice.Service + a *app.App + acc accountservice.Service + ctrl *gomock.Controller + mockNodeConf *mock_nodeconf.MockService } func (fx *fixture) Finish(t *testing.T) { diff --git a/nodeconf/config.go b/nodeconf/config.go index 5a60315b..911ee745 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -1,5 +1,18 @@ package nodeconf +import ( + "errors" + "time" +) + +type ConfigGetter interface { + GetNodeConf() Configuration +} + +var ( + ErrConfigurationNotFound = errors.New("node nodeConf not found") +) + type NodeType string const ( @@ -10,17 +23,21 @@ const ( NodeTypeCoordinator NodeType = "coordinator" ) -type configGetter interface { - GetNodes() []NodeConfig +type Node struct { + PeerId string `yaml:"peerId" bson:"peerId"` + Addresses []string `yaml:"addresses" bson:"addresses"` + Types []NodeType `yaml:"types,omitempty" bson:"types"` } -type NodeConfig struct { - PeerId string `yaml:"peerId"` - Addresses []string `yaml:"address"` - Types []NodeType `yaml:"types,omitempty"` +func (n Node) Id() string { + return n.PeerId } -func (n NodeConfig) HasType(t NodeType) bool { +func (n Node) Capacity() float64 { + return 1 +} + +func (n Node) HasType(t NodeType) bool { for _, nt := range n.Types { if nt == t { return true @@ -28,3 +45,10 @@ func (n NodeConfig) HasType(t NodeType) bool { } return false } + +type Configuration struct { + Id string `yaml:"id"` + NetworkId string `yaml:"networkId"` + Nodes []Node `yaml:"nodes"` + CreationTime time.Time `yaml:"creationTime"` +} diff --git a/nodeconf/mock_nodeconf/mock_nodeconf.go b/nodeconf/mock_nodeconf/mock_nodeconf.go index b8b2e800..b422c8a9 100644 --- a/nodeconf/mock_nodeconf/mock_nodeconf.go +++ b/nodeconf/mock_nodeconf/mock_nodeconf.go @@ -1,10 +1,11 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service,Configuration) +// Source: github.com/anytypeio/any-sync/nodeconf (interfaces: Service) // Package mock_nodeconf is a generated GoMock package. package mock_nodeconf import ( + context "context" reflect "reflect" app "github.com/anytypeio/any-sync/app" @@ -36,32 +37,102 @@ func (m *MockService) EXPECT() *MockServiceMockRecorder { return m.recorder } -// GetById mocks base method. -func (m *MockService) GetById(arg0 string) nodeconf.Configuration { +// CHash mocks base method. +func (m *MockService) CHash() chash.CHash { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetById", arg0) + ret := m.ctrl.Call(m, "CHash") + ret0, _ := ret[0].(chash.CHash) + return ret0 +} + +// CHash indicates an expected call of CHash. +func (mr *MockServiceMockRecorder) CHash() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockService)(nil).CHash)) +} + +// Close mocks base method. +func (m *MockService) Close(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockServiceMockRecorder) Close(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockService)(nil).Close), arg0) +} + +// Configuration mocks base method. +func (m *MockService) Configuration() nodeconf.Configuration { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Configuration") ret0, _ := ret[0].(nodeconf.Configuration) return ret0 } -// GetById indicates an expected call of GetById. -func (mr *MockServiceMockRecorder) GetById(arg0 interface{}) *gomock.Call { +// Configuration indicates an expected call of Configuration. +func (mr *MockServiceMockRecorder) Configuration() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetById", reflect.TypeOf((*MockService)(nil).GetById), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Configuration", reflect.TypeOf((*MockService)(nil).Configuration)) } -// GetLast mocks base method. -func (m *MockService) GetLast() nodeconf.Configuration { +// ConsensusPeers mocks base method. +func (m *MockService) ConsensusPeers() []string { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLast") - ret0, _ := ret[0].(nodeconf.Configuration) + ret := m.ctrl.Call(m, "ConsensusPeers") + ret0, _ := ret[0].([]string) return ret0 } -// GetLast indicates an expected call of GetLast. -func (mr *MockServiceMockRecorder) GetLast() *gomock.Call { +// ConsensusPeers indicates an expected call of ConsensusPeers. +func (mr *MockServiceMockRecorder) ConsensusPeers() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLast", reflect.TypeOf((*MockService)(nil).GetLast)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockService)(nil).ConsensusPeers)) +} + +// CoordinatorPeers mocks base method. +func (m *MockService) CoordinatorPeers() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CoordinatorPeers") + ret0, _ := ret[0].([]string) + return ret0 +} + +// CoordinatorPeers indicates an expected call of CoordinatorPeers. +func (mr *MockServiceMockRecorder) CoordinatorPeers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockService)(nil).CoordinatorPeers)) +} + +// FilePeers mocks base method. +func (m *MockService) FilePeers() []string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FilePeers") + ret0, _ := ret[0].([]string) + return ret0 +} + +// FilePeers indicates an expected call of FilePeers. +func (mr *MockServiceMockRecorder) FilePeers() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockService)(nil).FilePeers)) +} + +// Id mocks base method. +func (m *MockService) Id() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Id") + ret0, _ := ret[0].(string) + return ret0 +} + +// Id indicates an expected call of Id. +func (mr *MockServiceMockRecorder) Id() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockService)(nil).Id)) } // Init mocks base method. @@ -78,6 +149,20 @@ func (mr *MockServiceMockRecorder) Init(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockService)(nil).Init), arg0) } +// IsResponsible mocks base method. +func (m *MockService) IsResponsible(arg0 string) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsResponsible", arg0) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsResponsible indicates an expected call of IsResponsible. +func (mr *MockServiceMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockService)(nil).IsResponsible), arg0) +} + // Name mocks base method. func (m *MockService) Name() string { m.ctrl.T.Helper() @@ -92,129 +177,8 @@ func (mr *MockServiceMockRecorder) Name() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockService)(nil).Name)) } -// MockConfiguration is a mock of Configuration interface. -type MockConfiguration struct { - ctrl *gomock.Controller - recorder *MockConfigurationMockRecorder -} - -// MockConfigurationMockRecorder is the mock recorder for MockConfiguration. -type MockConfigurationMockRecorder struct { - mock *MockConfiguration -} - -// NewMockConfiguration creates a new mock instance. -func NewMockConfiguration(ctrl *gomock.Controller) *MockConfiguration { - mock := &MockConfiguration{ctrl: ctrl} - mock.recorder = &MockConfigurationMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockConfiguration) EXPECT() *MockConfigurationMockRecorder { - return m.recorder -} - -// Addresses mocks base method. -func (m *MockConfiguration) Addresses() map[string][]string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Addresses") - ret0, _ := ret[0].(map[string][]string) - return ret0 -} - -// Addresses indicates an expected call of Addresses. -func (mr *MockConfigurationMockRecorder) Addresses() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Addresses", reflect.TypeOf((*MockConfiguration)(nil).Addresses)) -} - -// CHash mocks base method. -func (m *MockConfiguration) CHash() chash.CHash { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CHash") - ret0, _ := ret[0].(chash.CHash) - return ret0 -} - -// CHash indicates an expected call of CHash. -func (mr *MockConfigurationMockRecorder) CHash() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CHash", reflect.TypeOf((*MockConfiguration)(nil).CHash)) -} - -// ConsensusPeers mocks base method. -func (m *MockConfiguration) ConsensusPeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ConsensusPeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// ConsensusPeers indicates an expected call of ConsensusPeers. -func (mr *MockConfigurationMockRecorder) ConsensusPeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusPeers", reflect.TypeOf((*MockConfiguration)(nil).ConsensusPeers)) -} - -// CoordinatorPeers mocks base method. -func (m *MockConfiguration) CoordinatorPeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CoordinatorPeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// CoordinatorPeers indicates an expected call of CoordinatorPeers. -func (mr *MockConfigurationMockRecorder) CoordinatorPeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CoordinatorPeers", reflect.TypeOf((*MockConfiguration)(nil).CoordinatorPeers)) -} - -// FilePeers mocks base method. -func (m *MockConfiguration) FilePeers() []string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FilePeers") - ret0, _ := ret[0].([]string) - return ret0 -} - -// FilePeers indicates an expected call of FilePeers. -func (mr *MockConfigurationMockRecorder) FilePeers() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilePeers", reflect.TypeOf((*MockConfiguration)(nil).FilePeers)) -} - -// Id mocks base method. -func (m *MockConfiguration) Id() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Id") - ret0, _ := ret[0].(string) - return ret0 -} - -// Id indicates an expected call of Id. -func (mr *MockConfigurationMockRecorder) Id() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Id", reflect.TypeOf((*MockConfiguration)(nil).Id)) -} - -// IsResponsible mocks base method. -func (m *MockConfiguration) IsResponsible(arg0 string) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsResponsible", arg0) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsResponsible indicates an expected call of IsResponsible. -func (mr *MockConfigurationMockRecorder) IsResponsible(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsResponsible", reflect.TypeOf((*MockConfiguration)(nil).IsResponsible), arg0) -} - // NodeIds mocks base method. -func (m *MockConfiguration) NodeIds(arg0 string) []string { +func (m *MockService) NodeIds(arg0 string) []string { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NodeIds", arg0) ret0, _ := ret[0].([]string) @@ -222,13 +186,13 @@ func (m *MockConfiguration) NodeIds(arg0 string) []string { } // NodeIds indicates an expected call of NodeIds. -func (mr *MockConfigurationMockRecorder) NodeIds(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) NodeIds(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockConfiguration)(nil).NodeIds), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeIds", reflect.TypeOf((*MockService)(nil).NodeIds), arg0) } // NodeTypes mocks base method. -func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType { +func (m *MockService) NodeTypes(arg0 string) []nodeconf.NodeType { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NodeTypes", arg0) ret0, _ := ret[0].([]nodeconf.NodeType) @@ -236,13 +200,13 @@ func (m *MockConfiguration) NodeTypes(arg0 string) []nodeconf.NodeType { } // NodeTypes indicates an expected call of NodeTypes. -func (mr *MockConfigurationMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) NodeTypes(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockConfiguration)(nil).NodeTypes), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeTypes", reflect.TypeOf((*MockService)(nil).NodeTypes), arg0) } // Partition mocks base method. -func (m *MockConfiguration) Partition(arg0 string) int { +func (m *MockService) Partition(arg0 string) int { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Partition", arg0) ret0, _ := ret[0].(int) @@ -250,7 +214,36 @@ func (m *MockConfiguration) Partition(arg0 string) int { } // Partition indicates an expected call of Partition. -func (mr *MockConfigurationMockRecorder) Partition(arg0 interface{}) *gomock.Call { +func (mr *MockServiceMockRecorder) Partition(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockConfiguration)(nil).Partition), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Partition", reflect.TypeOf((*MockService)(nil).Partition), arg0) +} + +// PeerAddresses mocks base method. +func (m *MockService) PeerAddresses(arg0 string) ([]string, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PeerAddresses", arg0) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// PeerAddresses indicates an expected call of PeerAddresses. +func (mr *MockServiceMockRecorder) PeerAddresses(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PeerAddresses", reflect.TypeOf((*MockService)(nil).PeerAddresses), arg0) +} + +// Run mocks base method. +func (m *MockService) Run(arg0 context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Run", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Run indicates an expected call of Run. +func (mr *MockServiceMockRecorder) Run(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockService)(nil).Run), arg0) } diff --git a/nodeconf/configuration.go b/nodeconf/nodeconf.go similarity index 64% rename from nodeconf/configuration.go rename to nodeconf/nodeconf.go index 121b79fa..3d673fe8 100644 --- a/nodeconf/configuration.go +++ b/nodeconf/nodeconf.go @@ -1,4 +1,4 @@ -//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service,Configuration +//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service package nodeconf import ( @@ -6,9 +6,11 @@ import ( "strings" ) -type Configuration interface { +type NodeConf interface { // Id returns current nodeconf id Id() string + // Configuration returns configuration struct + Configuration() Configuration // NodeIds returns list of peerId for given spaceId NodeIds(spaceId string) []string // IsResponsible checks if current account responsible for given spaceId @@ -19,8 +21,8 @@ type Configuration interface { ConsensusPeers() []string // CoordinatorPeers returns list of coordinator nodes CoordinatorPeers() []string - // Addresses returns map[peerId][]addr with connection addresses for all known nodes - Addresses() map[string][]string + // PeerAddresses returns peer addresses by peer id + PeerAddresses(peerId string) (addrs []string, ok bool) // CHash returns nodes consistent table CHash() chash.CHash // Partition returns partition number by spaceId @@ -29,21 +31,27 @@ type Configuration interface { NodeTypes(nodeId string) []NodeType } -type configuration struct { +type nodeConf struct { id string accountId string filePeers []string consensusPeers []string coordinatorPeers []string chash chash.CHash - allMembers []NodeConfig + allMembers []Node + c Configuration + addrs map[string][]string } -func (c *configuration) Id() string { +func (c *nodeConf) Id() string { return c.id } -func (c *configuration) NodeIds(spaceId string) []string { +func (c *nodeConf) Configuration() Configuration { + return c.c +} + +func (c *nodeConf) NodeIds(spaceId string) []string { members := c.chash.GetMembers(ReplKey(spaceId)) res := make([]string, 0, len(members)) for _, m := range members { @@ -54,7 +62,7 @@ func (c *configuration) NodeIds(spaceId string) []string { return res } -func (c *configuration) IsResponsible(spaceId string) bool { +func (c *nodeConf) IsResponsible(spaceId string) bool { for _, m := range c.chash.GetMembers(ReplKey(spaceId)) { if m.Id() == c.accountId { return true @@ -63,35 +71,32 @@ func (c *configuration) IsResponsible(spaceId string) bool { return false } -func (c *configuration) FilePeers() []string { +func (c *nodeConf) FilePeers() []string { return c.filePeers } -func (c *configuration) ConsensusPeers() []string { +func (c *nodeConf) ConsensusPeers() []string { return c.consensusPeers } -func (c *configuration) CoordinatorPeers() []string { +func (c *nodeConf) CoordinatorPeers() []string { return c.coordinatorPeers } -func (c *configuration) Addresses() map[string][]string { - res := make(map[string][]string) - for _, m := range c.allMembers { - res[m.PeerId] = m.Addresses - } - return res +func (c *nodeConf) PeerAddresses(peerId string) (addrs []string, ok bool) { + addrs, ok = c.addrs[peerId] + return } -func (c *configuration) CHash() chash.CHash { +func (c *nodeConf) CHash() chash.CHash { return c.chash } -func (c *configuration) Partition(spaceId string) (part int) { +func (c *nodeConf) Partition(spaceId string) (part int) { return c.chash.GetPartition(ReplKey(spaceId)) } -func (c *configuration) NodeTypes(nodeId string) []NodeType { +func (c *nodeConf) NodeTypes(nodeId string) []NodeType { for _, m := range c.allMembers { if m.PeerId == nodeId { return m.Types diff --git a/nodeconf/configuration_test.go b/nodeconf/nodeconf_test.go similarity index 98% rename from nodeconf/configuration_test.go rename to nodeconf/nodeconf_test.go index fee5eefb..3d73af80 100644 --- a/nodeconf/configuration_test.go +++ b/nodeconf/nodeconf_test.go @@ -21,7 +21,7 @@ func TestConfiguration_NodeIds(t *testing.T) { ReplicationFactor: ReplicationFactor, }) require.NoError(t, err) - conf := &configuration{ + conf := &nodeConf{ id: "last", accountId: "1", chash: ch, diff --git a/nodeconf/nodeconfstore/nodeconfstore.go b/nodeconf/nodeconfstore/nodeconfstore.go new file mode 100644 index 00000000..2033ffca --- /dev/null +++ b/nodeconf/nodeconfstore/nodeconfstore.go @@ -0,0 +1,65 @@ +package nodeconfstore + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/nodeconf" + "gopkg.in/yaml.v3" + "os" + "path/filepath" + "sync" +) + +func New() NodeConfStore { + return new(nodeConfStore) +} + +type NodeConfStore interface { + app.Component + nodeconf.Store +} + +type nodeConfStore struct { + path string + mu sync.Mutex +} + +type configGetter interface { + GetNodeConfStorePath() string +} + +func (n *nodeConfStore) Init(a *app.App) (err error) { + n.path = a.MustComponent("config").(configGetter).GetNodeConfStorePath() + if e := os.Mkdir(n.path, 0755); e != nil && !os.IsExist(e) { + return e + } + return +} + +func (n *nodeConfStore) Name() (name string) { + return nodeconf.CNameStore +} + +func (n *nodeConfStore) GetLast(ctx context.Context, netId string) (c nodeconf.Configuration, err error) { + n.mu.Lock() + defer n.mu.Unlock() + path := filepath.Join(n.path, netId+".yml") + data, err := os.ReadFile(path) + if os.IsNotExist(err) { + err = nodeconf.ErrConfigurationNotFound + return + } + err = yaml.Unmarshal(data, &c) + return +} + +func (n *nodeConfStore) SaveLast(ctx context.Context, c nodeconf.Configuration) (err error) { + n.mu.Lock() + defer n.mu.Unlock() + path := filepath.Join(n.path, c.NetworkId+".yml") + data, err := yaml.Marshal(c) + if err != nil { + return + } + return os.WriteFile(path, data, 0755) +} diff --git a/nodeconf/nodeconfstore/nodeconfstore_test.go b/nodeconf/nodeconfstore/nodeconfstore_test.go new file mode 100644 index 00000000..cb4d5202 --- /dev/null +++ b/nodeconf/nodeconfstore/nodeconfstore_test.go @@ -0,0 +1,87 @@ +package nodeconfstore + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/nodeconf" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "os" + "path/filepath" + "testing" + "time" +) + +var ctx = context.Background() + +func TestNodeConfStore_GetLast(t *testing.T) { + t.Run("not found", func(t *testing.T) { + fx := newFixture(t) + defer fx.finish(t) + _, err := fx.GetLast(ctx, "123") + assert.EqualError(t, err, nodeconf.ErrConfigurationNotFound.Error()) + }) + t.Run("success", func(t *testing.T) { + fx := newFixture(t) + defer fx.finish(t) + c := nodeconf.Configuration{ + Id: "123", + NetworkId: "456", + Nodes: []nodeconf.Node{ + { + PeerId: "peerId", + Addresses: []string{"addr1", "addr2"}, + Types: []nodeconf.NodeType{nodeconf.NodeTypeTree, nodeconf.NodeTypeCoordinator}, + }, + }, + CreationTime: time.Now().Round(time.Second), + } + require.NoError(t, fx.SaveLast(ctx, c)) + + res, err := fx.GetLast(ctx, "456") + require.NoError(t, err) + assert.Equal(t, c.CreationTime.Unix(), res.CreationTime.Unix()) + c.CreationTime = res.CreationTime + assert.Equal(t, c, res) + }) +} + +type fixture struct { + NodeConfStore + tmpPath string + a *app.App +} + +func newFixture(t *testing.T) *fixture { + fx := &fixture{ + NodeConfStore: New(), + a: new(app.App), + } + var err error + fx.tmpPath, err = os.MkdirTemp("", "") + require.NoError(t, err) + fx.a.Register(config{path: fx.tmpPath}).Register(fx.NodeConfStore) + require.NoError(t, fx.a.Start(ctx)) + return fx +} + +func (fx *fixture) finish(t *testing.T) { + defer os.RemoveAll(fx.tmpPath) + require.NoError(t, fx.a.Close(ctx)) +} + +type config struct { + path string +} + +func (c config) GetNodeConfStorePath() string { + return filepath.Join(c.path, "nodeconf") +} + +func (c config) Init(a *app.App) (err error) { + return +} + +func (c config) Name() (name string) { + return "config" +} diff --git a/nodeconf/service.go b/nodeconf/service.go index ad66fc5a..3f12e462 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -1,12 +1,14 @@ package nodeconf import ( + "context" commonaccount "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/util/crypto" + "github.com/anytypeio/any-sync/util/periodicsync" "github.com/anytypeio/go-chash" - "github.com/libp2p/go-libp2p/core/peer" + "go.uber.org/zap" + "sync" ) const CName = "common.nodeconf" @@ -23,109 +25,182 @@ func New() Service { } type Service interface { - GetLast() Configuration - GetById(id string) Configuration - app.Component + NodeConf + app.ComponentRunnable } type service struct { accountId string - last Configuration -} - -type Node struct { - Addresses []string - PeerId string - SigningKey crypto.PubKey -} - -func (n *Node) Id() string { - return n.PeerId -} - -func (n *Node) Capacity() float64 { - return 1 + config Configuration + source Source + store Store + last NodeConf + mu sync.RWMutex + sync periodicsync.PeriodicSync } func (s *service) Init(a *app.App) (err error) { - nodesConf := a.MustComponent("config").(configGetter).GetNodes() + s.config = a.MustComponent("config").(ConfigGetter).GetNodeConf() s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId - - fileConfig := &configuration{ - id: "config", - accountId: s.accountId, + s.source = a.MustComponent(CNameSource).(Source) + s.store = a.MustComponent(CNameStore).(Store) + lastStored, err := s.store.GetLast(context.Background(), s.config.NetworkId) + if err == ErrConfigurationNotFound { + lastStored = s.config + err = nil } - if fileConfig.chash, err = chash.New(chash.Config{ - PartitionCount: PartitionCount, - ReplicationFactor: ReplicationFactor, - }); err != nil { - return - } - - members := make([]chash.Member, 0, len(nodesConf)) - for _, n := range nodesConf { - if n.HasType(NodeTypeTree) { - var member *Node - member, err = nodeFromConfigNode(n) - if err != nil { - return + s.sync = periodicsync.NewPeriodicSync(600, 0, func(ctx context.Context) (err error) { + err = s.updateConfiguration(ctx) + if err != nil { + if err == ErrConfigurationNotChanged { + err = nil } - members = append(members, member) } - if n.HasType(NodeTypeConsensus) { - fileConfig.consensusPeers = append(fileConfig.consensusPeers, n.PeerId) - } - if n.HasType(NodeTypeFile) { - fileConfig.filePeers = append(fileConfig.filePeers, n.PeerId) - } - if n.HasType(NodeTypeCoordinator) { - fileConfig.coordinatorPeers = append(fileConfig.coordinatorPeers, n.PeerId) - } - fileConfig.allMembers = append(fileConfig.allMembers, n) - } - if err = fileConfig.chash.AddMembers(members...); err != nil { return - } - s.last = fileConfig - return + }, log) + return s.setLastConfiguration(lastStored) } func (s *service) Name() (name string) { return CName } -func (s *service) GetLast() Configuration { - return s.last +func (s *service) Run(_ context.Context) (err error) { + s.sync.Run() + return } -func (s *service) GetById(id string) Configuration { - //TODO implement me - panic("implement me") +func (s *service) updateConfiguration(ctx context.Context) (err error) { + last, err := s.source.GetLast(ctx, s.Configuration().Id) + if err != nil { + return + } + if err = s.store.SaveLast(ctx, last); err != nil { + return + } + return s.setLastConfiguration(last) } -func nodeFromConfigNode(n NodeConfig) (*Node, error) { - p, err := peer.Decode(n.PeerId) - if err != nil { - return nil, err - } - ic, err := p.ExtractPublicKey() - if err != nil { - return nil, err +func (s *service) setLastConfiguration(c Configuration) (err error) { + s.mu.Lock() + defer s.mu.Unlock() + if s.last != nil && s.last.Id() == c.Id { + return } - icRaw, err := ic.Raw() - if err != nil { - return nil, err + nc := &nodeConf{ + id: c.Id, + c: c, + accountId: s.accountId, + addrs: map[string][]string{}, + } + if nc.chash, err = chash.New(chash.Config{ + PartitionCount: PartitionCount, + ReplicationFactor: ReplicationFactor, + }); err != nil { + return } - sigPubKey, err := crypto.UnmarshalEd25519PublicKey(icRaw) - if err != nil { - return nil, err + members := make([]chash.Member, 0, len(c.Nodes)) + for _, n := range c.Nodes { + if n.HasType(NodeTypeTree) { + members = append(members, n) + } + if n.HasType(NodeTypeConsensus) { + nc.consensusPeers = append(nc.consensusPeers, n.PeerId) + } + if n.HasType(NodeTypeFile) { + nc.filePeers = append(nc.filePeers, n.PeerId) + } + if n.HasType(NodeTypeCoordinator) { + nc.coordinatorPeers = append(nc.coordinatorPeers, n.PeerId) + } + nc.allMembers = append(nc.allMembers, n) + nc.addrs[n.PeerId] = n.Addresses } - - return &Node{ - Addresses: n.Addresses, - PeerId: n.PeerId, - SigningKey: sigPubKey, - }, nil + if err = nc.chash.AddMembers(members...); err != nil { + return + } + var beforeId = "" + if s.last != nil { + beforeId = s.last.Id() + } + if s.last != nil { + log.Info("net configuration changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + } else { + log.Info("net configuration applied", zap.String("netId", nc.Configuration().NetworkId), zap.String("id", nc.Id())) + } + s.last = nc + return +} + +func (s *service) Id() string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Id() +} + +func (s *service) Configuration() Configuration { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Configuration() +} + +func (s *service) NodeIds(spaceId string) []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeIds(spaceId) +} + +func (s *service) IsResponsible(spaceId string) bool { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.IsResponsible(spaceId) +} + +func (s *service) FilePeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.FilePeers() +} + +func (s *service) ConsensusPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.ConsensusPeers() +} + +func (s *service) CoordinatorPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CoordinatorPeers() +} + +func (s *service) PeerAddresses(peerId string) ([]string, bool) { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.PeerAddresses(peerId) +} + +func (s *service) CHash() chash.CHash { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CHash() +} + +func (s *service) Partition(spaceId string) (part int) { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Partition(spaceId) +} + +func (s *service) NodeTypes(nodeId string) []NodeType { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeTypes(nodeId) +} + +func (s *service) Close(ctx context.Context) (err error) { + s.sync.Close() + return } diff --git a/nodeconf/source.go b/nodeconf/source.go new file mode 100644 index 00000000..56ea2c54 --- /dev/null +++ b/nodeconf/source.go @@ -0,0 +1,16 @@ +package nodeconf + +import ( + "context" + "errors" +) + +const CNameSource = "common.nodeconf.source" + +var ( + ErrConfigurationNotChanged = errors.New("configuration not changed") +) + +type Source interface { + GetLast(ctx context.Context, currentId string) (c Configuration, err error) +} diff --git a/nodeconf/store.go b/nodeconf/store.go new file mode 100644 index 00000000..70b1e644 --- /dev/null +++ b/nodeconf/store.go @@ -0,0 +1,10 @@ +package nodeconf + +import "context" + +const CNameStore = "common.nodeconf.store" + +type Store interface { + GetLast(ctx context.Context, netId string) (c Configuration, err error) + SaveLast(ctx context.Context, c Configuration) (err error) +} diff --git a/testutil/accounttest/accountservice.go b/testutil/accounttest/accountservice.go index 7aec1c14..eaa2a139 100644 --- a/testutil/accounttest/accountservice.go +++ b/testutil/accounttest/accountservice.go @@ -47,8 +47,8 @@ func (s *AccountTestService) Account() *accountdata.AccountKeys { return s.acc } -func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig { - return nodeconf.NodeConfig{ +func (s *AccountTestService) NodeConf(addrs []string) nodeconf.Node { + return nodeconf.Node{ PeerId: s.acc.PeerId, Addresses: addrs, Types: []nodeconf.NodeType{nodeconf.NodeTypeTree}, diff --git a/testutil/testnodeconf/testnodeconf.go b/testutil/testnodeconf/testnodeconf.go index 2d6b195e..ca1c4d06 100644 --- a/testutil/testnodeconf/testnodeconf.go +++ b/testutil/testnodeconf/testnodeconf.go @@ -17,21 +17,25 @@ func GenNodeConfig(num int) (conf *Config) { if err := ac.Init(nil); err != nil { panic(err) } - conf.nodes = append(conf.nodes, ac.NodeConf(nil)) + conf.nodes.Nodes = append(conf.nodes.Nodes, ac.NodeConf(nil)) conf.configs = append(conf.configs, ac) } return conf } type Config struct { - nodes []nodeconf.NodeConfig + nodes nodeconf.Configuration configs []*accounttest.AccountTestService } func (c *Config) Init(a *app.App) (err error) { return } func (c *Config) Name() string { return "config" } -func (c *Config) GetNodes() []nodeconf.NodeConfig { +func (c *Config) GetNodesConfId() string { + return "test" +} + +func (c *Config) GetNodeConf() nodeconf.Configuration { return c.nodes } diff --git a/util/crypto/ed25519.go b/util/crypto/ed25519.go index 424104a7..50b34161 100644 --- a/util/crypto/ed25519.go +++ b/util/crypto/ed25519.go @@ -158,6 +158,11 @@ func (k *Ed25519PubKey) Account() string { return res } +func (k *Ed25519PubKey) Network() string { + res, _ := strkey.Encode(strkey.NetworkAddressVersionByte, k.pubKey) + return res +} + // PeerId returns string representation of key for peer id func (k *Ed25519PubKey) PeerId() string { peerId, _ := IdFromSigningPubKey(k) diff --git a/util/crypto/key.go b/util/crypto/key.go index c5346841..72e9463c 100644 --- a/util/crypto/key.go +++ b/util/crypto/key.go @@ -47,6 +47,8 @@ type PubKey interface { Storage() []byte // Account returns string representation for anytype account Account() string + // Network returns string representation for anytype network + Network() string // PeerId returns string representation for peer id PeerId() string // LibP2P returns libp2p model diff --git a/util/strkey/strkey_test.go b/util/strkey/strkey_test.go new file mode 100644 index 00000000..07fc2a64 --- /dev/null +++ b/util/strkey/strkey_test.go @@ -0,0 +1,16 @@ +package strkey + +import ( + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" +) + +func TestDecode(t *testing.T) { + key := "ABCw4rFBR7qU2HGzHwnKLYo9mMRcjGhFK28gSy58RKc5feqz" + res, err := Decode(AccountAddressVersionByte, key) + require.NoError(t, err) + str, err := Encode(AccountAddressVersionByte, res) + require.NoError(t, err) + assert.Equal(t, key, str) +} diff --git a/util/strkey/versions.go b/util/strkey/versions.go index d59becdf..922e47f8 100644 --- a/util/strkey/versions.go +++ b/util/strkey/versions.go @@ -4,4 +4,5 @@ const ( AccountAddressVersionByte VersionByte = 0x5b // Base58-encodes to 'A...' AccountSeedVersionByte VersionByte = 0xff // Base58-encodes to 'S...' DeviceSeedVersionByte VersionByte = 0x7d // Base58-encodes to 'D...' + NetworkAddressVersionByte VersionByte = 0xd3 // Base58-encodes to `N...` )