From 25260793c6ebdc3d7692a22353ca629c08c4b8e7 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Mon, 10 Oct 2022 23:08:44 +0200 Subject: [PATCH] WIP storage --- common/commonspace/diffservice/diffsyncer.go | 1 - .../diffservice/diffsyncer_test.go | 8 +- common/commonspace/payloads.go | 34 +- common/commonspace/service.go | 4 +- .../spacesyncproto/protos/spacesync.proto | 13 +- .../spacesyncproto/spacesync.pb.go | 626 ++++++++++++++---- .../storage/mock_storage/mock_storage.go | 4 +- common/commonspace/storage/storage.go | 7 +- node/nodespace/rpchandler.go | 7 +- node/storage/keys.go | 6 +- node/storage/spacestorage.go | 21 +- node/storage/treestorage.go | 37 +- pkg/acl/aclrecordproto/aclrecord.pb.go | 1 - .../testutils/testchanges/proto/test.pb.go | 1 - .../tree/mock_objecttree/mock_objecttree.go | 4 +- 15 files changed, 614 insertions(+), 160 deletions(-) diff --git a/common/commonspace/diffservice/diffsyncer.go b/common/commonspace/diffservice/diffsyncer.go index fe1d5d93..d5022323 100644 --- a/common/commonspace/diffservice/diffsyncer.go +++ b/common/commonspace/diffservice/diffsyncer.go @@ -107,7 +107,6 @@ func (d *diffSyncer) sendPushSpaceRequest(ctx context.Context, cl spacesyncproto } _, err = cl.PushSpace(ctx, &spacesyncproto.PushSpaceRequest{ - SpaceId: d.spaceId, SpaceHeader: header, AclRoot: root, }) diff --git a/common/commonspace/diffservice/diffsyncer_test.go b/common/commonspace/diffservice/diffsyncer_test.go index 444b73fa..47fa3c2d 100644 --- a/common/commonspace/diffservice/diffsyncer_test.go +++ b/common/commonspace/diffservice/diffsyncer_test.go @@ -25,7 +25,7 @@ import ( type pushSpaceRequestMatcher struct { spaceId string aclRoot *aclrecordproto.RawACLRecordWithId - spaceHeader *spacesyncproto.SpaceHeader + spaceHeader *spacesyncproto.RawSpaceHeaderWithId } func (p pushSpaceRequestMatcher) Matches(x interface{}) bool { @@ -34,7 +34,7 @@ func (p pushSpaceRequestMatcher) Matches(x interface{}) bool { return false } - return res.SpaceId == p.spaceId && res.AclRoot == p.aclRoot && res.SpaceHeader == p.spaceHeader + return res.AclRoot == p.aclRoot && res.SpaceHeader == p.spaceHeader } func (p pushSpaceRequestMatcher) String() string { @@ -73,7 +73,7 @@ func (m mockPeer) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) func newPushSpaceRequestMatcher( spaceId string, aclRoot *aclrecordproto.RawACLRecordWithId, - spaceHeader *spacesyncproto.SpaceHeader) *pushSpaceRequestMatcher { + spaceHeader *spacesyncproto.RawSpaceHeaderWithId) *pushSpaceRequestMatcher { return &pushSpaceRequestMatcher{ spaceId: spaceId, aclRoot: aclRoot, @@ -125,7 +125,7 @@ func TestDiffSyncer_Sync(t *testing.T) { t.Run("diff syncer sync space missing", func(t *testing.T) { aclStorageMock := mock_aclstorage.NewMockListStorage(ctrl) aclRoot := &aclrecordproto.RawACLRecordWithId{} - spaceHeader := &spacesyncproto.SpaceHeader{} + spaceHeader := &spacesyncproto.RawSpaceHeaderWithId{} connectorMock.EXPECT(). GetResponsiblePeers(gomock.Any(), spaceId). diff --git a/common/commonspace/payloads.go b/common/commonspace/payloads.go index fae285ab..7c25884d 100644 --- a/common/commonspace/payloads.go +++ b/common/commonspace/payloads.go @@ -39,11 +39,21 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload st if err != nil { return } - id, err := cid.NewCIDFromBytes(marshalled) + signature, err := payload.SigningKey.Sign(marshalled) if err != nil { return } + rawHeader := &spacesyncproto.RawSpaceHeader{SpaceHeader: marshalled, Signature: signature} + marshalled, err = rawHeader.Marshal() + if err != nil { + return + } + id, err := cid.NewCIDFromBytes(marshalled) spaceId := NewSpaceId(id, payload.ReplicationKey) + rawHeaderWithId := &spacesyncproto.RawSpaceHeaderWithId{ + RawHeader: marshalled, + Id: spaceId, + } // encrypting read key hasher := fnv.New64() @@ -74,9 +84,8 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload st // creating storage storagePayload = storage.SpaceStorageCreatePayload{ - RecWithId: rawWithId, - SpaceHeader: header, - Id: id, + RecWithId: rawWithId, + SpaceHeaderWithId: rawHeaderWithId, } return } @@ -118,11 +127,21 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload st if err != nil { return } - id, err := cid.NewCIDFromBytes(marshalled) + signature, err := payload.SigningKey.Sign(marshalled) if err != nil { return } + rawHeader := &spacesyncproto.RawSpaceHeader{SpaceHeader: marshalled, Signature: signature} + marshalled, err = rawHeader.Marshal() + if err != nil { + return + } + id, err := cid.NewCIDFromBytes(marshalled) spaceId := NewSpaceId(id, repKey) + rawHeaderWithId := &spacesyncproto.RawSpaceHeaderWithId{ + RawHeader: marshalled, + Id: spaceId, + } // deriving and encrypting read key readKey, err := aclrecordproto.ACLReadKeyDerive(signPrivKey, encPrivKey) @@ -157,9 +176,8 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload st // creating storage storagePayload = storage.SpaceStorageCreatePayload{ - RecWithId: rawWithId, - SpaceHeader: header, - Id: id, + RecWithId: rawWithId, + SpaceHeaderWithId: rawHeaderWithId, } return } diff --git a/common/commonspace/service.go b/common/commonspace/service.go index adefcf7f..dd0347a1 100644 --- a/common/commonspace/service.go +++ b/common/commonspace/service.go @@ -62,7 +62,7 @@ func (s *service) CreateSpace( return } - return s.GetSpace(ctx, storageCreate.Id) + return s.GetSpace(ctx, storageCreate.SpaceHeaderWithId.GetId()) } func (s *service) DeriveSpace( @@ -78,7 +78,7 @@ func (s *service) DeriveSpace( return } - return s.GetSpace(ctx, storageCreate.Id) + return s.GetSpace(ctx, storageCreate.SpaceHeaderWithId.GetId()) } func (s *service) GetSpace(ctx context.Context, id string) (Space, error) { diff --git a/common/commonspace/spacesyncproto/protos/spacesync.proto b/common/commonspace/spacesyncproto/protos/spacesync.proto index 2b45d366..20bb12fa 100644 --- a/common/commonspace/spacesyncproto/protos/spacesync.proto +++ b/common/commonspace/spacesyncproto/protos/spacesync.proto @@ -102,8 +102,7 @@ message ObjectErrorResponse { // PushSpaceRequest is a request to add space on a node containing only one acl record message PushSpaceRequest { - string spaceId = 1; - SpaceHeader spaceHeader = 2; + RawSpaceHeaderWithId spaceHeader = 2; aclrecord.RawACLRecordWithId aclRoot = 3; } @@ -118,3 +117,13 @@ message SpaceHeader { uint64 replicationKey = 4; bytes seed = 5; } + +message RawSpaceHeader { + bytes spaceHeader = 1; + bytes signature = 2; +} + +message RawSpaceHeaderWithId { + bytes rawHeader = 1; + string id = 2; +} diff --git a/common/commonspace/spacesyncproto/spacesync.pb.go b/common/commonspace/spacesyncproto/spacesync.pb.go index 0c89fb20..2fe5cbc4 100644 --- a/common/commonspace/spacesyncproto/spacesync.pb.go +++ b/common/commonspace/spacesyncproto/spacesync.pb.go @@ -747,8 +747,7 @@ func (m *ObjectErrorResponse) GetError() string { // PushSpaceRequest is a request to add space on a node containing only one acl record type PushSpaceRequest struct { - SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - SpaceHeader *SpaceHeader `protobuf:"bytes,2,opt,name=spaceHeader,proto3" json:"spaceHeader,omitempty"` + SpaceHeader *RawSpaceHeaderWithId `protobuf:"bytes,2,opt,name=spaceHeader,proto3" json:"spaceHeader,omitempty"` AclRoot *aclrecordproto.RawACLRecordWithId `protobuf:"bytes,3,opt,name=aclRoot,proto3" json:"aclRoot,omitempty"` } @@ -785,14 +784,7 @@ func (m *PushSpaceRequest) XXX_DiscardUnknown() { var xxx_messageInfo_PushSpaceRequest proto.InternalMessageInfo -func (m *PushSpaceRequest) GetSpaceId() string { - if m != nil { - return m.SpaceId - } - return "" -} - -func (m *PushSpaceRequest) GetSpaceHeader() *SpaceHeader { +func (m *PushSpaceRequest) GetSpaceHeader() *RawSpaceHeaderWithId { if m != nil { return m.SpaceHeader } @@ -920,6 +912,110 @@ func (m *SpaceHeader) GetSeed() []byte { return nil } +type RawSpaceHeader struct { + SpaceHeader []byte `protobuf:"bytes,1,opt,name=spaceHeader,proto3" json:"spaceHeader,omitempty"` + Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *RawSpaceHeader) Reset() { *m = RawSpaceHeader{} } +func (m *RawSpaceHeader) String() string { return proto.CompactTextString(m) } +func (*RawSpaceHeader) ProtoMessage() {} +func (*RawSpaceHeader) Descriptor() ([]byte, []int) { + return fileDescriptor_5855f4ef9cf24cdb, []int{14} +} +func (m *RawSpaceHeader) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RawSpaceHeader) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RawSpaceHeader.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 *RawSpaceHeader) XXX_Merge(src proto.Message) { + xxx_messageInfo_RawSpaceHeader.Merge(m, src) +} +func (m *RawSpaceHeader) XXX_Size() int { + return m.Size() +} +func (m *RawSpaceHeader) XXX_DiscardUnknown() { + xxx_messageInfo_RawSpaceHeader.DiscardUnknown(m) +} + +var xxx_messageInfo_RawSpaceHeader proto.InternalMessageInfo + +func (m *RawSpaceHeader) GetSpaceHeader() []byte { + if m != nil { + return m.SpaceHeader + } + return nil +} + +func (m *RawSpaceHeader) GetSignature() []byte { + if m != nil { + return m.Signature + } + return nil +} + +type RawSpaceHeaderWithId struct { + RawHeader []byte `protobuf:"bytes,1,opt,name=rawHeader,proto3" json:"rawHeader,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` +} + +func (m *RawSpaceHeaderWithId) Reset() { *m = RawSpaceHeaderWithId{} } +func (m *RawSpaceHeaderWithId) String() string { return proto.CompactTextString(m) } +func (*RawSpaceHeaderWithId) ProtoMessage() {} +func (*RawSpaceHeaderWithId) Descriptor() ([]byte, []int) { + return fileDescriptor_5855f4ef9cf24cdb, []int{15} +} +func (m *RawSpaceHeaderWithId) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RawSpaceHeaderWithId) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RawSpaceHeaderWithId.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 *RawSpaceHeaderWithId) XXX_Merge(src proto.Message) { + xxx_messageInfo_RawSpaceHeaderWithId.Merge(m, src) +} +func (m *RawSpaceHeaderWithId) XXX_Size() int { + return m.Size() +} +func (m *RawSpaceHeaderWithId) XXX_DiscardUnknown() { + xxx_messageInfo_RawSpaceHeaderWithId.DiscardUnknown(m) +} + +var xxx_messageInfo_RawSpaceHeaderWithId proto.InternalMessageInfo + +func (m *RawSpaceHeaderWithId) GetRawHeader() []byte { + if m != nil { + return m.RawHeader + } + return nil +} + +func (m *RawSpaceHeaderWithId) GetId() string { + if m != nil { + return m.Id + } + return "" +} + func init() { proto.RegisterEnum("anySpace.ErrCodes", ErrCodes_name, ErrCodes_value) proto.RegisterType((*HeadSyncRange)(nil), "anySpace.HeadSyncRange") @@ -936,6 +1032,8 @@ func init() { proto.RegisterType((*PushSpaceRequest)(nil), "anySpace.PushSpaceRequest") proto.RegisterType((*PushSpaceResponse)(nil), "anySpace.PushSpaceResponse") proto.RegisterType((*SpaceHeader)(nil), "anySpace.SpaceHeader") + proto.RegisterType((*RawSpaceHeader)(nil), "anySpace.RawSpaceHeader") + proto.RegisterType((*RawSpaceHeaderWithId)(nil), "anySpace.RawSpaceHeaderWithId") } func init() { @@ -943,65 +1041,68 @@ func init() { } var fileDescriptor_5855f4ef9cf24cdb = []byte{ - // 919 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcd, 0x8e, 0x1b, 0x45, - 0x10, 0xf6, 0x78, 0xbd, 0x6b, 0xbb, 0xbc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c4, 0xe4, 0xee, - 0xd9, 0xe6, 0xb4, 0xfe, 0xe8, 0x21, 0x34, 0x86, 0x71, 0x7c, 0x2c, 0x3d, 0x54, 0x6c, 0x17, 0xe0, - 0x69, 0x88, 0x2f, 0x22, 0x74, 0x35, 0x7a, 0xed, 0x0a, 0x6b, 0xc3, 0x36, 0xd1, 0x7f, 0xe0, 0x2b, - 0xe5, 0x87, 0x93, 0xb6, 0xc5, 0xf6, 0xd2, 0x84, 0x86, 0x2f, 0x7c, 0xa5, 0x55, 0xbb, 0x6a, 0x14, - 0xd4, 0xbf, 0x47, 0x67, 0x67, 0x0a, 0x75, 0xdb, 0x1b, 0xbc, 0xb2, 0x60, 0x93, 0x20, 0xec, 0x2e, - 0x34, 0xb2, 0xfb, 0x9c, 0xbd, 0x57, 0x76, 0xc7, 0x53, 0x17, 0x3b, 0x9d, 0xd2, 0xeb, 0x3f, 0x19, - 0x86, 0x6f, 0xa0, 0xb9, 0xac, 0x2a, 0x2b, 0x00, 0xd7, 0x47, 0xa1, 0x73, 0xb3, 0xd4, 0x96, 0x46, - 0x39, 0x81, 0xad, 0x53, 0x1d, 0xa3, 0x98, 0xb1, 0x9b, 0x65, 0xcf, 0x40, 0xfa, 0x9c, 0x74, 0xde, - 0x64, 0x3c, 0xb0, 0x3e, 0xb5, 0xee, 0x1d, 0xfd, 0x73, 0xd1, 0xb5, 0x5e, 0x5e, 0x74, 0xad, 0x7f, - 0x2f, 0xba, 0xd6, 0x1f, 0x97, 0xdd, 0xca, 0xcb, 0xcb, 0x6e, 0xe5, 0xd5, 0x65, 0xb7, 0xf2, 0xc3, - 0x07, 0x57, 0xfe, 0xd5, 0x79, 0xb6, 0x45, 0x9f, 0xcf, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xce, - 0x99, 0xdc, 0xc5, 0x16, 0x09, 0x00, 0x00, + // 965 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x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 0xd1, 0xb3, 0x5e, 0x5c, 0xf4, 0xac, 0xff, 0x2e, 0x7a, + 0xd6, 0x5f, 0x97, 0xbd, 0xca, 0x8b, 0xcb, 0x5e, 0xe5, 0xe5, 0x65, 0xaf, 0xf2, 0xd3, 0x87, 0x6f, + 0xfd, 0xc7, 0xf5, 0x74, 0x17, 0xbf, 0x3e, 0xff, 0x3f, 0x00, 0x00, 0xff, 0xff, 0x2e, 0x4f, 0xd9, + 0xa3, 0x9d, 0x09, 0x00, 0x00, } func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { @@ -1632,13 +1733,6 @@ func (m *PushSpaceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.SpaceId) > 0 { - i -= len(m.SpaceId) - copy(dAtA[i:], m.SpaceId) - i = encodeVarintSpacesync(dAtA, i, uint64(len(m.SpaceId))) - i-- - dAtA[i] = 0xa - } return len(dAtA) - i, nil } @@ -1719,6 +1813,80 @@ func (m *SpaceHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *RawSpaceHeader) 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 *RawSpaceHeader) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RawSpaceHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x12 + } + if len(m.SpaceHeader) > 0 { + i -= len(m.SpaceHeader) + copy(dAtA[i:], m.SpaceHeader) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.SpaceHeader))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RawSpaceHeaderWithId) 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 *RawSpaceHeaderWithId) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RawSpaceHeaderWithId) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Id) > 0 { + i -= len(m.Id) + copy(dAtA[i:], m.Id) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.Id))) + i-- + dAtA[i] = 0x12 + } + if len(m.RawHeader) > 0 { + i -= len(m.RawHeader) + copy(dAtA[i:], m.RawHeader) + i = encodeVarintSpacesync(dAtA, i, uint64(len(m.RawHeader))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintSpacesync(dAtA []byte, offset int, v uint64) int { offset -= sovSpacesync(v) base := offset @@ -2010,10 +2178,6 @@ func (m *PushSpaceRequest) Size() (n int) { } var l int _ = l - l = len(m.SpaceId) - if l > 0 { - n += 1 + l + sovSpacesync(uint64(l)) - } if m.SpaceHeader != nil { l = m.SpaceHeader.Size() n += 1 + l + sovSpacesync(uint64(l)) @@ -2061,6 +2225,40 @@ func (m *SpaceHeader) Size() (n int) { return n } +func (m *RawSpaceHeader) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SpaceHeader) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } + return n +} + +func (m *RawSpaceHeaderWithId) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.RawHeader) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } + l = len(m.Id) + if l > 0 { + n += 1 + l + sovSpacesync(uint64(l)) + } + return n +} + func sovSpacesync(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3588,38 +3786,6 @@ func (m *PushSpaceRequest) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: PushSpaceRequest: 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 ErrIntOverflowSpacesync - } - 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 ErrInvalidLengthSpacesync - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthSpacesync - } - 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 SpaceHeader", wireType) @@ -3650,7 +3816,7 @@ func (m *PushSpaceRequest) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.SpaceHeader == nil { - m.SpaceHeader = &SpaceHeader{} + m.SpaceHeader = &RawSpaceHeaderWithId{} } if err := m.SpaceHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err @@ -3951,6 +4117,240 @@ func (m *SpaceHeader) Unmarshal(dAtA []byte) error { } return nil } +func (m *RawSpaceHeader) 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 ErrIntOverflowSpacesync + } + 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: RawSpaceHeader: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RawSpaceHeader: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpaceHeader", 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.SpaceHeader = append(m.SpaceHeader[:0], dAtA[iNdEx:postIndex]...) + if m.SpaceHeader == nil { + m.SpaceHeader = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", 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.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) + if m.Signature == nil { + m.Signature = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSpacesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSpacesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RawSpaceHeaderWithId) 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 ErrIntOverflowSpacesync + } + 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: RawSpaceHeaderWithId: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RawSpaceHeaderWithId: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RawHeader", 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.RawHeader = append(m.RawHeader[:0], dAtA[iNdEx:postIndex]...) + if m.RawHeader == nil { + m.RawHeader = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + 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 ErrInvalidLengthSpacesync + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Id = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSpacesync(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthSpacesync + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipSpacesync(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/common/commonspace/storage/mock_storage/mock_storage.go b/common/commonspace/storage/mock_storage/mock_storage.go index 14b6003f..197e13bd 100644 --- a/common/commonspace/storage/mock_storage/mock_storage.go +++ b/common/commonspace/storage/mock_storage/mock_storage.go @@ -149,10 +149,10 @@ func (mr *MockSpaceStorageMockRecorder) CreateTreeStorage(arg0 interface{}) *gom } // SpaceHeader mocks base method. -func (m *MockSpaceStorage) SpaceHeader() (*spacesyncproto.SpaceHeader, error) { +func (m *MockSpaceStorage) SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SpaceHeader") - ret0, _ := ret[0].(*spacesyncproto.SpaceHeader) + ret0, _ := ret[0].(*spacesyncproto.RawSpaceHeaderWithId) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/common/commonspace/storage/storage.go b/common/commonspace/storage/storage.go index 3a98da37..0dc9df99 100644 --- a/common/commonspace/storage/storage.go +++ b/common/commonspace/storage/storage.go @@ -17,14 +17,13 @@ var ErrSpaceStorageMissing = errors.New("space storage missing") type SpaceStorage interface { storage.Provider ACLStorage() (storage.ListStorage, error) - SpaceHeader() (*spacesyncproto.SpaceHeader, error) + SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error) StoredIds() ([]string, error) } type SpaceStorageCreatePayload struct { - RecWithId *aclrecordproto.RawACLRecordWithId - SpaceHeader *spacesyncproto.SpaceHeader - Id string + RecWithId *aclrecordproto.RawACLRecordWithId + SpaceHeaderWithId *spacesyncproto.RawSpaceHeaderWithId } type SpaceStorageProvider interface { diff --git a/node/nodespace/rpchandler.go b/node/nodespace/rpchandler.go index dd050fde..019c48af 100644 --- a/node/nodespace/rpchandler.go +++ b/node/nodespace/rpchandler.go @@ -12,7 +12,7 @@ type rpcHandler struct { } func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpaceRequest) (resp *spacesyncproto.PushSpaceResponse, err error) { - _, err = r.s.GetSpace(ctx, req.SpaceId) + _, err = r.s.GetSpace(ctx, req.SpaceHeader.Id) if err == nil { err = spacesyncproto.ErrSpaceExists return @@ -23,9 +23,8 @@ func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpac } payload := storage.SpaceStorageCreatePayload{ - RecWithId: req.AclRoot, - SpaceHeader: req.SpaceHeader, - Id: req.SpaceId, + RecWithId: req.AclRoot, + SpaceHeaderWithId: req.SpaceHeader, } _, err = r.s.spaceStorageProvider.CreateSpaceStorage(payload) if err != nil { diff --git a/node/storage/keys.go b/node/storage/keys.go index dbfdf385..de99e6e7 100644 --- a/node/storage/keys.go +++ b/node/storage/keys.go @@ -10,7 +10,7 @@ type treeKeys struct { } func (t treeKeys) HeadsKey() string { - return fmt.Sprintf("%s/heads", t.id) + return fmt.Sprintf("t/%s/heads", t.id) } func (t treeKeys) RootKey() string { @@ -18,7 +18,7 @@ func (t treeKeys) RootKey() string { } func (t treeKeys) RawChangeKey(id string) string { - return fmt.Sprintf("%s/%s", t.id, id) + return fmt.Sprintf("t/%s/%s", t.id, id) } type spaceKeys struct { @@ -33,5 +33,5 @@ func (s spaceKeys) ACLKey() string { } func isTreeKey(path string) bool { - return strings.HasPrefix(path, "t/") + return strings.HasPrefix(path, "t/") && len(strings.Split(path, "/")) > 2 } diff --git a/node/storage/spacestorage.go b/node/storage/spacestorage.go index 66279f72..8f775314 100644 --- a/node/storage/spacestorage.go +++ b/node/storage/spacestorage.go @@ -49,7 +49,8 @@ func newSpaceStorage(rootPath string, spaceId string) (store spacestorage.SpaceS } func createSpaceStorage(rootPath string, payload spacestorage.SpaceStorageCreatePayload) (store spacestorage.SpaceStorage, err error) { - dbPath := path.Join(rootPath, payload.Id) + // TODO: add payload verification + dbPath := path.Join(rootPath, payload.SpaceHeaderWithId.Id) db, err := pogreb.Open(dbPath, nil) if err != nil { return @@ -65,19 +66,24 @@ func createSpaceStorage(rootPath string, payload spacestorage.SpaceStorageCreate return } - err = db.Put([]byte(payload.RecWithId.Id), payload.RecWithId.Payload) + marshalledRec, err := payload.RecWithId.Marshal() + if err != nil { + return + } + err = db.Put([]byte(keys.ACLKey()), marshalledRec) if err != nil { return } - marshalled, err := payload.SpaceHeader.Marshal() + marshalledHeader, err := payload.SpaceHeaderWithId.Marshal() if err != nil { return } - err = db.Put([]byte(payload.Id), marshalled) + err = db.Put([]byte(keys.HeaderKey()), marshalledHeader) if err != nil { return } + store = &spaceStorage{ objDb: db, keys: keys, @@ -100,6 +106,7 @@ func (s *spaceStorage) CreateTreeStorage(payload storage.TreeStorageCreatePayloa err = spacestorage.ErrSpaceStorageExists return } + return createTreeStorage(s.objDb, payload) } @@ -107,19 +114,20 @@ func (s *spaceStorage) ACLStorage() (storage.ListStorage, error) { return nil, nil } -func (s *spaceStorage) SpaceHeader() (header *spacesyncproto.SpaceHeader, err error) { +func (s *spaceStorage) SpaceHeader() (header *spacesyncproto.RawSpaceHeaderWithId, err error) { res, err := s.objDb.Get([]byte(s.keys.HeaderKey())) if err != nil { return } - header = &spacesyncproto.SpaceHeader{} + header = &spacesyncproto.RawSpaceHeaderWithId{} err = proto.Unmarshal(res, header) return } func (s *spaceStorage) StoredIds() (ids []string, err error) { index := s.objDb.Items() + _, value, err := index.Next() for err == nil { strVal := string(value) @@ -128,6 +136,7 @@ func (s *spaceStorage) StoredIds() (ids []string, err error) { } _, value, err = index.Next() } + if err != pogreb.ErrIterationDone { return } diff --git a/node/storage/treestorage.go b/node/storage/treestorage.go index 2512f565..1fdeef2d 100644 --- a/node/storage/treestorage.go +++ b/node/storage/treestorage.go @@ -28,11 +28,19 @@ func newTreeStorage(db *pogreb.DB, treeId string) (ts storage.TreeStorage, err e if err != nil { return } + if heads == nil { + err = storage.ErrUnknownTreeId + return + } res, err := db.Get([]byte(path.RootKey())) if err != nil { return } + if res == nil { + err = storage.ErrUnknownTreeId + return + } root := &treechangeproto.RawTreeChangeWithId{} err = proto.Unmarshal(res, root) @@ -53,31 +61,46 @@ func newTreeStorage(db *pogreb.DB, treeId string) (ts storage.TreeStorage, err e } func createTreeStorage(db *pogreb.DB, payload storage.TreeStorageCreatePayload) (ts storage.TreeStorage, err error) { - path := treeKeys{payload.TreeId} + keys := treeKeys{id: payload.TreeId} + has, err := db.Has([]byte(keys.RootKey())) + if err != nil { + return + } + if !has { + err = storage.ErrUnknownTreeId + return + } + heads := createHeadsPayload(payload.Heads) for _, ch := range payload.Changes { - err = db.Put([]byte(path.RawChangeKey(ch.Id)), ch.GetRawChange()) + err = db.Put([]byte(keys.RawChangeKey(ch.Id)), ch.GetRawChange()) if err != nil { return } } - err = db.Put([]byte(path.HeadsKey()), heads) + err = db.Put([]byte(keys.HeadsKey()), heads) if err != nil { return } - err = db.Put([]byte(path.RootKey()), payload.RootRawChange.GetRawChange()) + // duplicating same change in raw changes + err = db.Put([]byte(keys.RawChangeKey(payload.TreeId)), payload.RootRawChange.GetRawChange()) + if err != nil { + return + } + + err = db.Put([]byte(keys.RootKey()), payload.RootRawChange.GetRawChange()) if err != nil { return } ts = &treeStorage{ db: db, - path: path, - rootPath: []byte(path.RootKey()), - headsPath: []byte(path.HeadsKey()), + path: keys, + rootPath: []byte(keys.RootKey()), + headsPath: []byte(keys.HeadsKey()), id: payload.TreeId, heads: payload.Heads, root: payload.RootRawChange, diff --git a/pkg/acl/aclrecordproto/aclrecord.pb.go b/pkg/acl/aclrecordproto/aclrecord.pb.go index e11f5209..158b70f5 100644 --- a/pkg/acl/aclrecordproto/aclrecord.pb.go +++ b/pkg/acl/aclrecordproto/aclrecord.pb.go @@ -324,7 +324,6 @@ func (m *ACLRoot) GetTimestamp() int64 { type ACLContentValue struct { // Types that are valid to be assigned to Value: - // // *ACLContentValue_UserAdd // *ACLContentValue_UserRemove // *ACLContentValue_UserPermissionChange diff --git a/pkg/acl/testutils/testchanges/proto/test.pb.go b/pkg/acl/testutils/testchanges/proto/test.pb.go index d99ba0b5..e8e43c54 100644 --- a/pkg/acl/testutils/testchanges/proto/test.pb.go +++ b/pkg/acl/testutils/testchanges/proto/test.pb.go @@ -60,7 +60,6 @@ var xxx_messageInfo_PlainTextChange proto.InternalMessageInfo type PlainTextChange_Content struct { // Types that are valid to be assigned to Value: - // // *PlainTextChange_Content_TextAppend Value isPlainTextChange_Content_Value `protobuf_oneof:"value"` } diff --git a/pkg/acl/tree/mock_objecttree/mock_objecttree.go b/pkg/acl/tree/mock_objecttree/mock_objecttree.go index b739900c..70afa9d4 100644 --- a/pkg/acl/tree/mock_objecttree/mock_objecttree.go +++ b/pkg/acl/tree/mock_objecttree/mock_objecttree.go @@ -137,7 +137,7 @@ func (mr *MockObjectTreeMockRecorder) HasChanges(arg0 ...interface{}) *gomock.Ca // Header mocks base method. func (m *MockObjectTree) Header() *treechangeproto.RawTreeChangeWithId { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HeaderKey") + ret := m.ctrl.Call(m, "Header") ret0, _ := ret[0].(*treechangeproto.RawTreeChangeWithId) return ret0 } @@ -145,7 +145,7 @@ func (m *MockObjectTree) Header() *treechangeproto.RawTreeChangeWithId { // Header indicates an expected call of Header. func (mr *MockObjectTreeMockRecorder) Header() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HeaderKey", reflect.TypeOf((*MockObjectTree)(nil).Header)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Header", reflect.TypeOf((*MockObjectTree)(nil).Header)) } // Heads mocks base method.