From 42121385467c9cfcf9f88411c8e35db0743fb5a5 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 27 Feb 2023 22:50:11 +0100 Subject: [PATCH 01/57] Update coordinator proto --- .../coordinatorproto/coordinator.pb.go | 850 +++++++++++++++++- .../coordinatorproto/coordinator_drpc.pb.go | 82 +- .../coordinatorproto/protos/coordinator.proto | 33 + 3 files changed, 937 insertions(+), 28 deletions(-) diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index fdd764ad..172ffe8a 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -22,6 +22,34 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type SpaceStatus int32 + +const ( + SpaceStatus_SpaceStatusCreated SpaceStatus = 0 + SpaceStatus_SpaceStatusPendingDeletion SpaceStatus = 1 + SpaceStatus_SpaceStatusDeleted SpaceStatus = 2 +) + +var SpaceStatus_name = map[int32]string{ + 0: "SpaceStatusCreated", + 1: "SpaceStatusPendingDeletion", + 2: "SpaceStatusDeleted", +} + +var SpaceStatus_value = map[string]int32{ + "SpaceStatusCreated": 0, + "SpaceStatusPendingDeletion": 1, + "SpaceStatusDeleted": 2, +} + +func (x SpaceStatus) String() string { + return proto.EnumName(SpaceStatus_name, int32(x)) +} + +func (SpaceStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{0} +} + type SpaceSignRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` } @@ -344,13 +372,214 @@ func (m *FileLimitCheckResponse) GetLimit() uint64 { return 0 } +// SpaceStatusCheckRequest contains the spaceId of requested space +type SpaceStatusCheckRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` +} + +func (m *SpaceStatusCheckRequest) Reset() { *m = SpaceStatusCheckRequest{} } +func (m *SpaceStatusCheckRequest) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusCheckRequest) ProtoMessage() {} +func (*SpaceStatusCheckRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{6} +} +func (m *SpaceStatusCheckRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusCheckRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusCheckRequest.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 *SpaceStatusCheckRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusCheckRequest.Merge(m, src) +} +func (m *SpaceStatusCheckRequest) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusCheckRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusCheckRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusCheckRequest proto.InternalMessageInfo + +func (m *SpaceStatusCheckRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +// SpaceStatusCheckResponse contains the status and deletion timestamp if needed +type SpaceStatusCheckResponse struct { + Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` + DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` +} + +func (m *SpaceStatusCheckResponse) Reset() { *m = SpaceStatusCheckResponse{} } +func (m *SpaceStatusCheckResponse) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusCheckResponse) ProtoMessage() {} +func (*SpaceStatusCheckResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{7} +} +func (m *SpaceStatusCheckResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusCheckResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusCheckResponse.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 *SpaceStatusCheckResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusCheckResponse.Merge(m, src) +} +func (m *SpaceStatusCheckResponse) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusCheckResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusCheckResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusCheckResponse proto.InternalMessageInfo + +func (m *SpaceStatusCheckResponse) GetStatus() SpaceStatus { + if m != nil { + return m.Status + } + return SpaceStatus_SpaceStatusCreated +} + +func (m *SpaceStatusCheckResponse) GetDeletionTimestamp() int64 { + if m != nil { + return m.DeletionTimestamp + } + return 0 +} + +// SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise +type SpaceStatusChangeRequest struct { + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + DeletionChangeId string `protobuf:"bytes,2,opt,name=deletionChangeId,proto3" json:"deletionChangeId,omitempty"` + DeletionChangePayload []byte `protobuf:"bytes,3,opt,name=deletionChangePayload,proto3" json:"deletionChangePayload,omitempty"` +} + +func (m *SpaceStatusChangeRequest) Reset() { *m = SpaceStatusChangeRequest{} } +func (m *SpaceStatusChangeRequest) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusChangeRequest) ProtoMessage() {} +func (*SpaceStatusChangeRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{8} +} +func (m *SpaceStatusChangeRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusChangeRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusChangeRequest.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 *SpaceStatusChangeRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusChangeRequest.Merge(m, src) +} +func (m *SpaceStatusChangeRequest) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusChangeRequest) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusChangeRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusChangeRequest proto.InternalMessageInfo + +func (m *SpaceStatusChangeRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +func (m *SpaceStatusChangeRequest) GetDeletionChangeId() string { + if m != nil { + return m.DeletionChangeId + } + return "" +} + +func (m *SpaceStatusChangeRequest) GetDeletionChangePayload() []byte { + if m != nil { + return m.DeletionChangePayload + } + return nil +} + +// SpaceStatusChangeResponse is always empty, you should check error in case something was wrong +type SpaceStatusChangeResponse struct { +} + +func (m *SpaceStatusChangeResponse) Reset() { *m = SpaceStatusChangeResponse{} } +func (m *SpaceStatusChangeResponse) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusChangeResponse) ProtoMessage() {} +func (*SpaceStatusChangeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{9} +} +func (m *SpaceStatusChangeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusChangeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusChangeResponse.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 *SpaceStatusChangeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusChangeResponse.Merge(m, src) +} +func (m *SpaceStatusChangeResponse) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusChangeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusChangeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusChangeResponse proto.InternalMessageInfo + func init() { + proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") proto.RegisterType((*SpaceSignResponse)(nil), "coordinator.SpaceSignResponse") proto.RegisterType((*SpaceReceiptWithSignature)(nil), "coordinator.SpaceReceiptWithSignature") proto.RegisterType((*SpaceReceipt)(nil), "coordinator.SpaceReceipt") proto.RegisterType((*FileLimitCheckRequest)(nil), "coordinator.FileLimitCheckRequest") proto.RegisterType((*FileLimitCheckResponse)(nil), "coordinator.FileLimitCheckResponse") + proto.RegisterType((*SpaceStatusCheckRequest)(nil), "coordinator.SpaceStatusCheckRequest") + proto.RegisterType((*SpaceStatusCheckResponse)(nil), "coordinator.SpaceStatusCheckResponse") + proto.RegisterType((*SpaceStatusChangeRequest)(nil), "coordinator.SpaceStatusChangeRequest") + proto.RegisterType((*SpaceStatusChangeResponse)(nil), "coordinator.SpaceStatusChangeResponse") } func init() { @@ -358,33 +587,44 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 409 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0xdd, 0x6a, 0xe2, 0x40, - 0x14, 0x76, 0x5c, 0x7f, 0xc8, 0x51, 0xf6, 0x67, 0x76, 0x57, 0xb2, 0xe2, 0x0e, 0x92, 0x85, 0xc5, - 0x8b, 0x45, 0x17, 0x97, 0xdd, 0xeb, 0xa5, 0x42, 0xc1, 0x52, 0x4a, 0x19, 0x91, 0xd2, 0xf6, 0x2a, - 0x4d, 0x86, 0x3a, 0x98, 0x66, 0xd2, 0x64, 0x2c, 0xf8, 0x16, 0x7d, 0x98, 0x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xa9, 0xf9, 0x4e, 0xb5, 0xd9, 0x86, 0x63, 0xf3, 0x8e, 0xf0, 0x65, 0x28, 0xbc, 0x13, - 0xe1, 0xb2, 0x15, 0xbb, 0x90, 0x98, 0xcf, 0x48, 0x61, 0x02, 0x70, 0x67, 0x7b, 0xdc, 0x1d, 0xfa, - 0x92, 0x7b, 0x66, 0xb1, 0x89, 0x5a, 0x05, 0xaa, 0x21, 0xd6, 0x25, 0x7c, 0x3d, 0xe4, 0x1e, 0x3b, - 0xe6, 0x37, 0x5c, 0xf6, 0x46, 0xcc, 0x19, 0xa7, 0x53, 0xcb, 0x30, 0x85, 0xb2, 0x4d, 0x69, 0x07, - 0xce, 0x6f, 0xce, 0xb7, 0x0d, 0xb5, 0xed, 0xe2, 0xcb, 0x21, 0x7f, 0x81, 0xa2, 0x17, 0xa3, 0xaa, - 0x66, 0x81, 0x26, 0x41, 0xf7, 0x01, 0x41, 0xa5, 0xb7, 0x9e, 0x35, 0x3e, 0x02, 0x63, 0xb5, 0x1f, - 0xf8, 0xfb, 0xdb, 0x35, 0xd0, 0xb6, 0xac, 0x4e, 0x76, 0xa5, 0x97, 0x1d, 0xcf, 0xe1, 0xfd, 0xa6, - 0x17, 0x6c, 0x6d, 0x28, 0x32, 0xff, 0x42, 0xfd, 0xc7, 0x5e, 0x4e, 0x52, 0xfa, 0xe0, 0xdf, 0xd3, - 0x9c, 0xa0, 0xd9, 0x9c, 0xa0, 0x97, 0x39, 0x41, 0xf7, 0x0b, 0x92, 0x9b, 0x2d, 0x48, 0xee, 0x79, - 0x41, 0x72, 0x17, 0x8d, 0x7d, 0x57, 0xea, 0xaa, 0xa4, 0x5e, 0x7f, 0x5e, 0x03, 0x00, 0x00, 0xff, - 0xff, 0x77, 0x20, 0x0a, 0xe9, 0x79, 0x03, 0x00, 0x00, + // 581 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x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xe9, 0xe3, 0xce, + 0xa2, 0xd7, 0xfd, 0xa2, 0xa2, 0xfe, 0x8e, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x24, 0x81, 0xc7, + 0xec, 0x04, 0x06, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -610,6 +850,136 @@ func (m *FileLimitCheckResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *SpaceStatusCheckRequest) 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 *SpaceStatusCheckRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusCheckRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusCheckResponse) 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 *SpaceStatusCheckResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusCheckResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DeletionTimestamp != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.DeletionTimestamp)) + i-- + dAtA[i] = 0x10 + } + if m.Status != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusChangeRequest) 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 *SpaceStatusChangeRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusChangeRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.DeletionChangePayload) > 0 { + i -= len(m.DeletionChangePayload) + copy(dAtA[i:], m.DeletionChangePayload) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.DeletionChangePayload))) + i-- + dAtA[i] = 0x1a + } + if len(m.DeletionChangeId) > 0 { + i -= len(m.DeletionChangeId) + copy(dAtA[i:], m.DeletionChangeId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.DeletionChangeId))) + i-- + dAtA[i] = 0x12 + } + if len(m.SpaceId) > 0 { + i -= len(m.SpaceId) + copy(dAtA[i:], m.SpaceId) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.SpaceId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SpaceStatusChangeResponse) 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 *SpaceStatusChangeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintCoordinator(dAtA []byte, offset int, v uint64) int { offset -= sovCoordinator(v) base := offset @@ -721,6 +1091,64 @@ func (m *FileLimitCheckResponse) Size() (n int) { return n } +func (m *SpaceStatusCheckRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusCheckResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Status != 0 { + n += 1 + sovCoordinator(uint64(m.Status)) + } + if m.DeletionTimestamp != 0 { + n += 1 + sovCoordinator(uint64(m.DeletionTimestamp)) + } + return n +} + +func (m *SpaceStatusChangeRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.DeletionChangeId) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + l = len(m.DeletionChangePayload) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } + return n +} + +func (m *SpaceStatusChangeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovCoordinator(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1399,6 +1827,374 @@ func (m *FileLimitCheckResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *SpaceStatusCheckRequest) 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: SpaceStatusCheckRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusCheckRequest: 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 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.SpaceId = 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 *SpaceStatusCheckResponse) 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: SpaceStatusCheckResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusCheckResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= SpaceStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionTimestamp", wireType) + } + m.DeletionTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DeletionTimestamp |= int64(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 *SpaceStatusChangeRequest) 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: SpaceStatusChangeRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusChangeRequest: 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 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.SpaceId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionChangeId", 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.DeletionChangeId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionChangePayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DeletionChangePayload = append(m.DeletionChangePayload[:0], dAtA[iNdEx:postIndex]...) + if m.DeletionChangePayload == nil { + m.DeletionChangePayload = []byte{} + } + 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 *SpaceStatusChangeResponse) 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: SpaceStatusChangeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusChangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + 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 67f72ef7..3fd4e199 100644 --- a/coordinator/coordinatorproto/coordinator_drpc.pb.go +++ b/coordinator/coordinatorproto/coordinator_drpc.pb.go @@ -42,6 +42,8 @@ type DRPCCoordinatorClient interface { SpaceSign(ctx context.Context, in *SpaceSignRequest) (*SpaceSignResponse, error) FileLimitCheck(ctx context.Context, in *FileLimitCheckRequest) (*FileLimitCheckResponse, error) + SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) + SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) } type drpcCoordinatorClient struct { @@ -72,9 +74,29 @@ func (c *drpcCoordinatorClient) FileLimitCheck(ctx context.Context, in *FileLimi return out, nil } +func (c *drpcCoordinatorClient) SpaceStatusCheck(ctx context.Context, in *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) { + out := new(SpaceStatusCheckResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/SpaceStatusCheck", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *drpcCoordinatorClient) SpaceStatusChange(ctx context.Context, in *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) { + out := new(SpaceStatusChangeResponse) + err := c.cc.Invoke(ctx, "/coordinator.Coordinator/SpaceStatusChange", 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) } type DRPCCoordinatorUnimplementedServer struct{} @@ -87,9 +109,17 @@ func (s *DRPCCoordinatorUnimplementedServer) FileLimitCheck(context.Context, *Fi return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } +func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusCheck(context.Context, *SpaceStatusCheckRequest) (*SpaceStatusCheckResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + +func (s *DRPCCoordinatorUnimplementedServer) SpaceStatusChange(context.Context, *SpaceStatusChangeRequest) (*SpaceStatusChangeResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + type DRPCCoordinatorDescription struct{} -func (DRPCCoordinatorDescription) NumMethods() int { return 2 } +func (DRPCCoordinatorDescription) NumMethods() int { return 4 } func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { switch n { @@ -111,6 +141,24 @@ func (DRPCCoordinatorDescription) Method(n int) (string, drpc.Encoding, drpc.Rec in1.(*FileLimitCheckRequest), ) }, DRPCCoordinatorServer.FileLimitCheck, true + case 2: + return "/coordinator.Coordinator/SpaceStatusCheck", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + SpaceStatusCheck( + ctx, + in1.(*SpaceStatusCheckRequest), + ) + }, DRPCCoordinatorServer.SpaceStatusCheck, true + case 3: + return "/coordinator.Coordinator/SpaceStatusChange", drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCCoordinatorServer). + SpaceStatusChange( + ctx, + in1.(*SpaceStatusChangeRequest), + ) + }, DRPCCoordinatorServer.SpaceStatusChange, true default: return "", nil, nil, nil, false } @@ -151,3 +199,35 @@ func (x *drpcCoordinator_FileLimitCheckStream) SendAndClose(m *FileLimitCheckRes } return x.CloseSend() } + +type DRPCCoordinator_SpaceStatusCheckStream interface { + drpc.Stream + SendAndClose(*SpaceStatusCheckResponse) error +} + +type drpcCoordinator_SpaceStatusCheckStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_SpaceStatusCheckStream) SendAndClose(m *SpaceStatusCheckResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_coordinator_coordinatorproto_protos_coordinator_proto{}); err != nil { + return err + } + return x.CloseSend() +} + +type DRPCCoordinator_SpaceStatusChangeStream interface { + drpc.Stream + SendAndClose(*SpaceStatusChangeResponse) error +} + +type drpcCoordinator_SpaceStatusChangeStream struct { + drpc.Stream +} + +func (x *drpcCoordinator_SpaceStatusChangeStream) SendAndClose(m *SpaceStatusChangeResponse) 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 b7e539bb..13267fd8 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -12,12 +12,24 @@ service Coordinator { // - if a handshake identity matches a given identity // - if a requester contains in nodeconf list rpc FileLimitCheck(FileLimitCheckRequest) returns (FileLimitCheckResponse); + + // SpaceStatusCheck checks the status of space and tells if it is deleted or not + rpc SpaceStatusCheck(SpaceStatusCheckRequest) returns (SpaceStatusCheckResponse); + + // SpaceStatusChange changes the status of space + rpc SpaceStatusChange(SpaceStatusChangeRequest) returns (SpaceStatusChangeResponse); } message SpaceSignRequest { string spaceId = 1; } +enum SpaceStatus { + SpaceStatusCreated = 0; + SpaceStatusPendingDeletion = 1; + SpaceStatusDeleted = 2; +} + message SpaceSignResponse { SpaceReceiptWithSignature receipt = 1; } @@ -53,3 +65,24 @@ message FileLimitCheckRequest { message FileLimitCheckResponse { uint64 limit = 1; } + +// SpaceStatusCheckRequest contains the spaceId of requested space +message SpaceStatusCheckRequest { + string spaceId = 1; +} + +// SpaceStatusCheckResponse contains the status and deletion timestamp if needed +message SpaceStatusCheckResponse { + SpaceStatus status = 1; + int64 deletionTimestamp = 2; +} + +// SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise +message SpaceStatusChangeRequest { + string spaceId = 1; + string deletionChangeId = 2; + bytes deletionChangePayload = 3; +} + +// SpaceStatusChangeResponse is always empty, you should check error in case something was wrong +message SpaceStatusChangeResponse {} From 00c344112ed95dccca42b390eecabb28017eff45 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Wed, 1 Mar 2023 22:06:37 +0100 Subject: [PATCH 02/57] Export VerifyDeleteChange --- commonspace/settings/settings.go | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 0cb4591d..8d9bb3c8 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/object/keychain" "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree/updatelistener" @@ -242,17 +243,7 @@ func (s *settingsObject) verifyDeleteSpace(raw *treechangeproto.RawTreeChangeWit if err != nil { return } - content := &spacesyncproto.SettingsData{} - err = proto.Unmarshal(data, content) - if err != nil { - return - } - if len(content.GetContent()) != 1 || - content.GetContent()[0].GetSpaceDelete() == nil || - content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() == "" { - return fmt.Errorf("incorrect delete change payload") - } - return + return verifyDeleteContent(data, "") } func (s *settingsObject) addContent(data []byte) (err error) { @@ -271,3 +262,27 @@ func (s *settingsObject) addContent(data []byte) (err error) { s.Update(s) return } + +func VerifyDeleteChange(raw *treechangeproto.RawTreeChangeWithId, peerId string) (err error) { + changeBuilder := objecttree.NewChangeBuilder(keychain.NewKeychain(), nil) + res, err := changeBuilder.Unmarshall(raw, true) + if err != nil { + return + } + return verifyDeleteContent(res.Data, peerId) +} + +func verifyDeleteContent(data []byte, peerId string) (err error) { + content := &spacesyncproto.SettingsData{} + err = proto.Unmarshal(data, content) + if err != nil { + return + } + if len(content.GetContent()) != 1 || + content.GetContent()[0].GetSpaceDelete() == nil || + (peerId == "" && content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() == "") || + (peerId != "" && content.GetContent()[0].GetSpaceDelete().GetDeleterPeerId() != peerId) { + return fmt.Errorf("incorrect delete change payload") + } + return +} From eae4f0a57dc866e2d833d9507758ed6912c1cfd5 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Wed, 1 Mar 2023 22:12:07 +0100 Subject: [PATCH 03/57] Change verify export --- commonspace/settings/settings.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 8d9bb3c8..920b385b 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -263,12 +263,15 @@ func (s *settingsObject) addContent(data []byte) (err error) { return } -func VerifyDeleteChange(raw *treechangeproto.RawTreeChangeWithId, peerId string) (err error) { +func VerifyDeleteChange(raw *treechangeproto.RawTreeChangeWithId, identity []byte, peerId string) (err error) { changeBuilder := objecttree.NewChangeBuilder(keychain.NewKeychain(), nil) res, err := changeBuilder.Unmarshall(raw, true) if err != nil { return } + if res.Identity != string(identity) { + return fmt.Errorf("incorrect identity") + } return verifyDeleteContent(res.Data, peerId) } From 3758e9cdf3c5d252381e1c8ee9153d887d7e6855 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 12:18:12 +0100 Subject: [PATCH 04/57] Add header to coordinator proto --- .../coordinatorproto/coordinator.pb.go | 130 +++++++++++++----- .../coordinatorproto/protos/coordinator.proto | 1 + 2 files changed, 93 insertions(+), 38 deletions(-) diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index 172ffe8a..d0785154 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -52,6 +52,7 @@ func (SpaceStatus) EnumDescriptor() ([]byte, []int) { type SpaceSignRequest struct { SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + Header []byte `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"` } func (m *SpaceSignRequest) Reset() { *m = SpaceSignRequest{} } @@ -94,6 +95,13 @@ func (m *SpaceSignRequest) GetSpaceId() string { return "" } +func (m *SpaceSignRequest) GetHeader() []byte { + if m != nil { + return m.Header + } + return nil +} + type SpaceSignResponse struct { Receipt *SpaceReceiptWithSignature `protobuf:"bytes,1,opt,name=receipt,proto3" json:"receipt,omitempty"` } @@ -587,44 +595,45 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 581 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0x8d, 0xd3, 0x36, 0x55, 0x26, 0x55, 0x49, 0x17, 0x1a, 0x4c, 0x28, 0x56, 0x65, 0xa0, 0x8a, - 0xaa, 0x2a, 0xad, 0x52, 0xe0, 0x8c, 0x28, 0x42, 0x0a, 0x42, 0xa8, 0x72, 0xa9, 0x10, 0x20, 0x84, - 0xb6, 0xf6, 0x28, 0x5d, 0xd5, 0xd9, 0x35, 0xf6, 0x06, 0xa9, 0x7c, 0x05, 0x27, 0xbe, 0x86, 0x0f, - 0xe0, 0xd8, 0x23, 0x47, 0x94, 0x7c, 0x05, 0x37, 0x94, 0xb5, 0x9d, 0xac, 0x13, 0x3b, 0xb9, 0x24, - 0xde, 0x37, 0xef, 0xcd, 0xcc, 0xee, 0xbc, 0x5d, 0x78, 0xea, 0x0a, 0x11, 0x7a, 0x8c, 0x53, 0x29, - 0xc2, 0x43, 0xed, 0x3b, 0x08, 0x85, 0x14, 0x87, 0xea, 0x37, 0xd2, 0xf1, 0xb6, 0x82, 0x48, 0x4d, - 0x83, 0xec, 0x03, 0xa8, 0x9f, 0x05, 0xd4, 0xc5, 0x33, 0xd6, 0xe3, 0x0e, 0x7e, 0x1d, 0x60, 0x24, - 0x89, 0x09, 0xeb, 0xd1, 0x18, 0xeb, 0x7a, 0xa6, 0xb1, 0x6b, 0xb4, 0xaa, 0x4e, 0xba, 0xb4, 0xcf, -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, 0x47, 0xe4, 0x51, 0x91, 0x5f, 0x32, - 0xe9, 0x1f, 0x2f, 0x61, 0x25, 0x05, 0x2e, 0xd2, 0xd7, 0x4e, 0x9b, 0x09, 0x59, 0xa0, 0xd5, 0xbc, - 0xd4, 0xdc, 0x5b, 0x46, 0x8b, 0x6b, 0xbc, 0x78, 0xf6, 0x7b, 0x68, 0x19, 0x37, 0x43, 0xcb, 0xf8, - 0x3b, 0xb4, 0x8c, 0x1f, 0x23, 0xab, 0x74, 0x33, 0xb2, 0x4a, 0x7f, 0x46, 0x56, 0xe9, 0xe3, 0xce, - 0xa2, 0xd7, 0xfd, 0xa2, 0xa2, 0xfe, 0x8e, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x24, 0x81, 0xc7, - 0xec, 0x04, 0x06, 0x00, 0x00, + // 593 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xd3, 0x3f, 0x65, 0x12, 0x95, 0x74, 0xa1, 0xc1, 0x84, 0x62, 0x45, 0x06, 0xaa, 0xa8, + 0x42, 0x69, 0x95, 0x02, 0x67, 0x44, 0x2b, 0xa4, 0x20, 0x84, 0x2a, 0x97, 0x0a, 0x01, 0x42, 0x68, + 0x6b, 0x8f, 0x92, 0x55, 0x1d, 0xaf, 0xb1, 0x37, 0x48, 0xe5, 0x29, 0x38, 0xf1, 0x34, 0x3c, 0x00, + 0xc7, 0x1e, 0x39, 0xa2, 0xe4, 0x29, 0xb8, 0xa1, 0xac, 0xd7, 0xc9, 0x3a, 0x71, 0x92, 0x4b, 0xe2, + 0xfd, 0x66, 0xbe, 0x99, 0xd9, 0x99, 0x6f, 0x07, 0x9e, 0xb9, 0x9c, 0x47, 0x1e, 0x0b, 0xa8, 0xe0, + 0xd1, 0xa1, 0xf6, 0x1d, 0x46, 0x5c, 0xf0, 0x43, 0xf9, 0x1b, 0xeb, 0x78, 0x4b, 0x42, 0xa4, 0xac, + 0x41, 0xf6, 0x29, 0x54, 0xcf, 0x43, 0xea, 0xe2, 0x39, 0xeb, 0x06, 0x0e, 0x7e, 0x1d, 0x60, 0x2c, + 0x88, 0x09, 0x5b, 0xf1, 0x18, 0xeb, 0x78, 0xa6, 0xd1, 0x30, 0x9a, 0x25, 0x27, 0x3d, 0x92, 0x1a, + 0x6c, 0xf6, 0x90, 0x7a, 0x18, 0x99, 0xc5, 0x86, 0xd1, 0xac, 0x38, 0xea, 0x64, 0x5f, 0xc0, 0x8e, + 0x16, 0x25, 0x0e, 0x79, 0x10, 0x23, 0x79, 0x01, 0x5b, 0x11, 0xba, 0xc8, 0x42, 0x21, 0xc3, 0x94, + 0xdb, 0xfb, 0x2d, 0xbd, 0x18, 0x49, 0x70, 0x12, 0x87, 0xf7, 0x4c, 0xf4, 0xc6, 0x5c, 0x2a, 0x06, + 0x11, 0x3a, 0x29, 0xcd, 0xbe, 0x82, 0x7b, 0x0b, 0xbd, 0xc8, 0x11, 0xdc, 0x8e, 0x35, 0xe3, 0x19, + 0xbd, 0xf6, 0x39, 0x4d, 0x2a, 0xae, 0x38, 0x79, 0x26, 0xb2, 0x07, 0xa5, 0x38, 0xa5, 0xab, 0x0b, + 0x4c, 0x01, 0xfb, 0x97, 0x01, 0x15, 0x3d, 0xdb, 0xf2, 0x36, 0x84, 0x88, 0x51, 0xc7, 0x93, 0x51, + 0x4a, 0x8e, 0x3a, 0x91, 0x26, 0xdc, 0xa2, 0xae, 0xcb, 0x07, 0x81, 0xe8, 0x78, 0x18, 0x08, 0x26, + 0xae, 0xcd, 0x35, 0x99, 0x66, 0x16, 0x1e, 0x17, 0xef, 0xf2, 0x40, 0x44, 0xdc, 0x7f, 0xcb, 0x3d, + 0x9c, 0x78, 0xaf, 0x27, 0xc5, 0xe7, 0x98, 0x88, 0x05, 0xf0, 0x8d, 0xfa, 0xcc, 0xbb, 0x08, 0x04, + 0x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f4, 0xaa, 0xc5, 0xf6, 0xbf, 0x22, 0x94, 0x4f, 0xa6, 0x6d, 0x26, + 0xaf, 0xa1, 0x34, 0x79, 0xe5, 0xe4, 0x41, 0xce, 0x04, 0xa6, 0x3b, 0xa4, 0x6e, 0x2d, 0x32, 0xab, + 0x81, 0x7e, 0x80, 0xed, 0xac, 0xa2, 0x88, 0x9d, 0x61, 0xe4, 0x6a, 0xb9, 0xfe, 0x70, 0xa9, 0x8f, + 0x0a, 0xfd, 0x25, 0x5d, 0x69, 0x53, 0x1d, 0x91, 0x47, 0x8b, 0xf4, 0x92, 0x09, 0xff, 0x78, 0x85, + 0x97, 0x4a, 0x70, 0x99, 0x6e, 0x3b, 0x6d, 0x26, 0x64, 0x09, 0x57, 0xd3, 0x52, 0x7d, 0x7f, 0x95, + 0x5b, 0x92, 0xe3, 0xe5, 0xf3, 0xdf, 0x43, 0xcb, 0xb8, 0x19, 0x5a, 0xc6, 0xdf, 0xa1, 0x65, 0xfc, + 0x18, 0x59, 0x85, 0x9b, 0x91, 0x55, 0xf8, 0x33, 0xb2, 0x0a, 0x1f, 0xf7, 0x96, 0x6d, 0xfd, 0xcb, + 0x4d, 0xf9, 0x77, 0xfc, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x1b, 0x0c, 0x45, 0x1c, 0x06, 0x00, + 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -647,6 +656,13 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Header) > 0 { + i -= len(m.Header) + copy(dAtA[i:], m.Header) + i = encodeVarintCoordinator(dAtA, i, uint64(len(m.Header))) + i-- + dAtA[i] = 0x12 + } if len(m.SpaceId) > 0 { i -= len(m.SpaceId) copy(dAtA[i:], m.SpaceId) @@ -1001,6 +1017,10 @@ func (m *SpaceSignRequest) Size() (n int) { if l > 0 { n += 1 + l + sovCoordinator(uint64(l)) } + l = len(m.Header) + if l > 0 { + n += 1 + l + sovCoordinator(uint64(l)) + } return n } @@ -1216,6 +1236,40 @@ func (m *SpaceSignRequest) Unmarshal(dAtA []byte) error { } m.SpaceId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCoordinator + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCoordinator + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Header = append(m.Header[:0], dAtA[iNdEx:postIndex]...) + if m.Header == nil { + m.Header = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 13267fd8..4343b143 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -22,6 +22,7 @@ service Coordinator { message SpaceSignRequest { string spaceId = 1; + bytes header = 2; } enum SpaceStatus { From 31b3fed274705be954dd51f68377fe66a54fc68e Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 13:23:43 +0100 Subject: [PATCH 05/57] Add space header validation --- commonspace/spacestorage/spacestorage.go | 41 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/commonspace/spacestorage/spacestorage.go b/commonspace/spacestorage/spacestorage.go index 1562d6b1..b19a4768 100644 --- a/commonspace/spacestorage/spacestorage.go +++ b/commonspace/spacestorage/spacestorage.go @@ -7,16 +7,22 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/liststorage" + "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + "github.com/anytypeio/any-sync/util/cidutil" + "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" + "github.com/gogo/protobuf/proto" + "strings" ) const CName = "common.commonspace.spacestorage" var ( - ErrSpaceStorageExists = errors.New("space storage exists") - ErrSpaceStorageMissing = errors.New("space storage missing") + ErrSpaceStorageExists = errors.New("space storage exists") + ErrSpaceStorageMissing = errors.New("space storage missing") + ErrIncorrectSpaceHeader = errors.New("incorrect space header") ErrTreeStorageAlreadyDeleted = errors.New("tree storage already deleted") ) @@ -63,3 +69,34 @@ func ValidateSpaceStorageCreatePayload(payload SpaceStorageCreatePayload) (err e // TODO: add proper validation return nil } + +func ValidateSpaceHeader(spaceId string, header []byte) (err error) { + split := strings.Split(spaceId, ".") + if len(split) != 2 { + return ErrIncorrectSpaceHeader + } + if !cidutil.VerifyCid(header, split[0]) { + err = objecttree.ErrIncorrectCid + return + } + raw := &spacesyncproto.RawSpaceHeader{} + err = proto.Unmarshal(header, raw) + if err != nil { + return + } + payload := &spacesyncproto.SpaceHeader{} + err = proto.Unmarshal(raw.SpaceHeader, raw) + if err != nil { + return + } + key, err := signingkey.NewSigningEd25519PubKeyFromBytes(payload.Identity) + if err != nil { + return + } + res, err := key.Verify(raw.SpaceHeader, raw.Signature) + if err != nil || !res { + err = ErrIncorrectSpaceHeader + return + } + return +} From 1ed8f162aed4d38c0c46e232eae4fa09fed57a6a Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 13:27:08 +0100 Subject: [PATCH 06/57] Update space header validation --- commonspace/spacestorage/spacestorage.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commonspace/spacestorage/spacestorage.go b/commonspace/spacestorage/spacestorage.go index b19a4768..9b0008fc 100644 --- a/commonspace/spacestorage/spacestorage.go +++ b/commonspace/spacestorage/spacestorage.go @@ -2,6 +2,7 @@ package spacestorage import ( + "bytes" "context" "errors" "github.com/anytypeio/any-sync/app" @@ -70,7 +71,7 @@ func ValidateSpaceStorageCreatePayload(payload SpaceStorageCreatePayload) (err e return nil } -func ValidateSpaceHeader(spaceId string, header []byte) (err error) { +func ValidateSpaceHeader(spaceId string, header, identity []byte) (err error) { split := strings.Split(spaceId, ".") if len(split) != 2 { return ErrIncorrectSpaceHeader @@ -89,6 +90,10 @@ func ValidateSpaceHeader(spaceId string, header []byte) (err error) { if err != nil { return } + if identity != nil && !bytes.Equal(identity, payload.Identity) { + err = ErrIncorrectSpaceHeader + return + } key, err := signingkey.NewSigningEd25519PubKeyFromBytes(payload.Identity) if err != nil { return From 9979a820d34257f6a9322123f2262373de549ff7 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 14:19:32 +0100 Subject: [PATCH 07/57] Update coordinator proto --- .../coordinatorproto/coordinator.pb.go | 87 ++++++++++--------- .../coordinatorproto/protos/coordinator.proto | 3 +- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index d0785154..4e7e5d6f 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -27,19 +27,22 @@ type SpaceStatus int32 const ( SpaceStatus_SpaceStatusCreated SpaceStatus = 0 SpaceStatus_SpaceStatusPendingDeletion SpaceStatus = 1 - SpaceStatus_SpaceStatusDeleted SpaceStatus = 2 + SpaceStatus_SpaceStatusDeletionStarted SpaceStatus = 2 + SpaceStatus_SpaceStatusDeleted SpaceStatus = 3 ) var SpaceStatus_name = map[int32]string{ 0: "SpaceStatusCreated", 1: "SpaceStatusPendingDeletion", - 2: "SpaceStatusDeleted", + 2: "SpaceStatusDeletionStarted", + 3: "SpaceStatusDeleted", } var SpaceStatus_value = map[string]int32{ "SpaceStatusCreated": 0, "SpaceStatusPendingDeletion": 1, - "SpaceStatusDeleted": 2, + "SpaceStatusDeletionStarted": 2, + "SpaceStatusDeleted": 3, } func (x SpaceStatus) String() string { @@ -595,45 +598,45 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 593 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x8e, 0xd3, 0x3f, 0x65, 0x12, 0x95, 0x74, 0xa1, 0xc1, 0x84, 0x62, 0x45, 0x06, 0xaa, 0xa8, - 0x42, 0x69, 0x95, 0x02, 0x67, 0x44, 0x2b, 0xa4, 0x20, 0x84, 0x2a, 0x97, 0x0a, 0x01, 0x42, 0x68, - 0x6b, 0x8f, 0x92, 0x55, 0x1d, 0xaf, 0xb1, 0x37, 0x48, 0xe5, 0x29, 0x38, 0xf1, 0x34, 0x3c, 0x00, - 0xc7, 0x1e, 0x39, 0xa2, 0xe4, 0x29, 0xb8, 0xa1, 0xac, 0xd7, 0xc9, 0x3a, 0x71, 0x92, 0x4b, 0xe2, - 0xfd, 0x66, 0xbe, 0x99, 0xd9, 0x99, 0x6f, 0x07, 0x9e, 0xb9, 0x9c, 0x47, 0x1e, 0x0b, 0xa8, 0xe0, - 0xd1, 0xa1, 0xf6, 0x1d, 0x46, 0x5c, 0xf0, 0x43, 0xf9, 0x1b, 0xeb, 0x78, 0x4b, 0x42, 0xa4, 0xac, - 0x41, 0xf6, 0x29, 0x54, 0xcf, 0x43, 0xea, 0xe2, 0x39, 0xeb, 0x06, 0x0e, 0x7e, 0x1d, 0x60, 0x2c, - 0x88, 0x09, 0x5b, 0xf1, 0x18, 0xeb, 0x78, 0xa6, 0xd1, 0x30, 0x9a, 0x25,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0xe4, 0x6a, 0xb9, 0xfe, 0x70, 0xa9, 0x8f, - 0x0a, 0xfd, 0x25, 0x5d, 0x69, 0x53, 0x1d, 0x91, 0x47, 0x8b, 0xf4, 0x92, 0x09, 0xff, 0x78, 0x85, - 0x97, 0x4a, 0x70, 0x99, 0x6e, 0x3b, 0x6d, 0x26, 0x64, 0x09, 0x57, 0xd3, 0x52, 0x7d, 0x7f, 0x95, - 0x5b, 0x92, 0xe3, 0xe5, 0xf3, 0xdf, 0x43, 0xcb, 0xb8, 0x19, 0x5a, 0xc6, 0xdf, 0xa1, 0x65, 0xfc, - 0x18, 0x59, 0x85, 0x9b, 0x91, 0x55, 0xf8, 0x33, 0xb2, 0x0a, 0x1f, 0xf7, 0x96, 0x6d, 0xfd, 0xcb, - 0x4d, 0xf9, 0x77, 0xfc, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x1b, 0x0c, 0x45, 0x1c, 0x06, 0x00, - 0x00, + // 604 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x55, 0x41, 0x6f, 0x12, 0x41, + 0x14, 0x66, 0x81, 0xd2, 0xf0, 0x20, 0x95, 0x8e, 0x16, 0x57, 0xac, 0x1b, 0xb2, 0x6a, 0x43, 0x1a, + 0x43, 0x1b, 0xaa, 0x9e, 0x8d, 0x6d, 0x4c, 0x30, 0xc6, 0x34, 0x8b, 0x8d, 0x51, 0x0f, 0x66, 0xba, + 0xfb, 0x02, 0x93, 0x2e, 0x3b, 0xeb, 0xee, 0x60, 0x52, 0x13, 0xff, 0x83, 0x27, 0x7f, 0x8d, 0x3f, + 0xc0, 0x63, 0x8f, 0x1e, 0x0d, 0xfc, 0x0a, 0x6f, 0x86, 0xd9, 0x5d, 0x98, 0x85, 0x05, 0x2e, 0xc0, + 0x7c, 0xdf, 0xfb, 0xde, 0x7b, 0x33, 0xef, 0x9b, 0x01, 0x9e, 0xd9, 0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a, 0x0a, 0x7e, 0x8e, 0x9e, 0xc3, 0xbc, 0xfe, 0x59, 0x5c, + 0xae, 0xa6, 0x2d, 0xf0, 0x09, 0xd1, 0x13, 0x34, 0x98, 0xea, 0xf3, 0x0b, 0x79, 0x25, 0x8f, 0x4e, + 0xad, 0xd0, 0xf9, 0x97, 0x87, 0xca, 0xe9, 0x7c, 0x0c, 0xe4, 0x35, 0x94, 0x67, 0xaf, 0x00, 0x79, + 0x90, 0x31, 0xa1, 0xf9, 0x1b, 0xd3, 0x30, 0x56, 0xd1, 0xf1, 0xc0, 0x3f, 0xc0, 0x4e, 0xda, 0x71, + 0xc4, 0x4c, 0x29, 0x32, 0xbd, 0xde, 0x78, 0xb8, 0x36, 0x26, 0x4e, 0xfd, 0x39, 0x79, 0xf2, 0xe6, + 0x3e, 0x23, 0x8f, 0x56, 0xf9, 0x29, 0x95, 0xfe, 0xf1, 0x86, 0xa8, 0xb8, 0xc0, 0x65, 0xf2, 0x1a, + 0x2a, 0x33, 0x23, 0x6b, 0xb4, 0x8a, 0xd7, 0x1a, 0x07, 0x9b, 0xc2, 0xa2, 0x1a, 0x2f, 0x9f, 0xff, + 0x1e, 0x1b, 0xda, 0xcd, 0xd8, 0xd0, 0xfe, 0x8e, 0x0d, 0xed, 0xc7, 0xc4, 0xc8, 0xdd, 0x4c, 0x8c, + 0xdc, 0x9f, 0x89, 0x91, 0xfb, 0xb8, 0xbf, 0xee, 0x5f, 0xe1, 0xb2, 0x24, 0xbf, 0x4e, 0xfe, 0x07, + 0x00, 0x00, 0xff, 0xff, 0x9a, 0xc2, 0x98, 0x37, 0x3c, 0x06, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 4343b143..3d8a6959 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -28,7 +28,8 @@ message SpaceSignRequest { enum SpaceStatus { SpaceStatusCreated = 0; SpaceStatusPendingDeletion = 1; - SpaceStatusDeleted = 2; + SpaceStatusDeletionStarted = 2; + SpaceStatusDeleted = 3; } message SpaceSignResponse { From fcb936bca95a612f8058c248a3fab3947217c8ce Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 19:55:27 +0100 Subject: [PATCH 08/57] Update coordinator client --- .../coordinatorclient/coordinatorclient.go | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index faac5483..03852795 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -4,6 +4,7 @@ package coordinatorclient import ( "context" "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/coordinator/coordinatorproto" "github.com/anytypeio/any-sync/net/pool" "github.com/anytypeio/any-sync/nodeconf" @@ -16,7 +17,9 @@ func New() CoordinatorClient { } type CoordinatorClient interface { - SpaceSign(ctx context.Context, spaceId string) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) + ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (err error) + StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusCheckResponse, err error) + SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) app.Component } @@ -26,6 +29,29 @@ type coordinatorClient struct { nodeConf nodeconf.Service } +func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + _, err = cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{ + SpaceId: spaceId, + DeletionChangeId: deleteRaw.Id, + DeletionChangePayload: deleteRaw.RawChange, + }) + return +} + +func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (response *coordinatorproto.SpaceStatusCheckResponse, err error) { + cl, err := c.client(ctx) + if err != nil { + return + } + return cl.SpaceStatusCheck(ctx, &coordinatorproto.SpaceStatusCheckRequest{ + SpaceId: spaceId, + }) +} + func (c *coordinatorClient) Init(a *app.App) (err error) { c.pool = a.MustComponent(pool.CName).(pool.Service).NewPool(CName) c.nodeConf = a.MustComponent(nodeconf.CName).(nodeconf.Service) @@ -36,13 +62,14 @@ func (c *coordinatorClient) Name() (name string) { return CName } -func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { +func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) { cl, err := c.client(ctx) if err != nil { return } resp, err := cl.SpaceSign(ctx, &coordinatorproto.SpaceSignRequest{ SpaceId: spaceId, + Header: spaceHeader, }) if err != nil { return From 6e5d0442516d120baa54057d3fd2e4bca9b36a0b Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 20:54:52 +0100 Subject: [PATCH 09/57] Update metrics to convert dots --- app/ocache/metrics.go | 9 ++++++++- app/ocache/metrics_test.go | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/ocache/metrics_test.go diff --git a/app/ocache/metrics.go b/app/ocache/metrics.go index b5fe9aa4..b520dff2 100644 --- a/app/ocache/metrics.go +++ b/app/ocache/metrics.go @@ -1,11 +1,18 @@ package ocache -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/prometheus/client_golang/prometheus" + "strings" +) func WithPrometheus(reg *prometheus.Registry, namespace, subsystem string) Option { if subsystem == "" { subsystem = "cache" } + nameSplit := strings.Split(namespace, ".") + subSplit := strings.Split(subsystem, ".") + namespace = strings.Join(nameSplit, "_") + subsystem = strings.Join(subSplit, "_") if reg == nil { return nil } diff --git a/app/ocache/metrics_test.go b/app/ocache/metrics_test.go new file mode 100644 index 00000000..e14d670d --- /dev/null +++ b/app/ocache/metrics_test.go @@ -0,0 +1,19 @@ +package ocache + +import ( + "context" + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/require" + "strings" + "testing" +) + +func TestWithPrometheus_MetricsConvertsDots(t *testing.T) { + opt := WithPrometheus(prometheus.NewRegistry(), "some.name", "some.system") + cache := New(func(ctx context.Context, id string) (value Object, err error) { + return &testObject{}, nil + }, opt).(*oCache) + _, err := cache.Get(context.Background(), "id") + require.NoError(t, err) + require.True(t, strings.Contains(cache.metrics.hit.Desc().String(), "some_name_some_system_hit")) +} From 5218eea8add9e692085d4c4b780f0f3f4d4ae697 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 21:08:14 +0100 Subject: [PATCH 10/57] Fix change builder with no root --- commonspace/object/tree/objecttree/changebuilder.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/commonspace/object/tree/objecttree/changebuilder.go b/commonspace/object/tree/objecttree/changebuilder.go index f23648b0..29a1a500 100644 --- a/commonspace/object/tree/objecttree/changebuilder.go +++ b/commonspace/object/tree/objecttree/changebuilder.go @@ -220,7 +220,7 @@ func (c *changeBuilder) Build(payload BuilderContent) (ch *Change, rawIdChange * } func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChangeWithId, err error) { - if ch.Id == c.rootChange.Id { + if c.isRoot(ch.Id) { return c.rootChange, nil } treeChange := &treechangeproto.TreeChange{ @@ -255,7 +255,7 @@ func (c *changeBuilder) Marshall(ch *Change) (raw *treechangeproto.RawTreeChange } func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, id string) (ch *Change, err error) { - if c.rootChange.Id == id { + if c.isRoot(id) { unmarshalled := &treechangeproto.RootChange{} err = proto.Unmarshal(raw.Payload, unmarshalled) if err != nil { @@ -274,3 +274,10 @@ func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, ch = NewChange(id, unmarshalled, raw.Signature) return } + +func (c *changeBuilder) isRoot(id string) bool { + if c.rootChange != nil { + return c.rootChange.Id == id + } + return false +} From 897c50e8e69da0c3c1d0e73663c885ee8edd3885 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 22:04:37 +0100 Subject: [PATCH 11/57] Add credential provider --- .../credentialprovider/credentialprovider.go | 48 ++++++ .../mock_credentialprovider.go | 80 +++++++++ commonspace/headsync/diffsyncer.go | 45 +++-- commonspace/headsync/diffsyncer_test.go | 16 +- commonspace/headsync/headsync.go | 4 +- commonspace/spaceservice.go | 5 +- .../spacesyncproto/protos/spacesync.proto | 1 + commonspace/spacesyncproto/spacesync.pb.go | 162 ++++++++++++------ .../mock_coordinatorclient.go | 38 +++- nodeconf/mock_nodeconf/mock_nodeconf.go | 14 ++ 10 files changed, 332 insertions(+), 81 deletions(-) create mode 100644 commonspace/credentialprovider/credentialprovider.go create mode 100644 commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go diff --git a/commonspace/credentialprovider/credentialprovider.go b/commonspace/credentialprovider/credentialprovider.go new file mode 100644 index 00000000..04641be9 --- /dev/null +++ b/commonspace/credentialprovider/credentialprovider.go @@ -0,0 +1,48 @@ +//go:generate mockgen -destination mock_credentialprovider/mock_credentialprovider.go github.com/anytypeio/any-sync/commonspace/credentialprovider CredentialProvider +package credentialprovider + +import ( + "context" + "github.com/anytypeio/any-sync/app" + "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + "github.com/anytypeio/any-sync/coordinator/coordinatorclient" + "github.com/anytypeio/any-sync/nodeconf" + "github.com/gogo/protobuf/proto" +) + +const CName = "common.commonspace.credentialprovider" + +func New() CredentialProvider { + return &credentialProvider{} +} + +type CredentialProvider interface { + app.Component + GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) +} + +type credentialProvider struct { + conf nodeconf.Service + client coordinatorclient.CoordinatorClient +} + +func (c *credentialProvider) Init(a *app.App) (err error) { + c.conf = a.MustComponent(nodeconf.CName).(nodeconf.Service) + c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) + return +} + +func (c *credentialProvider) Name() (name string) { + return CName +} + +func (c *credentialProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + if c.conf.GetLast().IsResponsible(spaceHeader.Id) { + return nil, nil + } + receipt, err := c.client.SpaceSign(ctx, spaceHeader.Id, spaceHeader.RawHeader) + if err != nil { + return nil, err + } + return proto.Marshal(receipt) +} diff --git a/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go new file mode 100644 index 00000000..8a39d925 --- /dev/null +++ b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go @@ -0,0 +1,80 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/anytypeio/any-sync/commonspace/credentialprovider (interfaces: CredentialProvider) + +// Package mock_credentialprovider is a generated GoMock package. +package mock_credentialprovider + +import ( + context "context" + reflect "reflect" + + app "github.com/anytypeio/any-sync/app" + spacesyncproto "github.com/anytypeio/any-sync/commonspace/spacesyncproto" + gomock "github.com/golang/mock/gomock" +) + +// MockCredentialProvider is a mock of CredentialProvider interface. +type MockCredentialProvider struct { + ctrl *gomock.Controller + recorder *MockCredentialProviderMockRecorder +} + +// MockCredentialProviderMockRecorder is the mock recorder for MockCredentialProvider. +type MockCredentialProviderMockRecorder struct { + mock *MockCredentialProvider +} + +// NewMockCredentialProvider creates a new mock instance. +func NewMockCredentialProvider(ctrl *gomock.Controller) *MockCredentialProvider { + mock := &MockCredentialProvider{ctrl: ctrl} + mock.recorder = &MockCredentialProviderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCredentialProvider) EXPECT() *MockCredentialProviderMockRecorder { + return m.recorder +} + +// GetCredential mocks base method. +func (m *MockCredentialProvider) GetCredential(arg0 context.Context, arg1 *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCredential", arg0, arg1) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCredential indicates an expected call of GetCredential. +func (mr *MockCredentialProviderMockRecorder) GetCredential(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCredential", reflect.TypeOf((*MockCredentialProvider)(nil).GetCredential), arg0, arg1) +} + +// Init mocks base method. +func (m *MockCredentialProvider) Init(arg0 *app.App) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Init", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Init indicates an expected call of Init. +func (mr *MockCredentialProviderMockRecorder) Init(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockCredentialProvider)(nil).Init), arg0) +} + +// Name mocks base method. +func (m *MockCredentialProvider) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockCredentialProviderMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockCredentialProvider)(nil).Name)) +} diff --git a/commonspace/headsync/diffsyncer.go b/commonspace/headsync/diffsyncer.go index 141509d4..3f3f3f82 100644 --- a/commonspace/headsync/diffsyncer.go +++ b/commonspace/headsync/diffsyncer.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/tree/synctree" "github.com/anytypeio/any-sync/commonspace/object/treegetter" "github.com/anytypeio/any-sync/commonspace/peermanager" @@ -33,29 +34,32 @@ func newDiffSyncer( storage spacestorage.SpaceStorage, clientFactory spacesyncproto.ClientFactory, syncStatus syncstatus.StatusUpdater, + credentialProvider credentialprovider.CredentialProvider, log logger.CtxLogger) DiffSyncer { return &diffSyncer{ - diff: diff, - spaceId: spaceId, - cache: cache, - storage: storage, - peerManager: peerManager, - clientFactory: clientFactory, - log: log, - syncStatus: syncStatus, + diff: diff, + spaceId: spaceId, + cache: cache, + storage: storage, + peerManager: peerManager, + clientFactory: clientFactory, + credentialProvider: credentialProvider, + log: log, + syncStatus: syncStatus, } } type diffSyncer struct { - spaceId string - diff ldiff.Diff - peerManager peermanager.PeerManager - cache treegetter.TreeGetter - storage spacestorage.SpaceStorage - clientFactory spacesyncproto.ClientFactory - log logger.CtxLogger - deletionState settingsstate.ObjectDeletionState - syncStatus syncstatus.StatusUpdater + spaceId string + diff ldiff.Diff + peerManager peermanager.PeerManager + cache treegetter.TreeGetter + storage spacestorage.SpaceStorage + clientFactory spacesyncproto.ClientFactory + log logger.CtxLogger + deletionState settingsstate.ObjectDeletionState + credentialProvider credentialprovider.CredentialProvider + syncStatus syncstatus.StatusUpdater } func (d *diffSyncer) Init(deletionState settingsstate.ObjectDeletionState) { @@ -192,6 +196,10 @@ func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, peerId string, cl return } + cred, err := d.credentialProvider.GetCredential(ctx, header) + if err != nil { + return + } spacePayload := &spacesyncproto.SpacePayload{ SpaceHeader: header, AclPayload: root.Payload, @@ -200,7 +208,8 @@ func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, peerId string, cl SpaceSettingsPayloadId: spaceSettingsRoot.Id, } _, err = cl.SpacePush(ctx, &spacesyncproto.SpacePushRequest{ - Payload: spacePayload, + Payload: spacePayload, + Credential: cred, }) if err != nil { return diff --git a/commonspace/headsync/diffsyncer_test.go b/commonspace/headsync/diffsyncer_test.go index f5d776c4..e73eb55a 100644 --- a/commonspace/headsync/diffsyncer_test.go +++ b/commonspace/headsync/diffsyncer_test.go @@ -1,11 +1,13 @@ package headsync import ( + "bytes" "context" "fmt" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/ldiff/mock_ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider/mock_credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/liststorage/mock_liststorage" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" @@ -30,6 +32,7 @@ type pushSpaceRequestMatcher struct { spaceId string aclRootId string settingsId string + credential []byte spaceHeader *spacesyncproto.RawSpaceHeaderWithId } @@ -39,7 +42,7 @@ func (p pushSpaceRequestMatcher) Matches(x interface{}) bool { return false } - return res.Payload.AclPayloadId == p.aclRootId && res.Payload.SpaceHeader == p.spaceHeader && res.Payload.SpaceSettingsPayloadId == p.settingsId + return res.Payload.AclPayloadId == p.aclRootId && res.Payload.SpaceHeader == p.spaceHeader && res.Payload.SpaceSettingsPayloadId == p.settingsId && bytes.Equal(p.credential, res.Credential) } func (p pushSpaceRequestMatcher) String() string { @@ -83,11 +86,13 @@ func newPushSpaceRequestMatcher( spaceId string, aclRootId string, settingsId string, + credential []byte, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) *pushSpaceRequestMatcher { return &pushSpaceRequestMatcher{ spaceId: spaceId, aclRootId: aclRootId, settingsId: settingsId, + credential: credential, spaceHeader: spaceHeader, } } @@ -106,11 +111,12 @@ func TestDiffSyncer_Sync(t *testing.T) { factory := spacesyncproto.ClientFactoryFunc(func(cc drpc.Conn) spacesyncproto.DRPCSpaceSyncClient { return clientMock }) + credentialProvider := mock_credentialprovider.NewMockCredentialProvider(ctrl) delState := mock_settingsstate.NewMockObjectDeletionState(ctrl) spaceId := "spaceId" aclRootId := "aclRootId" l := logger.NewNamed(spaceId) - diffSyncer := newDiffSyncer(spaceId, diffMock, peerManagerMock, cacheMock, stMock, factory, syncstatus.NewNoOpSyncStatus(), l) + diffSyncer := newDiffSyncer(spaceId, diffMock, peerManagerMock, cacheMock, stMock, factory, syncstatus.NewNoOpSyncStatus(), credentialProvider, l) delState.EXPECT().AddObserver(gomock.Any()) diffSyncer.Init(delState) @@ -172,6 +178,7 @@ func TestDiffSyncer_Sync(t *testing.T) { } spaceHeader := &spacesyncproto.RawSpaceHeaderWithId{} spaceSettingsId := "spaceSettingsId" + credential := []byte("credential") peerManagerMock.EXPECT(). GetResponsiblePeers(gomock.Any()). @@ -189,8 +196,11 @@ func TestDiffSyncer_Sync(t *testing.T) { aclStorageMock.EXPECT(). Root(). Return(aclRoot, nil) + credentialProvider.EXPECT(). + GetCredential(gomock.Any(), spaceHeader). + Return(credential, nil) clientMock.EXPECT(). - SpacePush(gomock.Any(), newPushSpaceRequestMatcher(spaceId, aclRootId, settingsId, spaceHeader)). + SpacePush(gomock.Any(), newPushSpaceRequestMatcher(spaceId, aclRootId, settingsId, credential, spaceHeader)). Return(nil, nil) peerManagerMock.EXPECT().SendPeer(gomock.Any(), "mockId", gomock.Any()) diff --git a/commonspace/headsync/headsync.go b/commonspace/headsync/headsync.go index 98e20c20..08d6d9e3 100644 --- a/commonspace/headsync/headsync.go +++ b/commonspace/headsync/headsync.go @@ -5,6 +5,7 @@ import ( "context" "github.com/anytypeio/any-sync/app/ldiff" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/object/treegetter" "github.com/anytypeio/any-sync/commonspace/peermanager" "github.com/anytypeio/any-sync/commonspace/settings/settingsstate" @@ -60,12 +61,13 @@ func NewHeadSync( peerManager peermanager.PeerManager, cache treegetter.TreeGetter, syncStatus syncstatus.StatusUpdater, + credentialProvider credentialprovider.CredentialProvider, log logger.CtxLogger) HeadSync { diff := ldiff.New(16, 16) l := log.With(zap.String("spaceId", spaceId)) factory := spacesyncproto.ClientFactoryFunc(spacesyncproto.NewDRPCSpaceSyncClient) - syncer := newDiffSyncer(spaceId, diff, peerManager, cache, storage, factory, syncStatus, l) + syncer := newDiffSyncer(spaceId, diff, peerManager, cache, storage, factory, syncStatus, credentialProvider, l) sync := func(ctx context.Context) (err error) { // for clients cancelling the sync process if spaceIsDeleted.Load() && !configuration.IsResponsible(spaceId) { diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 8cf79947..42de938a 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -5,6 +5,7 @@ import ( "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/commonspace/credentialprovider" "github.com/anytypeio/any-sync/commonspace/headsync" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" @@ -45,6 +46,7 @@ type spaceService struct { configurationService nodeconf.Service storageProvider spacestorage.SpaceStorageProvider peermanagerProvider peermanager.PeerManagerProvider + credentialProvider credentialprovider.CredentialProvider treeGetter treegetter.TreeGetter pool pool.Pool } @@ -56,6 +58,7 @@ func (s *spaceService) Init(a *app.App) (err error) { s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service) s.treeGetter = a.MustComponent(treegetter.CName).(treegetter.TreeGetter) s.peermanagerProvider = a.MustComponent(peermanager.CName).(peermanager.PeerManagerProvider) + s.credentialProvider = a.MustComponent(credentialprovider.CName).(credentialprovider.CredentialProvider) s.pool = a.MustComponent(pool.CName).(pool.Pool) return nil } @@ -139,7 +142,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { return nil, err } - headSync := headsync.NewHeadSync(id, spaceIsDeleted, s.config.SyncPeriod, lastConfiguration, st, peerManager, getter, syncStatus, log) + headSync := headsync.NewHeadSync(id, spaceIsDeleted, s.config.SyncPeriod, lastConfiguration, st, peerManager, getter, syncStatus, s.credentialProvider, log) objectSync := objectsync.NewObjectSync(id, spaceIsDeleted, lastConfiguration, peerManager, getter) sp := &space{ id: id, diff --git a/commonspace/spacesyncproto/protos/spacesync.proto b/commonspace/spacesyncproto/protos/spacesync.proto index 06f2bf9f..48b44e0f 100644 --- a/commonspace/spacesyncproto/protos/spacesync.proto +++ b/commonspace/spacesyncproto/protos/spacesync.proto @@ -66,6 +66,7 @@ message ObjectSyncMessage { // SpacePushRequest is a request to add space on a node containing only one acl record message SpacePushRequest { SpacePayload payload = 1; + bytes Credential = 2; } // SpacePushResponse is an empty response diff --git a/commonspace/spacesyncproto/spacesync.pb.go b/commonspace/spacesyncproto/spacesync.pb.go index 5ef50a67..8fb1a914 100644 --- a/commonspace/spacesyncproto/spacesync.pb.go +++ b/commonspace/spacesyncproto/spacesync.pb.go @@ -437,7 +437,8 @@ func (m *ObjectSyncMessage) GetObjectId() string { // SpacePushRequest is a request to add space on a node containing only one acl record type SpacePushRequest struct { - Payload *SpacePayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Payload *SpacePayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Credential []byte `protobuf:"bytes,2,opt,name=Credential,proto3" json:"Credential,omitempty"` } func (m *SpacePushRequest) Reset() { *m = SpacePushRequest{} } @@ -480,6 +481,13 @@ func (m *SpacePushRequest) GetPayload() *SpacePayload { return nil } +func (m *SpacePushRequest) GetCredential() []byte { + if m != nil { + return m.Credential + } + return nil +} + // SpacePushResponse is an empty response type SpacePushResponse struct { } @@ -1232,21 +1240,21 @@ func init() { } var fileDescriptor_80e49f1f4ac27799 = []byte{ - // 1019 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0x4b, 0x6f, 0xdb, 0x46, + // 1030 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0x4b, 0x6f, 0xdb, 0x46, 0x10, 0x16, 0xe9, 0xa7, 0xc6, 0xb2, 0xcc, 0x6c, 0x9c, 0x44, 0x55, 0x0c, 0x45, 0x58, 0x14, 0x85, - 0x91, 0x43, 0x1e, 0x72, 0x51, 0x20, 0x69, 0x7b, 0x48, 0x6c, 0xa5, 0x11, 0x8a, 0xd4, 0xc6, 0xaa, + 0x91, 0x43, 0x1e, 0x72, 0x51, 0x20, 0x69, 0x7b, 0x48, 0x64, 0xa7, 0x11, 0x8a, 0xd4, 0xc6, 0xaa, 0x41, 0x81, 0x02, 0x39, 0xac, 0xc9, 0xb1, 0xc4, 0x96, 0x22, 0x59, 0xee, 0xaa, 0xb6, 0x8e, 0x3d, 0xf5, 0xda, 0x73, 0x7b, 0xea, 0x7f, 0xe8, 0x8f, 0xe8, 0x31, 0xc7, 0x1e, 0x0b, 0xfb, 0x8f, 0x14, - 0xbb, 0x5c, 0x3e, 0x24, 0x51, 0x39, 0xf4, 0x22, 0x73, 0xbf, 0x99, 0xf9, 0xe6, 0xb5, 0x3b, 0x63, - 0x78, 0xea, 0x46, 0x93, 0x49, 0x14, 0x8a, 0x98, 0xbb, 0xf8, 0x58, 0xff, 0x8a, 0x59, 0xe8, 0xc6, - 0x49, 0x24, 0xa3, 0xc7, 0xfa, 0x57, 0x14, 0xe8, 0x23, 0x0d, 0x90, 0x7a, 0x0e, 0xd0, 0x01, 0xec, - 0xbe, 0x46, 0xee, 0x0d, 0x67, 0xa1, 0xcb, 0x78, 0x38, 0x42, 0x42, 0x60, 0xfd, 0x22, 0x89, 0x26, - 0x2d, 0xab, 0x6b, 0x1d, 0xae, 0x33, 0xfd, 0x4d, 0x9a, 0x60, 0xcb, 0xa8, 0x65, 0x6b, 0xc4, 0x96, - 0x11, 0xd9, 0x87, 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 0x52, 0xb4, 0xec, 0xee, 0xda, 0xe1, 0x4e, 0xaf, + 0xfb, 0xa8, 0x88, 0x6f, 0x9e, 0xe0, 0x24, 0x55, 0x64, 0xb9, 0x85, 0xf2, 0xec, 0x46, 0xd3, 0x30, 0xf7, 0xac, 0x0f, 0xf4, 0x73, 0xb8, 0x53, 0x69, 0xa8, 0x02, 0xf7, 0x3d, 0xed, 0xbe, 0xce, 0x6c, 0xdf, 0xd3, 0x01, 0x21, 0xf7, 0x74, 0x2a, 0x75, 0xa6, 0xbf, 0xe9, 0x3b, 0xd8, 0x2b, 0x8c, 0x7f, 0x9a, 0xa2, 0x90, 0xa4, 0x05, 0x5b, 0x3a, 0xa4, 0x41, 0x66, 0x9b, 0x1d, 0xc9, 0x13, 0xd8, 0x4c, @@ -1256,47 +1264,48 @@ var fileDescriptor_80e49f1f4ac27799 = []byte{ 0x42, 0xf0, 0x11, 0x7e, 0x20, 0xd4, 0x03, 0xa8, 0x27, 0x69, 0x3e, 0x83, 0x2c, 0xe1, 0x02, 0x50, 0x76, 0x09, 0xc6, 0xc1, 0x6c, 0xe0, 0xe9, 0x52, 0xd6, 0x59, 0x76, 0x54, 0x92, 0x98, 0xcf, 0x82, 0x88, 0x7b, 0xad, 0x75, 0xdd, 0xb7, 0xec, 0x48, 0xda, 0xb0, 0x1d, 0xe9, 0x00, 0x06, 0x5e, 0x6b, - 0x43, 0x1b, 0xe5, 0x67, 0xda, 0x07, 0x67, 0xa8, 0x1c, 0x9f, 0x4d, 0xc5, 0x38, 0x2b, 0xe3, 0xd3, - 0x82, 0x49, 0xc5, 0xb6, 0xd3, 0xbb, 0x57, 0x4a, 0x33, 0xd5, 0x4e, 0xc5, 0xb9, 0x0b, 0x7a, 0x1b, - 0x6e, 0x95, 0x68, 0xd2, 0x72, 0x51, 0x9a, 0x73, 0x07, 0x41, 0xc6, 0xbd, 0xd0, 0x59, 0xfa, 0x2a, - 0x37, 0x54, 0x3a, 0xa6, 0xce, 0xff, 0x23, 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xa6, 0xef, 0x46, 0xfc, 0x31, 0xec, + 0x7a, 0xfa, 0x2b, 0x39, 0x43, 0x4c, 0xf2, 0x09, 0x34, 0x0f, 0xd2, 0x77, 0x70, 0x67, 0x2e, 0xe1, + 0x61, 0xc8, 0x63, 0x31, 0x8e, 0xa4, 0xba, 0xf6, 0xa9, 0xa6, 0x37, 0xf0, 0xd2, 0x41, 0x58, 0x67, + 0x25, 0x64, 0x99, 0xde, 0xae, 0xa2, 0xff, 0xd5, 0x82, 0x46, 0x46, 0x7d, 0xcc, 0x25, 0x27, 0xcf, + 0x60, 0xcb, 0x4d, 0x6b, 0x6a, 0x86, 0xeb, 0x83, 0xc5, 0x2a, 0x2c, 0x94, 0x9e, 0x65, 0xfa, 0x6a, + 0x37, 0x09, 0x13, 0x9d, 0xa9, 0x60, 0x77, 0x95, 0x6d, 0x96, 0x05, 0xcb, 0x2d, 0xe8, 0x8f, 0x66, + 0xc4, 0x0c, 0xa7, 0xe7, 0xc2, 0x4d, 0xfc, 0x58, 0x5d, 0x4f, 0xf5, 0x36, 0xcc, 0x40, 0xce, 0x52, + 0xcc, 0xcf, 0xe4, 0x39, 0x6c, 0x72, 0x57, 0x69, 0x69, 0x67, 0xcd, 0x1e, 0x5d, 0x72, 0x56, 0x62, + 0x7a, 0xa1, 0x35, 0x99, 0xb1, 0x78, 0x78, 0x09, 0xdb, 0x27, 0x49, 0xd2, 0x8f, 0x3c, 0x14, 0xa4, + 0x09, 0xf0, 0x36, 0xc4, 0xab, 0x18, 0x5d, 0x89, 0x9e, 0x53, 0x23, 0x8e, 0x19, 0x51, 0x6f, 0x7c, + 0x21, 0xfc, 0x70, 0xe4, 0x58, 0x64, 0xcf, 0x34, 0xee, 0xe4, 0xca, 0x17, 0x52, 0x38, 0x36, 0xb9, + 0x0d, 0x7b, 0x1a, 0xf8, 0x26, 0x92, 0x83, 0xb0, 0xcf, 0xdd, 0x31, 0x3a, 0x6b, 0x84, 0x40, 0x53, + 0x83, 0x03, 0x91, 0x36, 0xd8, 0x73, 0xd6, 0x95, 0xe5, 0x49, 0x92, 0x44, 0xc9, 0xe9, 0xc5, 0x85, + 0x40, 0xe9, 0x78, 0x0f, 0x9f, 0xc1, 0xbd, 0x15, 0xb1, 0x91, 0x5d, 0xa8, 0x1b, 0xf4, 0x1c, 0x9d, + 0x9a, 0x32, 0x7d, 0x1b, 0x8a, 0x1c, 0xb0, 0x7a, 0x7f, 0xd9, 0x50, 0x4f, 0x6d, 0x67, 0xa1, 0x4b, + 0xfa, 0xb0, 0x9d, 0xad, 0x3a, 0xd2, 0xae, 0xdc, 0x7f, 0x7a, 0x92, 0xb7, 0xef, 0x57, 0xef, 0xc6, + 0x74, 0x82, 0xbf, 0x32, 0x8c, 0x6a, 0x1f, 0x90, 0xfb, 0x4b, 0xd3, 0xbb, 0x58, 0x46, 0xed, 0x83, + 0x6a, 0xe1, 0x12, 0x4f, 0x10, 0x54, 0xf1, 0xe4, 0x8b, 0xa5, 0x8a, 0xa7, 0xb4, 0x51, 0x18, 0x38, + 0xc5, 0x8e, 0x1e, 0xca, 0x04, 0xf9, 0x84, 0x1c, 0x2c, 0xbd, 0xe1, 0xd2, 0x02, 0x6f, 0x7f, 0x50, + 0x7a, 0x68, 0x3d, 0xb1, 0x5e, 0x7e, 0xfa, 0xf7, 0x75, 0xc7, 0x7a, 0x7f, 0xdd, 0xb1, 0xfe, 0xbd, + 0xee, 0x58, 0xbf, 0xdd, 0x74, 0x6a, 0xef, 0x6f, 0x3a, 0xb5, 0x7f, 0x6e, 0x3a, 0xb5, 0xef, 0xdb, + 0xab, 0xff, 0xf5, 0x3b, 0xdf, 0xd4, 0x7f, 0x8e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x96, + 0xb3, 0xaa, 0x1f, 0x0a, 0x00, 0x00, } func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { @@ -1582,6 +1591,13 @@ func (m *SpacePushRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Credential) > 0 { + i -= len(m.Credential) + copy(dAtA[i:], m.Credential) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.Credential))) + i-- + dAtA[i] = 0x12 + } if m.Payload != nil { { size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) @@ -2276,6 +2292,10 @@ func (m *SpacePushRequest) Size() (n int) { l = m.Payload.Size() n += 1 + l + sovSpacesync(uint64(l)) } + l = len(m.Credential) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } return n } @@ -3363,6 +3383,40 @@ func (m *SpacePushRequest) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Credential", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSpacesync + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Credential = append(m.Credential[:0], dAtA[iNdEx:postIndex]...) + if m.Credential == nil { + m.Credential = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSpacesync(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index aa246870..b6b6931e 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -9,6 +9,7 @@ import ( reflect "reflect" app "github.com/anytypeio/any-sync/app" + treechangeproto "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" coordinatorproto "github.com/anytypeio/any-sync/coordinator/coordinatorproto" gomock "github.com/golang/mock/gomock" ) @@ -36,6 +37,20 @@ func (m *MockCoordinatorClient) EXPECT() *MockCoordinatorClientMockRecorder { return m.recorder } +// ChangeStatus mocks base method. +func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeStatus", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChangeStatus indicates an expected call of ChangeStatus. +func (mr *MockCoordinatorClientMockRecorder) ChangeStatus(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeStatus", reflect.TypeOf((*MockCoordinatorClient)(nil).ChangeStatus), arg0, arg1, arg2) +} + // FileLimitCheck mocks base method. func (m *MockCoordinatorClient) FileLimitCheck(arg0 context.Context, arg1 string, arg2 []byte) (uint64, error) { m.ctrl.T.Helper() @@ -80,16 +95,31 @@ func (mr *MockCoordinatorClientMockRecorder) Name() *gomock.Call { } // SpaceSign mocks base method. -func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceReceiptWithSignature, error) { +func (m *MockCoordinatorClient) SpaceSign(arg0 context.Context, arg1 string, arg2 []byte) (*coordinatorproto.SpaceReceiptWithSignature, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1) + ret := m.ctrl.Call(m, "SpaceSign", arg0, arg1, arg2) ret0, _ := ret[0].(*coordinatorproto.SpaceReceiptWithSignature) ret1, _ := ret[1].(error) return ret0, ret1 } // SpaceSign indicates an expected call of SpaceSign. -func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceSign", reflect.TypeOf((*MockCoordinatorClient)(nil).SpaceSign), arg0, arg1, arg2) +} + +// StatusCheck mocks base method. +func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusCheckResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StatusCheck", arg0, arg1) + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusCheckResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StatusCheck indicates an expected call of StatusCheck. +func (mr *MockCoordinatorClientMockRecorder) StatusCheck(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StatusCheck", reflect.TypeOf((*MockCoordinatorClient)(nil).StatusCheck), arg0, arg1) } diff --git a/nodeconf/mock_nodeconf/mock_nodeconf.go b/nodeconf/mock_nodeconf/mock_nodeconf.go index a403da04..b8b2e800 100644 --- a/nodeconf/mock_nodeconf/mock_nodeconf.go +++ b/nodeconf/mock_nodeconf/mock_nodeconf.go @@ -157,6 +157,20 @@ func (mr *MockConfigurationMockRecorder) ConsensusPeers() *gomock.Call { 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() From cda401356d726a46aa7258986915137c17a03a44 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 22:40:56 +0100 Subject: [PATCH 12/57] Simplify cred provider logic --- .../credentialprovider/credentialprovider.go | 20 ++++++++----- .../mock_credentialprovider.go | 29 ------------------- commonspace/spaceservice.go | 7 ++++- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/commonspace/credentialprovider/credentialprovider.go b/commonspace/credentialprovider/credentialprovider.go index 04641be9..14f7f653 100644 --- a/commonspace/credentialprovider/credentialprovider.go +++ b/commonspace/credentialprovider/credentialprovider.go @@ -6,28 +6,35 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" "github.com/anytypeio/any-sync/coordinator/coordinatorclient" - "github.com/anytypeio/any-sync/nodeconf" "github.com/gogo/protobuf/proto" ) const CName = "common.commonspace.credentialprovider" -func New() CredentialProvider { +func New() app.Component { return &credentialProvider{} } +func NewNoOp() CredentialProvider { + return &noOpProvider{} +} + type CredentialProvider interface { - app.Component GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) } +type noOpProvider struct { +} + +func (n noOpProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { + return nil, nil +} + type credentialProvider struct { - conf nodeconf.Service client coordinatorclient.CoordinatorClient } func (c *credentialProvider) Init(a *app.App) (err error) { - c.conf = a.MustComponent(nodeconf.CName).(nodeconf.Service) c.client = a.MustComponent(coordinatorclient.CName).(coordinatorclient.CoordinatorClient) return } @@ -37,9 +44,6 @@ func (c *credentialProvider) Name() (name string) { } func (c *credentialProvider) GetCredential(ctx context.Context, spaceHeader *spacesyncproto.RawSpaceHeaderWithId) ([]byte, error) { - if c.conf.GetLast().IsResponsible(spaceHeader.Id) { - return nil, nil - } receipt, err := c.client.SpaceSign(ctx, spaceHeader.Id, spaceHeader.RawHeader) if err != nil { return nil, err diff --git a/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go index 8a39d925..daa3ccab 100644 --- a/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go +++ b/commonspace/credentialprovider/mock_credentialprovider/mock_credentialprovider.go @@ -8,7 +8,6 @@ import ( context "context" reflect "reflect" - app "github.com/anytypeio/any-sync/app" spacesyncproto "github.com/anytypeio/any-sync/commonspace/spacesyncproto" gomock "github.com/golang/mock/gomock" ) @@ -50,31 +49,3 @@ func (mr *MockCredentialProviderMockRecorder) GetCredential(arg0, arg1 interface mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCredential", reflect.TypeOf((*MockCredentialProvider)(nil).GetCredential), arg0, arg1) } - -// Init mocks base method. -func (m *MockCredentialProvider) Init(arg0 *app.App) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Init", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// Init indicates an expected call of Init. -func (mr *MockCredentialProviderMockRecorder) Init(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockCredentialProvider)(nil).Init), arg0) -} - -// Name mocks base method. -func (m *MockCredentialProvider) Name() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Name") - ret0, _ := ret[0].(string) - return ret0 -} - -// Name indicates an expected call of Name. -func (mr *MockCredentialProviderMockRecorder) Name() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockCredentialProvider)(nil).Name)) -} diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 42de938a..d10fb35b 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -58,7 +58,12 @@ func (s *spaceService) Init(a *app.App) (err error) { s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service) s.treeGetter = a.MustComponent(treegetter.CName).(treegetter.TreeGetter) s.peermanagerProvider = a.MustComponent(peermanager.CName).(peermanager.PeerManagerProvider) - s.credentialProvider = a.MustComponent(credentialprovider.CName).(credentialprovider.CredentialProvider) + credProvider := a.Component(credentialprovider.CName) + if credProvider != nil { + s.credentialProvider = credProvider.(credentialprovider.CredentialProvider) + } else { + s.credentialProvider = credentialprovider.NewNoOp() + } s.pool = a.MustComponent(pool.CName).(pool.Pool) return nil } From 3f48831e8bd37c1cf2756ac2f8a08b923dd7635d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 2 Mar 2023 23:28:46 +0100 Subject: [PATCH 13/57] Fix spacestorage --- commonspace/spacestorage/spacestorage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commonspace/spacestorage/spacestorage.go b/commonspace/spacestorage/spacestorage.go index 9b0008fc..ff24d316 100644 --- a/commonspace/spacestorage/spacestorage.go +++ b/commonspace/spacestorage/spacestorage.go @@ -86,7 +86,7 @@ func ValidateSpaceHeader(spaceId string, header, identity []byte) (err error) { return } payload := &spacesyncproto.SpaceHeader{} - err = proto.Unmarshal(raw.SpaceHeader, raw) + err = proto.Unmarshal(raw.SpaceHeader, payload) if err != nil { return } From 3ea11abb56e91092f27e757eded3bc2702a66304 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 3 Mar 2023 23:10:05 +0100 Subject: [PATCH 14/57] Update status method --- .../coordinatorclient/coordinatorclient.go | 21 +- .../coordinatorproto/coordinator.pb.go | 433 ++++++++++++++---- .../coordinatorproto/protos/coordinator.proto | 16 +- 3 files changed, 363 insertions(+), 107 deletions(-) diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index 03852795..627bba1b 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -17,8 +17,8 @@ func New() CoordinatorClient { } type CoordinatorClient interface { - ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (err error) - StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusCheckResponse, err error) + ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) + StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) SpaceSign(ctx context.Context, spaceId string, spaceHeader []byte) (receipt *coordinatorproto.SpaceReceiptWithSignature, err error) FileLimitCheck(ctx context.Context, spaceId string, identity []byte) (limit uint64, err error) app.Component @@ -29,27 +29,36 @@ type coordinatorClient struct { nodeConf nodeconf.Service } -func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (err error) { +func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, deleteRaw *treechangeproto.RawTreeChangeWithId) (status *coordinatorproto.SpaceStatusPayload, err error) { cl, err := c.client(ctx) if err != nil { return } - _, err = cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{ + resp, err := cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{ SpaceId: spaceId, DeletionChangeId: deleteRaw.Id, DeletionChangePayload: deleteRaw.RawChange, }) + if err != nil { + return + } + status = resp.Payload return } -func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (response *coordinatorproto.SpaceStatusCheckResponse, err error) { +func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (status *coordinatorproto.SpaceStatusPayload, err error) { cl, err := c.client(ctx) if err != nil { return } - return cl.SpaceStatusCheck(ctx, &coordinatorproto.SpaceStatusCheckRequest{ + resp, err := cl.SpaceStatusCheck(ctx, &coordinatorproto.SpaceStatusCheckRequest{ SpaceId: spaceId, }) + if err != nil { + return + } + status = resp.Payload + return } func (c *coordinatorClient) Init(a *app.App) (err error) { diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index 4e7e5d6f..b638938c 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -105,6 +105,58 @@ func (m *SpaceSignRequest) GetHeader() []byte { return nil } +type SpaceStatusPayload struct { + Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` + DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` +} + +func (m *SpaceStatusPayload) Reset() { *m = SpaceStatusPayload{} } +func (m *SpaceStatusPayload) String() string { return proto.CompactTextString(m) } +func (*SpaceStatusPayload) ProtoMessage() {} +func (*SpaceStatusPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{1} +} +func (m *SpaceStatusPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SpaceStatusPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SpaceStatusPayload.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 *SpaceStatusPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_SpaceStatusPayload.Merge(m, src) +} +func (m *SpaceStatusPayload) XXX_Size() int { + return m.Size() +} +func (m *SpaceStatusPayload) XXX_DiscardUnknown() { + xxx_messageInfo_SpaceStatusPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_SpaceStatusPayload proto.InternalMessageInfo + +func (m *SpaceStatusPayload) GetStatus() SpaceStatus { + if m != nil { + return m.Status + } + return SpaceStatus_SpaceStatusCreated +} + +func (m *SpaceStatusPayload) GetDeletionTimestamp() int64 { + if m != nil { + return m.DeletionTimestamp + } + return 0 +} + type SpaceSignResponse struct { Receipt *SpaceReceiptWithSignature `protobuf:"bytes,1,opt,name=receipt,proto3" json:"receipt,omitempty"` } @@ -113,7 +165,7 @@ func (m *SpaceSignResponse) Reset() { *m = SpaceSignResponse{} } func (m *SpaceSignResponse) String() string { return proto.CompactTextString(m) } func (*SpaceSignResponse) ProtoMessage() {} func (*SpaceSignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{1} + return fileDescriptor_d94f6f99586adae2, []int{2} } func (m *SpaceSignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -159,7 +211,7 @@ func (m *SpaceReceiptWithSignature) Reset() { *m = SpaceReceiptWithSigna func (m *SpaceReceiptWithSignature) String() string { return proto.CompactTextString(m) } func (*SpaceReceiptWithSignature) ProtoMessage() {} func (*SpaceReceiptWithSignature) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{2} + return fileDescriptor_d94f6f99586adae2, []int{3} } func (m *SpaceReceiptWithSignature) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -220,7 +272,7 @@ func (m *SpaceReceipt) Reset() { *m = SpaceReceipt{} } func (m *SpaceReceipt) String() string { return proto.CompactTextString(m) } func (*SpaceReceipt) ProtoMessage() {} func (*SpaceReceipt) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{3} + return fileDescriptor_d94f6f99586adae2, []int{4} } func (m *SpaceReceipt) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -295,7 +347,7 @@ func (m *FileLimitCheckRequest) Reset() { *m = FileLimitCheckRequest{} } func (m *FileLimitCheckRequest) String() string { return proto.CompactTextString(m) } func (*FileLimitCheckRequest) ProtoMessage() {} func (*FileLimitCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{4} + return fileDescriptor_d94f6f99586adae2, []int{5} } func (m *FileLimitCheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -347,7 +399,7 @@ func (m *FileLimitCheckResponse) Reset() { *m = FileLimitCheckResponse{} func (m *FileLimitCheckResponse) String() string { return proto.CompactTextString(m) } func (*FileLimitCheckResponse) ProtoMessage() {} func (*FileLimitCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{5} + return fileDescriptor_d94f6f99586adae2, []int{6} } func (m *FileLimitCheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -392,7 +444,7 @@ func (m *SpaceStatusCheckRequest) Reset() { *m = SpaceStatusCheckRequest func (m *SpaceStatusCheckRequest) String() string { return proto.CompactTextString(m) } func (*SpaceStatusCheckRequest) ProtoMessage() {} func (*SpaceStatusCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{6} + return fileDescriptor_d94f6f99586adae2, []int{7} } func (m *SpaceStatusCheckRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -428,17 +480,16 @@ func (m *SpaceStatusCheckRequest) GetSpaceId() string { return "" } -// SpaceStatusCheckResponse contains the status and deletion timestamp if needed +// SpaceStatusCheckResponse contains the current status of space type SpaceStatusCheckResponse struct { - Status SpaceStatus `protobuf:"varint,1,opt,name=status,proto3,enum=coordinator.SpaceStatus" json:"status,omitempty"` - DeletionTimestamp int64 `protobuf:"varint,2,opt,name=deletionTimestamp,proto3" json:"deletionTimestamp,omitempty"` + Payload *SpaceStatusPayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` } func (m *SpaceStatusCheckResponse) Reset() { *m = SpaceStatusCheckResponse{} } func (m *SpaceStatusCheckResponse) String() string { return proto.CompactTextString(m) } func (*SpaceStatusCheckResponse) ProtoMessage() {} func (*SpaceStatusCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{7} + return fileDescriptor_d94f6f99586adae2, []int{8} } func (m *SpaceStatusCheckResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -467,18 +518,11 @@ func (m *SpaceStatusCheckResponse) XXX_DiscardUnknown() { var xxx_messageInfo_SpaceStatusCheckResponse proto.InternalMessageInfo -func (m *SpaceStatusCheckResponse) GetStatus() SpaceStatus { +func (m *SpaceStatusCheckResponse) GetPayload() *SpaceStatusPayload { if m != nil { - return m.Status + return m.Payload } - return SpaceStatus_SpaceStatusCreated -} - -func (m *SpaceStatusCheckResponse) GetDeletionTimestamp() int64 { - if m != nil { - return m.DeletionTimestamp - } - return 0 + return nil } // SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise @@ -492,7 +536,7 @@ func (m *SpaceStatusChangeRequest) Reset() { *m = SpaceStatusChangeReque func (m *SpaceStatusChangeRequest) String() string { return proto.CompactTextString(m) } func (*SpaceStatusChangeRequest) ProtoMessage() {} func (*SpaceStatusChangeRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{8} + return fileDescriptor_d94f6f99586adae2, []int{9} } func (m *SpaceStatusChangeRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -542,15 +586,16 @@ func (m *SpaceStatusChangeRequest) GetDeletionChangePayload() []byte { return nil } -// SpaceStatusChangeResponse is always empty, you should check error in case something was wrong +// SpaceStatusChangeResponse contains changed status of space type SpaceStatusChangeResponse struct { + Payload *SpaceStatusPayload `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` } func (m *SpaceStatusChangeResponse) Reset() { *m = SpaceStatusChangeResponse{} } func (m *SpaceStatusChangeResponse) String() string { return proto.CompactTextString(m) } func (*SpaceStatusChangeResponse) ProtoMessage() {} func (*SpaceStatusChangeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{9} + return fileDescriptor_d94f6f99586adae2, []int{10} } func (m *SpaceStatusChangeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -579,9 +624,17 @@ func (m *SpaceStatusChangeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_SpaceStatusChangeResponse proto.InternalMessageInfo +func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { + if m != nil { + return m.Payload + } + return nil +} + func init() { proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") + proto.RegisterType((*SpaceStatusPayload)(nil), "coordinator.SpaceStatusPayload") proto.RegisterType((*SpaceSignResponse)(nil), "coordinator.SpaceSignResponse") proto.RegisterType((*SpaceReceiptWithSignature)(nil), "coordinator.SpaceReceiptWithSignature") proto.RegisterType((*SpaceReceipt)(nil), "coordinator.SpaceReceipt") @@ -598,45 +651,47 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 604 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x55, 0x41, 0x6f, 0x12, 0x41, - 0x14, 0x66, 0x81, 0xd2, 0xf0, 0x20, 0x95, 0x8e, 0x16, 0x57, 0xac, 0x1b, 0xb2, 0x6a, 0x43, 0x1a, - 0x43, 0x1b, 0xaa, 0x9e, 0x8d, 0x6d, 0x4c, 0x30, 0xc6, 0x34, 0x8b, 0x8d, 0x51, 0x0f, 0x66, 0xba, - 0xfb, 0x02, 0x93, 0x2e, 0x3b, 0xeb, 0xee, 0x60, 0x52, 0x13, 0xff, 0x83, 0x27, 0x7f, 0x8d, 0x3f, - 0xc0, 0x63, 0x8f, 0x1e, 0x0d, 0xfc, 0x0a, 0x6f, 0x86, 0xd9, 0x5d, 0x98, 0x85, 0x05, 0x2e, 0xc0, - 0x7c, 0xdf, 0xfb, 0xde, 0x7b, 0x33, 0xef, 0x9b, 0x01, 0x9e, 0xd9, 0x9c, 0x07, 0x0e, 0xf3, 0xa8, - 0xe0, 0xc1, 0x91, 0xf2, 0xdb, 0x0f, 0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6, 0x2d, 0xf0, 0x09, 0xd1, 0x13, 0x34, 0x98, 0xea, 0xf3, 0x0b, 0x79, 0x25, 0x8f, 0x4e, - 0xad, 0xd0, 0xf9, 0x97, 0x87, 0xca, 0xe9, 0x7c, 0x0c, 0xe4, 0x35, 0x94, 0x67, 0xaf, 0x00, 0x79, - 0x90, 0x31, 0xa1, 0xf9, 0x1b, 0xd3, 0x30, 0x56, 0xd1, 0xf1, 0xc0, 0x3f, 0xc0, 0x4e, 0xda, 0x71, - 0xc4, 0x4c, 0x29, 0x32, 0xbd, 0xde, 0x78, 0xb8, 0x36, 0x26, 0x4e, 0xfd, 0x39, 0x79, 0xf2, 0xe6, - 0x3e, 0x23, 0x8f, 0x56, 0xf9, 0x29, 0x95, 0xfe, 0xf1, 0x86, 0xa8, 0xb8, 0xc0, 0x65, 0xf2, 0x1a, - 0x2a, 0x33, 0x23, 0x6b, 0xb4, 0x8a, 0xd7, 0x1a, 0x07, 0x9b, 0xc2, 0xa2, 0x1a, 0x2f, 0x9f, 0xff, - 0x1e, 0x1b, 0xda, 0xcd, 0xd8, 0xd0, 0xfe, 0x8e, 0x0d, 0xed, 0xc7, 0xc4, 0xc8, 0xdd, 0x4c, 0x8c, - 0xdc, 0x9f, 0x89, 0x91, 0xfb, 0xb8, 0xbf, 0xee, 0x5f, 0xe1, 0xb2, 0x24, 0xbf, 0x4e, 0xfe, 0x07, - 0x00, 0x00, 0xff, 0xff, 0x9a, 0xc2, 0x98, 0x37, 0x3c, 0x06, 0x00, 0x00, + // 630 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcd, 0x6e, 0x13, 0x3d, + 0x14, 0xcd, 0xa4, 0x7f, 0xca, 0x4d, 0xd5, 0x2f, 0xf5, 0x47, 0xcb, 0x10, 0x95, 0xa1, 0x32, 0x50, + 0x45, 0x15, 0x6a, 0xab, 0x14, 0x90, 0xd8, 0x21, 0x5a, 0x21, 0x15, 0x21, 0x84, 0x5c, 0x02, 0x02, + 0x16, 0xc8, 0x1d, 0x5b, 0x89, 0xd5, 0xc9, 0x78, 0x98, 0x71, 0x90, 0xba, 0xe0, 0x1d, 0x58, 0xf1, + 0x34, 0x3c, 0x00, 0xcb, 0x2e, 0x59, 0xa2, 0xe4, 0x29, 0xd8, 0xa1, 0x78, 0x3c, 0x89, 0x27, 0x99, + 0x24, 0x0b, 0x36, 0x49, 0x7c, 0xce, 0xbd, 0xe7, 0x1e, 0x5f, 0x5f, 0x3b, 0xf0, 0xc8, 0x97, 0x32, + 0x66, 0x22, 0xa4, 0x4a, 0xc6, 0x87, 0xd6, 0xef, 0x28, 0x96, 0x4a, 0x1e, 0xea, 0xcf, 0xc4, 0xc6, + 0x0f, 0x34, 0x84, 0xaa, 0x16, 0x84, 0x4f, 0xa1, 0x76, 0x1e, 0x51, 0x9f, 0x9f, 0x8b, 0x76, 0x48, + 0xf8, 0xe7, 0x1e, 0x4f, 0x14, 0x72, 0x61, 0x2d, 0x19, 0x62, 0x67, 0xcc, 0x75, 0x76, 0x9d, 0x46, + 0x85, 0x64, 0x4b, 0xb4, 0x0d, 0xab, 0x1d, 0x4e, 0x19, 0x8f, 0xdd, 0xf2, 0xae, 0xd3, 0x58, 0x27, + 0x66, 0x85, 0x15, 0xa0, 0x54, 0x45, 0x51, 0xd5, 0x4b, 0x5e, 0xd3, 0xab, 0x40, 0x52, 0x86, 0x8e, + 0x60, 0x35, 0xd1, 0x80, 0x96, 0xd9, 0x68, 0xba, 0x07, 0xb6, 0x19, 0x2b, 0x81, 0x98, 0x38, 0xf4, + 0x00, 0x36, 0x19, 0x0f, 0xb8, 0x12, 0x32, 0x7c, 0x23, 0xba, 0x3c, 0x51, 0xb4, 0x1b, 0xe9, 0x52, + 0x4b, 0x64, 0x9a, 0xc0, 0x2d, 0xd8, 0xb4, 0xbc, 0x27, 0x91, 0x0c, 0x13, 0x8e, 0x9e, 0xc2, 0x5a, +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 0x73, 0xdd, 0xf7, 0x9c, + 0xdf, 0x7d, 0xcf, 0xf9, 0x36, 0xf0, 0x4a, 0xd7, 0x03, 0xaf, 0xf4, 0x6b, 0xe0, 0x95, 0x3e, 0xec, + 0xcc, 0xfb, 0x87, 0xba, 0x58, 0xd5, 0x5f, 0xc7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x70, + 0x9d, 0x63, 0xc8, 0x06, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { @@ -676,6 +731,39 @@ func (m *SpaceSignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *SpaceStatusPayload) 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 *SpaceStatusPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SpaceStatusPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.DeletionTimestamp != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.DeletionTimestamp)) + i-- + dAtA[i] = 0x10 + } + if m.Status != 0 { + i = encodeVarintCoordinator(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *SpaceSignResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -919,15 +1007,17 @@ func (m *SpaceStatusCheckResponse) MarshalToSizedBuffer(dAtA []byte) (int, error _ = i var l int _ = l - if m.DeletionTimestamp != 0 { - i = encodeVarintCoordinator(dAtA, i, uint64(m.DeletionTimestamp)) + if m.Payload != nil { + { + size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } i-- - dAtA[i] = 0x10 - } - if m.Status != 0 { - i = encodeVarintCoordinator(dAtA, i, uint64(m.Status)) - i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -996,6 +1086,18 @@ func (m *SpaceStatusChangeResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l + if m.Payload != nil { + { + size, err := m.Payload.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCoordinator(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } return len(dAtA) - i, nil } @@ -1027,6 +1129,21 @@ func (m *SpaceSignRequest) Size() (n int) { return n } +func (m *SpaceStatusPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Status != 0 { + n += 1 + sovCoordinator(uint64(m.Status)) + } + if m.DeletionTimestamp != 0 { + n += 1 + sovCoordinator(uint64(m.DeletionTimestamp)) + } + return n +} + func (m *SpaceSignResponse) Size() (n int) { if m == nil { return 0 @@ -1133,11 +1250,9 @@ func (m *SpaceStatusCheckResponse) Size() (n int) { } var l int _ = l - if m.Status != 0 { - n += 1 + sovCoordinator(uint64(m.Status)) - } - if m.DeletionTimestamp != 0 { - n += 1 + sovCoordinator(uint64(m.DeletionTimestamp)) + if m.Payload != nil { + l = m.Payload.Size() + n += 1 + l + sovCoordinator(uint64(l)) } return n } @@ -1169,6 +1284,10 @@ func (m *SpaceStatusChangeResponse) Size() (n int) { } var l int _ = l + if m.Payload != nil { + l = m.Payload.Size() + n += 1 + l + sovCoordinator(uint64(l)) + } return n } @@ -1294,6 +1413,94 @@ func (m *SpaceSignRequest) Unmarshal(dAtA []byte) error { } return nil } +func (m *SpaceStatusPayload) 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: SpaceStatusPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SpaceStatusPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= SpaceStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DeletionTimestamp", wireType) + } + m.DeletionTimestamp = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCoordinator + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DeletionTimestamp |= int64(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 *SpaceSignResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1996,10 +2203,10 @@ func (m *SpaceStatusCheckResponse) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) } - m.Status = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowCoordinator @@ -2009,30 +2216,28 @@ func (m *SpaceStatusCheckResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Status |= SpaceStatus(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DeletionTimestamp", wireType) + if msglen < 0 { + return ErrInvalidLengthCoordinator } - m.DeletionTimestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCoordinator - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.DeletionTimestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCoordinator } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Payload == nil { + m.Payload = &SpaceStatusPayload{} + } + if err := m.Payload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) @@ -2231,6 +2436,42 @@ func (m *SpaceStatusChangeResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: SpaceStatusChangeResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", 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 + } + if m.Payload == nil { + m.Payload = &SpaceStatusPayload{} + } + if err := m.Payload.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCoordinator(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 3d8a6959..4e2c2777 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -32,6 +32,11 @@ enum SpaceStatus { SpaceStatusDeleted = 3; } +message SpaceStatusPayload { + SpaceStatus status = 1; + int64 deletionTimestamp = 2; +} + message SpaceSignResponse { SpaceReceiptWithSignature receipt = 1; } @@ -73,10 +78,9 @@ message SpaceStatusCheckRequest { string spaceId = 1; } -// SpaceStatusCheckResponse contains the status and deletion timestamp if needed +// SpaceStatusCheckResponse contains the current status of space message SpaceStatusCheckResponse { - SpaceStatus status = 1; - int64 deletionTimestamp = 2; + SpaceStatusPayload payload = 1; } // SpaceStatusChangeRequest contains the deletionChange if we want to delete space, or it is empty otherwise @@ -86,5 +90,7 @@ message SpaceStatusChangeRequest { bytes deletionChangePayload = 3; } -// SpaceStatusChangeResponse is always empty, you should check error in case something was wrong -message SpaceStatusChangeResponse {} +// SpaceStatusChangeResponse contains changed status of space +message SpaceStatusChangeResponse { + SpaceStatusPayload payload = 1; +} From 3895dc8e1446aaa3d268ab9c27d86c697eab1d53 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sat, 4 Mar 2023 12:10:32 +0100 Subject: [PATCH 15/57] Add errors to coordinator proto --- .../coordinatorproto/coordinator.pb.go | 126 ++++++++++++------ coordinator/coordinatorproto/errors.go | 16 +++ .../coordinatorproto/protos/coordinator.proto | 9 ++ 3 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 coordinator/coordinatorproto/errors.go diff --git a/coordinator/coordinatorproto/coordinator.pb.go b/coordinator/coordinatorproto/coordinator.pb.go index b638938c..d35c7b8a 100644 --- a/coordinator/coordinatorproto/coordinator.pb.go +++ b/coordinator/coordinatorproto/coordinator.pb.go @@ -22,6 +22,43 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type ErrorCodes int32 + +const ( + ErrorCodes_Unexpected ErrorCodes = 0 + ErrorCodes_SpaceDeleted ErrorCodes = 1 + ErrorCodes_SpaceDeletionPending ErrorCodes = 2 + ErrorCodes_SpaceCreated ErrorCodes = 3 + ErrorCodes_SpaceNotExists ErrorCodes = 4 + ErrorCodes_ErrorOffset ErrorCodes = 300 +) + +var ErrorCodes_name = map[int32]string{ + 0: "Unexpected", + 1: "SpaceDeleted", + 2: "SpaceDeletionPending", + 3: "SpaceCreated", + 4: "SpaceNotExists", + 300: "ErrorOffset", +} + +var ErrorCodes_value = map[string]int32{ + "Unexpected": 0, + "SpaceDeleted": 1, + "SpaceDeletionPending": 2, + "SpaceCreated": 3, + "SpaceNotExists": 4, + "ErrorOffset": 300, +} + +func (x ErrorCodes) String() string { + return proto.EnumName(ErrorCodes_name, int32(x)) +} + +func (ErrorCodes) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_d94f6f99586adae2, []int{0} +} + type SpaceStatus int32 const ( @@ -50,7 +87,7 @@ func (x SpaceStatus) String() string { } func (SpaceStatus) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_d94f6f99586adae2, []int{0} + return fileDescriptor_d94f6f99586adae2, []int{1} } type SpaceSignRequest struct { @@ -632,6 +669,7 @@ func (m *SpaceStatusChangeResponse) GetPayload() *SpaceStatusPayload { } func init() { + proto.RegisterEnum("coordinator.ErrorCodes", ErrorCodes_name, ErrorCodes_value) proto.RegisterEnum("coordinator.SpaceStatus", SpaceStatus_name, SpaceStatus_value) proto.RegisterType((*SpaceSignRequest)(nil), "coordinator.SpaceSignRequest") proto.RegisterType((*SpaceStatusPayload)(nil), "coordinator.SpaceStatusPayload") @@ -651,47 +689,51 @@ func init() { } var fileDescriptor_d94f6f99586adae2 = []byte{ - // 630 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcd, 0x6e, 0x13, 0x3d, - 0x14, 0xcd, 0xa4, 0x7f, 0xca, 0x4d, 0xd5, 0x2f, 0xf5, 0x47, 0xcb, 0x10, 0x95, 0xa1, 0x32, 0x50, - 0x45, 0x15, 0x6a, 0xab, 0x14, 0x90, 0xd8, 0x21, 0x5a, 0x21, 0x15, 0x21, 0x84, 0x5c, 0x02, 0x02, - 0x16, 0xc8, 0x1d, 0x5b, 0x89, 0xd5, 0xc9, 0x78, 0x98, 0x71, 0x90, 0xba, 0xe0, 0x1d, 0x58, 0xf1, - 0x34, 0x3c, 0x00, 0xcb, 0x2e, 0x59, 0xa2, 0xe4, 0x29, 0xd8, 0xa1, 0x78, 0x3c, 0x89, 0x27, 0x99, - 0x24, 0x0b, 0x36, 0x49, 0x7c, 0xce, 0xbd, 0xe7, 0x1e, 0x5f, 0x5f, 0x3b, 0xf0, 0xc8, 0x97, 0x32, - 0x66, 0x22, 0xa4, 0x4a, 0xc6, 0x87, 0xd6, 0xef, 0x28, 0x96, 0x4a, 0x1e, 0xea, 0xcf, 0xc4, 0xc6, - 0x0f, 0x34, 0x84, 0xaa, 0x16, 0x84, 0x4f, 0xa1, 0x76, 0x1e, 0x51, 0x9f, 0x9f, 0x8b, 0x76, 0x48, - 0xf8, 0xe7, 0x1e, 0x4f, 0x14, 0x72, 0x61, 0x2d, 0x19, 0x62, 0x67, 0xcc, 0x75, 0x76, 0x9d, 0x46, - 0x85, 0x64, 0x4b, 0xb4, 0x0d, 0xab, 0x1d, 0x4e, 0x19, 0x8f, 0xdd, 0xf2, 0xae, 0xd3, 0x58, 0x27, - 0x66, 0x85, 0x15, 0xa0, 0x54, 0x45, 0x51, 0xd5, 0x4b, 0x5e, 0xd3, 0xab, 0x40, 0x52, 0x86, 0x8e, - 0x60, 0x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 0xd4, - 0xef, 0xce, 0x8d, 0x31, 0xd2, 0x9f, 0xb2, 0xe7, 0x77, 0x3c, 0x7d, 0xe8, 0xde, 0xac, 0x9e, 0xe7, - 0xe4, 0xef, 0x2f, 0x88, 0x32, 0x05, 0x2e, 0xb2, 0x37, 0xd2, 0x3a, 0x6e, 0x34, 0x27, 0xd7, 0x1a, - 0xd3, 0xfa, 0xde, 0xa2, 0xb0, 0xb4, 0xc6, 0xb3, 0xc7, 0x3f, 0xfb, 0x9e, 0x73, 0xdd, 0xf7, 0x9c, - 0xdf, 0x7d, 0xcf, 0xf9, 0x36, 0xf0, 0x4a, 0xd7, 0x03, 0xaf, 0xf4, 0x6b, 0xe0, 0x95, 0x3e, 0xec, - 0xcc, 0xfb, 0x87, 0xba, 0x58, 0xd5, 0x5f, 0xc7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x70, - 0x9d, 0x63, 0xc8, 0x06, 0x00, 0x00, + // 704 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x4d, 0x4f, 0x13, 0x4f, + 0x18, 0xef, 0xb6, 0x05, 0xd2, 0xa7, 0xa4, 0xff, 0x65, 0xfe, 0x80, 0x6b, 0x83, 0x2b, 0x59, 0x95, + 0x34, 0xc4, 0x00, 0x29, 0x6a, 0xe2, 0xcd, 0x58, 0x30, 0xc1, 0x18, 0x24, 0x8b, 0xd5, 0xa8, 0x07, + 0xb3, 0xec, 0x3e, 0xc0, 0x84, 0x65, 0x67, 0xdd, 0x99, 0x1a, 0x38, 0x98, 0xf8, 0x11, 0x3c, 0xf9, + 0x29, 0xfc, 0x08, 0x7e, 0x00, 0x8f, 0x1c, 0x3d, 0x1a, 0xf8, 0x14, 0xde, 0xcc, 0xbe, 0x4c, 0x3b, + 0xdb, 0x6e, 0xcb, 0xc1, 0x0b, 0x74, 0x7e, 0xcf, 0xcb, 0xef, 0xf7, 0xbc, 0xcc, 0x2c, 0x3c, 0x74, + 0x19, 0x8b, 0x3c, 0x1a, 0x38, 0x82, 0x45, 0xeb, 0xca, 0xef, 0x30, 0x62, 0x82, 0xad, 0x27, 0x7f, + 0xb9, 0x8a, 0xaf, 0x25, 0x10, 0xa9, 0x2b, 0x90, 0xb5, 0x05, 0xfa, 0x7e, 0xe8, 0xb8, 0xb8, 0x4f, + 0x8f, 0x02, 0x1b, 0x3f, 0xf6, 0x90, 0x0b, 0x62, 0xc0, 0x0c, 0x8f, 0xb1, 0x1d, 0xcf, 0xd0, 0x96, + 0xb5, 0x56, 0xcd, 0x96, 0x47, 0xb2, 0x08, 0xd3, 0xc7, 0xe8, 0x78, 0x18, 0x19, 0xe5, 0x65, 0xad, + 0x35, 0x6b, 0x67, 0x27, 0x4b, 0x00, 0x49, 0xb3, 0x08, 0x47, 0xf4, 0xf8, 0x9e, 0x73, 0xee, 0x33, + 0xc7, 0x23, 0x1b, 0x30, 0xcd, 0x13, 0x20, 0x49, 0xd3, 0x68, 0x1b, 0x6b, 0xaa, 0x18, 0x25, 0xc0, + 0xce, 0xfc, 0xc8, 0x7d, 0x98, 0xf3, 0xd0, 0x47, 0x41, 0x59, 0xf0, 0x8a, 0x9e, 0x22, 0x17, 0xce, + 0x69, 0x98, 0x50, 0x55, 0xec, 0x51, 0x83, 0xd5, 0x85, 0x39, 0x45, 0x3b, 0x0f, 0x59, 0xc0, 0x91, + 0x3c, 0x81, 0x99, 0x08, 0x5d, 0xa4, 0xa1, 0x48, 0x58, 0xeb, 0xed, 0x95, 0x51, 0x56, 0x3b, 0x75, + 0x78, 0x43, 0xc5, 0x71, 0x1c, 0xeb, 0x88, 0x5e, 0x84, 0xb6, 0x0c, 0xb3, 0x4e, 0xe0, 0xe6, 0x58, + 0x2f, 0xb2, 0x01, 0xff, 0x73, 0xc5, 0x98, 0x95, 0x9a, 0x50, 0xcd, 0xda, 0x45, 0x26, 0xb2, 0x04, + 0x35, 0x2e, 0x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, 0x46, 0x70, + 0x20, 0x9f, 0x69, 0x65, 0xe3, 0xc8, 0x84, 0x58, 0xe5, 0xa6, 0x34, 0x57, 0xae, 0x73, 0x4b, 0x39, + 0x9e, 0x3e, 0xfa, 0x79, 0x69, 0x6a, 0x17, 0x97, 0xa6, 0xf6, 0xfb, 0xd2, 0xd4, 0xbe, 0x5e, 0x99, + 0xa5, 0x8b, 0x2b, 0xb3, 0xf4, 0xeb, 0xca, 0x2c, 0xbd, 0x5b, 0x9a, 0xf4, 0x91, 0x3c, 0x98, 0x4e, + 0xfe, 0x6d, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xe4, 0x76, 0x96, 0x0f, 0x4b, 0x07, 0x00, 0x00, } func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { diff --git a/coordinator/coordinatorproto/errors.go b/coordinator/coordinatorproto/errors.go new file mode 100644 index 00000000..1fb41a2c --- /dev/null +++ b/coordinator/coordinatorproto/errors.go @@ -0,0 +1,16 @@ +package coordinatorproto + +import ( + "errors" + "github.com/anytypeio/any-sync/net/rpc/rpcerr" +) + +var ( + errGroup = rpcerr.ErrGroup(ErrorCodes_ErrorOffset) + + ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrorCodes_Unexpected)) + ErrSpaceIsCreated = errGroup.Register(errors.New("space is missing"), uint64(ErrorCodes_SpaceCreated)) + ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrorCodes_SpaceDeleted)) + ErrSpaceDeletionPending = errGroup.Register(errors.New("space is set out for deletion"), uint64(ErrorCodes_SpaceDeletionPending)) + ErrSpaceNotExists = errGroup.Register(errors.New("space not exists"), uint64(ErrorCodes_SpaceNotExists)) +) diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index 4e2c2777..b828740c 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -25,6 +25,15 @@ message SpaceSignRequest { bytes header = 2; } +enum ErrorCodes { + Unexpected = 0; + SpaceDeleted = 1; + SpaceDeletionPending = 2; + SpaceCreated = 3; + SpaceNotExists = 4; + ErrorOffset = 300; +} + enum SpaceStatus { SpaceStatusCreated = 0; SpaceStatusPendingDeletion = 1; From 58f01da459ab9679ce7679b5f39aaa9165e34c28 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 6 Mar 2023 09:31:27 +0100 Subject: [PATCH 16/57] Add safe access in case no delete change provided --- coordinator/coordinatorclient/coordinatorclient.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index 627bba1b..9ebdcb9b 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -36,8 +36,8 @@ func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, de } resp, err := cl.SpaceStatusChange(ctx, &coordinatorproto.SpaceStatusChangeRequest{ SpaceId: spaceId, - DeletionChangeId: deleteRaw.Id, - DeletionChangePayload: deleteRaw.RawChange, + DeletionChangeId: deleteRaw.GetId(), + DeletionChangePayload: deleteRaw.GetRawChange(), }) if err != nil { return From e1f6dad499d41ad0816b33cda12ec9b4540e2f0d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 6 Mar 2023 09:41:45 +0100 Subject: [PATCH 17/57] Add error unwrapping --- coordinator/coordinatorclient/coordinatorclient.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/coordinator/coordinatorclient/coordinatorclient.go b/coordinator/coordinatorclient/coordinatorclient.go index 9ebdcb9b..7e490268 100644 --- a/coordinator/coordinatorclient/coordinatorclient.go +++ b/coordinator/coordinatorclient/coordinatorclient.go @@ -7,6 +7,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/coordinator/coordinatorproto" "github.com/anytypeio/any-sync/net/pool" + "github.com/anytypeio/any-sync/net/rpc/rpcerr" "github.com/anytypeio/any-sync/nodeconf" ) @@ -40,6 +41,7 @@ func (c *coordinatorClient) ChangeStatus(ctx context.Context, spaceId string, de DeletionChangePayload: deleteRaw.GetRawChange(), }) if err != nil { + err = rpcerr.Unwrap(err) return } status = resp.Payload @@ -55,6 +57,7 @@ func (c *coordinatorClient) StatusCheck(ctx context.Context, spaceId string) (st SpaceId: spaceId, }) if err != nil { + err = rpcerr.Unwrap(err) return } status = resp.Payload @@ -81,6 +84,7 @@ func (c *coordinatorClient) SpaceSign(ctx context.Context, spaceId string, space Header: spaceHeader, }) if err != nil { + err = rpcerr.Unwrap(err) return } return resp.Receipt, nil @@ -96,6 +100,7 @@ func (c *coordinatorClient) FileLimitCheck(ctx context.Context, spaceId string, SpaceId: spaceId, }) if err != nil { + err = rpcerr.Unwrap(err) return } return resp.Limit, nil From 998f631ee82d6ace33d43ca759954d342905efbc Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 6 Mar 2023 11:08:27 +0100 Subject: [PATCH 18/57] Update diffsyncer to directly sync settings tree --- commonspace/headsync/diffsyncer.go | 4 ++++ commonspace/headsync/diffsyncer_test.go | 17 ++++++++++++++++- commonspace/objectsync/objectsync.go | 12 +++++++++--- commonspace/spaceservice.go | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/commonspace/headsync/diffsyncer.go b/commonspace/headsync/diffsyncer.go index 3f3f3f82..0e7d9e3f 100644 --- a/commonspace/headsync/diffsyncer.go +++ b/commonspace/headsync/diffsyncer.go @@ -121,6 +121,10 @@ func (d *diffSyncer) syncWithPeer(ctx context.Context, p peer.Peer) (err error) newIds, changedIds, removedIds, err := d.diff.Diff(ctx, rdiff) err = rpcerr.Unwrap(err) if err != nil && err != spacesyncproto.ErrSpaceMissing { + if err == spacesyncproto.ErrSpaceIsDeleted { + d.log.Debug("got space deleted while syncing") + d.syncTrees(ctx, p.Id(), []string{d.storage.SpaceSettingsId()}) + } d.syncStatus.SetNodesOnline(p.Id(), false) return fmt.Errorf("diff error: %v", err) } diff --git a/commonspace/headsync/diffsyncer_test.go b/commonspace/headsync/diffsyncer_test.go index e73eb55a..f9622ca6 100644 --- a/commonspace/headsync/diffsyncer_test.go +++ b/commonspace/headsync/diffsyncer_test.go @@ -207,7 +207,7 @@ func TestDiffSyncer_Sync(t *testing.T) { require.NoError(t, diffSyncer.Sync(ctx)) }) - t.Run("diff syncer sync other error", func(t *testing.T) { + t.Run("diff syncer sync unexpected", func(t *testing.T) { peerManagerMock.EXPECT(). GetResponsiblePeers(gomock.Any()). Return([]peer.Peer{mockPeer{}}, nil) @@ -217,4 +217,19 @@ func TestDiffSyncer_Sync(t *testing.T) { require.NoError(t, diffSyncer.Sync(ctx)) }) + + t.Run("diff syncer sync space is deleted error", func(t *testing.T) { + peerManagerMock.EXPECT(). + GetResponsiblePeers(gomock.Any()). + Return([]peer.Peer{mockPeer{}}, nil) + diffMock.EXPECT(). + Diff(gomock.Any(), gomock.Eq(NewRemoteDiff(spaceId, clientMock))). + Return(nil, nil, nil, spacesyncproto.ErrSpaceIsDeleted) + stMock.EXPECT().SpaceSettingsId().Return("settingsId") + cacheMock.EXPECT(). + GetTree(gomock.Any(), spaceId, "settingsId"). + Return(nil, nil) + + require.NoError(t, diffSyncer.Sync(ctx)) + }) } diff --git a/commonspace/objectsync/objectsync.go b/commonspace/objectsync/objectsync.go index a1f17b49..7c72e635 100644 --- a/commonspace/objectsync/objectsync.go +++ b/commonspace/objectsync/objectsync.go @@ -7,6 +7,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/syncobjectgetter" "github.com/anytypeio/any-sync/commonspace/objectsync/synchandler" "github.com/anytypeio/any-sync/commonspace/peermanager" + "github.com/anytypeio/any-sync/commonspace/spacestorage" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" "github.com/anytypeio/any-sync/nodeconf" "go.uber.org/zap" @@ -32,6 +33,7 @@ type objectSync struct { messagePool MessagePool objectGetter syncobjectgetter.SyncObjectGetter configuration nodeconf.Configuration + spaceStorage spacestorage.SpaceStorage syncCtx context.Context cancelSync context.CancelFunc @@ -43,13 +45,15 @@ func NewObjectSync( spaceIsDeleted *atomic.Bool, configuration nodeconf.Configuration, peerManager peermanager.PeerManager, - objectGetter syncobjectgetter.SyncObjectGetter) ObjectSync { + objectGetter syncobjectgetter.SyncObjectGetter, + storage spacestorage.SpaceStorage) ObjectSync { syncCtx, cancel := context.WithCancel(context.Background()) os := newObjectSync( spaceId, spaceIsDeleted, configuration, objectGetter, + storage, syncCtx, cancel) msgPool := newMessagePool(peerManager, os.handleMessage) @@ -62,11 +66,13 @@ func newObjectSync( spaceIsDeleted *atomic.Bool, configuration nodeconf.Configuration, objectGetter syncobjectgetter.SyncObjectGetter, + spaceStorage spacestorage.SpaceStorage, syncCtx context.Context, cancel context.CancelFunc, ) *objectSync { return &objectSync{ objectGetter: objectGetter, + spaceStorage: spaceStorage, spaceId: spaceId, syncCtx: syncCtx, cancelSync: cancel, @@ -95,8 +101,8 @@ func (s *objectSync) handleMessage(ctx context.Context, senderId string, msg *sp log := log.With(zap.String("objectId", msg.ObjectId), zap.String("replyId", msg.ReplyId)) if s.spaceIsDeleted.Load() { log = log.With(zap.Bool("isDeleted", true)) - // preventing sync with other clients - if !slices.Contains(s.configuration.NodeIds(s.spaceId), senderId) { + // preventing sync with other clients if they are not just syncing the settings tree + if !slices.Contains(s.configuration.NodeIds(s.spaceId), senderId) && msg.ObjectId != s.spaceStorage.SpaceSettingsId() { return spacesyncproto.ErrSpaceIsDeleted } } diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index d10fb35b..89e9283b 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -148,7 +148,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { } headSync := headsync.NewHeadSync(id, spaceIsDeleted, s.config.SyncPeriod, lastConfiguration, st, peerManager, getter, syncStatus, s.credentialProvider, log) - objectSync := objectsync.NewObjectSync(id, spaceIsDeleted, lastConfiguration, peerManager, getter) + objectSync := objectsync.NewObjectSync(id, spaceIsDeleted, lastConfiguration, peerManager, getter, st) sp := &space{ id: id, objectSync: objectSync, From 61cd658ab08f97742cd32d86d5edcb1c72209180 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 6 Mar 2023 14:29:07 +0100 Subject: [PATCH 19/57] Add todo --- commonspace/headsync/diffsyncer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/commonspace/headsync/diffsyncer.go b/commonspace/headsync/diffsyncer.go index 0e7d9e3f..9d3434c1 100644 --- a/commonspace/headsync/diffsyncer.go +++ b/commonspace/headsync/diffsyncer.go @@ -90,6 +90,7 @@ func (d *diffSyncer) UpdateHeads(id string, heads []string) { } func (d *diffSyncer) Sync(ctx context.Context) error { + // TODO: split diffsyncer into components st := time.Now() // diffing with responsible peers according to configuration peers, err := d.peerManager.GetResponsiblePeers(ctx) From 6a1c3d27f8481bea5d50287f68fdbc4b698441ae Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 6 Mar 2023 19:08:16 +0100 Subject: [PATCH 20/57] Add strkey for string encoding --- util/crc16/crc16.go | 122 ++++++++++++++++++++++++++++++++++++++++ util/strkey/strkey.go | 117 ++++++++++++++++++++++++++++++++++++++ util/strkey/versions.go | 7 +++ 3 files changed, 246 insertions(+) create mode 100644 util/crc16/crc16.go create mode 100644 util/strkey/strkey.go create mode 100644 util/strkey/versions.go diff --git a/util/crc16/crc16.go b/util/crc16/crc16.go new file mode 100644 index 00000000..810f4bed --- /dev/null +++ b/util/crc16/crc16.go @@ -0,0 +1,122 @@ +// Package crc16 is implementation according to CCITT standards. +// +// Note by @antirez: this is actually the XMODEM CRC 16 algorithm, using the +// following parameters: +// +// Name : "XMODEM", also known as "ZMODEM", "CRC-16/ACORN" +// Width : 16 bit +// Poly : 1021 (That is actually x^16 + x^12 + x^5 + 1) +// Initialization : 0000 +// Reflect Input byte : False +// Reflect Output CRC : False +// Xor constant to output CRC : 0000 +// Output for "123456789" : 31C3 +// +// ported from the c++ code in the stellar-core codebase +// (https://github.com/stellar/stellar-core). The code is licensed +// as: +/* + * Copyright 2001-2010 Georges Menie (www.menie.org) + * Copyright 2010-2012 Salvatore Sanfilippo (adapted to Redis coding style) + * Copyright 2015 Stellar Development Foundation (ported to go) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the University of California, Berkeley nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package crc16 + +import ( + "bytes" + "encoding/binary" + "fmt" +) + +// ErrInvalidChecksum is returned when Validate determines either the checksum +// or the payload has been corrupted +var ErrInvalidChecksum = fmt.Errorf("invalid checksum") + +var crc16tab = [256]uint16{ + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, +} + +// Checksum returns the 2-byte checksum for the provided data +func Checksum(data []byte) []byte { + var crc uint16 + var out bytes.Buffer + for _, b := range data { + crc = ((crc << 8) & 0xffff) ^ crc16tab[((crc>>8)^uint16(b))&0x00FF] + } + + err := binary.Write(&out, binary.LittleEndian, crc) + if err != nil { + panic(err) + } + + return out.Bytes() +} + +// Validate returns an error if the provided checksum does not match +// the calculated checksum of the provided data +func Validate(data []byte, expected []byte) error { + + actual := Checksum(data) + + // validate the provided checksum against the calculated + if !bytes.Equal(actual, expected) { + return ErrInvalidChecksum + } + + return nil +} diff --git a/util/strkey/strkey.go b/util/strkey/strkey.go new file mode 100644 index 00000000..c6dcfc3b --- /dev/null +++ b/util/strkey/strkey.go @@ -0,0 +1,117 @@ +package strkey + +import ( + "bytes" + "encoding/binary" + "fmt" + "github.com/anytypeio/any-sync/util/crc16" + + "github.com/mr-tron/base58/base58" +) + +// ErrInvalidVersionByte is returned when the version byte from a provided +// strkey-encoded string is not one of the valid values. +var ErrInvalidVersionByte = fmt.Errorf("invalid version byte") + +// VersionByte represents one of the possible prefix values for a StrKey base +// string--the string the when encoded using base58 yields a final StrKey. +type VersionByte byte + +// Decode decodes the provided StrKey into a raw value, checking the checksum +// and ensuring the expected VersionByte (the version parameter) is the value +// actually encoded into the provided src string. +func Decode(expected VersionByte, src string) ([]byte, error) { + raw, err := decodeString(src) + if err != nil { + return nil, err + } + + // decode into components + version := VersionByte(raw[0]) + vp := raw[0 : len(raw)-2] + payload := raw[1 : len(raw)-2] + checksum := raw[len(raw)-2:] + + // ensure version byte is expected + if version != expected { + return nil, ErrInvalidVersionByte + } + + // ensure checksum is valid + if err := crc16.Validate(vp, checksum); err != nil { + return nil, err + } + + // if we made it through the gaunlet, return the decoded value + return payload, nil +} + +// MustDecode is like Decode, but panics on error +func MustDecode(expected VersionByte, src string) []byte { + d, err := Decode(expected, src) + if err != nil { + panic(err) + } + return d +} + +// Encode encodes the provided data to a StrKey, using the provided version +// byte. +func Encode(version VersionByte, src []byte) (string, error) { + var raw bytes.Buffer + + // write version byte + if err := binary.Write(&raw, binary.LittleEndian, version); err != nil { + return "", err + } + + // write payload + if _, err := raw.Write(src); err != nil { + return "", err + } + + // calculate and write checksum + checksum := crc16.Checksum(raw.Bytes()) + if _, err := raw.Write(checksum); err != nil { + return "", err + } + + result := base58.FastBase58Encoding(raw.Bytes()) + return result, nil +} + +// MustEncode is like Encode, but panics on error +func MustEncode(version VersionByte, src []byte) string { + e, err := Encode(version, src) + if err != nil { + panic(err) + } + return e +} + +// Version extracts and returns the version byte from the provided source +// string. +func Version(src string) (VersionByte, error) { + raw, err := decodeString(src) + if err != nil { + return VersionByte(0), err + } + + return VersionByte(raw[0]), nil +} + +// decodeString decodes a base58 string into the raw bytes, and ensures it could +// potentially be strkey encoded (i.e. it has both a version byte and a +// checksum, neither of which are explicitly checked by this func) +func decodeString(src string) ([]byte, error) { + raw, err := base58.FastBase58Decoding(src) + if err != nil { + return nil, fmt.Errorf("base58 decode failed: %s", err) + } + + if len(raw) < 3 { + return nil, fmt.Errorf("encoded value is %d bytes; minimum valid length is 3", len(raw)) + } + + return raw, nil +} diff --git a/util/strkey/versions.go b/util/strkey/versions.go new file mode 100644 index 00000000..d59becdf --- /dev/null +++ b/util/strkey/versions.go @@ -0,0 +1,7 @@ +package strkey + +const ( + AccountAddressVersionByte VersionByte = 0x5b // Base58-encodes to 'A...' + AccountSeedVersionByte VersionByte = 0xff // Base58-encodes to 'S...' + DeviceSeedVersionByte VersionByte = 0x7d // Base58-encodes to 'D...' +) From 0314ea11033f10dcec094be4036205981fb21a4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:09:36 +0000 Subject: [PATCH 21/57] Bump golang.org/x/net from 0.7.0 to 0.8.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.7.0 to 0.8.0. - [Release notes](https://github.com/golang/net/releases) - [Commits](https://github.com/golang/net/compare/v0.7.0...v0.8.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 6c2d9fec..6753ba9b 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/zeebo/errs v1.3.0 go.uber.org/zap v1.24.0 golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 - golang.org/x/net v0.7.0 + golang.org/x/net v0.8.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/yaml.v3 v3.0.1 storj.io/drpc v0.0.32 @@ -99,7 +99,7 @@ require ( golang.org/x/crypto v0.4.0 // indirect golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.5.0 // indirect + golang.org/x/sys v0.6.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/protobuf v1.28.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect diff --git a/go.sum b/go.sum index 4528855f..f3c1449f 100644 --- a/go.sum +++ b/go.sum @@ -576,8 +576,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -647,8 +647,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= From e043c84cae58152b336af275498efc3f013cdfe2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 18:09:49 +0000 Subject: [PATCH 22/57] Bump github.com/ipfs/go-unixfs from 0.4.3 to 0.4.4 Bumps [github.com/ipfs/go-unixfs](https://github.com/ipfs/go-unixfs) from 0.4.3 to 0.4.4. - [Release notes](https://github.com/ipfs/go-unixfs/releases) - [Commits](https://github.com/ipfs/go-unixfs/compare/v0.4.3...v0.4.4) --- updated-dependencies: - dependency-name: github.com/ipfs/go-unixfs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6c2d9fec..af98255e 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/ipfs/go-ipfs-exchange-interface v0.2.0 github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-merkledag v0.10.0 - github.com/ipfs/go-unixfs v0.4.3 + github.com/ipfs/go-unixfs v0.4.4 github.com/libp2p/go-libp2p v0.24.1 github.com/minio/sha256-simd v1.0.0 github.com/multiformats/go-multibase v0.1.1 diff --git a/go.sum b/go.sum index 4528855f..cdb544ed 100644 --- a/go.sum +++ b/go.sum @@ -253,8 +253,8 @@ github.com/ipfs/go-merkledag v0.10.0/go.mod h1:zkVav8KiYlmbzUzNM6kENzkdP5+qR7+2m 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-unixfs v0.4.3 h1:EdDc1sNZNFDUlo4UrVAvvAofVI5EwTnKu8Nv8mgXkWQ= -github.com/ipfs/go-unixfs v0.4.3/go.mod h1:TSG7G1UuT+l4pNj91raXAPkX0BhJi3jST1FDTfQ5QyM= +github.com/ipfs/go-unixfs v0.4.4 h1:D/dLBOJgny5ZLIur2vIXVQVW0EyDHdOMBDEhgHrt6rY= +github.com/ipfs/go-unixfs v0.4.4/go.mod h1:TSG7G1UuT+l4pNj91raXAPkX0BhJi3jST1FDTfQ5QyM= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG5Wb4xnPU= github.com/ipld/go-codec-dagpb v1.6.0 h1:9nYazfyu9B1p3NAgfVdpRco3Fs2nFC72DqVsMj6rOcc= From d4c19f790de568c96406efec11f6370a4344141b Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Mon, 6 Mar 2023 22:25:43 +0100 Subject: [PATCH 23/57] add an ability to set levels separately for named loggers with glob support --- app/logger/config.go | 40 ++++++++++++++----- app/logger/log.go | 93 ++++++++++++++++++++++++++++++++++++-------- go.mod | 3 +- go.sum | 2 + 4 files changed, 110 insertions(+), 28 deletions(-) diff --git a/app/logger/config.go b/app/logger/config.go index 2f3547ce..7906312c 100644 --- a/app/logger/config.go +++ b/app/logger/config.go @@ -1,11 +1,17 @@ package logger -import "go.uber.org/zap" +import ( + "go.uber.org/zap" + + "github.com/anytypeio/any-sync/util/slice" +) type Config struct { - Production bool `yaml:"production"` - DefaultLevel string `yaml:"defaultLevel"` - NamedLevels map[string]string `yaml:"namedLevels"` + Production bool `yaml:"production"` + DefaultLevel string `yaml:"defaultLevel"` + NamedLevels map[string]string `yaml:"namedLevels"` + AddOutputPaths []string + DisableStdErr bool } func (l Config) ApplyGlobal() { @@ -15,19 +21,33 @@ func (l Config) ApplyGlobal() { } else { conf = zap.NewDevelopmentConfig() } + if len(l.AddOutputPaths) > 0 { + conf.OutputPaths = append(conf.OutputPaths, l.AddOutputPaths...) + } + if l.DisableStdErr { + conf.OutputPaths = slice.Filter(conf.OutputPaths, func(path string) bool { + return path != "stderr" + }) + } + + var err error if defaultLevel, err := zap.ParseAtomicLevel(l.DefaultLevel); err == nil { conf.Level = defaultLevel } - var levels = make(map[string]zap.AtomicLevel) + var lvl = make(map[string]zap.AtomicLevel) for k, v := range l.NamedLevels { - if lev, err := zap.ParseAtomicLevel(v); err != nil { - levels[k] = lev + if lev, err := zap.ParseAtomicLevel(v); err == nil { + lvl[k] = lev + // we need to have a minimum level of all named loggers for the main logger + if lev.Level() < conf.Level.Level() { + conf.Level.SetLevel(lev.Level()) + } } } - defaultLogger, err := conf.Build() + lg, err := conf.Build() if err != nil { Default().Fatal("can't build logger", zap.Error(err)) } - SetDefault(defaultLogger) - SetNamedLevels(levels) + SetDefault(lg) + SetNamedLevels(lvl) } diff --git a/app/logger/log.go b/app/logger/log.go index 028c9988..ce09c3cd 100644 --- a/app/logger/log.go +++ b/app/logger/log.go @@ -1,51 +1,110 @@ package logger import ( - "go.uber.org/zap" "sync" + + "github.com/gobwas/glob" + "go.uber.org/zap" ) var ( - mu sync.Mutex - defaultLogger *zap.Logger - levels = make(map[string]zap.AtomicLevel) - loggers = make(map[string]CtxLogger) + mu sync.Mutex + logger *zap.Logger + loggerConfig zap.Config + namedLevels = make(map[string]zap.AtomicLevel) + namedGlobs = make(map[string]glob.Glob) + namedLoggers = make(map[string]CtxLogger) ) func init() { - defaultLogger, _ = zap.NewDevelopment() - zap.NewProduction() + loggerConfig = zap.NewDevelopmentConfig() + logger, _ = loggerConfig.Build() } +// SetDefault replaces the default logger +// you need to call SetNamedLevels after in case you have named loggers, +// otherwise they will use the old logger func SetDefault(l *zap.Logger) { mu.Lock() defer mu.Unlock() - *defaultLogger = *l - for name, l := range loggers { - *l.Logger = *defaultLogger.Named(name) - } + *logger = *l } +// SetNamedLevels sets the namedLevels for named loggers +// it also supports glob patterns for names, like "app*" +// can be racy in case there are existing named loggers +// so consider to call only once at the beginning func SetNamedLevels(l map[string]zap.AtomicLevel) { mu.Lock() defer mu.Unlock() - levels = l + namedLevels = l + + var minLevel = logger.Level() + for k, l := range namedLevels { + g, err := glob.Compile(k) + if err == nil { + namedGlobs[k] = g + } + namedLevels[k] = l + if l.Level() < minLevel { + minLevel = l.Level() + } + } + + if minLevel < logger.Level() { + // recreate logger if the min level is lower than the current min one + loggerConfig.Level = zap.NewAtomicLevelAt(minLevel) + logger, _ = loggerConfig.Build() + } + + for name, lg := range namedLoggers { + level := getLevel(name) + // this can be racy, but + lg.Logger = zap.New(logger.Core()).WithOptions( + zap.IncreaseLevel(level), + ).Named(name) + } } func Default() *zap.Logger { mu.Lock() defer mu.Unlock() - return defaultLogger + return logger +} + +func getLevel(name string) zap.AtomicLevel { + level, ok := namedLevels[name] + if !ok { + var found bool + for globName, glob := range namedGlobs { + if glob.Match(name) { + found = true + level, _ = namedLevels[globName] + // no need to check ok, because we know that globName exists + break + } + } + if !found { + level = loggerConfig.Level + } + } + return level } func NewNamed(name string, fields ...zap.Field) CtxLogger { mu.Lock() defer mu.Unlock() - l := defaultLogger.Named(name) - if len(fields) > 0 { - l = l.With(fields...) + + if l, nameExists := namedLoggers[name]; nameExists { + return l } + + level := getLevel(name) + l := zap.New(logger.Core()).WithOptions( + zap.IncreaseLevel(level), + ).Named(name) + ctxL := CtxLogger{l} - loggers[name] = ctxL + namedLoggers[name] = ctxL return ctxL } diff --git a/go.mod b/go.mod index a4c42fac..1c763027 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/awalterschulze/gographviz v2.0.3+incompatible github.com/cespare/xxhash v1.1.0 github.com/cheggaaa/mb/v3 v3.0.1 + github.com/gobwas/glob v0.2.3 github.com/goccy/go-graphviz v0.1.0 github.com/gogo/protobuf v1.3.2 github.com/golang/mock v1.6.0 @@ -22,6 +23,7 @@ require ( github.com/ipfs/go-unixfs v0.4.4 github.com/libp2p/go-libp2p v0.24.1 github.com/minio/sha256-simd v1.0.0 + github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multibase v0.1.1 github.com/multiformats/go-multihash v0.2.1 github.com/prometheus/client_golang v1.14.0 @@ -74,7 +76,6 @@ require ( 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/mr-tron/base58 v1.2.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 diff --git a/go.sum b/go.sum index d8708cf2..1cc3b14b 100644 --- a/go.sum +++ b/go.sum @@ -106,6 +106,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/goccy/go-graphviz v0.1.0 h1:6OqQoQ5PeAiHYe/YcusyeulqBrOkUb16HQ4ctRdyVUU= github.com/goccy/go-graphviz v0.1.0/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= From 3693218fc53e319f2f8c9c212cd47ecd7edf7de6 Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Mon, 6 Mar 2023 22:26:32 +0100 Subject: [PATCH 24/57] rename logger common.commonspace.settings -> commonspace.settings --- commonspace/settings/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 920b385b..1b75e42d 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -22,7 +22,7 @@ import ( "golang.org/x/exp/slices" ) -var log = logger.NewNamed("common.commonspace.settings") +var log = logger.NewNamed("commonspace.settings") type SettingsObject interface { synctree.SyncTree From 0d4083819612745e243e6b86e07b09556359ec59 Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Tue, 7 Mar 2023 10:42:36 +0100 Subject: [PATCH 25/57] rename some loggers to the same convention --- app/logger/log.go | 4 ++-- commonspace/object/tree/synctree/synctree.go | 5 +++-- commonspace/objectsync/objectsync.go | 7 ++++--- commonspace/settings/settings.go | 5 +++-- commonspace/syncstatus/syncstatus.go | 9 +++++---- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/logger/log.go b/app/logger/log.go index ce09c3cd..264cdaf1 100644 --- a/app/logger/log.go +++ b/app/logger/log.go @@ -57,10 +57,10 @@ func SetNamedLevels(l map[string]zap.AtomicLevel) { logger, _ = loggerConfig.Build() } - for name, lg := range namedLoggers { + for name, nl := range namedLoggers { level := getLevel(name) // this can be racy, but - lg.Logger = zap.New(logger.Core()).WithOptions( + nl.Logger = zap.New(logger.Core()).WithOptions( zap.IncreaseLevel(level), ).Named(name) } diff --git a/commonspace/object/tree/synctree/synctree.go b/commonspace/object/tree/synctree/synctree.go index d9084017..f25e14d0 100644 --- a/commonspace/object/tree/synctree/synctree.go +++ b/commonspace/object/tree/synctree/synctree.go @@ -3,6 +3,7 @@ package synctree import ( "context" "errors" + "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/commonspace/object/acl/list" "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" @@ -10,7 +11,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/commonspace/objectsync" "github.com/anytypeio/any-sync/commonspace/objectsync/synchandler" - spacestorage "github.com/anytypeio/any-sync/commonspace/spacestorage" + "github.com/anytypeio/any-sync/commonspace/spacestorage" "github.com/anytypeio/any-sync/commonspace/syncstatus" "github.com/anytypeio/any-sync/net/peer" "github.com/anytypeio/any-sync/nodeconf" @@ -50,7 +51,7 @@ type syncTree struct { isDeleted bool } -var log = logger.NewNamed("commonspace.synctree") +var log = logger.NewNamed("common.commonspace.synctree") var buildObjectTree = objecttree.BuildObjectTree var createSyncClient = newSyncClient diff --git a/commonspace/objectsync/objectsync.go b/commonspace/objectsync/objectsync.go index 7c72e635..85c587d9 100644 --- a/commonspace/objectsync/objectsync.go +++ b/commonspace/objectsync/objectsync.go @@ -2,6 +2,9 @@ package objectsync import ( "context" + "sync/atomic" + "time" + "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/commonspace/object/syncobjectgetter" @@ -12,11 +15,9 @@ import ( "github.com/anytypeio/any-sync/nodeconf" "go.uber.org/zap" "golang.org/x/exp/slices" - "sync/atomic" - "time" ) -var log = logger.NewNamed("commonspace.objectsync") +var log = logger.NewNamed("common.commonspace.objectsync") type ObjectSync interface { ocache.ObjectLastUsage diff --git a/commonspace/settings/settings.go b/commonspace/settings/settings.go index 1b75e42d..453df055 100644 --- a/commonspace/settings/settings.go +++ b/commonspace/settings/settings.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/commonspace/object/keychain" @@ -14,7 +15,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" "github.com/anytypeio/any-sync/commonspace/object/treegetter" "github.com/anytypeio/any-sync/commonspace/settings/settingsstate" - spacestorage "github.com/anytypeio/any-sync/commonspace/spacestorage" + "github.com/anytypeio/any-sync/commonspace/spacestorage" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" "github.com/anytypeio/any-sync/nodeconf" "github.com/gogo/protobuf/proto" @@ -22,7 +23,7 @@ import ( "golang.org/x/exp/slices" ) -var log = logger.NewNamed("commonspace.settings") +var log = logger.NewNamed("common.commonspace.settings") type SettingsObject interface { synctree.SyncTree diff --git a/commonspace/syncstatus/syncstatus.go b/commonspace/syncstatus/syncstatus.go index b5a489a5..091988f5 100644 --- a/commonspace/syncstatus/syncstatus.go +++ b/commonspace/syncstatus/syncstatus.go @@ -3,15 +3,16 @@ package syncstatus import ( "context" "fmt" + "sync" + "time" + "github.com/anytypeio/any-sync/app/logger" - treestorage "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" + "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/commonspace/spacestorage" "github.com/anytypeio/any-sync/nodeconf" "github.com/anytypeio/any-sync/util/periodicsync" "github.com/anytypeio/any-sync/util/slice" "golang.org/x/exp/slices" - "sync" - "time" ) const ( @@ -19,7 +20,7 @@ const ( syncTimeout = time.Second ) -var log = logger.NewNamed("commonspace.syncstatus") +var log = logger.NewNamed("common.commonspace.syncstatus") type UpdateReceiver interface { UpdateTree(ctx context.Context, treeId string, status SyncStatus) (err error) From 589f885b63a9b5837cc8ea3cd6702307e9696ebb Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Tue, 7 Mar 2023 18:52:28 +0100 Subject: [PATCH 26/57] logger: add Format in config support json, color, plaintext --- app/logger/config.go | 68 +++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/app/logger/config.go b/app/logger/config.go index 7906312c..03082828 100644 --- a/app/logger/config.go +++ b/app/logger/config.go @@ -2,37 +2,71 @@ package logger import ( "go.uber.org/zap" + "go.uber.org/zap/zapcore" "github.com/anytypeio/any-sync/util/slice" ) +type LogFormat int + +const ( + ColorizedOutput LogFormat = iota + PlaintextOutput + JSONOutput +) + type Config struct { Production bool `yaml:"production"` DefaultLevel string `yaml:"defaultLevel"` NamedLevels map[string]string `yaml:"namedLevels"` - AddOutputPaths []string - DisableStdErr bool + AddOutputPaths []string `yaml:"outputPaths"` + DisableStdErr bool `yaml:"disableStdErr"` + Format LogFormat `yaml:"format"` + ZapConfig *zap.Config `yaml:"-"` // optional, if set it will be used instead of other config options } func (l Config) ApplyGlobal() { var conf zap.Config - if l.Production { - conf = zap.NewProductionConfig() + if l.ZapConfig != nil { + conf = *l.ZapConfig } else { - conf = zap.NewDevelopmentConfig() - } - if len(l.AddOutputPaths) > 0 { - conf.OutputPaths = append(conf.OutputPaths, l.AddOutputPaths...) - } - if l.DisableStdErr { - conf.OutputPaths = slice.Filter(conf.OutputPaths, func(path string) bool { - return path != "stderr" - }) - } + if l.Production { + conf = zap.NewProductionConfig() + } else { + conf = zap.NewDevelopmentConfig() + } + var encConfig zapcore.EncoderConfig + switch l.Format { + case PlaintextOutput: + encConfig.EncodeLevel = zapcore.CapitalLevelEncoder + conf.Encoding = "console" + case JSONOutput: + encConfig.MessageKey = "msg" + encConfig.TimeKey = "ts" + encConfig.LevelKey = "level" + encConfig.NameKey = "logger" + encConfig.CallerKey = "caller" + encConfig.EncodeTime = zapcore.ISO8601TimeEncoder + conf.Encoding = "json" + default: + // default is ColorizedOutput + conf.Encoding = "console" + encConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder + } - var err error - if defaultLevel, err := zap.ParseAtomicLevel(l.DefaultLevel); err == nil { - conf.Level = defaultLevel + conf.EncoderConfig = encConfig + if len(l.AddOutputPaths) > 0 { + conf.OutputPaths = append(conf.OutputPaths, l.AddOutputPaths...) + } + if l.DisableStdErr { + conf.OutputPaths = slice.Filter(conf.OutputPaths, func(path string) bool { + return path != "stderr" + }) + } + + if defaultLevel, err := zap.ParseAtomicLevel(l.DefaultLevel); err == nil { + conf.Level = defaultLevel + } } var lvl = make(map[string]zap.AtomicLevel) for k, v := range l.NamedLevels { From 7adae54f87ea498c2d7e77c59c9b3060b87b60bc Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Tue, 7 Mar 2023 19:37:21 +0100 Subject: [PATCH 27/57] fix default logger encoding config --- app/logger/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logger/config.go b/app/logger/config.go index 03082828..e882092e 100644 --- a/app/logger/config.go +++ b/app/logger/config.go @@ -35,7 +35,7 @@ func (l Config) ApplyGlobal() { } else { conf = zap.NewDevelopmentConfig() } - var encConfig zapcore.EncoderConfig + encConfig := conf.EncoderConfig switch l.Format { case PlaintextOutput: encConfig.EncodeLevel = zapcore.CapitalLevelEncoder From 07c6e8000c6adfcd5a21524d9c96f12b07397b5d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Wed, 8 Mar 2023 22:07:44 +0100 Subject: [PATCH 28/57] Add ocache tryClose --- app/ocache/ocache.go | 325 ++++++++++++++++++++------------------ app/ocache/ocache_test.go | 41 ++--- 2 files changed, 197 insertions(+), 169 deletions(-) diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index df19b220..eb67f120 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -4,6 +4,7 @@ import ( "context" "errors" "github.com/anytypeio/any-sync/app/logger" + "github.com/anytypeio/any-sync/util/slice" "go.uber.org/zap" "sync" "time" @@ -44,12 +45,6 @@ var WithGCPeriod = func(gcPeriod time.Duration) Option { } } -var WithRefCounter = func(enable bool) Option { - return func(cache *oCache) { - cache.refCounter = enable - } -} - func New(loadFunc LoadFunc, opts ...Option) OCache { c := &oCache{ data: make(map[string]*entry), @@ -73,33 +68,117 @@ func New(loadFunc LoadFunc, opts ...Option) OCache { type Object interface { Close() (err error) + TryClose() (res bool, err error) } -type ObjectLocker interface { - Object - Locked() bool -} +type entryState int -type ObjectLastUsage interface { - LastUsage() time.Time -} +const ( + entryStateLoading = iota + entryStateActive + entryStateClosing + entryStateClosed +) type entry struct { id string + state entryState lastUsage time.Time - refCount uint32 - isClosing bool load chan struct{} loadErr error value Object close chan struct{} + mx sync.Mutex } -func (e *entry) locked() bool { - if locker, ok := e.value.(ObjectLocker); ok { - return locker.Locked() +func newEntry(id string, value Object, state entryState) *entry { + return &entry{ + id: id, + load: make(chan struct{}), + lastUsage: time.Now(), + state: state, + value: value, } - return false +} + +func (e *entry) getState() entryState { + e.mx.Lock() + defer e.mx.Unlock() + return e.state +} + +func (e *entry) isClosing() bool { + e.mx.Lock() + defer e.mx.Unlock() + return e.state == entryStateClosed || e.state == entryStateClosing +} + +func (e *entry) waitLoad(ctx context.Context, id string) (value Object, err error) { + select { + case <-ctx.Done(): + log.DebugCtx(ctx, "ctx done while waiting on object load", zap.String("id", id)) + return nil, ctx.Err() + case <-e.load: + return e.value, e.loadErr + } +} + +func (e *entry) waitClose(ctx context.Context, id string) (res bool, err error) { + e.mx.Lock() + switch e.state { + case entryStateClosing: + waitCh := e.close + e.mx.Unlock() + select { + case <-ctx.Done(): + log.DebugCtx(ctx, "ctx done while waiting on object close", zap.String("id", id)) + return false, ctx.Err() + case <-waitCh: + return true, nil + } + case entryStateClosed: + e.mx.Unlock() + return true, nil + default: + e.mx.Unlock() + return false, nil + } +} + +func (e *entry) setClosing(wait bool) (prevState entryState) { + e.mx.Lock() + prevState = e.state + if e.state == entryStateClosing { + waitCh := e.close + e.mx.Unlock() + if !wait { + return + } + <-waitCh + e.mx.Lock() + } + if e.state != entryStateClosed { + e.state = entryStateClosing + e.close = make(chan struct{}) + } + e.mx.Unlock() + return +} + +func (e *entry) setActive(chClose bool) { + e.mx.Lock() + defer e.mx.Unlock() + if chClose { + close(e.close) + } + e.state = entryStateActive +} + +func (e *entry) setClosed() { + e.mx.Lock() + defer e.mx.Unlock() + close(e.close) + e.state = entryStateClosed } type OCache interface { @@ -116,10 +195,6 @@ type OCache interface { // Add adds new object to cache // Returns error when object exists Add(id string, value Object) (err error) - // Release decreases the refs counter - Release(id string) bool - // Reset sets refs counter to 0 - Reset(id string) bool // Remove closes and removes object Remove(id string) (ok bool, err error) // ForEach iterates over all loaded objects, breaks when callback returns false @@ -134,17 +209,16 @@ type OCache interface { } type oCache struct { - mu sync.Mutex - data map[string]*entry - loadFunc LoadFunc - timeNow func() time.Time - ttl time.Duration - gc time.Duration - closed bool - closeCh chan struct{} - log *zap.SugaredLogger - metrics *metrics - refCounter bool + mu sync.Mutex + data map[string]*entry + loadFunc LoadFunc + timeNow func() time.Time + ttl time.Duration + gc time.Duration + closed bool + closeCh chan struct{} + log *zap.SugaredLogger + metrics *metrics } func (c *oCache) Get(ctx context.Context, id string) (value Object, err error) { @@ -160,69 +234,46 @@ Load: return nil, ErrClosed } if e, ok = c.data[id]; !ok { + e = newEntry(id, nil, entryStateLoading) load = true - e = &entry{ - id: id, - load: make(chan struct{}), - } c.data[id] = e } - closing := e.isClosing - if !e.isClosing { - e.lastUsage = c.timeNow() - if c.refCounter { - e.refCount++ - } - } c.mu.Unlock() - if closing { - select { - case <-ctx.Done(): - log.DebugCtx(ctx, "ctx done while waiting on object close", zap.String("id", id)) - return nil, ctx.Err() - case <-e.close: - goto Load - } + reload, err := e.waitClose(ctx, id) + if err != nil { + return nil, err + } + if reload { + goto Load } - if load { go c.load(ctx, id, e) } - if c.metrics != nil { - if load { - c.metrics.miss.Inc() - } else { - c.metrics.hit.Inc() - } + c.metricsGet(!load) + return e.waitLoad(ctx, id) +} + +func (c *oCache) metricsGet(hit bool) { + if c.metrics == nil { + return } - select { - case <-ctx.Done(): - log.DebugCtx(ctx, "ctx done while waiting on object load", zap.String("id", id)) - return nil, ctx.Err() - case <-e.load: + if hit { + c.metrics.hit.Inc() + } else { + c.metrics.miss.Inc() } - return e.value, e.loadErr } func (c *oCache) Pick(ctx context.Context, id string) (value Object, err error) { c.mu.Lock() val, ok := c.data[id] - if !ok || val.isClosing { + if !ok || val.isClosing() { c.mu.Unlock() return nil, ErrNotExists } c.mu.Unlock() - - if c.metrics != nil { - c.metrics.hit.Inc() - } - - select { - case <-ctx.Done(): - return nil, ctx.Err() - case <-val.load: - return val.value, val.loadErr - } + c.metricsGet(true) + return val.waitLoad(ctx, id) } func (c *oCache) load(ctx context.Context, id string, e *entry) { @@ -236,37 +287,10 @@ func (c *oCache) load(ctx context.Context, id string, e *entry) { delete(c.data, id) } else { e.value = value + e.setActive(false) } } -func (c *oCache) Release(id string) bool { - c.mu.Lock() - defer c.mu.Unlock() - if c.closed { - return false - } - if e, ok := c.data[id]; ok { - if c.refCounter && e.refCount > 0 { - e.refCount-- - return true - } - } - return false -} - -func (c *oCache) Reset(id string) bool { - c.mu.Lock() - defer c.mu.Unlock() - if c.closed { - return false - } - if e, ok := c.data[id]; ok { - e.refCount = 0 - return true - } - return false -} - func (c *oCache) Remove(id string) (ok bool, err error) { c.mu.Lock() if c.closed { @@ -274,25 +298,33 @@ func (c *oCache) Remove(id string) (ok bool, err error) { err = ErrClosed return } - var e *entry - e, ok = c.data[id] - if !ok || e.isClosing { + e, ok := c.data[id] + if !ok { c.mu.Unlock() return } - e.isClosing = true - e.close = make(chan struct{}) c.mu.Unlock() + return c.remove(e, true) +} +func (c *oCache) remove(e *entry, remData bool) (ok bool, err error) { <-e.load - if e.value != nil { + if e.value == nil { + return false, ErrNotExists + } + prevState := e.setClosing(true) + if prevState == entryStateActive { err = e.value.Close() + e.setClosed() + } + if !remData { + return } c.mu.Lock() - close(e.close) - delete(c.data, e.id) + if prevState == entryStateActive { + delete(c.data, e.id) + } c.mu.Unlock() - return } @@ -314,13 +346,7 @@ func (c *oCache) Add(id string, value Object) (err error) { if _, ok := c.data[id]; ok { return ErrExists } - e := &entry{ - id: id, - lastUsage: time.Now(), - refCount: 0, - load: make(chan struct{}), - value: value, - } + e := newEntry(id, value, entryStateActive) close(e.load) c.data[id] = e return @@ -332,7 +358,7 @@ func (c *oCache) ForEach(f func(obj Object) (isContinue bool)) { for _, v := range c.data { select { case <-v.load: - if v.value != nil && !v.isClosing { + if v.value != nil && !v.isClosing() { objects = append(objects, v.value) } default: @@ -368,15 +394,10 @@ func (c *oCache) GC() { deadline := c.timeNow().Add(-c.ttl) var toClose []*entry for _, e := range c.data { - if e.isClosing { + if e.getState() != entryStateActive { continue } - lu := e.lastUsage - if lug, ok := e.value.(ObjectLastUsage); ok { - lu = lug.LastUsage() - } - if !e.locked() && e.refCount <= 0 && lu.Before(deadline) { - e.isClosing = true + if e.lastUsage.Before(deadline) { e.close = make(chan struct{}) toClose = append(toClose, e) } @@ -384,21 +405,33 @@ func (c *oCache) GC() { size := len(c.data) c.mu.Unlock() - for _, e := range toClose { - <-e.load - if e.value != nil { - if err := e.value.Close(); err != nil { - c.log.With("object_id", e.id).Warnf("GC: object close error: %v", err) - } + for idx, e := range toClose { + prevState := e.setClosing(false) + if prevState == entryStateClosing || prevState == entryStateClosed { + toClose[idx] = nil + continue + } + ok, err := e.value.TryClose() + if !ok { + e.setActive(true) + toClose[idx] = nil + continue + } else { + e.setClosed() + } + if err != nil { + c.log.With("object_id", e.id).Warnf("GC: object close error: %v", err) } } + toClose = slice.DiscardFromSlice(toClose, func(e *entry) bool { + return e == nil + }) c.log.Infof("GC: removed %d; cache size: %d", len(toClose), size) if len(toClose) > 0 && c.metrics != nil { c.metrics.gc.Add(float64(len(toClose))) } c.mu.Lock() for _, e := range toClose { - close(e.close) delete(c.data, e.id) } c.mu.Unlock() @@ -418,25 +451,15 @@ func (c *oCache) Close() (err error) { } c.closed = true close(c.closeCh) - var toClose, alreadyClosing []*entry + var toClose []*entry for _, e := range c.data { - if e.isClosing { - alreadyClosing = append(alreadyClosing, e) - } else { - toClose = append(toClose, e) - } + toClose = append(toClose, e) } c.mu.Unlock() for _, e := range toClose { - <-e.load - if e.value != nil { - if clErr := e.value.Close(); clErr != nil { - c.log.With("object_id", e.id).Warnf("cache close: object close error: %v", clErr) - } + if _, err := c.remove(e, false); err != ErrNotExists { + c.log.With("object_id", e.id).Warnf("cache close: object close error: %v", err) } } - for _, e := range alreadyClosing { - <-e.close - } return nil } diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 54034141..d32b01f7 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -12,15 +12,17 @@ import ( ) type testObject struct { - name string - closeErr error - closeCh chan struct{} + name string + closeErr error + closeCh chan struct{} + tryReturn bool } -func NewTestObject(name string, closeCh chan struct{}) *testObject { +func NewTestObject(name string, tryReturn bool, closeCh chan struct{}) *testObject { return &testObject{ - name: name, - closeCh: closeCh, + name: name, + closeCh: closeCh, + tryReturn: tryReturn, } } @@ -31,6 +33,14 @@ func (t *testObject) Close() (err error) { return t.closeErr } +func (t *testObject) TryClose() (res bool, err error) { + if t.closeCh != nil { + <-t.closeCh + return true, t.closeErr + } + return t.tryReturn, nil +} + func TestOCache_Get(t *testing.T) { t.Run("successful", func(t *testing.T) { c := New(func(ctx context.Context, id string) (value Object, err error) { @@ -118,8 +128,8 @@ func TestOCache_Get(t *testing.T) { func TestOCache_GC(t *testing.T) { t.Run("test without close wait", func(t *testing.T) { c := New(func(ctx context.Context, id string) (value Object, err error) { - return &testObject{name: id}, nil - }, WithTTL(time.Millisecond*10), WithRefCounter(true)) + return NewTestObject(id, true, nil), nil + }, WithTTL(time.Millisecond*10)) val, err := c.Get(context.TODO(), "id") require.NoError(t, err) require.NotNil(t, val) @@ -128,24 +138,19 @@ func TestOCache_GC(t *testing.T) { assert.Equal(t, 1, c.Len()) time.Sleep(time.Millisecond * 30) c.GC() - assert.Equal(t, 1, c.Len()) - assert.True(t, c.Release("id")) - c.GC() assert.Equal(t, 0, c.Len()) - assert.False(t, c.Release("id")) }) t.Run("test with close wait", func(t *testing.T) { closeCh := make(chan struct{}) getCh := make(chan struct{}) c := New(func(ctx context.Context, id string) (value Object, err error) { - return NewTestObject(id, closeCh), nil - }, WithTTL(time.Millisecond*10), WithRefCounter(true)) + return NewTestObject(id, true, closeCh), nil + }, WithTTL(time.Millisecond*10)) val, err := c.Get(context.TODO(), "id") require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - assert.True(t, c.Release("id")) // making ttl pass time.Sleep(time.Millisecond * 40) // first gc will be run after 20 secs, so calling it manually @@ -160,9 +165,9 @@ func TestOCache_GC(t *testing.T) { events = append(events, "get") close(getCh) }() - events = append(events, "close") // sleeping to make sure that Get is called time.Sleep(time.Millisecond * 40) + events = append(events, "close") close(closeCh) <-getCh @@ -175,7 +180,7 @@ func Test_OCache_Remove(t *testing.T) { getCh := make(chan struct{}) c := New(func(ctx context.Context, id string) (value Object, err error) { - return NewTestObject(id, closeCh), nil + return NewTestObject(id, false, closeCh), nil }, WithTTL(time.Millisecond*10)) val, err := c.Get(context.TODO(), "id") require.NoError(t, err) @@ -196,9 +201,9 @@ func Test_OCache_Remove(t *testing.T) { events = append(events, "get") close(getCh) }() - events = append(events, "close") // sleeping to make sure that Get is called time.Sleep(time.Millisecond * 40) + events = append(events, "close") close(closeCh) <-getCh From 65496d247ff8237b926d40acdf878540241198ba Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Wed, 8 Mar 2023 22:52:43 +0100 Subject: [PATCH 29/57] Test returning to cache after tryclose --- app/ocache/ocache_test.go | 64 ++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index d32b01f7..8d963214 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -3,6 +3,7 @@ package ocache import ( "context" "errors" + "sync" "sync/atomic" "testing" "time" @@ -12,10 +13,12 @@ import ( ) type testObject struct { - name string - closeErr error - closeCh chan struct{} - tryReturn bool + name string + closeErr error + closeCh chan struct{} + tryReturn bool + closeCalled bool + tryCloseCalled bool } func NewTestObject(name string, tryReturn bool, closeCh chan struct{}) *testObject { @@ -27,6 +30,7 @@ func NewTestObject(name string, tryReturn bool, closeCh chan struct{}) *testObje } func (t *testObject) Close() (err error) { + t.closeCalled = true if t.closeCh != nil { <-t.closeCh } @@ -34,6 +38,7 @@ func (t *testObject) Close() (err error) { } func (t *testObject) TryClose() (res bool, err error) { + t.tryCloseCalled = true if t.closeCh != nil { <-t.closeCh return true, t.closeErr @@ -126,7 +131,7 @@ func TestOCache_Get(t *testing.T) { } func TestOCache_GC(t *testing.T) { - t.Run("test without close wait", func(t *testing.T) { + t.Run("test gc expired object", func(t *testing.T) { c := New(func(ctx context.Context, id string) (value Object, err error) { return NewTestObject(id, true, nil), nil }, WithTTL(time.Millisecond*10)) @@ -140,7 +145,7 @@ func TestOCache_GC(t *testing.T) { c.GC() assert.Equal(t, 0, c.Len()) }) - t.Run("test with close wait", func(t *testing.T) { + t.Run("test gc tryClose true, close before get", func(t *testing.T) { closeCh := make(chan struct{}) getCh := make(chan struct{}) @@ -173,15 +178,60 @@ func TestOCache_GC(t *testing.T) { <-getCh require.Equal(t, []string{"close", "get"}, events) }) + t.Run("test gc tryClose false, many get", func(t *testing.T) { + timesCalled := &atomic.Int32{} + obj := NewTestObject("id", false, nil) + c := New(func(ctx context.Context, id string) (value Object, err error) { + timesCalled.Add(1) + return obj, nil + }, WithTTL(time.Millisecond*10)) + + val, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + require.NotNil(t, val) + assert.Equal(t, 1, c.Len()) + // making ttl pass + time.Sleep(time.Millisecond * 40) + // first gc will be run after 20 secs, so calling it manually + begin := make(chan struct{}) + wg := sync.WaitGroup{} + once := sync.Once{} + + wg.Add(1) + go func() { + <-begin + c.GC() + wg.Done() + }() + + for i := 0; i < 5; i++ { + wg.Add(1) + go func(i int) { + once.Do(func() { + close(begin) + }) + if i > 0 { + time.Sleep(time.Duration(i) * time.Millisecond) + } + _, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + wg.Done() + }(i) + } + require.NoError(t, err) + wg.Wait() + require.Equal(t, timesCalled.Load(), int32(1)) + require.True(t, obj.tryCloseCalled) + }) } func Test_OCache_Remove(t *testing.T) { closeCh := make(chan struct{}) getCh := make(chan struct{}) - c := New(func(ctx context.Context, id string) (value Object, err error) { return NewTestObject(id, false, closeCh), nil }, WithTTL(time.Millisecond*10)) + val, err := c.Get(context.TODO(), "id") require.NoError(t, err) require.NotNil(t, val) From 9836caf2cb1127a0e94cb54cd8b9ed155957708d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 09:06:02 +0100 Subject: [PATCH 30/57] More tests and split entry --- app/ocache/entry.go | 120 ++++++++++++++++++++++++++++++++++++++ app/ocache/ocache.go | 118 ++----------------------------------- app/ocache/ocache_test.go | 51 +++++++++++++--- 3 files changed, 168 insertions(+), 121 deletions(-) create mode 100644 app/ocache/entry.go diff --git a/app/ocache/entry.go b/app/ocache/entry.go new file mode 100644 index 00000000..ad985fa0 --- /dev/null +++ b/app/ocache/entry.go @@ -0,0 +1,120 @@ +package ocache + +import ( + "context" + "go.uber.org/zap" + "sync" + "time" +) + +type entryState int + +const ( + entryStateLoading = iota + entryStateActive + entryStateClosing + entryStateClosed +) + +type entry struct { + id string + state entryState + lastUsage time.Time + load chan struct{} + loadErr error + value Object + close chan struct{} + mx sync.Mutex +} + +func newEntry(id string, value Object, state entryState) *entry { + return &entry{ + id: id, + load: make(chan struct{}), + lastUsage: time.Now(), + state: state, + value: value, + } +} + +func (e *entry) getState() entryState { + e.mx.Lock() + defer e.mx.Unlock() + return e.state +} + +func (e *entry) isClosing() bool { + e.mx.Lock() + defer e.mx.Unlock() + return e.state == entryStateClosed || e.state == entryStateClosing +} + +func (e *entry) waitLoad(ctx context.Context, id string) (value Object, err error) { + select { + case <-ctx.Done(): + log.DebugCtx(ctx, "ctx done while waiting on object load", zap.String("id", id)) + return nil, ctx.Err() + case <-e.load: + return e.value, e.loadErr + } +} + +func (e *entry) waitClose(ctx context.Context, id string) (res bool, err error) { + e.mx.Lock() + switch e.state { + case entryStateClosing: + waitCh := e.close + e.mx.Unlock() + select { + case <-ctx.Done(): + log.DebugCtx(ctx, "ctx done while waiting on object close", zap.String("id", id)) + return false, ctx.Err() + case <-waitCh: + return true, nil + } + case entryStateClosed: + e.mx.Unlock() + return true, nil + default: + e.mx.Unlock() + return false, nil + } +} + +func (e *entry) setClosing(wait bool) (prevState, curState entryState) { + e.mx.Lock() + prevState = e.state + curState = e.state + if e.state == entryStateClosing { + waitCh := e.close + e.mx.Unlock() + if !wait { + return + } + <-waitCh + e.mx.Lock() + } + if e.state != entryStateClosed { + e.state = entryStateClosing + e.close = make(chan struct{}) + } + curState = e.state + e.mx.Unlock() + return +} + +func (e *entry) setActive(chClose bool) { + e.mx.Lock() + defer e.mx.Unlock() + if chClose { + close(e.close) + } + e.state = entryStateActive +} + +func (e *entry) setClosed() { + e.mx.Lock() + defer e.mx.Unlock() + close(e.close) + e.state = entryStateClosed +} diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index eb67f120..4599f789 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -71,116 +71,6 @@ type Object interface { TryClose() (res bool, err error) } -type entryState int - -const ( - entryStateLoading = iota - entryStateActive - entryStateClosing - entryStateClosed -) - -type entry struct { - id string - state entryState - lastUsage time.Time - load chan struct{} - loadErr error - value Object - close chan struct{} - mx sync.Mutex -} - -func newEntry(id string, value Object, state entryState) *entry { - return &entry{ - id: id, - load: make(chan struct{}), - lastUsage: time.Now(), - state: state, - value: value, - } -} - -func (e *entry) getState() entryState { - e.mx.Lock() - defer e.mx.Unlock() - return e.state -} - -func (e *entry) isClosing() bool { - e.mx.Lock() - defer e.mx.Unlock() - return e.state == entryStateClosed || e.state == entryStateClosing -} - -func (e *entry) waitLoad(ctx context.Context, id string) (value Object, err error) { - select { - case <-ctx.Done(): - log.DebugCtx(ctx, "ctx done while waiting on object load", zap.String("id", id)) - return nil, ctx.Err() - case <-e.load: - return e.value, e.loadErr - } -} - -func (e *entry) waitClose(ctx context.Context, id string) (res bool, err error) { - e.mx.Lock() - switch e.state { - case entryStateClosing: - waitCh := e.close - e.mx.Unlock() - select { - case <-ctx.Done(): - log.DebugCtx(ctx, "ctx done while waiting on object close", zap.String("id", id)) - return false, ctx.Err() - case <-waitCh: - return true, nil - } - case entryStateClosed: - e.mx.Unlock() - return true, nil - default: - e.mx.Unlock() - return false, nil - } -} - -func (e *entry) setClosing(wait bool) (prevState entryState) { - e.mx.Lock() - prevState = e.state - if e.state == entryStateClosing { - waitCh := e.close - e.mx.Unlock() - if !wait { - return - } - <-waitCh - e.mx.Lock() - } - if e.state != entryStateClosed { - e.state = entryStateClosing - e.close = make(chan struct{}) - } - e.mx.Unlock() - return -} - -func (e *entry) setActive(chClose bool) { - e.mx.Lock() - defer e.mx.Unlock() - if chClose { - close(e.close) - } - e.state = entryStateActive -} - -func (e *entry) setClosed() { - e.mx.Lock() - defer e.mx.Unlock() - close(e.close) - e.state = entryStateClosed -} - type OCache interface { // DoLockedIfNotExists does an action if the object with id is not in cache // under a global lock, this will prevent a race which otherwise occurs @@ -312,8 +202,8 @@ func (c *oCache) remove(e *entry, remData bool) (ok bool, err error) { if e.value == nil { return false, ErrNotExists } - prevState := e.setClosing(true) - if prevState == entryStateActive { + _, curState := e.setClosing(true) + if curState == entryStateClosing { err = e.value.Close() e.setClosed() } @@ -321,7 +211,7 @@ func (c *oCache) remove(e *entry, remData bool) (ok bool, err error) { return } c.mu.Lock() - if prevState == entryStateActive { + if curState == entryStateClosing { delete(c.data, e.id) } c.mu.Unlock() @@ -406,7 +296,7 @@ func (c *oCache) GC() { c.mu.Unlock() for idx, e := range toClose { - prevState := e.setClosing(false) + prevState, _ := e.setClosing(false) if prevState == entryStateClosing || prevState == entryStateClosed { toClose[idx] = nil continue diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 8d963214..43773184 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -3,6 +3,7 @@ package ocache import ( "context" "errors" + "fmt" "sync" "sync/atomic" "testing" @@ -178,7 +179,7 @@ func TestOCache_GC(t *testing.T) { <-getCh require.Equal(t, []string{"close", "get"}, events) }) - t.Run("test gc tryClose false, many get", func(t *testing.T) { + t.Run("test gc tryClose false, many parallel get", func(t *testing.T) { timesCalled := &atomic.Int32{} obj := NewTestObject("id", false, nil) c := New(func(ctx context.Context, id string) (value Object, err error) { @@ -190,9 +191,7 @@ func TestOCache_GC(t *testing.T) { require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - // making ttl pass time.Sleep(time.Millisecond * 40) - // first gc will be run after 20 secs, so calling it manually begin := make(chan struct{}) wg := sync.WaitGroup{} once := sync.Once{} @@ -203,15 +202,14 @@ func TestOCache_GC(t *testing.T) { c.GC() wg.Done() }() - - for i := 0; i < 5; i++ { + for i := 0; i < 50; i++ { wg.Add(1) go func(i int) { once.Do(func() { close(begin) }) - if i > 0 { - time.Sleep(time.Duration(i) * time.Millisecond) + if i%2 != 0 { + time.Sleep(time.Millisecond) } _, err := c.Get(context.TODO(), "id") require.NoError(t, err) @@ -223,6 +221,45 @@ func TestOCache_GC(t *testing.T) { require.Equal(t, timesCalled.Load(), int32(1)) require.True(t, obj.tryCloseCalled) }) + t.Run("test gc tryClose different, many objects", func(t *testing.T) { + tryCloseIds := make(map[string]bool) + called := make(map[string]int) + max := 1000 + getId := func(i int) string { + return fmt.Sprintf("id%d", i) + } + for i := 0; i < max; i++ { + if i%2 == 1 { + tryCloseIds[getId(i)] = true + } else { + tryCloseIds[getId(i)] = false + } + } + c := New(func(ctx context.Context, id string) (value Object, err error) { + called[id] = called[id] + 1 + return NewTestObject(id, tryCloseIds[id], nil), nil + }, WithTTL(time.Millisecond*10)) + + for i := 0; i < max; i++ { + val, err := c.Get(context.TODO(), getId(i)) + require.NoError(t, err) + require.NotNil(t, val) + } + assert.Equal(t, max, c.Len()) + time.Sleep(time.Millisecond * 40) + c.GC() + for i := 0; i < max; i++ { + val, err := c.Get(context.TODO(), getId(i)) + require.NoError(t, err) + require.NotNil(t, val) + } + for i := 0; i < max; i++ { + val, err := c.Get(context.TODO(), getId(i)) + require.NoError(t, err) + require.NotNil(t, val) + require.Equal(t, called[getId(i)], i%2+1) + } + }) } func Test_OCache_Remove(t *testing.T) { From 4fb34fcb7ca98aabe2b4c29ad3e2458c587dc78a Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 09:38:45 +0100 Subject: [PATCH 31/57] Readability improvements --- app/ocache/entry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/ocache/entry.go b/app/ocache/entry.go index ad985fa0..fbe60e26 100644 --- a/app/ocache/entry.go +++ b/app/ocache/entry.go @@ -37,10 +37,10 @@ func newEntry(id string, value Object, state entryState) *entry { } } -func (e *entry) getState() entryState { +func (e *entry) isActive() bool { e.mx.Lock() defer e.mx.Unlock() - return e.state + return e.state == entryStateActive } func (e *entry) isClosing() bool { From 63ba0a9fab3b40c05bae6a571a5f8d8fba5eb284 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 20:25:01 +0100 Subject: [PATCH 32/57] Update cache logic to remove from entries on close --- app/ocache/ocache.go | 90 ++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index 4599f789..931cb431 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -4,7 +4,6 @@ import ( "context" "errors" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/util/slice" "go.uber.org/zap" "sync" "time" @@ -143,17 +142,6 @@ Load: return e.waitLoad(ctx, id) } -func (c *oCache) metricsGet(hit bool) { - if c.metrics == nil { - return - } - if hit { - c.metrics.hit.Inc() - } else { - c.metrics.miss.Inc() - } -} - func (c *oCache) Pick(ctx context.Context, id string) (value Object, err error) { c.mu.Lock() val, ok := c.data[id] @@ -191,13 +179,13 @@ func (c *oCache) Remove(id string) (ok bool, err error) { e, ok := c.data[id] if !ok { c.mu.Unlock() - return + return false, ErrNotExists } c.mu.Unlock() - return c.remove(e, true) + return c.remove(e) } -func (c *oCache) remove(e *entry, remData bool) (ok bool, err error) { +func (c *oCache) remove(e *entry) (ok bool, err error) { <-e.load if e.value == nil { return false, ErrNotExists @@ -205,16 +193,11 @@ func (c *oCache) remove(e *entry, remData bool) (ok bool, err error) { _, curState := e.setClosing(true) if curState == entryStateClosing { err = e.value.Close() + c.mu.Lock() e.setClosed() - } - if !remData { - return - } - c.mu.Lock() - if curState == entryStateClosing { delete(c.data, e.id) + c.mu.Unlock() } - c.mu.Unlock() return } @@ -284,47 +267,35 @@ func (c *oCache) GC() { deadline := c.timeNow().Add(-c.ttl) var toClose []*entry for _, e := range c.data { - if e.getState() != entryStateActive { - continue - } - if e.lastUsage.Before(deadline) { + if e.isActive() && e.lastUsage.Before(deadline) { e.close = make(chan struct{}) toClose = append(toClose, e) } } size := len(c.data) c.mu.Unlock() - - for idx, e := range toClose { + closedNum := 0 + for _, e := range toClose { prevState, _ := e.setClosing(false) if prevState == entryStateClosing || prevState == entryStateClosed { - toClose[idx] = nil continue } - ok, err := e.value.TryClose() - if !ok { - e.setActive(true) - toClose[idx] = nil - continue - } else { - e.setClosed() - } + closed, err := e.value.TryClose() if err != nil { c.log.With("object_id", e.id).Warnf("GC: object close error: %v", err) } + if !closed { + e.setActive(true) + continue + } else { + closedNum++ + c.mu.Lock() + e.setClosed() + delete(c.data, e.id) + c.mu.Unlock() + } } - toClose = slice.DiscardFromSlice(toClose, func(e *entry) bool { - return e == nil - }) - c.log.Infof("GC: removed %d; cache size: %d", len(toClose), size) - if len(toClose) > 0 && c.metrics != nil { - c.metrics.gc.Add(float64(len(toClose))) - } - c.mu.Lock() - for _, e := range toClose { - delete(c.data, e.id) - } - c.mu.Unlock() + c.metricsClosed(closedNum, size) } func (c *oCache) Len() int { @@ -347,9 +318,28 @@ func (c *oCache) Close() (err error) { } c.mu.Unlock() for _, e := range toClose { - if _, err := c.remove(e, false); err != ErrNotExists { + if _, err := c.remove(e); err != ErrNotExists { c.log.With("object_id", e.id).Warnf("cache close: object close error: %v", err) } } return nil } + +func (c *oCache) metricsGet(hit bool) { + if c.metrics == nil { + return + } + if hit { + c.metrics.hit.Inc() + } else { + c.metrics.miss.Inc() + } +} + +func (c *oCache) metricsClosed(closedLen, size int) { + c.log.Infof("GC: removed %d; cache size: %d", closedLen, size) + if c.metrics == nil || closedLen == 0 { + return + } + c.metrics.gc.Add(float64(closedLen)) +} From ca2ea8cef99b3002a91dd08b498bff9102dd878e Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 22:03:45 +0100 Subject: [PATCH 33/57] Add some fuzzy tests --- app/ocache/ocache.go | 3 +- app/ocache/ocache_test.go | 254 +++++++++++++++++++++++++++++++++----- 2 files changed, 227 insertions(+), 30 deletions(-) diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index 931cb431..cf8f6f88 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -192,6 +192,7 @@ func (c *oCache) remove(e *entry) (ok bool, err error) { } _, curState := e.setClosing(true) if curState == entryStateClosing { + ok = true err = e.value.Close() c.mu.Lock() e.setClosed() @@ -318,7 +319,7 @@ func (c *oCache) Close() (err error) { } c.mu.Unlock() for _, e := range toClose { - if _, err := c.remove(e); err != ErrNotExists { + if _, err := c.remove(e); err != nil && err != ErrNotExists { c.log.With("object_id", e.id).Warnf("cache close: object close error: %v", err) } } diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 43773184..5a99e5cf 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -31,6 +31,9 @@ func NewTestObject(name string, tryReturn bool, closeCh chan struct{}) *testObje } func (t *testObject) Close() (err error) { + if t.closeCalled || (t.tryCloseCalled && t.tryReturn) { + panic("close called twice") + } t.closeCalled = true if t.closeCh != nil { <-t.closeCh @@ -39,10 +42,13 @@ func (t *testObject) Close() (err error) { } func (t *testObject) TryClose() (res bool, err error) { + if t.closeCalled || (t.tryCloseCalled && t.tryReturn) { + panic("close called twice") + } t.tryCloseCalled = true if t.closeCh != nil { <-t.closeCh - return true, t.closeErr + return t.tryReturn, t.closeErr } return t.tryReturn, nil } @@ -263,36 +269,226 @@ func TestOCache_GC(t *testing.T) { } func Test_OCache_Remove(t *testing.T) { - closeCh := make(chan struct{}) - getCh := make(chan struct{}) - c := New(func(ctx context.Context, id string) (value Object, err error) { - return NewTestObject(id, false, closeCh), nil - }, WithTTL(time.Millisecond*10)) + t.Run("remove simple", func(t *testing.T) { + closeCh := make(chan struct{}) + getCh := make(chan struct{}) + c := New(func(ctx context.Context, id string) (value Object, err error) { + return NewTestObject(id, false, closeCh), nil + }, WithTTL(time.Millisecond*10)) - val, err := c.Get(context.TODO(), "id") - require.NoError(t, err) - require.NotNil(t, val) - assert.Equal(t, 1, c.Len()) - // removing the object, so we will wait on closing - go func() { - _, err := c.Remove("id") - require.NoError(t, err) - }() - time.Sleep(time.Millisecond * 40) - - var events []string - go func() { - _, err := c.Get(context.TODO(), "id") + val, err := c.Get(context.TODO(), "id") require.NoError(t, err) require.NotNil(t, val) - events = append(events, "get") - close(getCh) - }() - // sleeping to make sure that Get is called - time.Sleep(time.Millisecond * 40) - events = append(events, "close") - close(closeCh) + assert.Equal(t, 1, c.Len()) + // removing the object, so we will wait on closing + go func() { + _, err := c.Remove("id") + require.NoError(t, err) + }() + time.Sleep(time.Millisecond * 40) - <-getCh - require.Equal(t, []string{"close", "get"}, events) + var events []string + go func() { + _, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + require.NotNil(t, val) + events = append(events, "get") + close(getCh) + }() + // sleeping to make sure that Get is called + time.Sleep(time.Millisecond * 40) + events = append(events, "close") + close(closeCh) + + <-getCh + require.Equal(t, []string{"close", "get"}, events) + }) + t.Run("test remove while gc, tryClose false", func(t *testing.T) { + closeCh := make(chan struct{}) + removeCh := make(chan struct{}) + + c := New(func(ctx context.Context, id string) (value Object, err error) { + return NewTestObject(id, false, closeCh), nil + }, WithTTL(time.Millisecond*10)) + val, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + require.NotNil(t, val) + assert.Equal(t, 1, c.Len()) + time.Sleep(time.Millisecond * 40) + go c.GC() + time.Sleep(time.Millisecond * 40) + var events []string + go func() { + ok, err := c.Remove("id") + require.NoError(t, err) + require.True(t, ok) + events = append(events, "remove") + close(removeCh) + }() + time.Sleep(time.Millisecond * 40) + events = append(events, "close") + close(closeCh) + + <-removeCh + require.Equal(t, []string{"close", "remove"}, events) + }) + t.Run("test remove while gc, tryClose true", func(t *testing.T) { + closeCh := make(chan struct{}) + removeCh := make(chan struct{}) + + c := New(func(ctx context.Context, id string) (value Object, err error) { + return NewTestObject(id, true, closeCh), nil + }, WithTTL(time.Millisecond*10)) + val, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + require.NotNil(t, val) + assert.Equal(t, 1, c.Len()) + time.Sleep(time.Millisecond * 40) + go c.GC() + time.Sleep(time.Millisecond * 40) + var events []string + go func() { + ok, err := c.Remove("id") + require.NoError(t, err) + require.False(t, ok) + events = append(events, "remove") + close(removeCh) + }() + time.Sleep(time.Millisecond * 40) + events = append(events, "close") + close(closeCh) + + <-removeCh + require.Equal(t, []string{"close", "remove"}, events) + }) + t.Run("test gc while remove, tryClose true", func(t *testing.T) { + closeCh := make(chan struct{}) + removeCh := make(chan struct{}) + + c := New(func(ctx context.Context, id string) (value Object, err error) { + return NewTestObject(id, true, closeCh), nil + }, WithTTL(time.Millisecond*10)) + val, err := c.Get(context.TODO(), "id") + require.NoError(t, err) + require.NotNil(t, val) + assert.Equal(t, 1, c.Len()) + go func() { + ok, err := c.Remove("id") + require.NoError(t, err) + require.True(t, ok) + close(removeCh) + }() + time.Sleep(20 * time.Millisecond) + c.GC() + close(closeCh) + <-removeCh + }) +} + +func TestOCacheFuzzy(t *testing.T) { + t.Run("test many objects gc, get and remove simultaneously, close after", func(t *testing.T) { + tryCloseIds := make(map[string]bool) + called := make(map[string]int) + max := 2000 + getId := func(i int) string { + return fmt.Sprintf("id%d", i) + } + for i := 0; i < max; i++ { + if i%2 == 1 { + tryCloseIds[getId(i)] = true + } else { + tryCloseIds[getId(i)] = false + } + } + c := New(func(ctx context.Context, id string) (value Object, err error) { + called[id] = called[id] + 1 + return NewTestObject(id, tryCloseIds[id], nil), nil + }, WithTTL(time.Nanosecond)) + + stopGC := make(chan struct{}) + wg := sync.WaitGroup{} + go func() { + for { + select { + case <-stopGC: + return + default: + c.GC() + } + } + }() + wg.Add(1) + go func() { + defer wg.Done() + for j := 0; j < 10; j++ { + for i := 0; i < max; i++ { + val, err := c.Get(context.TODO(), getId(i)) + require.NoError(t, err) + require.NotNil(t, val) + } + } + }() + wg.Add(1) + go func() { + defer wg.Done() + for j := 0; j < 10; j++ { + for i := 0; i < max; i++ { + c.Remove(getId(i)) + } + } + }() + wg.Wait() + close(stopGC) + err := c.Close() + require.NoError(t, err) + require.Equal(t, 0, c.Len()) + }) + t.Run("test many objects gc, get, remove and close simultaneously", func(t *testing.T) { + tryCloseIds := make(map[string]bool) + called := make(map[string]int) + max := 2000 + getId := func(i int) string { + return fmt.Sprintf("id%d", i) + } + for i := 0; i < max; i++ { + if i%2 == 1 { + tryCloseIds[getId(i)] = true + } else { + tryCloseIds[getId(i)] = false + } + } + c := New(func(ctx context.Context, id string) (value Object, err error) { + called[id] = called[id] + 1 + return NewTestObject(id, tryCloseIds[id], nil), nil + }, WithTTL(time.Nanosecond)) + + go func() { + for { + c.GC() + } + }() + go func() { + for j := 0; j < 10; j++ { + for i := 0; i < max; i++ { + val, err := c.Get(context.TODO(), getId(i)) + if err == ErrClosed { + return + } + require.NoError(t, err) + require.NotNil(t, val) + } + } + }() + go func() { + for j := 0; j < 10; j++ { + for i := 0; i < max; i++ { + c.Remove(getId(i)) + } + } + }() + time.Sleep(time.Millisecond) + err := c.Close() + require.NoError(t, err) + require.Equal(t, 0, c.Len()) + }) } From 43a35f48787d695938e825f3e17b61d14123a5b0 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 22:52:31 +0100 Subject: [PATCH 34/57] Add tryclose everywhere --- commonspace/headsync/diffsyncer_test.go | 4 +++ commonspace/objectsync/msgpool.go | 7 ++++-- commonspace/objectsync/objectsync.go | 3 +-- commonspace/space.go | 33 ++++++++++++------------- commonspace/spaceservice.go | 2 ++ net/dialer/dialer.go | 2 +- net/peer/peer.go | 12 ++++++++- net/pool/pool_test.go | 4 +++ net/rpc/rpctest/pool.go | 4 +++ 9 files changed, 48 insertions(+), 23 deletions(-) diff --git a/commonspace/headsync/diffsyncer_test.go b/commonspace/headsync/diffsyncer_test.go index f9622ca6..2b163a19 100644 --- a/commonspace/headsync/diffsyncer_test.go +++ b/commonspace/headsync/diffsyncer_test.go @@ -51,6 +51,10 @@ func (p pushSpaceRequestMatcher) String() string { type mockPeer struct{} +func (m mockPeer) TryClose() (res bool, err error) { + return true, m.Close() +} + func (m mockPeer) Id() string { return "mockId" } diff --git a/commonspace/objectsync/msgpool.go b/commonspace/objectsync/msgpool.go index 3dd14a2e..533efc7e 100644 --- a/commonspace/objectsync/msgpool.go +++ b/commonspace/objectsync/msgpool.go @@ -3,7 +3,6 @@ package objectsync import ( "context" "fmt" - "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/commonspace/objectsync/synchandler" "github.com/anytypeio/any-sync/commonspace/peermanager" "github.com/anytypeio/any-sync/commonspace/spacesyncproto" @@ -15,9 +14,13 @@ import ( "time" ) +type LastUsage interface { + LastUsage() time.Time +} + // MessagePool can be made generic to work with different streams type MessagePool interface { - ocache.ObjectLastUsage + LastUsage synchandler.SyncHandler peermanager.PeerManager SendSync(ctx context.Context, peerId string, message *spacesyncproto.ObjectSyncMessage) (reply *spacesyncproto.ObjectSyncMessage, err error) diff --git a/commonspace/objectsync/objectsync.go b/commonspace/objectsync/objectsync.go index 85c587d9..74b3f7fa 100644 --- a/commonspace/objectsync/objectsync.go +++ b/commonspace/objectsync/objectsync.go @@ -6,7 +6,6 @@ import ( "time" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/commonspace/object/syncobjectgetter" "github.com/anytypeio/any-sync/commonspace/objectsync/synchandler" "github.com/anytypeio/any-sync/commonspace/peermanager" @@ -20,7 +19,7 @@ import ( var log = logger.NewNamed("common.commonspace.objectsync") type ObjectSync interface { - ocache.ObjectLastUsage + LastUsage synchandler.SyncHandler MessagePool() MessagePool diff --git a/commonspace/space.go b/commonspace/space.go index d18c9e8a..00b38a8d 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/app/ocache" "github.com/anytypeio/any-sync/commonspace/headsync" "github.com/anytypeio/any-sync/commonspace/object/acl/list" "github.com/anytypeio/any-sync/commonspace/object/acl/syncacl" @@ -81,9 +80,6 @@ func NewSpaceId(id string, repKey uint64) string { } type Space interface { - ocache.ObjectLocker - ocache.ObjectLastUsage - Id() string Init(ctx context.Context) error @@ -112,9 +108,10 @@ type Space interface { } type space struct { - id string - mu sync.RWMutex - header *spacesyncproto.RawSpaceHeaderWithId + id string + mu sync.RWMutex + header *spacesyncproto.RawSpaceHeaderWithId + spaceTTL time.Duration objectSync objectsync.ObjectSync headSync headsync.HeadSync @@ -134,16 +131,6 @@ type space struct { treesUsed *atomic.Int32 } -func (s *space) LastUsage() time.Time { - return s.objectSync.LastUsage() -} - -func (s *space) Locked() bool { - locked := s.treesUsed.Load() > 1 - log.With(zap.Int32("trees used", s.treesUsed.Load()), zap.Bool("locked", locked), zap.String("spaceId", s.id)).Debug("space lock status check") - return locked -} - func (s *space) Id() string { return s.id } @@ -462,3 +449,15 @@ func (s *space) Close() error { log.With(zap.String("id", s.id)).Debug("space closed") return mError.Err() } + +func (s *space) TryClose() (close bool, err error) { + if time.Now().Sub(s.objectSync.LastUsage()) < s.spaceTTL { + return false, nil + } + locked := s.treesUsed.Load() > 1 + log.With(zap.Int32("trees used", s.treesUsed.Load()), zap.Bool("locked", locked), zap.String("spaceId", s.id)).Debug("space lock status check") + if locked { + return false, nil + } + return true, s.Close() +} diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 89e9283b..0e086923 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -19,6 +19,7 @@ import ( "github.com/anytypeio/any-sync/net/pool" "github.com/anytypeio/any-sync/nodeconf" "sync/atomic" + "time" ) const CName = "common.commonspace" @@ -162,6 +163,7 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { treesUsed: &atomic.Int32{}, isClosed: spaceIsClosed, isDeleted: spaceIsDeleted, + spaceTTL: time.Duration(s.config.GCTTL) * time.Second, } return sp, nil } diff --git a/net/dialer/dialer.go b/net/dialer/dialer.go index 7252a4f3..64b0c191 100644 --- a/net/dialer/dialer.go +++ b/net/dialer/dialer.go @@ -100,7 +100,7 @@ func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err erro if err != nil { return } - return peer.NewPeer(sc, conn), nil + return peer.NewPeer(sc, conn, time.Minute), nil } func (d *dialer) handshake(ctx context.Context, addr string) (conn drpc.Conn, sc sec.SecureConn, err error) { diff --git a/net/peer/peer.go b/net/peer/peer.go index 9c9f547d..bc9353d0 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -12,10 +12,11 @@ import ( var log = logger.NewNamed("peer") -func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer { +func NewPeer(sc sec.SecureConn, conn drpc.Conn, ttl time.Duration) Peer { return &peer{ id: sc.RemotePeer().String(), lastUsage: time.Now().Unix(), + ttl: ttl, sc: sc, Conn: conn, } @@ -25,11 +26,13 @@ type Peer interface { Id() string LastUsage() time.Time UpdateLastUsage() + TryClose() (res bool, err error) drpc.Conn } type peer struct { id string + ttl time.Duration lastUsage int64 sc sec.SecureConn drpc.Conn @@ -76,6 +79,13 @@ func (p *peer) UpdateLastUsage() { atomic.StoreInt64(&p.lastUsage, time.Now().Unix()) } +func (p *peer) TryClose() (res bool, err error) { + if time.Now().Sub(p.LastUsage()) < p.ttl { + return false, nil + } + return true, p.Close() +} + func (p *peer) Close() (err error) { log.Debug("peer close", zap.String("peerId", p.id)) return p.Conn.Close() diff --git a/net/pool/pool_test.go b/net/pool/pool_test.go index f913333c..8ae08e3b 100644 --- a/net/pool/pool_test.go +++ b/net/pool/pool_test.go @@ -194,6 +194,10 @@ func (t *testPeer) LastUsage() time.Time { func (t *testPeer) UpdateLastUsage() {} +func (t *testPeer) TryClose() (res bool, err error) { + return true, t.Close() +} + func (t *testPeer) Close() error { select { case <-t.closed: diff --git a/net/rpc/rpctest/pool.go b/net/rpc/rpctest/pool.go index 7fdbdda4..40b7bb1d 100644 --- a/net/rpc/rpctest/pool.go +++ b/net/rpc/rpctest/pool.go @@ -103,6 +103,10 @@ type testPeer struct { drpc.Conn } +func (t testPeer) TryClose() (res bool, err error) { + return true, t.Close() +} + func (t testPeer) Id() string { return t.id } From 83476a9e8488f823225f597db688d17729efb2e8 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 22:56:59 +0100 Subject: [PATCH 35/57] Lower timeouts --- app/ocache/ocache_test.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 5a99e5cf..3a2941a1 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -148,7 +148,7 @@ func TestOCache_GC(t *testing.T) { assert.Equal(t, 1, c.Len()) c.GC() assert.Equal(t, 1, c.Len()) - time.Sleep(time.Millisecond * 30) + time.Sleep(time.Millisecond * 20) c.GC() assert.Equal(t, 0, c.Len()) }) @@ -164,11 +164,11 @@ func TestOCache_GC(t *testing.T) { require.NotNil(t, val) assert.Equal(t, 1, c.Len()) // making ttl pass - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) // first gc will be run after 20 secs, so calling it manually go c.GC() // waiting until all objects are marked as closing - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) var events []string go func() { _, err := c.Get(context.TODO(), "id") @@ -178,7 +178,7 @@ func TestOCache_GC(t *testing.T) { close(getCh) }() // sleeping to make sure that Get is called - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) events = append(events, "close") close(closeCh) @@ -197,7 +197,7 @@ func TestOCache_GC(t *testing.T) { require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) begin := make(chan struct{}) wg := sync.WaitGroup{} once := sync.Once{} @@ -252,7 +252,7 @@ func TestOCache_GC(t *testing.T) { require.NotNil(t, val) } assert.Equal(t, max, c.Len()) - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) c.GC() for i := 0; i < max; i++ { val, err := c.Get(context.TODO(), getId(i)) @@ -285,7 +285,7 @@ func Test_OCache_Remove(t *testing.T) { _, err := c.Remove("id") require.NoError(t, err) }() - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) var events []string go func() { @@ -296,7 +296,7 @@ func Test_OCache_Remove(t *testing.T) { close(getCh) }() // sleeping to make sure that Get is called - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) events = append(events, "close") close(closeCh) @@ -314,9 +314,9 @@ func Test_OCache_Remove(t *testing.T) { require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) go c.GC() - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) var events []string go func() { ok, err := c.Remove("id") @@ -325,7 +325,7 @@ func Test_OCache_Remove(t *testing.T) { events = append(events, "remove") close(removeCh) }() - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) events = append(events, "close") close(closeCh) @@ -343,9 +343,9 @@ func Test_OCache_Remove(t *testing.T) { require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) go c.GC() - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) var events []string go func() { ok, err := c.Remove("id") @@ -354,7 +354,7 @@ func Test_OCache_Remove(t *testing.T) { events = append(events, "remove") close(removeCh) }() - time.Sleep(time.Millisecond * 40) + time.Sleep(time.Millisecond * 20) events = append(events, "close") close(closeCh) From 94f28430a378e593c10a3b4b1669fa1e20923190 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 22:58:36 +0100 Subject: [PATCH 36/57] Remove called records in fuzzy test --- app/ocache/ocache_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 3a2941a1..9ed130df 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -388,7 +388,6 @@ func Test_OCache_Remove(t *testing.T) { func TestOCacheFuzzy(t *testing.T) { t.Run("test many objects gc, get and remove simultaneously, close after", func(t *testing.T) { tryCloseIds := make(map[string]bool) - called := make(map[string]int) max := 2000 getId := func(i int) string { return fmt.Sprintf("id%d", i) @@ -401,7 +400,6 @@ func TestOCacheFuzzy(t *testing.T) { } } c := New(func(ctx context.Context, id string) (value Object, err error) { - called[id] = called[id] + 1 return NewTestObject(id, tryCloseIds[id], nil), nil }, WithTTL(time.Nanosecond)) @@ -445,7 +443,6 @@ func TestOCacheFuzzy(t *testing.T) { }) t.Run("test many objects gc, get, remove and close simultaneously", func(t *testing.T) { tryCloseIds := make(map[string]bool) - called := make(map[string]int) max := 2000 getId := func(i int) string { return fmt.Sprintf("id%d", i) @@ -458,7 +455,6 @@ func TestOCacheFuzzy(t *testing.T) { } } c := New(func(ctx context.Context, id string) (value Object, err error) { - called[id] = called[id] + 1 return NewTestObject(id, tryCloseIds[id], nil), nil }, WithTTL(time.Nanosecond)) From 0c797412166d0080f8bd675d560ab1a8f7cadfe0 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 23:09:26 +0100 Subject: [PATCH 37/57] Update objecttree with tryclose --- .../objecttree/mock_objecttree/mock_objecttree.go | 15 +++++++++++++++ commonspace/object/tree/objecttree/objecttree.go | 5 +++++ .../tree/synctree/mock_synctree/mock_synctree.go | 15 +++++++++++++++ commonspace/object/tree/synctree/synctree.go | 4 ++++ .../mock_coordinatorclient.go | 11 ++++++----- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go index 541fa779..d64e7dea 100644 --- a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go +++ b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go @@ -336,6 +336,21 @@ func (mr *MockObjectTreeMockRecorder) Storage() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Storage", reflect.TypeOf((*MockObjectTree)(nil).Storage)) } +// TryClose mocks base method. +func (m *MockObjectTree) TryClose() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TryClose") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TryClose indicates an expected call of TryClose. +func (mr *MockObjectTreeMockRecorder) TryClose() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockObjectTree)(nil).TryClose)) +} + // TryLock mocks base method. func (m *MockObjectTree) TryLock() bool { m.ctrl.T.Helper() diff --git a/commonspace/object/tree/objecttree/objecttree.go b/commonspace/object/tree/objecttree/objecttree.go index 31abc01a..003cdd39 100644 --- a/commonspace/object/tree/objecttree/objecttree.go +++ b/commonspace/object/tree/objecttree/objecttree.go @@ -81,6 +81,7 @@ type ObjectTree interface { Delete() error Close() error + TryClose() (bool, error) } type objectTree struct { @@ -555,6 +556,10 @@ func (ot *objectTree) Root() *Change { return ot.tree.Root() } +func (ot *objectTree) TryClose() (bool, error) { + return true, ot.Close() +} + func (ot *objectTree) Close() error { return nil } diff --git a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go index d7fe181f..31ee3607 100644 --- a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go +++ b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go @@ -487,6 +487,21 @@ func (mr *MockSyncTreeMockRecorder) SyncWithPeer(arg0, arg1 interface{}) *gomock return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncWithPeer", reflect.TypeOf((*MockSyncTree)(nil).SyncWithPeer), arg0, arg1) } +// TryClose mocks base method. +func (m *MockSyncTree) TryClose() (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TryClose") + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TryClose indicates an expected call of TryClose. +func (mr *MockSyncTreeMockRecorder) TryClose() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockSyncTree)(nil).TryClose)) +} + // TryLock mocks base method. func (m *MockSyncTree) TryLock() bool { m.ctrl.T.Helper() diff --git a/commonspace/object/tree/synctree/synctree.go b/commonspace/object/tree/synctree/synctree.go index f25e14d0..fe429768 100644 --- a/commonspace/object/tree/synctree/synctree.go +++ b/commonspace/object/tree/synctree/synctree.go @@ -209,6 +209,10 @@ func (s *syncTree) Delete() (err error) { return } +func (s *syncTree) TryClose() (bool, error) { + return true, s.Close() +} + func (s *syncTree) Close() (err error) { log.Debug("closing sync tree", zap.String("id", s.Id())) defer func() { diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index b6b6931e..7216e1eb 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -38,11 +38,12 @@ func (m *MockCoordinatorClient) EXPECT() *MockCoordinatorClientMockRecorder { } // ChangeStatus mocks base method. -func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) error { +func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) (*coordinatorproto.SpaceStatusPayload, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ChangeStatus", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusPayload) + ret1, _ := ret[1].(error) + return ret0, ret1 } // ChangeStatus indicates an expected call of ChangeStatus. @@ -110,10 +111,10 @@ func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1, arg2 interfac } // StatusCheck mocks base method. -func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusCheckResponse, error) { +func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusPayload, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StatusCheck", arg0, arg1) - ret0, _ := ret[0].(*coordinatorproto.SpaceStatusCheckResponse) + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusPayload) ret1, _ := ret[1].(error) return ret0, ret1 } From 067ad8cf16e5f8568aeef3d6e9ebef438f479775 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 9 Mar 2023 23:11:20 +0100 Subject: [PATCH 38/57] Add TryClose to space interface --- commonspace/space.go | 1 + 1 file changed, 1 insertion(+) diff --git a/commonspace/space.go b/commonspace/space.go index 00b38a8d..fafee759 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -104,6 +104,7 @@ type Space interface { HandleMessage(ctx context.Context, msg HandleMessage) (err error) + TryClose() (close bool, err error) Close() error } From 74f39239c6f82204fb7345eb65b035d9fca4d4a9 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 10:17:57 +0100 Subject: [PATCH 39/57] Update tryclose with ttl --- app/ocache/ocache.go | 5 +++-- app/ocache/ocache_test.go | 2 +- commonspace/headsync/diffsyncer_test.go | 2 +- .../objecttree/mock_objecttree/mock_objecttree.go | 9 +++++---- commonspace/object/tree/objecttree/objecttree.go | 5 +++-- .../tree/synctree/mock_synctree/mock_synctree.go | 9 +++++---- commonspace/object/tree/synctree/synctree.go | 3 ++- commonspace/space.go | 13 ++++++------- commonspace/spaceservice.go | 2 -- net/dialer/dialer.go | 2 +- net/peer/peer.go | 9 ++++----- net/pool/pool_test.go | 2 +- net/rpc/rpctest/pool.go | 2 +- 13 files changed, 33 insertions(+), 32 deletions(-) diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index cf8f6f88..7375c643 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -67,7 +67,7 @@ func New(loadFunc LoadFunc, opts ...Option) OCache { type Object interface { Close() (err error) - TryClose() (res bool, err error) + TryClose(objectTTL time.Duration) (res bool, err error) } type OCache interface { @@ -127,6 +127,7 @@ Load: load = true c.data[id] = e } + e.lastUsage = time.Now() c.mu.Unlock() reload, err := e.waitClose(ctx, id) if err != nil { @@ -281,7 +282,7 @@ func (c *oCache) GC() { if prevState == entryStateClosing || prevState == entryStateClosed { continue } - closed, err := e.value.TryClose() + closed, err := e.value.TryClose(c.ttl) if err != nil { c.log.With("object_id", e.id).Warnf("GC: object close error: %v", err) } diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 9ed130df..14a59b1a 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -41,7 +41,7 @@ func (t *testObject) Close() (err error) { return t.closeErr } -func (t *testObject) TryClose() (res bool, err error) { +func (t *testObject) TryClose(objectTTL time.Duration) (res bool, err error) { if t.closeCalled || (t.tryCloseCalled && t.tryReturn) { panic("close called twice") } diff --git a/commonspace/headsync/diffsyncer_test.go b/commonspace/headsync/diffsyncer_test.go index 2b163a19..ae40e5a7 100644 --- a/commonspace/headsync/diffsyncer_test.go +++ b/commonspace/headsync/diffsyncer_test.go @@ -51,7 +51,7 @@ func (p pushSpaceRequestMatcher) String() string { type mockPeer struct{} -func (m mockPeer) TryClose() (res bool, err error) { +func (m mockPeer) TryClose(objectTTL time.Duration) (res bool, err error) { return true, m.Close() } diff --git a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go index d64e7dea..4d5898fe 100644 --- a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go +++ b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go @@ -7,6 +7,7 @@ package mock_objecttree import ( context "context" reflect "reflect" + time "time" list "github.com/anytypeio/any-sync/commonspace/object/acl/list" objecttree "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" @@ -337,18 +338,18 @@ func (mr *MockObjectTreeMockRecorder) Storage() *gomock.Call { } // TryClose mocks base method. -func (m *MockObjectTree) TryClose() (bool, error) { +func (m *MockObjectTree) TryClose(arg0 time.Duration) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TryClose") + ret := m.ctrl.Call(m, "TryClose", arg0) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // TryClose indicates an expected call of TryClose. -func (mr *MockObjectTreeMockRecorder) TryClose() *gomock.Call { +func (mr *MockObjectTreeMockRecorder) TryClose(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockObjectTree)(nil).TryClose)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockObjectTree)(nil).TryClose), arg0) } // TryLock mocks base method. diff --git a/commonspace/object/tree/objecttree/objecttree.go b/commonspace/object/tree/objecttree/objecttree.go index 003cdd39..f72a5a5d 100644 --- a/commonspace/object/tree/objecttree/objecttree.go +++ b/commonspace/object/tree/objecttree/objecttree.go @@ -5,6 +5,7 @@ import ( "context" "errors" "sync" + "time" "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/acl/list" @@ -81,7 +82,7 @@ type ObjectTree interface { Delete() error Close() error - TryClose() (bool, error) + TryClose(objectTTL time.Duration) (bool, error) } type objectTree struct { @@ -556,7 +557,7 @@ func (ot *objectTree) Root() *Change { return ot.tree.Root() } -func (ot *objectTree) TryClose() (bool, error) { +func (ot *objectTree) TryClose(objectTTL time.Duration) (bool, error) { return true, ot.Close() } diff --git a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go index 31ee3607..a4205132 100644 --- a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go +++ b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go @@ -7,6 +7,7 @@ package mock_synctree import ( context "context" reflect "reflect" + time "time" list "github.com/anytypeio/any-sync/commonspace/object/acl/list" objecttree "github.com/anytypeio/any-sync/commonspace/object/tree/objecttree" @@ -488,18 +489,18 @@ func (mr *MockSyncTreeMockRecorder) SyncWithPeer(arg0, arg1 interface{}) *gomock } // TryClose mocks base method. -func (m *MockSyncTree) TryClose() (bool, error) { +func (m *MockSyncTree) TryClose(arg0 time.Duration) (bool, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TryClose") + ret := m.ctrl.Call(m, "TryClose", arg0) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } // TryClose indicates an expected call of TryClose. -func (mr *MockSyncTreeMockRecorder) TryClose() *gomock.Call { +func (mr *MockSyncTreeMockRecorder) TryClose(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockSyncTree)(nil).TryClose)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TryClose", reflect.TypeOf((*MockSyncTree)(nil).TryClose), arg0) } // TryLock mocks base method. diff --git a/commonspace/object/tree/synctree/synctree.go b/commonspace/object/tree/synctree/synctree.go index fe429768..56d07c1c 100644 --- a/commonspace/object/tree/synctree/synctree.go +++ b/commonspace/object/tree/synctree/synctree.go @@ -3,6 +3,7 @@ package synctree import ( "context" "errors" + "time" "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/commonspace/object/acl/list" @@ -209,7 +210,7 @@ func (s *syncTree) Delete() (err error) { return } -func (s *syncTree) TryClose() (bool, error) { +func (s *syncTree) TryClose(objectTTL time.Duration) (bool, error) { return true, s.Close() } diff --git a/commonspace/space.go b/commonspace/space.go index fafee759..6f2a3af2 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -104,15 +104,14 @@ type Space interface { HandleMessage(ctx context.Context, msg HandleMessage) (err error) - TryClose() (close bool, err error) + TryClose(objectTTL time.Duration) (close bool, err error) Close() error } type space struct { - id string - mu sync.RWMutex - header *spacesyncproto.RawSpaceHeaderWithId - spaceTTL time.Duration + id string + mu sync.RWMutex + header *spacesyncproto.RawSpaceHeaderWithId objectSync objectsync.ObjectSync headSync headsync.HeadSync @@ -451,8 +450,8 @@ func (s *space) Close() error { return mError.Err() } -func (s *space) TryClose() (close bool, err error) { - if time.Now().Sub(s.objectSync.LastUsage()) < s.spaceTTL { +func (s *space) TryClose(objectTTL time.Duration) (close bool, err error) { + if time.Now().Sub(s.objectSync.LastUsage()) < objectTTL { return false, nil } locked := s.treesUsed.Load() > 1 diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 0e086923..89e9283b 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -19,7 +19,6 @@ import ( "github.com/anytypeio/any-sync/net/pool" "github.com/anytypeio/any-sync/nodeconf" "sync/atomic" - "time" ) const CName = "common.commonspace" @@ -163,7 +162,6 @@ func (s *spaceService) NewSpace(ctx context.Context, id string) (Space, error) { treesUsed: &atomic.Int32{}, isClosed: spaceIsClosed, isDeleted: spaceIsDeleted, - spaceTTL: time.Duration(s.config.GCTTL) * time.Second, } return sp, nil } diff --git a/net/dialer/dialer.go b/net/dialer/dialer.go index 64b0c191..7252a4f3 100644 --- a/net/dialer/dialer.go +++ b/net/dialer/dialer.go @@ -100,7 +100,7 @@ func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err erro if err != nil { return } - return peer.NewPeer(sc, conn, time.Minute), nil + return peer.NewPeer(sc, conn), nil } func (d *dialer) handshake(ctx context.Context, addr string) (conn drpc.Conn, sc sec.SecureConn, err error) { diff --git a/net/peer/peer.go b/net/peer/peer.go index bc9353d0..c96cd4ba 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -12,11 +12,10 @@ import ( var log = logger.NewNamed("peer") -func NewPeer(sc sec.SecureConn, conn drpc.Conn, ttl time.Duration) Peer { +func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer { return &peer{ id: sc.RemotePeer().String(), lastUsage: time.Now().Unix(), - ttl: ttl, sc: sc, Conn: conn, } @@ -26,7 +25,7 @@ type Peer interface { Id() string LastUsage() time.Time UpdateLastUsage() - TryClose() (res bool, err error) + TryClose(objectTTL time.Duration) (res bool, err error) drpc.Conn } @@ -79,8 +78,8 @@ func (p *peer) UpdateLastUsage() { atomic.StoreInt64(&p.lastUsage, time.Now().Unix()) } -func (p *peer) TryClose() (res bool, err error) { - if time.Now().Sub(p.LastUsage()) < p.ttl { +func (p *peer) TryClose(objectTTL time.Duration) (res bool, err error) { + if time.Now().Sub(p.LastUsage()) < objectTTL { return false, nil } return true, p.Close() diff --git a/net/pool/pool_test.go b/net/pool/pool_test.go index 8ae08e3b..ce3876e0 100644 --- a/net/pool/pool_test.go +++ b/net/pool/pool_test.go @@ -194,7 +194,7 @@ func (t *testPeer) LastUsage() time.Time { func (t *testPeer) UpdateLastUsage() {} -func (t *testPeer) TryClose() (res bool, err error) { +func (t *testPeer) TryClose(objectTTL time.Duration) (res bool, err error) { return true, t.Close() } diff --git a/net/rpc/rpctest/pool.go b/net/rpc/rpctest/pool.go index 40b7bb1d..630cbb6a 100644 --- a/net/rpc/rpctest/pool.go +++ b/net/rpc/rpctest/pool.go @@ -103,7 +103,7 @@ type testPeer struct { drpc.Conn } -func (t testPeer) TryClose() (res bool, err error) { +func (t testPeer) TryClose(objectTTL time.Duration) (res bool, err error) { return true, t.Close() } From ea745622903d8fe6071a3882d3e52a6293fb9fa0 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 14:37:03 +0100 Subject: [PATCH 40/57] Add change type and payload --- commonspace/object/tree/objecttree/change.go | 9 +- .../object/tree/objecttree/changebuilder.go | 43 +-- .../mock_objecttree/mock_objecttree.go | 14 + .../object/tree/objecttree/objecttree.go | 5 + .../tree/objecttree/objecttreefactory.go | 26 +- .../synctree/mock_synctree/mock_synctree.go | 14 + .../treechangeproto/protos/treechange.proto | 8 + .../tree/treechangeproto/treechange.pb.go | 365 ++++++++++++++++-- commonspace/payloads.go | 26 +- commonspace/space.go | 6 +- .../spacesyncproto/protos/spacesync.proto | 1 + commonspace/spacesyncproto/spacesync.pb.go | 196 ++++++---- .../mock_coordinatorclient.go | 11 +- 13 files changed, 551 insertions(+), 173 deletions(-) diff --git a/commonspace/object/tree/objecttree/change.go b/commonspace/object/tree/objecttree/change.go index 8ded2d43..ff59c991 100644 --- a/commonspace/object/tree/objecttree/change.go +++ b/commonspace/object/tree/objecttree/change.go @@ -3,6 +3,7 @@ package objecttree import ( "errors" "github.com/anytypeio/any-sync/commonspace/object/tree/treechangeproto" + "github.com/gogo/protobuf/proto" ) var ( @@ -48,6 +49,11 @@ func NewChange(id string, ch *treechangeproto.TreeChange, signature []byte) *Cha } func NewChangeFromRoot(id string, ch *treechangeproto.RootChange, signature []byte) *Change { + changeInfo := &treechangeproto.TreeChangeInfo{ + ChangeType: ch.ChangeType, + ChangePayload: ch.ChangePayload, + } + data, _ := proto.Marshal(changeInfo) return &Change{ Next: nil, AclHeadId: ch.AclHeadId, @@ -56,7 +62,8 @@ func NewChangeFromRoot(id string, ch *treechangeproto.RootChange, signature []by Timestamp: ch.Timestamp, Identity: string(ch.Identity), Signature: signature, - Data: []byte(ch.ChangeType), + Data: data, + Model: changeInfo, } } diff --git a/commonspace/object/tree/objecttree/changebuilder.go b/commonspace/object/tree/objecttree/changebuilder.go index 29a1a500..8ef6e5a0 100644 --- a/commonspace/object/tree/objecttree/changebuilder.go +++ b/commonspace/object/tree/objecttree/changebuilder.go @@ -26,13 +26,14 @@ type BuilderContent struct { } type InitialContent struct { - AclHeadId string - Identity []byte - SigningKey signingkey.PrivKey - SpaceId string - Seed []byte - ChangeType string - Timestamp int64 + AclHeadId string + Identity []byte + SigningKey signingkey.PrivKey + SpaceId string + Seed []byte + ChangeType string + ChangePayload []byte + Timestamp int64 } type nonVerifiableChangeBuilder struct { @@ -122,41 +123,35 @@ func (c *changeBuilder) SetRootRawChange(rawIdChange *treechangeproto.RawTreeCha func (c *changeBuilder) BuildRoot(payload InitialContent) (ch *Change, rawIdChange *treechangeproto.RawTreeChangeWithId, err error) { change := &treechangeproto.RootChange{ - AclHeadId: payload.AclHeadId, - Timestamp: payload.Timestamp, - Identity: payload.Identity, - ChangeType: payload.ChangeType, - SpaceId: payload.SpaceId, - Seed: payload.Seed, + AclHeadId: payload.AclHeadId, + Timestamp: payload.Timestamp, + Identity: payload.Identity, + ChangeType: payload.ChangeType, + ChangePayload: payload.ChangePayload, + SpaceId: payload.SpaceId, + Seed: payload.Seed, } - marshalledChange, err := proto.Marshal(change) if err != nil { return } - signature, err := payload.SigningKey.Sign(marshalledChange) if err != nil { return } - raw := &treechangeproto.RawTreeChange{ Payload: marshalledChange, Signature: signature, } - marshalledRawChange, err := proto.Marshal(raw) if err != nil { return } - id, err := cidutil.NewCidFromBytes(marshalledRawChange) if err != nil { return } - ch = NewChangeFromRoot(id, change, signature) - rawIdChange = &treechangeproto.RawTreeChangeWithId{ RawChange: marshalledRawChange, Id: id, @@ -184,34 +179,27 @@ func (c *changeBuilder) Build(payload BuilderContent) (ch *Change, rawIdChange * } else { change.ChangesData = payload.Content } - marshalledChange, err := proto.Marshal(change) if err != nil { return } - signature, err := payload.SigningKey.Sign(marshalledChange) if err != nil { return } - raw := &treechangeproto.RawTreeChange{ Payload: marshalledChange, Signature: signature, } - marshalledRawChange, err := proto.Marshal(raw) if err != nil { return } - id, err := cidutil.NewCidFromBytes(marshalledRawChange) if err != nil { return } - ch = NewChange(id, change, signature) - rawIdChange = &treechangeproto.RawTreeChangeWithId{ RawChange: marshalledRawChange, Id: id, @@ -264,7 +252,6 @@ func (c *changeBuilder) unmarshallRawChange(raw *treechangeproto.RawTreeChange, ch = NewChangeFromRoot(id, unmarshalled, raw.Signature) return } - unmarshalled := &treechangeproto.TreeChange{} err = proto.Unmarshal(raw.Payload, unmarshalled) if err != nil { diff --git a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go index 541fa779..12dd4a95 100644 --- a/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go +++ b/commonspace/object/tree/objecttree/mock_objecttree/mock_objecttree.go @@ -82,6 +82,20 @@ func (mr *MockObjectTreeMockRecorder) AddRawChanges(arg0, arg1 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRawChanges", reflect.TypeOf((*MockObjectTree)(nil).AddRawChanges), arg0, arg1) } +// ChangeInfo mocks base method. +func (m *MockObjectTree) ChangeInfo() *treechangeproto.TreeChangeInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeInfo") + ret0, _ := ret[0].(*treechangeproto.TreeChangeInfo) + return ret0 +} + +// ChangeInfo indicates an expected call of ChangeInfo. +func (mr *MockObjectTreeMockRecorder) ChangeInfo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeInfo", reflect.TypeOf((*MockObjectTree)(nil).ChangeInfo)) +} + // ChangesAfterCommonSnapshot mocks base method. func (m *MockObjectTree) ChangesAfterCommonSnapshot(arg0, arg1 []string) ([]*treechangeproto.RawTreeChangeWithId, error) { m.ctrl.T.Helper() diff --git a/commonspace/object/tree/objecttree/objecttree.go b/commonspace/object/tree/objecttree/objecttree.go index 31abc01a..170f183e 100644 --- a/commonspace/object/tree/objecttree/objecttree.go +++ b/commonspace/object/tree/objecttree/objecttree.go @@ -52,6 +52,7 @@ type ReadableObjectTree interface { Id() string Header() *treechangeproto.RawTreeChangeWithId UnmarshalledHeader() *Change + ChangeInfo() *treechangeproto.TreeChangeInfo Heads() []string Root() *Change @@ -142,6 +143,10 @@ func (ot *objectTree) UnmarshalledHeader() *Change { return ot.root } +func (ot *objectTree) ChangeInfo() *treechangeproto.TreeChangeInfo { + return ot.root.Model.(*treechangeproto.TreeChangeInfo) +} + func (ot *objectTree) Storage() treestorage.TreeStorage { return ot.treeStorage } diff --git a/commonspace/object/tree/objecttree/objecttreefactory.go b/commonspace/object/tree/objecttree/objecttreefactory.go index eb0ec8e2..cfceefe0 100644 --- a/commonspace/object/tree/objecttree/objecttreefactory.go +++ b/commonspace/object/tree/objecttree/objecttreefactory.go @@ -12,11 +12,12 @@ import ( ) type ObjectTreeCreatePayload struct { - SignKey signingkey.PrivKey - ChangeType string - SpaceId string - Identity []byte - IsEncrypted bool + SignKey signingkey.PrivKey + ChangeType string + ChangePayload []byte + SpaceId string + Identity []byte + IsEncrypted bool } type HistoryTreeParams struct { @@ -165,13 +166,14 @@ func createObjectTreeRoot( return } cnt := InitialContent{ - AclHeadId: aclHeadId, - Identity: payload.Identity, - SigningKey: payload.SignKey, - SpaceId: payload.SpaceId, - ChangeType: payload.ChangeType, - Timestamp: timestamp, - Seed: seed, + AclHeadId: aclHeadId, + Identity: payload.Identity, + SigningKey: payload.SignKey, + SpaceId: payload.SpaceId, + ChangeType: payload.ChangeType, + ChangePayload: payload.ChangePayload, + Timestamp: timestamp, + Seed: seed, } _, root, err = NewChangeBuilder(keychain.NewKeychain(), nil).BuildRoot(cnt) diff --git a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go index d7fe181f..e5ee2d8a 100644 --- a/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go +++ b/commonspace/object/tree/synctree/mock_synctree/mock_synctree.go @@ -193,6 +193,20 @@ func (mr *MockSyncTreeMockRecorder) AddRawChanges(arg0, arg1 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRawChanges", reflect.TypeOf((*MockSyncTree)(nil).AddRawChanges), arg0, arg1) } +// ChangeInfo mocks base method. +func (m *MockSyncTree) ChangeInfo() *treechangeproto.TreeChangeInfo { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChangeInfo") + ret0, _ := ret[0].(*treechangeproto.TreeChangeInfo) + return ret0 +} + +// ChangeInfo indicates an expected call of ChangeInfo. +func (mr *MockSyncTreeMockRecorder) ChangeInfo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChangeInfo", reflect.TypeOf((*MockSyncTree)(nil).ChangeInfo)) +} + // ChangesAfterCommonSnapshot mocks base method. func (m *MockSyncTree) ChangesAfterCommonSnapshot(arg0, arg1 []string) ([]*treechangeproto.RawTreeChangeWithId, error) { m.ctrl.T.Helper() diff --git a/commonspace/object/tree/treechangeproto/protos/treechange.proto b/commonspace/object/tree/treechangeproto/protos/treechange.proto index 9bc47b0a..b4ae84d9 100644 --- a/commonspace/object/tree/treechangeproto/protos/treechange.proto +++ b/commonspace/object/tree/treechangeproto/protos/treechange.proto @@ -16,6 +16,8 @@ message RootChange { bytes seed = 5; // Identity is a public key of the tree's creator bytes identity = 6; + // ChangePayload is a payload related to ChangeType + bytes changePayload = 7; } // TreeChange is a change of a tree @@ -94,3 +96,9 @@ message TreeFullSyncResponse { message TreeErrorResponse { string error = 1; } + +// TreeChangeInfo is used internally in Tree implementation for ease of marshalling +message TreeChangeInfo { + string changeType = 1; + bytes changePayload = 2; +} \ No newline at end of file diff --git a/commonspace/object/tree/treechangeproto/treechange.pb.go b/commonspace/object/tree/treechangeproto/treechange.pb.go index caf98ad2..da70a466 100644 --- a/commonspace/object/tree/treechangeproto/treechange.pb.go +++ b/commonspace/object/tree/treechangeproto/treechange.pb.go @@ -36,6 +36,8 @@ type RootChange struct { Seed []byte `protobuf:"bytes,5,opt,name=seed,proto3" json:"seed,omitempty"` // Identity is a public key of the tree's creator Identity []byte `protobuf:"bytes,6,opt,name=identity,proto3" json:"identity,omitempty"` + // ChangePayload is a payload related to ChangeType + ChangePayload []byte `protobuf:"bytes,7,opt,name=changePayload,proto3" json:"changePayload,omitempty"` } func (m *RootChange) Reset() { *m = RootChange{} } @@ -113,6 +115,13 @@ func (m *RootChange) GetIdentity() []byte { return nil } +func (m *RootChange) GetChangePayload() []byte { + if m != nil { + return m.ChangePayload + } + return nil +} + // TreeChange is a change of a tree type TreeChange struct { // TreeHeadIds are previous ids for this TreeChange @@ -725,6 +734,59 @@ func (m *TreeErrorResponse) GetError() string { return "" } +// TreeChangeInfo is used internally in Tree implementation for ease of marshalling +type TreeChangeInfo struct { + ChangeType string `protobuf:"bytes,1,opt,name=changeType,proto3" json:"changeType,omitempty"` + ChangePayload []byte `protobuf:"bytes,2,opt,name=changePayload,proto3" json:"changePayload,omitempty"` +} + +func (m *TreeChangeInfo) Reset() { *m = TreeChangeInfo{} } +func (m *TreeChangeInfo) String() string { return proto.CompactTextString(m) } +func (*TreeChangeInfo) ProtoMessage() {} +func (*TreeChangeInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_5033f0301ef9b772, []int{10} +} +func (m *TreeChangeInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TreeChangeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TreeChangeInfo.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 *TreeChangeInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_TreeChangeInfo.Merge(m, src) +} +func (m *TreeChangeInfo) XXX_Size() int { + return m.Size() +} +func (m *TreeChangeInfo) XXX_DiscardUnknown() { + xxx_messageInfo_TreeChangeInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_TreeChangeInfo proto.InternalMessageInfo + +func (m *TreeChangeInfo) GetChangeType() string { + if m != nil { + return m.ChangeType + } + return "" +} + +func (m *TreeChangeInfo) GetChangePayload() []byte { + if m != nil { + return m.ChangePayload + } + return nil +} + func init() { proto.RegisterType((*RootChange)(nil), "treechange.RootChange") proto.RegisterType((*TreeChange)(nil), "treechange.TreeChange") @@ -736,6 +798,7 @@ func init() { proto.RegisterType((*TreeFullSyncRequest)(nil), "treechange.TreeFullSyncRequest") proto.RegisterType((*TreeFullSyncResponse)(nil), "treechange.TreeFullSyncResponse") proto.RegisterType((*TreeErrorResponse)(nil), "treechange.TreeErrorResponse") + proto.RegisterType((*TreeChangeInfo)(nil), "treechange.TreeChangeInfo") } func init() { @@ -743,48 +806,51 @@ func init() { } var fileDescriptor_5033f0301ef9b772 = []byte{ - // 656 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xf5, 0x3a, 0x69, 0xd3, 0x4e, 0xd3, 0x16, 0xb6, 0x3d, 0x58, 0x15, 0x18, 0xcb, 0x07, 0x08, - 0x97, 0x56, 0x2a, 0x27, 0x10, 0x52, 0x45, 0x4b, 0x8b, 0xab, 0x0a, 0x84, 0xb6, 0x05, 0x24, 0x6e, - 0x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95, 0x89, 0x2a, 0x25, 0x7a, 0xa2, 0xe3, 0xdf, 0xf7, 0x22, - 0xd8, 0x7d, 0xf6, 0xe7, 0xd2, 0x25, 0x17, 0x97, 0x2e, 0xf9, 0x77, 0xe9, 0x92, 0x1f, 0x23, 0xd7, - 0xba, 0x18, 0xb9, 0xd6, 0xdf, 0x91, 0x6b, 0xbd, 0x7f, 0x70, 0xcd, 0xff, 0x9b, 0xd3, 0x79, 0xfd, - 0xf1, 0xe8, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0xa5, 0xe2, 0x7c, 0xa1, 0x06, 0x00, 0x00, + // 690 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xc1, 0x4e, 0xdb, 0x4a, + 0x14, 0xf5, 0x38, 0x01, 0xc3, 0x25, 0xc0, 0x7b, 0x03, 0x0b, 0x0b, 0xbd, 0xe7, 0x5a, 0x56, 0xd5, + 0xa6, 0x1b, 0x90, 0xe8, 0xaa, 0x55, 0x25, 0x54, 0x28, 0xd4, 0x11, 0x6a, 0x85, 0x06, 0x4a, 0xa5, + 0xee, 0x06, 0xfb, 0x42, 0x5c, 0x25, 0xb6, 0xeb, 0x99, 0x14, 0xe5, 0x03, 0xba, 0x69, 0xa5, 0xaa, + 0x9f, 0xd0, 0x5f, 0xe9, 0xae, 0x4b, 0x96, 0x2c, 0x2b, 0xf8, 0x91, 0xca, 0x63, 0x3b, 0xb1, 0x1d, + 0x2f, 0xd8, 0xb1, 0x71, 0x72, 0x8f, 0xef, 0x3d, 0x73, 0xee, 0xb9, 0x33, 0x63, 0xd8, 0xf1, 0xa2, + 0xe1, 0x30, 0x0a, 0x45, 0xcc, 0x3d, 0xdc, 0x8a, 0xce, 0x3e, 0xa2, 0x27, 0xb7, 0x64, 0x82, 0xa8, + 0x1e, 0x5e, 0x9f, 0x87, 0x17, 0x18, 0x27, 0x91, 0x8c, 0xb6, 0xd4, 0x53, 0x94, 0xe0, 0x4d, 0x85, + 0x50, 0x98, 0x22, 0xce, 0x35, 0x01, 0x60, 0x51, 0x24, 0xf7, 0x54, 0x48, 0xff, 0x83, 0x45, 0xee, + 0x0d, 0x5c, 0xe4, 0x7e, 0xcf, 0x37, 0x89, 0x4d, 0xba, 0x8b, 0x6c, 0x0a, 0x50, 0x13, 0x0c, 0xb5, + 0x6a, 0xcf, 0x37, 0x75, 0xf5, 0xae, 0x08, 0xa9, 0x05, 0x90, 0x11, 0x9e, 0x8c, 0x63, 0x34, 0x5b, + 0xea, 0x65, 0x09, 0x49, 0x79, 0x65, 0x30, 0x44, 0x21, 0xf9, 0x30, 0x36, 0xdb, 0x36, 0xe9, 0xb6, + 0xd8, 0x14, 0xa0, 0x14, 0xda, 0x02, 0xd1, 0x37, 0xe7, 0x6c, 0xd2, 0xed, 0x30, 0xf5, 0x9f, 0x6e, + 0xc0, 0x42, 0xe0, 0x63, 0x28, 0x03, 0x39, 0x36, 0xe7, 0x15, 0x3e, 0x89, 0xe9, 0x43, 0x58, 0xce, + 0xb8, 0x8f, 0xf8, 0x78, 0x10, 0x71, 0xdf, 0x34, 0x54, 0x42, 0x15, 0x74, 0x7e, 0xea, 0x00, 0x27, + 0x09, 0x62, 0xde, 0x9a, 0x0d, 0x4b, 0x69, 0xdf, 0x59, 0x2b, 0xc2, 0x24, 0x76, 0xab, 0xbb, 0xc8, + 0xca, 0x50, 0xb5, 0x79, 0xbd, 0xde, 0xfc, 0x23, 0x58, 0x11, 0x21, 0x8f, 0x45, 0x3f, 0x92, 0xbb, + 0x5c, 0xa4, 0x1e, 0x64, 0x6d, 0xd6, 0xd0, 0x74, 0x9d, 0x4c, 0x87, 0x78, 0xc5, 0x25, 0x57, 0xcd, + 0x76, 0x58, 0x19, 0xa2, 0x9b, 0x40, 0xbd, 0x51, 0x92, 0x60, 0x28, 0x19, 0x72, 0xff, 0x10, 0xc7, + 0x2e, 0x17, 0x7d, 0xd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0xaf, 0x7e, 0x9e, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x24, 0x93, 0x3b, 0x00, 0x1f, 0x07, + 0x00, 0x00, } func (m *RootChange) Marshal() (dAtA []byte, err error) { @@ -807,6 +873,13 @@ func (m *RootChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.ChangePayload) > 0 { + i -= len(m.ChangePayload) + copy(dAtA[i:], m.ChangePayload) + i = encodeVarintTreechange(dAtA, i, uint64(len(m.ChangePayload))) + i-- + dAtA[i] = 0x3a + } if len(m.Identity) > 0 { i -= len(m.Identity) copy(dAtA[i:], m.Identity) @@ -1362,6 +1435,43 @@ func (m *TreeErrorResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *TreeChangeInfo) 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 *TreeChangeInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TreeChangeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ChangePayload) > 0 { + i -= len(m.ChangePayload) + copy(dAtA[i:], m.ChangePayload) + i = encodeVarintTreechange(dAtA, i, uint64(len(m.ChangePayload))) + i-- + dAtA[i] = 0x12 + } + if len(m.ChangeType) > 0 { + i -= len(m.ChangeType) + copy(dAtA[i:], m.ChangeType) + i = encodeVarintTreechange(dAtA, i, uint64(len(m.ChangeType))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTreechange(dAtA []byte, offset int, v uint64) int { offset -= sovTreechange(v) base := offset @@ -1402,6 +1512,10 @@ func (m *RootChange) Size() (n int) { if l > 0 { n += 1 + l + sovTreechange(uint64(l)) } + l = len(m.ChangePayload) + if l > 0 { + n += 1 + l + sovTreechange(uint64(l)) + } return n } @@ -1650,6 +1764,23 @@ func (m *TreeErrorResponse) Size() (n int) { return n } +func (m *TreeChangeInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ChangeType) + if l > 0 { + n += 1 + l + sovTreechange(uint64(l)) + } + l = len(m.ChangePayload) + if l > 0 { + n += 1 + l + sovTreechange(uint64(l)) + } + return n +} + func sovTreechange(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1868,6 +1999,40 @@ func (m *RootChange) Unmarshal(dAtA []byte) error { m.Identity = []byte{} } iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChangePayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTreechange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTreechange + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTreechange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChangePayload = append(m.ChangePayload[:0], dAtA[iNdEx:postIndex]...) + if m.ChangePayload == nil { + m.ChangePayload = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTreechange(dAtA[iNdEx:]) @@ -3233,6 +3398,122 @@ func (m *TreeErrorResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *TreeChangeInfo) 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 ErrIntOverflowTreechange + } + 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: TreeChangeInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TreeChangeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChangeType", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTreechange + } + 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 ErrInvalidLengthTreechange + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTreechange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChangeType = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ChangePayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTreechange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTreechange + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTreechange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ChangePayload = append(m.ChangePayload[:0], dAtA[iNdEx:postIndex]...) + if m.ChangePayload == nil { + m.ChangePayload = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTreechange(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTreechange + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTreechange(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/commonspace/payloads.go b/commonspace/payloads.go index c6d25503..6e76a2ed 100644 --- a/commonspace/payloads.go +++ b/commonspace/payloads.go @@ -14,8 +14,8 @@ import ( ) const ( - SpaceSettingsChangeType = "reserved.spacesettings" - SpaceDerivationScheme = "derivation.standard" + SpaceReserved = "space.reserved" + SpaceDerivationScheme = "derivation.standard" ) func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload spacestorage.SpaceStorageCreatePayload, err error) { @@ -36,11 +36,12 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp return } header := &spacesyncproto.SpaceHeader{ - Identity: identity, - Timestamp: time.Now().UnixNano(), - SpaceType: payload.SpaceType, - ReplicationKey: payload.ReplicationKey, - Seed: spaceHeaderSeed, + Identity: identity, + Timestamp: time.Now().UnixNano(), + SpaceType: payload.SpaceType, + SpaceHeaderPayload: payload.SpacePayload, + ReplicationKey: payload.ReplicationKey, + Seed: spaceHeaderSeed, } marshalled, err := header.Marshal() if err != nil { @@ -101,7 +102,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp SigningKey: payload.SigningKey, SpaceId: spaceId, Seed: spaceSettingsSeed, - ChangeType: SpaceSettingsChangeType, + ChangeType: SpaceReserved, Timestamp: time.Now().UnixNano(), }) if err != nil { @@ -146,9 +147,10 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp // preparing header and space id header := &spacesyncproto.SpaceHeader{ - Identity: identity, - SpaceType: SpaceTypeDerived, - ReplicationKey: repKey, + Identity: identity, + SpaceType: payload.SpaceType, + SpaceHeaderPayload: payload.SpacePayload, + ReplicationKey: repKey, } marshalled, err := header.Marshal() if err != nil { @@ -201,7 +203,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload sp Identity: aclRoot.Identity, SigningKey: payload.SigningKey, SpaceId: spaceId, - ChangeType: SpaceSettingsChangeType, + ChangeType: SpaceReserved, }) if err != nil { return diff --git a/commonspace/space.go b/commonspace/space.go index d18c9e8a..ba31af7e 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -52,6 +52,8 @@ type SpaceCreatePayload struct { ReadKey []byte // ReplicationKey is a key which is to be used to determine the node where the space should be held ReplicationKey uint64 + // SpacePayload is an arbitrary payload related to space type + SpacePayload []byte } type HandleMessage struct { @@ -61,11 +63,11 @@ type HandleMessage struct { Message *spacesyncproto.ObjectSyncMessage } -const SpaceTypeDerived = "derived.space" - type SpaceDerivePayload struct { SigningKey signingkey.PrivKey EncryptionKey encryptionkey.PrivKey + SpaceType string + SpacePayload []byte } type SpaceDescription struct { diff --git a/commonspace/spacesyncproto/protos/spacesync.proto b/commonspace/spacesyncproto/protos/spacesync.proto index 48b44e0f..3bf03320 100644 --- a/commonspace/spacesyncproto/protos/spacesync.proto +++ b/commonspace/spacesyncproto/protos/spacesync.proto @@ -98,6 +98,7 @@ message SpaceHeader { string spaceType = 3; uint64 replicationKey = 4; bytes seed = 5; + bytes spaceHeaderPayload = 6; } // RawSpaceHeader is raw header for SpaceHeader diff --git a/commonspace/spacesyncproto/spacesync.pb.go b/commonspace/spacesyncproto/spacesync.pb.go index 8fb1a914..bb5b0e6e 100644 --- a/commonspace/spacesyncproto/spacesync.pb.go +++ b/commonspace/spacesyncproto/spacesync.pb.go @@ -694,11 +694,12 @@ func (m *SpacePayload) GetSpaceSettingsPayloadId() string { // SpaceHeader is a header for a space type SpaceHeader struct { - Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` - Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - SpaceType string `protobuf:"bytes,3,opt,name=spaceType,proto3" json:"spaceType,omitempty"` - ReplicationKey uint64 `protobuf:"varint,4,opt,name=replicationKey,proto3" json:"replicationKey,omitempty"` - Seed []byte `protobuf:"bytes,5,opt,name=seed,proto3" json:"seed,omitempty"` + Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` + Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + SpaceType string `protobuf:"bytes,3,opt,name=spaceType,proto3" json:"spaceType,omitempty"` + ReplicationKey uint64 `protobuf:"varint,4,opt,name=replicationKey,proto3" json:"replicationKey,omitempty"` + Seed []byte `protobuf:"bytes,5,opt,name=seed,proto3" json:"seed,omitempty"` + SpaceHeaderPayload []byte `protobuf:"bytes,6,opt,name=spaceHeaderPayload,proto3" json:"spaceHeaderPayload,omitempty"` } func (m *SpaceHeader) Reset() { *m = SpaceHeader{} } @@ -769,6 +770,13 @@ func (m *SpaceHeader) GetSeed() []byte { return nil } +func (m *SpaceHeader) GetSpaceHeaderPayload() []byte { + if m != nil { + return m.SpaceHeaderPayload + } + return nil +} + // RawSpaceHeader is raw header for SpaceHeader type RawSpaceHeader struct { SpaceHeader []byte `protobuf:"bytes,1,opt,name=spaceHeader,proto3" json:"spaceHeader,omitempty"` @@ -1240,72 +1248,73 @@ func init() { } var fileDescriptor_80e49f1f4ac27799 = []byte{ - // 1030 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0x4b, 0x6f, 0xdb, 0x46, - 0x10, 0x16, 0xe9, 0xa7, 0xc6, 0xb2, 0xcc, 0x6c, 0x9c, 0x44, 0x55, 0x0c, 0x45, 0x58, 0x14, 0x85, - 0x91, 0x43, 0x1e, 0x72, 0x51, 0x20, 0x69, 0x7b, 0x48, 0x64, 0xa7, 0x11, 0x8a, 0xd4, 0xc6, 0xaa, - 0x41, 0x81, 0x02, 0x39, 0xac, 0xc9, 0xb1, 0xc4, 0x96, 0x22, 0x59, 0xee, 0xaa, 0xb6, 0x8e, 0x3d, - 0xf5, 0xda, 0x73, 0x7b, 0xea, 0x7f, 0xe8, 0x8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fa, 0xf7, 0x75, 0xc7, 0x7a, 0x7f, 0xdd, 0xb1, 0xfe, 0xbd, - 0xee, 0x58, 0xbf, 0xdd, 0x74, 0x6a, 0xef, 0x6f, 0x3a, 0xb5, 0x7f, 0x6e, 0x3a, 0xb5, 0xef, 0xdb, - 0xab, 0xff, 0xf5, 0x3b, 0xdf, 0xd4, 0x7f, 0x8e, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x96, - 0xb3, 0xaa, 0x1f, 0x0a, 0x00, 0x00, + // 1042 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0x6e, 0xd2, 0x24, 0x7e, 0x71, 0x9c, 0xed, 0x34, 0x6d, 0x8d, 0x1b, 0xb9, 0xd6, 0x08, + 0xa1, 0xa8, 0x87, 0xb4, 0x75, 0x10, 0x52, 0x0b, 0x1c, 0x5a, 0x27, 0xa5, 0x16, 0x2a, 0x89, 0xc6, + 0x54, 0x48, 0x48, 0x3d, 0x4c, 0x76, 0x5f, 0xec, 0x85, 0xf5, 0xee, 0xb2, 0x33, 0x26, 0xf1, 0x91, + 0x13, 0x57, 0xce, 0xf0, 0x35, 0xf8, 0x10, 0x1c, 0xcb, 0x8d, 0x23, 0x4a, 0xbe, 0x08, 0x9a, 0xd9, + 0xd9, 0x3f, 0xb6, 0xd7, 0x95, 0xb8, 0x38, 0x3b, 0xbf, 0xf7, 0xde, 0xef, 0xfd, 0x9b, 0x79, 0x2f, + 0xf0, 0xd4, 0x8d, 0x26, 0x93, 0x28, 0x14, 0x31, 0x77, 0xf1, 0xb1, 0xfe, 0x15, 0xb3, 0xd0, 0x8d, + 0x93, 0x48, 0x46, 0x8f, 0xf5, 0xaf, 0x28, 0xd0, 0x43, 0x0d, 0x90, 0x7a, 0x0e, 0xd0, 0x01, 0xec, + 0xbc, 0x46,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xe7, 0x17, 0x4f, 0x0a, + 0x00, 0x00, } func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { @@ -1784,6 +1793,13 @@ func (m *SpaceHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.SpaceHeaderPayload) > 0 { + i -= len(m.SpaceHeaderPayload) + copy(dAtA[i:], m.SpaceHeaderPayload) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.SpaceHeaderPayload))) + i-- + dAtA[i] = 0x32 + } if len(m.Seed) > 0 { i -= len(m.Seed) copy(dAtA[i:], m.Seed) @@ -2387,6 +2403,10 @@ func (m *SpaceHeader) Size() (n int) { if l > 0 { n += 1 + l + sovSpacesync(uint64(l)) } + l = len(m.SpaceHeaderPayload) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } return n } @@ -4041,6 +4061,40 @@ func (m *SpaceHeader) Unmarshal(dAtA []byte) error { m.Seed = []byte{} } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceHeaderPayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthSpacesync + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SpaceHeaderPayload = append(m.SpaceHeaderPayload[:0], dAtA[iNdEx:postIndex]...) + if m.SpaceHeaderPayload == nil { + m.SpaceHeaderPayload = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipSpacesync(dAtA[iNdEx:]) diff --git a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go index b6b6931e..7216e1eb 100644 --- a/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go +++ b/coordinator/coordinatorclient/mock_coordinatorclient/mock_coordinatorclient.go @@ -38,11 +38,12 @@ func (m *MockCoordinatorClient) EXPECT() *MockCoordinatorClientMockRecorder { } // ChangeStatus mocks base method. -func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) error { +func (m *MockCoordinatorClient) ChangeStatus(arg0 context.Context, arg1 string, arg2 *treechangeproto.RawTreeChangeWithId) (*coordinatorproto.SpaceStatusPayload, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ChangeStatus", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusPayload) + ret1, _ := ret[1].(error) + return ret0, ret1 } // ChangeStatus indicates an expected call of ChangeStatus. @@ -110,10 +111,10 @@ func (mr *MockCoordinatorClientMockRecorder) SpaceSign(arg0, arg1, arg2 interfac } // StatusCheck mocks base method. -func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusCheckResponse, error) { +func (m *MockCoordinatorClient) StatusCheck(arg0 context.Context, arg1 string) (*coordinatorproto.SpaceStatusPayload, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StatusCheck", arg0, arg1) - ret0, _ := ret[0].(*coordinatorproto.SpaceStatusCheckResponse) + ret0, _ := ret[0].(*coordinatorproto.SpaceStatusPayload) ret1, _ := ret[1].(error) return ret0, ret1 } From 19930e6252bc64a7c9e0cd21518ad353bf1d4496 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 15:07:45 +0100 Subject: [PATCH 41/57] Update space reserved constant --- commonspace/payloads.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commonspace/payloads.go b/commonspace/payloads.go index 6e76a2ed..8c816343 100644 --- a/commonspace/payloads.go +++ b/commonspace/payloads.go @@ -14,7 +14,7 @@ import ( ) const ( - SpaceReserved = "space.reserved" + SpaceReserved = "any-sync.space" SpaceDerivationScheme = "derivation.standard" ) From 7d39332a79b9c8b7f010de4845c54974fe1ee6f9 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 16:33:13 +0100 Subject: [PATCH 42/57] Update state builder to fix root change --- commonspace/settings/settingsstate/statebuilder.go | 2 +- commonspace/settings/settingsstate/statebuilder_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/commonspace/settings/settingsstate/statebuilder.go b/commonspace/settings/settingsstate/statebuilder.go index 7f889ede..a6cf2c68 100644 --- a/commonspace/settings/settingsstate/statebuilder.go +++ b/commonspace/settings/settingsstate/statebuilder.go @@ -48,7 +48,7 @@ func (s *stateBuilder) Build(tr objecttree.ObjectTree, oldState *State) (state * func (s *stateBuilder) processChange(change *objecttree.Change, rootId string, state *State) *State { // ignoring root change which has empty model or startId change - if change.Model == nil || state.LastIteratedId == change.Id { + if len(change.PreviousIds) == 0 || state.LastIteratedId == change.Id { return state } diff --git a/commonspace/settings/settingsstate/statebuilder_test.go b/commonspace/settings/settingsstate/statebuilder_test.go index 7c8916ef..e2ac4448 100644 --- a/commonspace/settings/settingsstate/statebuilder_test.go +++ b/commonspace/settings/settingsstate/statebuilder_test.go @@ -42,6 +42,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) { t.Run("changeId is equal to rootId", func(t *testing.T) { ch := &objecttree.Change{} + ch.PreviousIds = []string{"someId"} ch.Model = &spacesyncproto.SettingsData{ Snapshot: &spacesyncproto.SpaceSettingsSnapshot{ DeletedIds: []string{"id1", "id2"}, @@ -56,6 +57,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) { t.Run("changeId is not equal to lastIteratedId or rootId", func(t *testing.T) { ch := &objecttree.Change{} + ch.PreviousIds = []string{"someId"} ch.Model = &spacesyncproto.SettingsData{ Content: []*spacesyncproto.SpaceSettingsContent{ {Value: &spacesyncproto.SpaceSettingsContent_ObjectDelete{ From 01e170ba694bc5596b63de63eef9b349dd52735d Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 16:52:30 +0100 Subject: [PATCH 43/57] Add newline to treechangeproto --- commonspace/object/tree/treechangeproto/protos/treechange.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commonspace/object/tree/treechangeproto/protos/treechange.proto b/commonspace/object/tree/treechangeproto/protos/treechange.proto index b4ae84d9..2211f58f 100644 --- a/commonspace/object/tree/treechangeproto/protos/treechange.proto +++ b/commonspace/object/tree/treechangeproto/protos/treechange.proto @@ -101,4 +101,4 @@ message TreeErrorResponse { message TreeChangeInfo { string changeType = 1; bytes changePayload = 2; -} \ No newline at end of file +} From bb86e5b7e521b92fd4ae8a6b52f7fd03bd0e4a3c Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Fri, 10 Mar 2023 18:22:08 +0100 Subject: [PATCH 44/57] Fix test --- app/ocache/ocache_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 14a59b1a..843586b7 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -191,13 +191,12 @@ func TestOCache_GC(t *testing.T) { c := New(func(ctx context.Context, id string) (value Object, err error) { timesCalled.Add(1) return obj, nil - }, WithTTL(time.Millisecond*10)) + }, WithTTL(0)) val, err := c.Get(context.TODO(), "id") require.NoError(t, err) require.NotNil(t, val) assert.Equal(t, 1, c.Len()) - time.Sleep(time.Millisecond * 20) begin := make(chan struct{}) wg := sync.WaitGroup{} once := sync.Once{} From ec0d8a0c0795cc8844082cf68e561c4d84b564af Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Fri, 10 Mar 2023 19:18:15 +0100 Subject: [PATCH 45/57] fix replacing existing logger --- app/logger/ctxfiled.go | 7 ++- app/logger/log.go | 48 ++++++++++++++----- commonspace/object/acl/list/aclstate.go | 7 +-- .../object/tree/objecttree/treebuilder.go | 5 +- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/logger/ctxfiled.go b/app/logger/ctxfiled.go index 83d8bba4..5597ba54 100644 --- a/app/logger/ctxfiled.go +++ b/app/logger/ctxfiled.go @@ -32,6 +32,7 @@ func CtxGetFields(ctx context.Context) (fields []zap.Field) { type CtxLogger struct { *zap.Logger + name string } func (cl CtxLogger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field) { @@ -51,5 +52,9 @@ func (cl CtxLogger) ErrorCtx(ctx context.Context, msg string, fields ...zap.Fiel } func (cl CtxLogger) With(fields ...zap.Field) CtxLogger { - return CtxLogger{cl.Logger.With(fields...)} + return CtxLogger{cl.Logger.With(fields...), cl.name} +} + +func (cl CtxLogger) Sugar() *zap.SugaredLogger { + return NewNamedSugared(cl.name) } diff --git a/app/logger/log.go b/app/logger/log.go index 264cdaf1..e41c20d1 100644 --- a/app/logger/log.go +++ b/app/logger/log.go @@ -8,12 +8,13 @@ import ( ) var ( - mu sync.Mutex - logger *zap.Logger - loggerConfig zap.Config - namedLevels = make(map[string]zap.AtomicLevel) - namedGlobs = make(map[string]glob.Glob) - namedLoggers = make(map[string]CtxLogger) + mu sync.Mutex + logger *zap.Logger + loggerConfig zap.Config + namedLevels = make(map[string]zap.AtomicLevel) + namedGlobs = make(map[string]glob.Glob) + namedLoggers = make(map[string]CtxLogger) + namedSugarLoggers = make(map[string]*zap.SugaredLogger) ) func init() { @@ -59,10 +60,18 @@ func SetNamedLevels(l map[string]zap.AtomicLevel) { for name, nl := range namedLoggers { level := getLevel(name) - // this can be racy, but - nl.Logger = zap.New(logger.Core()).WithOptions( + newCore := zap.New(logger.Core()).Named(name).WithOptions( zap.IncreaseLevel(level), - ).Named(name) + ) + *(nl.Logger) = *newCore + } + + for name, nl := range namedSugarLoggers { + level := getLevel(name) + newCore := zap.New(logger.Core()).Named(name).WithOptions( + zap.IncreaseLevel(level), + ).Sugar() + *(nl) = *newCore } } @@ -100,11 +109,24 @@ func NewNamed(name string, fields ...zap.Field) CtxLogger { } level := getLevel(name) - l := zap.New(logger.Core()).WithOptions( - zap.IncreaseLevel(level), - ).Named(name) + l := zap.New(logger.Core()).Named(name).WithOptions(zap.IncreaseLevel(level), + zap.Fields(fields...)) - ctxL := CtxLogger{l} + ctxL := CtxLogger{Logger: l, name: name} namedLoggers[name] = ctxL return ctxL } + +func NewNamedSugared(name string) *zap.SugaredLogger { + mu.Lock() + defer mu.Unlock() + + if l, nameExists := namedSugarLoggers[name]; nameExists { + return l + } + + level := getLevel(name) + l := zap.New(logger.Core()).Named(name).Sugar().WithOptions(zap.IncreaseLevel(level)) + namedSugarLoggers[name] = l + return l +} diff --git a/commonspace/object/acl/list/aclstate.go b/commonspace/object/acl/list/aclstate.go index 9808dddf..3acb0166 100644 --- a/commonspace/object/acl/list/aclstate.go +++ b/commonspace/object/acl/list/aclstate.go @@ -4,8 +4,10 @@ import ( "bytes" "errors" "fmt" + "hash/fnv" + "github.com/anytypeio/any-sync/app/logger" - aclrecordproto "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" + "github.com/anytypeio/any-sync/commonspace/object/acl/aclrecordproto" "github.com/anytypeio/any-sync/commonspace/object/keychain" "github.com/anytypeio/any-sync/util/keys" "github.com/anytypeio/any-sync/util/keys/asymmetric/encryptionkey" @@ -13,10 +15,9 @@ import ( "github.com/anytypeio/any-sync/util/keys/symmetric" "github.com/gogo/protobuf/proto" "go.uber.org/zap" - "hash/fnv" ) -var log = logger.NewNamed("acllist").Sugar() +var log = logger.NewNamedSugared("acllist") var ( ErrNoSuchUser = errors.New("no such user") diff --git a/commonspace/object/tree/objecttree/treebuilder.go b/commonspace/object/tree/objecttree/treebuilder.go index 113b8381..78ccceea 100644 --- a/commonspace/object/tree/objecttree/treebuilder.go +++ b/commonspace/object/tree/objecttree/treebuilder.go @@ -4,15 +4,16 @@ import ( "context" "errors" "fmt" + "time" + "github.com/anytypeio/any-sync/app/logger" "github.com/anytypeio/any-sync/commonspace/object/tree/treestorage" "github.com/anytypeio/any-sync/util/slice" "go.uber.org/zap" - "time" ) var ( - log = logger.NewNamed("acltree").Sugar() + log = logger.NewNamedSugared("acltree") ErrEmpty = errors.New("logs empty") ) From df9a5f11ae590c5cc30fea15d4944e2fbc7c05bf Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Fri, 10 Mar 2023 19:32:20 +0100 Subject: [PATCH 46/57] cleanup logger names --- commonspace/object/acl/list/aclstate.go | 2 +- commonspace/object/tree/objecttree/treebuilder.go | 2 +- net/peer/peer.go | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/commonspace/object/acl/list/aclstate.go b/commonspace/object/acl/list/aclstate.go index 3acb0166..fb6d4b49 100644 --- a/commonspace/object/acl/list/aclstate.go +++ b/commonspace/object/acl/list/aclstate.go @@ -17,7 +17,7 @@ import ( "go.uber.org/zap" ) -var log = logger.NewNamedSugared("acllist") +var log = logger.NewNamedSugared("common.commonspace.acllist") var ( ErrNoSuchUser = errors.New("no such user") diff --git a/commonspace/object/tree/objecttree/treebuilder.go b/commonspace/object/tree/objecttree/treebuilder.go index 78ccceea..edaa3ede 100644 --- a/commonspace/object/tree/objecttree/treebuilder.go +++ b/commonspace/object/tree/objecttree/treebuilder.go @@ -13,7 +13,7 @@ import ( ) var ( - log = logger.NewNamedSugared("acltree") + log = logger.NewNamedSugared("common.commonspace.objecttree") ErrEmpty = errors.New("logs empty") ) diff --git a/net/peer/peer.go b/net/peer/peer.go index 9c9f547d..21fb85f8 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -2,15 +2,16 @@ package peer import ( "context" + "sync/atomic" + "time" + "github.com/anytypeio/any-sync/app/logger" "github.com/libp2p/go-libp2p/core/sec" "go.uber.org/zap" "storj.io/drpc" - "sync/atomic" - "time" ) -var log = logger.NewNamed("peer") +var log = logger.NewNamed("net.peer") func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer { return &peer{ From 67ca417cb8afb2537f968bd57a9540bb575291c9 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sat, 11 Mar 2023 12:52:42 +0100 Subject: [PATCH 47/57] Change timeestamps --- commonspace/object/acl/list/aclrecordbuilder.go | 2 +- .../acl/testutils/acllistbuilder/liststoragebuilder.go | 2 +- commonspace/object/tree/objecttree/changebuilder.go | 2 +- commonspace/object/tree/objecttree/objecttreefactory.go | 4 ++-- commonspace/object/tree/objecttree/tree_test.go | 2 +- commonspace/payloads.go | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/commonspace/object/acl/list/aclrecordbuilder.go b/commonspace/object/acl/list/aclrecordbuilder.go index c7ba4390..8f0a0071 100644 --- a/commonspace/object/acl/list/aclrecordbuilder.go +++ b/commonspace/object/acl/list/aclrecordbuilder.go @@ -88,7 +88,7 @@ func (a *aclRecordBuilder) BuildUserJoin(acceptPrivKeyBytes []byte, encSymKeyByt Identity: state.Identity(), Data: marshalledJoin, CurrentReadKeyHash: state.CurrentReadKeyHash(), - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), } marshalledRecord, err := aclRecord.Marshal() if err != nil { diff --git a/commonspace/object/acl/testutils/acllistbuilder/liststoragebuilder.go b/commonspace/object/acl/testutils/acllistbuilder/liststoragebuilder.go index ac268df5..35a17bda 100644 --- a/commonspace/object/acl/testutils/acllistbuilder/liststoragebuilder.go +++ b/commonspace/object/acl/testutils/acllistbuilder/liststoragebuilder.go @@ -126,7 +126,7 @@ func (t *AclListStorageBuilder) parseRecord(rec *Record, prevId string) *aclreco Identity: []byte(t.keychain.GetIdentity(rec.Identity)), Data: bytes, CurrentReadKeyHash: k.Hash, - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), } } diff --git a/commonspace/object/tree/objecttree/changebuilder.go b/commonspace/object/tree/objecttree/changebuilder.go index 8ef6e5a0..8e312309 100644 --- a/commonspace/object/tree/objecttree/changebuilder.go +++ b/commonspace/object/tree/objecttree/changebuilder.go @@ -165,7 +165,7 @@ func (c *changeBuilder) Build(payload BuilderContent) (ch *Change, rawIdChange * AclHeadId: payload.AclHeadId, SnapshotBaseId: payload.SnapshotBaseId, CurrentReadKeyHash: payload.CurrentReadKeyHash, - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), Identity: payload.Identity, IsSnapshot: payload.IsSnapshot, } diff --git a/commonspace/object/tree/objecttree/objecttreefactory.go b/commonspace/object/tree/objecttree/objecttreefactory.go index cfceefe0..e3ec5c6f 100644 --- a/commonspace/object/tree/objecttree/objecttreefactory.go +++ b/commonspace/object/tree/objecttree/objecttreefactory.go @@ -76,7 +76,7 @@ func CreateObjectTreeRoot(payload ObjectTreeCreatePayload, aclList list.AclList) if err != nil { return } - return createObjectTreeRoot(payload, time.Now().UnixNano(), bytes, aclList) + return createObjectTreeRoot(payload, time.Now().Unix(), bytes, aclList) } func DeriveObjectTreeRoot(payload ObjectTreeCreatePayload, aclList list.AclList) (root *treechangeproto.RawTreeChangeWithId, err error) { @@ -126,7 +126,7 @@ func CreateObjectTree( if err != nil { return } - return createObjectTree(payload, time.Now().UnixNano(), bytes, aclList, createStorage) + return createObjectTree(payload, time.Now().Unix(), bytes, aclList, createStorage) } func createObjectTree( diff --git a/commonspace/object/tree/objecttree/tree_test.go b/commonspace/object/tree/objecttree/tree_test.go index 8bbed0cc..4bda3527 100644 --- a/commonspace/object/tree/objecttree/tree_test.go +++ b/commonspace/object/tree/objecttree/tree_test.go @@ -125,7 +125,7 @@ func TestTree_Hash(t *testing.T) { } func TestTree_AddFuzzy(t *testing.T) { - rand.Seed(time.Now().UnixNano()) + rand.Seed(time.Now().Unix()) getChanges := func() []*Change { changes := []*Change{ newChange("1", "root", "root"), diff --git a/commonspace/payloads.go b/commonspace/payloads.go index 8c816343..ba45dff6 100644 --- a/commonspace/payloads.go +++ b/commonspace/payloads.go @@ -37,7 +37,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp } header := &spacesyncproto.SpaceHeader{ Identity: identity, - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), SpaceType: payload.SpaceType, SpaceHeaderPayload: payload.SpacePayload, ReplicationKey: payload.ReplicationKey, @@ -82,7 +82,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp SpaceId: spaceId, EncryptedReadKey: encReadKey, CurrentReadKeyHash: readKeyHash, - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), } rawWithId, err := marshalAclRoot(aclRoot, payload.SigningKey) if err != nil { @@ -103,7 +103,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload sp SpaceId: spaceId, Seed: spaceSettingsSeed, ChangeType: SpaceReserved, - Timestamp: time.Now().UnixNano(), + Timestamp: time.Now().Unix(), }) if err != nil { return From 981378c2e3cee783ba48872160ec6f4aca4b6f3e Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sat, 11 Mar 2023 13:41:07 +0100 Subject: [PATCH 48/57] Ocache remove with ctx --- app/ocache/ocache.go | 15 +++++++-------- app/ocache/ocache_test.go | 14 ++++++++------ net/pool/pool.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/ocache/ocache.go b/app/ocache/ocache.go index 7375c643..8c9011e1 100644 --- a/app/ocache/ocache.go +++ b/app/ocache/ocache.go @@ -85,7 +85,7 @@ type OCache interface { // Returns error when object exists Add(id string, value Object) (err error) // Remove closes and removes object - Remove(id string) (ok bool, err error) + Remove(ctx context.Context, id string) (ok bool, err error) // ForEach iterates over all loaded objects, breaks when callback returns false ForEach(f func(v Object) (isContinue bool)) // GC frees not used and expired objects @@ -170,7 +170,7 @@ func (c *oCache) load(ctx context.Context, id string, e *entry) { } } -func (c *oCache) Remove(id string) (ok bool, err error) { +func (c *oCache) Remove(ctx context.Context, id string) (ok bool, err error) { c.mu.Lock() if c.closed { c.mu.Unlock() @@ -183,13 +183,12 @@ func (c *oCache) Remove(id string) (ok bool, err error) { return false, ErrNotExists } c.mu.Unlock() - return c.remove(e) + return c.remove(ctx, e) } -func (c *oCache) remove(e *entry) (ok bool, err error) { - <-e.load - if e.value == nil { - return false, ErrNotExists +func (c *oCache) remove(ctx context.Context, e *entry) (ok bool, err error) { + if _, err = e.waitLoad(ctx, e.id); err != nil { + return false, err } _, curState := e.setClosing(true) if curState == entryStateClosing { @@ -320,7 +319,7 @@ func (c *oCache) Close() (err error) { } c.mu.Unlock() for _, e := range toClose { - if _, err := c.remove(e); err != nil && err != ErrNotExists { + if _, err := c.remove(context.Background(), e); err != nil && err != ErrNotExists { c.log.With("object_id", e.id).Warnf("cache close: object close error: %v", err) } } diff --git a/app/ocache/ocache_test.go b/app/ocache/ocache_test.go index 843586b7..d78345b0 100644 --- a/app/ocache/ocache_test.go +++ b/app/ocache/ocache_test.go @@ -13,6 +13,8 @@ import ( "github.com/stretchr/testify/require" ) +var ctx = context.Background() + type testObject struct { name string closeErr error @@ -281,7 +283,7 @@ func Test_OCache_Remove(t *testing.T) { assert.Equal(t, 1, c.Len()) // removing the object, so we will wait on closing go func() { - _, err := c.Remove("id") + _, err := c.Remove(ctx, "id") require.NoError(t, err) }() time.Sleep(time.Millisecond * 20) @@ -318,7 +320,7 @@ func Test_OCache_Remove(t *testing.T) { time.Sleep(time.Millisecond * 20) var events []string go func() { - ok, err := c.Remove("id") + ok, err := c.Remove(ctx, "id") require.NoError(t, err) require.True(t, ok) events = append(events, "remove") @@ -347,7 +349,7 @@ func Test_OCache_Remove(t *testing.T) { time.Sleep(time.Millisecond * 20) var events []string go func() { - ok, err := c.Remove("id") + ok, err := c.Remove(ctx, "id") require.NoError(t, err) require.False(t, ok) events = append(events, "remove") @@ -372,7 +374,7 @@ func Test_OCache_Remove(t *testing.T) { require.NotNil(t, val) assert.Equal(t, 1, c.Len()) go func() { - ok, err := c.Remove("id") + ok, err := c.Remove(ctx, "id") require.NoError(t, err) require.True(t, ok) close(removeCh) @@ -430,7 +432,7 @@ func TestOCacheFuzzy(t *testing.T) { defer wg.Done() for j := 0; j < 10; j++ { for i := 0; i < max; i++ { - c.Remove(getId(i)) + c.Remove(ctx, getId(i)) } } }() @@ -477,7 +479,7 @@ func TestOCacheFuzzy(t *testing.T) { go func() { for j := 0; j < 10; j++ { for i := 0; i < max; i++ { - c.Remove(getId(i)) + c.Remove(ctx, getId(i)) } } }() diff --git a/net/pool/pool.go b/net/pool/pool.go index e5a8cc1d..287ab512 100644 --- a/net/pool/pool.go +++ b/net/pool/pool.go @@ -49,7 +49,7 @@ func (p *pool) Get(ctx context.Context, id string) (peer.Peer, error) { default: return pr, nil } - _, _ = p.cache.Remove(id) + _, _ = p.cache.Remove(ctx, id) return p.Get(ctx, id) } From 6b2667d4dc01be09ab8b54db08ab7645efc50b60 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 13 Mar 2023 12:58:37 +0100 Subject: [PATCH 49/57] Add increment/decrement logs --- commonspace/space.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commonspace/space.go b/commonspace/space.go index ece7437d..69277c5a 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -330,7 +330,7 @@ func (s *space) BuildTree(ctx context.Context, id string, opts BuildTreeOpts) (t if t, err = synctree.BuildSyncTreeOrGetRemote(ctx, id, deps); err != nil { return nil, err } - log.Debug("incrementing counter", zap.String("id", id), zap.String("spaceId", s.id)) + log.Debug("incrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()+1), zap.String("spaceId", s.id)) s.treesUsed.Add(1) return } @@ -406,7 +406,7 @@ func (s *space) handleMessage(msg HandleMessage) { } func (s *space) onObjectClose(id string) { - log.Debug("decrementing counter", zap.String("id", id), zap.String("spaceId", s.id)) + log.Debug("decrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()+1), zap.String("spaceId", s.id)) s.treesUsed.Add(-1) _ = s.handleQueue.CloseThread(id) } From a2efcafb3e191c6b3430108f4fa9c1857340ec17 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 13 Mar 2023 13:04:23 +0100 Subject: [PATCH 50/57] Update counters --- commonspace/space.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commonspace/space.go b/commonspace/space.go index 69277c5a..172de668 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -330,8 +330,8 @@ func (s *space) BuildTree(ctx context.Context, id string, opts BuildTreeOpts) (t if t, err = synctree.BuildSyncTreeOrGetRemote(ctx, id, deps); err != nil { return nil, err } - log.Debug("incrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()+1), zap.String("spaceId", s.id)) s.treesUsed.Add(1) + log.Debug("incrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id)) return } @@ -406,8 +406,8 @@ func (s *space) handleMessage(msg HandleMessage) { } func (s *space) onObjectClose(id string) { - log.Debug("decrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()+1), zap.String("spaceId", s.id)) s.treesUsed.Add(-1) + log.Debug("decrementing counter", zap.String("id", id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id)) _ = s.handleQueue.CloseThread(id) } From 25b0695d3ee0278406378c67f31903e3ff3fe7bd Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 13 Mar 2023 13:46:36 +0100 Subject: [PATCH 51/57] Add counter for put sync tree --- commonspace/space.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commonspace/space.go b/commonspace/space.go index 172de668..f6de90ea 100644 --- a/commonspace/space.go +++ b/commonspace/space.go @@ -295,7 +295,13 @@ func (s *space) PutTree(ctx context.Context, payload treestorage.TreeStorageCrea SyncStatus: s.syncStatus, PeerGetter: s.peerManager, } - return synctree.PutSyncTree(ctx, payload, deps) + t, err = synctree.PutSyncTree(ctx, payload, deps) + if err != nil { + return + } + s.treesUsed.Add(1) + log.Debug("incrementing counter", zap.String("id", payload.RootRawChange.Id), zap.Int32("trees", s.treesUsed.Load()), zap.String("spaceId", s.id)) + return } type BuildTreeOpts struct { From 86dcc83461541e201a27d70541d2f6d3ef262cf2 Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Mon, 13 Mar 2023 14:14:55 +0100 Subject: [PATCH 52/57] change logger name --- net/peer/peer.go | 2 +- net/timeoutconn/conn.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/peer/peer.go b/net/peer/peer.go index 21fb85f8..21eee669 100644 --- a/net/peer/peer.go +++ b/net/peer/peer.go @@ -11,7 +11,7 @@ import ( "storj.io/drpc" ) -var log = logger.NewNamed("net.peer") +var log = logger.NewNamed("common.net.peer") func NewPeer(sc sec.SecureConn, conn drpc.Conn) Peer { return &peer{ diff --git a/net/timeoutconn/conn.go b/net/timeoutconn/conn.go index 0f5c5d30..62917dbc 100644 --- a/net/timeoutconn/conn.go +++ b/net/timeoutconn/conn.go @@ -2,14 +2,15 @@ package timeoutconn import ( "errors" - "github.com/anytypeio/any-sync/app/logger" - "go.uber.org/zap" "net" "os" "time" + + "github.com/anytypeio/any-sync/app/logger" + "go.uber.org/zap" ) -var log = logger.NewNamed("net.timeoutconn") +var log = logger.NewNamed("common.net.timeoutconn") type Conn struct { net.Conn From e568f899aab0e56b93621429b79f2711f83ad64e Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 13 Mar 2023 17:18:21 +0100 Subject: [PATCH 53/57] Remove old connection from pool on close (GetOneOf) --- net/pool/pool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/net/pool/pool.go b/net/pool/pool.go index 287ab512..b2e4ae22 100644 --- a/net/pool/pool.go +++ b/net/pool/pool.go @@ -67,6 +67,7 @@ func (p *pool) GetOneOf(ctx context.Context, peerIds []string) (peer.Peer, error default: return pr, nil } + _, _ = p.cache.Remove(ctx, peerId) } } // shuffle ids for better consistency From 417b203b0919fc8407722ae71bde93caf905161f Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 16 Mar 2023 17:57:10 +0100 Subject: [PATCH 54/57] Derive space id as a separate method --- commonspace/spaceservice.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 89e9283b..0fc01125 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -35,6 +35,7 @@ const AddSpaceCtxKey ctxKey = 0 type SpaceService interface { DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error) + DerivedId(ctx context.Context, payload SpaceDerivePayload) (string, error) CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error) NewSpace(ctx context.Context, id string) (sp Space, err error) app.Component @@ -88,6 +89,15 @@ func (s *spaceService) CreateSpace(ctx context.Context, payload SpaceCreatePaylo return store.Id(), nil } +func (s *spaceService) DerivedId(ctx context.Context, payload SpaceDerivePayload) (id string, err error) { + storageCreate, err := storagePayloadForSpaceDerive(payload) + if err != nil { + return + } + id = storageCreate.SpaceHeaderWithId.Id + return +} + func (s *spaceService) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (id string, err error) { storageCreate, err := storagePayloadForSpaceDerive(payload) if err != nil { From 2691da66f7506149867728664647a31dc07e00f4 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 16 Mar 2023 18:27:19 +0100 Subject: [PATCH 55/57] Update rpc err in pull space --- commonspace/spaceservice.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 0fc01125..47427831 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -17,6 +17,7 @@ import ( "github.com/anytypeio/any-sync/commonspace/syncstatus" "github.com/anytypeio/any-sync/net/peer" "github.com/anytypeio/any-sync/net/pool" + "github.com/anytypeio/any-sync/net/rpc/rpcerr" "github.com/anytypeio/any-sync/nodeconf" "sync/atomic" ) @@ -216,6 +217,7 @@ func (s *spaceService) getSpaceStorageFromRemote(ctx context.Context, id string) cl := spacesyncproto.NewDRPCSpaceSyncClient(p) res, err := cl.SpacePull(ctx, &spacesyncproto.SpacePullRequest{Id: id}) if err != nil { + err = rpcerr.Unwrap(err) return } From ed1b597fc5fb1af755e4b68cead44868dda72ecf Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 16 Mar 2023 18:46:48 +0100 Subject: [PATCH 56/57] Add error wrapping in app --- app/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 85d67f61..3655724c 100644 --- a/app/app.go +++ b/app/app.go @@ -172,7 +172,7 @@ func (app *App) Start(ctx context.Context) (err error) { for i, s := range app.components { if err = s.Init(app); err != nil { closeServices(i) - return fmt.Errorf("can't init service '%s': %v", s.Name(), err) + return fmt.Errorf("can't init service '%s': %w", s.Name(), err) } } @@ -181,7 +181,7 @@ func (app *App) Start(ctx context.Context) (err error) { start := time.Now() if err = serviceRun.Run(ctx); err != nil { closeServices(i) - return fmt.Errorf("can't run service '%s': %v", serviceRun.Name(), err) + return fmt.Errorf("can't run service '%s': %w", serviceRun.Name(), err) } spent := time.Since(start).Milliseconds() app.startStat.SpentMsTotal += spent From 305c509fc6a1edce94fbc31e84fb6867631fa66b Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Thu, 16 Mar 2023 19:01:05 +0100 Subject: [PATCH 57/57] Update derive id method name --- commonspace/spaceservice.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commonspace/spaceservice.go b/commonspace/spaceservice.go index 47427831..cf4a2710 100644 --- a/commonspace/spaceservice.go +++ b/commonspace/spaceservice.go @@ -36,7 +36,7 @@ const AddSpaceCtxKey ctxKey = 0 type SpaceService interface { DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error) - DerivedId(ctx context.Context, payload SpaceDerivePayload) (string, error) + DeriveId(ctx context.Context, payload SpaceDerivePayload) (string, error) CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error) NewSpace(ctx context.Context, id string) (sp Space, err error) app.Component @@ -90,7 +90,7 @@ func (s *spaceService) CreateSpace(ctx context.Context, payload SpaceCreatePaylo return store.Id(), nil } -func (s *spaceService) DerivedId(ctx context.Context, payload SpaceDerivePayload) (id string, err error) { +func (s *spaceService) DeriveId(ctx context.Context, payload SpaceDerivePayload) (id string, err error) { storageCreate, err := storagePayloadForSpaceDerive(payload) if err != nil { return