From 6bfda6743ecad5deb7df77c3da814f77cc28f8d6 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Sat, 20 Aug 2022 14:28:06 +0200 Subject: [PATCH] Update code to work with acl lists and new models --- Makefile | 8 +- pkg/acl/list/list.go | 12 +- pkg/acl/list/storage.go | 14 - pkg/acl/{treestorage => storage}/inmemory.go | 18 +- pkg/acl/storage/liststorage.go | 14 + pkg/acl/{treestorage => storage}/provider.go | 4 +- pkg/acl/storage/storage.go | 8 + .../storage.go => storage/treestorage.go} | 6 +- .../testutils/testchanges/proto/test.pb.go | 1088 +++++++++++++++++ .../testutils/testchanges/proto/test.proto | 24 + pkg/acl/tree/commontree.go | 4 +- pkg/acl/tree/doctree.go | 10 +- pkg/acl/tree/treebuilder.go | 6 +- pkg/acl/tree/treestorage.go | 6 +- service/api/service.go | 16 +- service/document/service.go | 97 +- service/storage/service.go | 15 +- service/sync/message/service.go | 2 +- service/sync/requesthandler/requesthandler.go | 227 +--- service/treecache/service.go | 23 +- syncproto/helpers.go | 2 +- syncproto/proto/sync.proto | 3 +- syncproto/sync.pb.go | 122 +- 23 files changed, 1338 insertions(+), 391 deletions(-) delete mode 100644 pkg/acl/list/storage.go rename pkg/acl/{treestorage => storage}/inmemory.go (81%) create mode 100644 pkg/acl/storage/liststorage.go rename pkg/acl/{treestorage => storage}/provider.go (81%) create mode 100644 pkg/acl/storage/storage.go rename pkg/acl/{treestorage/storage.go => storage/treestorage.go} (81%) create mode 100644 pkg/acl/testutils/testchanges/proto/test.pb.go create mode 100644 pkg/acl/testutils/testchanges/proto/test.proto diff --git a/Makefile b/Makefile index aeddb2d3..aad9273a 100644 --- a/Makefile +++ b/Makefile @@ -18,19 +18,17 @@ protos-go: # Uncomment if needed @$(eval ROOT_PKG := pkg) @$(eval GOGO_START := GOGO_NO_UNDERSCORE=1 GOGO_EXPORT_ONEOF_INTERFACE=1) - @$(eval P_TREE_STORAGE_PATH_PB := $(ROOT_PKG)/acl/treestorage/treepb) @$(eval P_ACL_CHANGES_PATH_PB := $(ROOT_PKG)/acl/aclchanges/aclpb) - @$(eval P_PLAINTEXT_CHANGES_PATH_PB := $(ROOT_PKG)/acl/testutils/testchanges/testchangepb) @$(eval P_SYNC_CHANGES_PATH_PB := syncproto) + @$(eval P_TEST_CHANGES_PATH_PB := $(ROOT_PKG)/acl/testutils/testchanges) @$(eval P_TIMESTAMP := Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types) @$(eval P_STRUCT := Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types) @$(eval P_ACL_CHANGES := M$(P_ACL_CHANGES_PATH_PB)/protos/aclchanges.proto=github.com/anytypeio/go-anytype-infrastructure-experiments/$(P_ACL_CHANGES_PATH_PB)) - @$(eval P_TREE_CHANGES := M$(P_TREE_STORAGE_PATH_PB)/protos/tree.proto=github.com/anytypeio/go-anytype-infrastructure-experiments/$(P_TREE_STORAGE_PATH_PB)) # use if needed $(eval PKGMAP := $$(P_TIMESTAMP),$$(P_STRUCT)) $(GOGO_START) protoc --gogofaster_out=:. $(P_ACL_CHANGES_PATH_PB)/protos/*.proto; mv $(P_ACL_CHANGES_PATH_PB)/protos/*.go $(P_ACL_CHANGES_PATH_PB) - $(GOGO_START) protoc --gogofaster_out=:. $(P_TREE_STORAGE_PATH_PB)/protos/*.proto; mv $(P_TREE_STORAGE_PATH_PB)/protos/*.go $(P_TREE_STORAGE_PATH_PB) - $(eval PKGMAP := $$(P_ACL_CHANGES),$$(P_TREE_CHANGES)) + $(GOGO_START) protoc --gogofaster_out=:. $(P_TEST_CHANGES_PATH_PB)/proto/*.proto + $(eval PKGMAP := $$(P_ACL_CHANGES)) $(GOGO_START) protoc --gogofaster_out=$(PKGMAP),plugins=grpc:. $(P_SYNC_CHANGES_PATH_PB)/proto/*.proto build: diff --git a/pkg/acl/list/list.go b/pkg/acl/list/list.go index dc355f4c..ee4a570b 100644 --- a/pkg/acl/list/list.go +++ b/pkg/acl/list/list.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" "sync" ) @@ -21,6 +22,7 @@ type ACLList interface { Get(id string) (*Record, error) Iterate(iterFunc IterFunc) IterateFrom(startId string, iterFunc IterFunc) + Close() (err error) } type aclList struct { @@ -35,7 +37,7 @@ type aclList struct { sync.RWMutex } -func BuildACLListWithIdentity(acc *account.AccountData, storage Storage) (ACLList, error) { +func BuildACLListWithIdentity(acc *account.AccountData, storage storage.ListStorage) (ACLList, error) { builder := newACLStateBuilderWithIdentity(acc.Decoder, acc) header, err := storage.Header() if err != nil { @@ -54,7 +56,7 @@ func BuildACLListWithIdentity(acc *account.AccountData, storage Storage) (ACLLis records := []*Record{record} for record.Content.PrevId != "" { - rawRecord, err = storage.GetRecord(context.Background(), record.Content.PrevId) + rawRecord, err = storage.GetRawRecord(context.Background(), record.Content.PrevId) if err != nil { return nil, err } @@ -109,7 +111,7 @@ func (a *aclList) IsAfter(first string, second string) (bool, error) { if !okFirst || !okSecond { return false, fmt.Errorf("not all entries are there: first (%b), second (%b)", okFirst, okSecond) } - return firstRec > secondRec, nil + return firstRec >= secondRec, nil } func (a *aclList) Head() *Record { @@ -143,3 +145,7 @@ func (a *aclList) IterateFrom(startId string, iterFunc IterFunc) { } } } + +func (a *aclList) Close() (err error) { + return nil +} diff --git a/pkg/acl/list/storage.go b/pkg/acl/list/storage.go deleted file mode 100644 index d606aa94..00000000 --- a/pkg/acl/list/storage.go +++ /dev/null @@ -1,14 +0,0 @@ -package list - -import ( - "context" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" -) - -type Storage interface { - ID() (string, error) - Head() (*aclpb.RawRecord, error) - Header() (*aclpb.Header, error) - GetRecord(ctx context.Context, id string) (*aclpb.RawRecord, error) - AddRecord(ctx context.Context, rec *aclpb.RawRecord) error -} diff --git a/pkg/acl/treestorage/inmemory.go b/pkg/acl/storage/inmemory.go similarity index 81% rename from pkg/acl/treestorage/inmemory.go rename to pkg/acl/storage/inmemory.go index 1fd98e7a..94e65557 100644 --- a/pkg/acl/treestorage/inmemory.go +++ b/pkg/acl/storage/inmemory.go @@ -1,4 +1,4 @@ -package treestorage +package storage import ( "context" @@ -86,21 +86,21 @@ func (t *inMemoryTreeStorage) GetRawChange(ctx context.Context, changeId string) return nil, fmt.Errorf("could not get change with id: %s", changeId) } -type inMemoryTreeStorageProvider struct { - trees map[string]TreeStorage +type inMemoryStorageProvider struct { + objects map[string]Storage sync.RWMutex } -func (i *inMemoryTreeStorageProvider) TreeStorage(treeId string) (TreeStorage, error) { +func (i *inMemoryStorageProvider) Storage(id string) (Storage, error) { i.RLock() defer i.RUnlock() - if tree, exists := i.trees[treeId]; exists { + if tree, exists := i.objects[id]; exists { return tree, nil } return nil, ErrUnknownTreeId } -func (i *inMemoryTreeStorageProvider) CreateTreeStorage(treeId string, header *aclpb.Header, changes []*aclpb.RawChange) (TreeStorage, error) { +func (i *inMemoryStorageProvider) CreateTreeStorage(treeId string, header *aclpb.Header, changes []*aclpb.RawChange) (TreeStorage, error) { i.Lock() defer i.Unlock() res, err := NewInMemoryTreeStorage(treeId, header, changes) @@ -108,12 +108,12 @@ func (i *inMemoryTreeStorageProvider) CreateTreeStorage(treeId string, header *a return nil, err } - i.trees[treeId] = res + i.objects[treeId] = res return res, nil } func NewInMemoryTreeStorageProvider() Provider { - return &inMemoryTreeStorageProvider{ - trees: make(map[string]TreeStorage), + return &inMemoryStorageProvider{ + objects: make(map[string]Storage), } } diff --git a/pkg/acl/storage/liststorage.go b/pkg/acl/storage/liststorage.go new file mode 100644 index 00000000..ff2ff426 --- /dev/null +++ b/pkg/acl/storage/liststorage.go @@ -0,0 +1,14 @@ +package storage + +import ( + "context" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" +) + +type ListStorage interface { + Storage + Head() (*aclpb.RawRecord, error) + + GetRawRecord(ctx context.Context, id string) (*aclpb.RawRecord, error) + AddRawRecord(ctx context.Context, rec *aclpb.RawRecord) error +} diff --git a/pkg/acl/treestorage/provider.go b/pkg/acl/storage/provider.go similarity index 81% rename from pkg/acl/treestorage/provider.go rename to pkg/acl/storage/provider.go index 2a2a98e2..8dff81db 100644 --- a/pkg/acl/treestorage/provider.go +++ b/pkg/acl/storage/provider.go @@ -1,4 +1,4 @@ -package treestorage +package storage import ( "errors" @@ -8,6 +8,6 @@ import ( var ErrUnknownTreeId = errors.New("tree does not exist") type Provider interface { - TreeStorage(treeId string) (TreeStorage, error) + Storage(id string) (Storage, error) CreateTreeStorage(treeId string, header *aclpb.Header, changes []*aclpb.RawChange) (TreeStorage, error) } diff --git a/pkg/acl/storage/storage.go b/pkg/acl/storage/storage.go new file mode 100644 index 00000000..7f14166c --- /dev/null +++ b/pkg/acl/storage/storage.go @@ -0,0 +1,8 @@ +package storage + +import "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" + +type Storage interface { + ID() (string, error) + Header() (*aclpb.Header, error) +} diff --git a/pkg/acl/treestorage/storage.go b/pkg/acl/storage/treestorage.go similarity index 81% rename from pkg/acl/treestorage/storage.go rename to pkg/acl/storage/treestorage.go index bc3f5406..65146c39 100644 --- a/pkg/acl/treestorage/storage.go +++ b/pkg/acl/storage/treestorage.go @@ -1,4 +1,4 @@ -package treestorage +package storage import ( "context" @@ -6,9 +6,7 @@ import ( ) type TreeStorage interface { - ID() (string, error) - - Header() (*aclpb.Header, error) + Storage Heads() ([]string, error) SetHeads(heads []string) error diff --git a/pkg/acl/testutils/testchanges/proto/test.pb.go b/pkg/acl/testutils/testchanges/proto/test.pb.go new file mode 100644 index 00000000..53be5aba --- /dev/null +++ b/pkg/acl/testutils/testchanges/proto/test.pb.go @@ -0,0 +1,1088 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: pkg/acl/testutils/testchanges/proto/test.proto + +package testchanges + +import ( + fmt "fmt" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type PlainTextChange struct { +} + +func (m *PlainTextChange) Reset() { *m = PlainTextChange{} } +func (m *PlainTextChange) String() string { return proto.CompactTextString(m) } +func (*PlainTextChange) ProtoMessage() {} +func (*PlainTextChange) Descriptor() ([]byte, []int) { + return fileDescriptor_37f33c266ada4318, []int{0} +} +func (m *PlainTextChange) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PlainTextChange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PlainTextChange.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 *PlainTextChange) XXX_Merge(src proto.Message) { + xxx_messageInfo_PlainTextChange.Merge(m, src) +} +func (m *PlainTextChange) XXX_Size() int { + return m.Size() +} +func (m *PlainTextChange) XXX_DiscardUnknown() { + xxx_messageInfo_PlainTextChange.DiscardUnknown(m) +} + +var xxx_messageInfo_PlainTextChange proto.InternalMessageInfo + +type PlainTextChangeContent struct { + // Types that are valid to be assigned to Value: + // *PlainTextChangeContentValueOfTextAppend + Value IsPlainTextChangeContentValue `protobuf_oneof:"value"` +} + +func (m *PlainTextChangeContent) Reset() { *m = PlainTextChangeContent{} } +func (m *PlainTextChangeContent) String() string { return proto.CompactTextString(m) } +func (*PlainTextChangeContent) ProtoMessage() {} +func (*PlainTextChangeContent) Descriptor() ([]byte, []int) { + return fileDescriptor_37f33c266ada4318, []int{0, 0} +} +func (m *PlainTextChangeContent) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PlainTextChangeContent) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PlainTextChangeContent.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 *PlainTextChangeContent) XXX_Merge(src proto.Message) { + xxx_messageInfo_PlainTextChangeContent.Merge(m, src) +} +func (m *PlainTextChangeContent) XXX_Size() int { + return m.Size() +} +func (m *PlainTextChangeContent) XXX_DiscardUnknown() { + xxx_messageInfo_PlainTextChangeContent.DiscardUnknown(m) +} + +var xxx_messageInfo_PlainTextChangeContent proto.InternalMessageInfo + +type IsPlainTextChangeContentValue interface { + IsPlainTextChangeContentValue() + MarshalTo([]byte) (int, error) + Size() int +} + +type PlainTextChangeContentValueOfTextAppend struct { + TextAppend *PlainTextChangeTextAppend `protobuf:"bytes,1,opt,name=textAppend,proto3,oneof" json:"textAppend,omitempty"` +} + +func (*PlainTextChangeContentValueOfTextAppend) IsPlainTextChangeContentValue() {} + +func (m *PlainTextChangeContent) GetValue() IsPlainTextChangeContentValue { + if m != nil { + return m.Value + } + return nil +} + +func (m *PlainTextChangeContent) GetTextAppend() *PlainTextChangeTextAppend { + if x, ok := m.GetValue().(*PlainTextChangeContentValueOfTextAppend); ok { + return x.TextAppend + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*PlainTextChangeContent) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*PlainTextChangeContentValueOfTextAppend)(nil), + } +} + +type PlainTextChangeTextAppend struct { + Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` +} + +func (m *PlainTextChangeTextAppend) Reset() { *m = PlainTextChangeTextAppend{} } +func (m *PlainTextChangeTextAppend) String() string { return proto.CompactTextString(m) } +func (*PlainTextChangeTextAppend) ProtoMessage() {} +func (*PlainTextChangeTextAppend) Descriptor() ([]byte, []int) { + return fileDescriptor_37f33c266ada4318, []int{0, 1} +} +func (m *PlainTextChangeTextAppend) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PlainTextChangeTextAppend) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PlainTextChangeTextAppend.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 *PlainTextChangeTextAppend) XXX_Merge(src proto.Message) { + xxx_messageInfo_PlainTextChangeTextAppend.Merge(m, src) +} +func (m *PlainTextChangeTextAppend) XXX_Size() int { + return m.Size() +} +func (m *PlainTextChangeTextAppend) XXX_DiscardUnknown() { + xxx_messageInfo_PlainTextChangeTextAppend.DiscardUnknown(m) +} + +var xxx_messageInfo_PlainTextChangeTextAppend proto.InternalMessageInfo + +func (m *PlainTextChangeTextAppend) GetText() string { + if m != nil { + return m.Text + } + return "" +} + +type PlainTextChangeSnapshot struct { + Text string `protobuf:"bytes,1,opt,name=text,proto3" json:"text,omitempty"` +} + +func (m *PlainTextChangeSnapshot) Reset() { *m = PlainTextChangeSnapshot{} } +func (m *PlainTextChangeSnapshot) String() string { return proto.CompactTextString(m) } +func (*PlainTextChangeSnapshot) ProtoMessage() {} +func (*PlainTextChangeSnapshot) Descriptor() ([]byte, []int) { + return fileDescriptor_37f33c266ada4318, []int{0, 2} +} +func (m *PlainTextChangeSnapshot) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PlainTextChangeSnapshot) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PlainTextChangeSnapshot.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 *PlainTextChangeSnapshot) XXX_Merge(src proto.Message) { + xxx_messageInfo_PlainTextChangeSnapshot.Merge(m, src) +} +func (m *PlainTextChangeSnapshot) XXX_Size() int { + return m.Size() +} +func (m *PlainTextChangeSnapshot) XXX_DiscardUnknown() { + xxx_messageInfo_PlainTextChangeSnapshot.DiscardUnknown(m) +} + +var xxx_messageInfo_PlainTextChangeSnapshot proto.InternalMessageInfo + +func (m *PlainTextChangeSnapshot) GetText() string { + if m != nil { + return m.Text + } + return "" +} + +type PlainTextChangeData struct { + Content []*PlainTextChangeContent `protobuf:"bytes,1,rep,name=content,proto3" json:"content,omitempty"` + Snapshot *PlainTextChangeSnapshot `protobuf:"bytes,2,opt,name=snapshot,proto3" json:"snapshot,omitempty"` +} + +func (m *PlainTextChangeData) Reset() { *m = PlainTextChangeData{} } +func (m *PlainTextChangeData) String() string { return proto.CompactTextString(m) } +func (*PlainTextChangeData) ProtoMessage() {} +func (*PlainTextChangeData) Descriptor() ([]byte, []int) { + return fileDescriptor_37f33c266ada4318, []int{0, 3} +} +func (m *PlainTextChangeData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PlainTextChangeData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PlainTextChangeData.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 *PlainTextChangeData) XXX_Merge(src proto.Message) { + xxx_messageInfo_PlainTextChangeData.Merge(m, src) +} +func (m *PlainTextChangeData) XXX_Size() int { + return m.Size() +} +func (m *PlainTextChangeData) XXX_DiscardUnknown() { + xxx_messageInfo_PlainTextChangeData.DiscardUnknown(m) +} + +var xxx_messageInfo_PlainTextChangeData proto.InternalMessageInfo + +func (m *PlainTextChangeData) GetContent() []*PlainTextChangeContent { + if m != nil { + return m.Content + } + return nil +} + +func (m *PlainTextChangeData) GetSnapshot() *PlainTextChangeSnapshot { + if m != nil { + return m.Snapshot + } + return nil +} + +func init() { + proto.RegisterType((*PlainTextChange)(nil), "anytype.PlainTextChange") + proto.RegisterType((*PlainTextChangeContent)(nil), "anytype.PlainTextChange.Content") + proto.RegisterType((*PlainTextChangeTextAppend)(nil), "anytype.PlainTextChange.TextAppend") + proto.RegisterType((*PlainTextChangeSnapshot)(nil), "anytype.PlainTextChange.Snapshot") + proto.RegisterType((*PlainTextChangeData)(nil), "anytype.PlainTextChange.Data") +} + +func init() { + proto.RegisterFile("pkg/acl/testutils/testchanges/proto/test.proto", fileDescriptor_37f33c266ada4318) +} + +var fileDescriptor_37f33c266ada4318 = []byte{ + // 266 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2b, 0xc8, 0x4e, 0xd7, + 0x4f, 0x4c, 0xce, 0xd1, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x2d, 0xc9, 0xcc, 0x29, 0x06, 0xb3, 0x92, + 0x33, 0x12, 0xf3, 0xd2, 0x53, 0x8b, 0xf5, 0x0b, 0x8a, 0xf2, 0x4b, 0xf2, 0xc1, 0x22, 0x7a, 0x60, + 0xa6, 0x10, 0x7b, 0x62, 0x5e, 0x65, 0x49, 0x65, 0x41, 0xaa, 0xd2, 0x26, 0x26, 0x2e, 0xfe, 0x80, + 0x9c, 0xc4, 0xcc, 0xbc, 0x90, 0xd4, 0x8a, 0x12, 0x67, 0xb0, 0x72, 0xa9, 0x48, 0x2e, 0x76, 0xe7, + 0xfc, 0xbc, 0x92, 0xd4, 0xbc, 0x12, 0x21, 0x57, 0x2e, 0xae, 0x92, 0xd4, 0x8a, 0x12, 0xc7, 0x82, + 0x82, 0xd4, 0xbc, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x65, 0x3d, 0xa8, 0x66, 0x3d, + 0x34, 0x8d, 0x7a, 0x21, 0x70, 0xa5, 0x1e, 0x0c, 0x41, 0x48, 0x1a, 0x9d, 0xd8, 0xb9, 0x58, 0xcb, + 0x12, 0x73, 0x4a, 0x53, 0xa5, 0x14, 0xb8, 0xb8, 0x10, 0x8a, 0x84, 0x84, 0xb8, 0x58, 0x40, 0x8a, + 0xc0, 0xe6, 0x72, 0x06, 0x81, 0xd9, 0x52, 0x72, 0x5c, 0x1c, 0xc1, 0x79, 0x89, 0x05, 0xc5, 0x19, + 0xf9, 0x25, 0x58, 0xe5, 0x1b, 0x19, 0xb9, 0x58, 0x5c, 0x12, 0x4b, 0x12, 0x85, 0xac, 0xb8, 0xd8, + 0x93, 0x21, 0xae, 0x94, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0x52, 0xc0, 0xe9, 0x2e, 0xa8, 0x6f, + 0x82, 0x60, 0x1a, 0x84, 0x6c, 0xb9, 0x38, 0x8a, 0xa1, 0x96, 0x48, 0x30, 0x81, 0x3d, 0xa5, 0x88, + 0x53, 0x33, 0xcc, 0x35, 0x41, 0x70, 0x2d, 0x4e, 0xaa, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, + 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, + 0x2c, 0xc7, 0x10, 0xc5, 0x8d, 0x14, 0xea, 0x49, 0x6c, 0xe0, 0xb0, 0x36, 0x06, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xf8, 0x8c, 0x6a, 0x1d, 0x9d, 0x01, 0x00, 0x00, +} + +func (m *PlainTextChange) 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 *PlainTextChange) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *PlainTextChangeContent) 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 *PlainTextChangeContent) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChangeContent) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Value != nil { + { + size := m.Value.Size() + i -= size + if _, err := m.Value.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *PlainTextChangeContentValueOfTextAppend) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChangeContentValueOfTextAppend) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.TextAppend != nil { + { + size, err := m.TextAppend.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *PlainTextChangeTextAppend) 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 *PlainTextChangeTextAppend) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChangeTextAppend) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Text) > 0 { + i -= len(m.Text) + copy(dAtA[i:], m.Text) + i = encodeVarintTest(dAtA, i, uint64(len(m.Text))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PlainTextChangeSnapshot) 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 *PlainTextChangeSnapshot) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChangeSnapshot) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Text) > 0 { + i -= len(m.Text) + copy(dAtA[i:], m.Text) + i = encodeVarintTest(dAtA, i, uint64(len(m.Text))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PlainTextChangeData) 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 *PlainTextChangeData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PlainTextChangeData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Snapshot != nil { + { + size, err := m.Snapshot.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Content) > 0 { + for iNdEx := len(m.Content) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Content[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func encodeVarintTest(dAtA []byte, offset int, v uint64) int { + offset -= sovTest(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PlainTextChange) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *PlainTextChangeContent) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Value != nil { + n += m.Value.Size() + } + return n +} + +func (m *PlainTextChangeContentValueOfTextAppend) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.TextAppend != nil { + l = m.TextAppend.Size() + n += 1 + l + sovTest(uint64(l)) + } + return n +} +func (m *PlainTextChangeTextAppend) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Text) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func (m *PlainTextChangeSnapshot) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Text) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func (m *PlainTextChangeData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Content) > 0 { + for _, e := range m.Content { + l = e.Size() + n += 1 + l + sovTest(uint64(l)) + } + } + if m.Snapshot != nil { + l = m.Snapshot.Size() + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func sovTest(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTest(x uint64) (n int) { + return sovTest(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PlainTextChange) 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 ErrIntOverflowTest + } + 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: PlainTextChange: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PlainTextChange: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PlainTextChangeContent) 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 ErrIntOverflowTest + } + 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: Content: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Content: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TextAppend", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PlainTextChangeTextAppend{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Value = &PlainTextChangeContentValueOfTextAppend{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PlainTextChangeTextAppend) 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 ErrIntOverflowTest + } + 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: TextAppend: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TextAppend: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Text", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Text = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PlainTextChangeSnapshot) 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 ErrIntOverflowTest + } + 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: Snapshot: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Snapshot: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Text", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Text = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PlainTextChangeData) 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 ErrIntOverflowTest + } + 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: Data: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Data: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Content", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Content = append(m.Content, &PlainTextChangeContent{}) + if err := m.Content[len(m.Content)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Snapshot", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Snapshot == nil { + m.Snapshot = &PlainTextChangeSnapshot{} + } + if err := m.Snapshot.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTest(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTest + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTest + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTest + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTest = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTest = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTest = fmt.Errorf("proto: unexpected end of group") +) diff --git a/pkg/acl/testutils/testchanges/proto/test.proto b/pkg/acl/testutils/testchanges/proto/test.proto new file mode 100644 index 00000000..b861050e --- /dev/null +++ b/pkg/acl/testutils/testchanges/proto/test.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; +package anytype; +option go_package = "testchanges"; + +message PlainTextChange { + message Content { + oneof value { + TextAppend textAppend = 1; + } + } + + message TextAppend { + string text = 1; + } + + message Snapshot { + string text = 1; + } + + message Data { + repeated Content content = 1; + Snapshot snapshot = 2; + } +} \ No newline at end of file diff --git a/pkg/acl/tree/commontree.go b/pkg/acl/tree/commontree.go index 9018c878..50a9b0f6 100644 --- a/pkg/acl/tree/commontree.go +++ b/pkg/acl/tree/commontree.go @@ -2,7 +2,7 @@ package tree import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" ) type CommonTree interface { @@ -15,7 +15,7 @@ type CommonTree interface { HasChange(string) bool SnapshotPath() []string ChangesAfterCommonSnapshot(snapshotPath []string) ([]*aclpb.RawChange, error) - Storage() treestorage.TreeStorage + Storage() storage.TreeStorage DebugDump() (string, error) Close() error } diff --git a/pkg/acl/tree/doctree.go b/pkg/acl/tree/doctree.go index 8e1cfad5..f7ae2e4c 100644 --- a/pkg/acl/tree/doctree.go +++ b/pkg/acl/tree/doctree.go @@ -6,7 +6,7 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" @@ -56,7 +56,7 @@ type DocTree interface { } type docTree struct { - treeStorage treestorage.TreeStorage + treeStorage storage.TreeStorage accountData *account.AccountData updateListener TreeUpdateListener @@ -76,7 +76,7 @@ type docTree struct { sync.RWMutex } -func BuildDocTreeWithIdentity(t treestorage.TreeStorage, acc *account.AccountData, listener TreeUpdateListener, aclList list.ACLList) (DocTree, error) { +func BuildDocTreeWithIdentity(t storage.TreeStorage, acc *account.AccountData, listener TreeUpdateListener, aclList list.ACLList) (DocTree, error) { treeBuilder := newTreeBuilder(t, acc.Decoder) validator := newTreeValidator() @@ -112,7 +112,7 @@ func BuildDocTreeWithIdentity(t treestorage.TreeStorage, acc *account.AccountDat return docTree, nil } -func BuildDocTree(t treestorage.TreeStorage, decoder keys.Decoder, listener TreeUpdateListener, aclList list.ACLList) (DocTree, error) { +func BuildDocTree(t storage.TreeStorage, decoder keys.Decoder, listener TreeUpdateListener, aclList list.ACLList) (DocTree, error) { treeBuilder := newTreeBuilder(t, decoder) validator := newTreeValidator() @@ -182,7 +182,7 @@ func (d *docTree) Header() *aclpb.Header { return d.header } -func (d *docTree) Storage() treestorage.TreeStorage { +func (d *docTree) Storage() storage.TreeStorage { return d.treeStorage } diff --git a/pkg/acl/tree/treebuilder.go b/pkg/acl/tree/treebuilder.go index ea93af90..11e95955 100644 --- a/pkg/acl/tree/treebuilder.go +++ b/pkg/acl/tree/treebuilder.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" @@ -23,10 +23,10 @@ type treeBuilder struct { identityKeys map[string]signingkey.PubKey signingPubKeyDecoder keys.Decoder tree *Tree - treeStorage treestorage.TreeStorage + treeStorage storage.TreeStorage } -func newTreeBuilder(t treestorage.TreeStorage, decoder keys.Decoder) *treeBuilder { +func newTreeBuilder(t storage.TreeStorage, decoder keys.Decoder) *treeBuilder { return &treeBuilder{ signingPubKeyDecoder: decoder, treeStorage: t, diff --git a/pkg/acl/tree/treestorage.go b/pkg/acl/tree/treestorage.go index 5c9e753b..a82a1ce6 100644 --- a/pkg/acl/tree/treestorage.go +++ b/pkg/acl/tree/treestorage.go @@ -4,7 +4,7 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/gogo/protobuf/proto" "time" @@ -14,7 +14,7 @@ import ( //func CreateNewTreeStorageWithACL( // acc *account.AccountData, // build func(builder list.ACLChangeBuilder) error, -// create treestorage.CreatorFunc) (treestorage.TreeStorage, error) { +// create treestorage.CreatorFunc) (treestorage.Storage, error) { // bld := list.newACLChangeBuilder() // bld.Init( // list.newACLStateWithIdentity(acc.Identity, acc.EncKey, signingkey.NewEd25519PubKeyDecoder()), @@ -56,7 +56,7 @@ func CreateNewTreeStorage( acc *account.AccountData, aclList list.ACLList, content proto.Marshaler, - create treestorage.CreatorFunc) (treestorage.TreeStorage, error) { + create storage.CreatorFunc) (storage.TreeStorage, error) { state := aclList.ACLState() change := &aclpb.Change{ diff --git a/service/api/service.go b/service/api/service.go index a9b7f1f3..b98ca820 100644 --- a/service/api/service.go +++ b/service/api/service.go @@ -54,7 +54,6 @@ func (s *service) Run(ctx context.Context) (err error) { mux := http.NewServeMux() mux.HandleFunc("/treeDump", s.treeDump) mux.HandleFunc("/createDocumentTree", s.createDocumentTree) - mux.HandleFunc("/createACLTree", s.createACLTree) mux.HandleFunc("/appendDocument", s.appendDocument) s.srv.Handler = mux @@ -99,21 +98,10 @@ func (s *service) createDocumentTree(w http.ResponseWriter, req *http.Request) { var ( query = req.URL.Query() text = query.Get("text") - aclTreeId = query.Get("aclTreeId") + aclListId = query.Get("aclListId") ) timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second*30) - treeId, err := s.documentService.CreateDocumentTree(timeoutCtx, aclTreeId, text) - cancel() - if err != nil { - sendText(w, http.StatusInternalServerError, err.Error()) - return - } - sendText(w, http.StatusOK, treeId) -} - -func (s *service) createACLTree(w http.ResponseWriter, req *http.Request) { - timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second*30) - treeId, err := s.documentService.CreateACLTree(timeoutCtx) + treeId, err := s.documentService.CreateDocumentTree(timeoutCtx, aclListId, text) cancel() if err != nil { sendText(w, http.StatusInternalServerError, err.Error()) diff --git a/service/document/service.go b/service/document/service.go index 33e6a271..369d8f1c 100644 --- a/service/document/service.go +++ b/service/document/service.go @@ -7,9 +7,8 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/testchangepb" + testchanges "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/testchanges/proto" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/treepb" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/node" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/storage" @@ -35,7 +34,6 @@ type service struct { type Service interface { UpdateDocumentTree(ctx context.Context, id, text string) error - CreateACLTree(ctx context.Context) (id string, err error) CreateDocumentTree(ctx context.Context, aclTreeId string, text string) (id string, err error) } @@ -60,7 +58,7 @@ func (s *service) Name() (name string) { } func (s *service) Run(ctx context.Context) (err error) { - return nil + return s.importACLList(ctx) } func (s *service) Close(ctx context.Context) (err error) { @@ -70,7 +68,7 @@ func (s *service) Close(ctx context.Context) (err error) { func (s *service) UpdateDocumentTree(ctx context.Context, id, text string) (err error) { var ( ch *aclpb.RawChange - header *treepb.TreeHeader + header *aclpb.Header snapshotPath []string heads []string ) @@ -85,8 +83,8 @@ func (s *service) UpdateDocumentTree(ctx context.Context, id, text string) (err docTree.Lock() defer docTree.Unlock() - err = s.treeCache.Do(ctx, docTree.Header().AclTreeId, func(obj interface{}) error { - aclTree := obj.(tree.ACLTree) + err = s.treeCache.Do(ctx, docTree.Header().AclListId, func(obj interface{}) error { + aclTree := obj.(list.ACLList) aclTree.RLock() defer aclTree.RUnlock() @@ -123,69 +121,20 @@ func (s *service) UpdateDocumentTree(ctx context.Context, id, text string) (err }, header, id)) } -func (s *service) CreateACLTree(ctx context.Context) (id string, err error) { - acc := s.account.Account() - var ( - ch *aclpb.RawChange - header *treepb.TreeHeader - snapshotPath []string - heads []string - ) - - t, err := tree.CreateNewTreeStorageWithACL(acc, func(builder list.ACLChangeBuilder) error { - err := builder.UserAdd(acc.Identity, acc.EncKey.GetPublic(), aclpb.ACLChange_Admin) - if err != nil { - return err - } - // adding all predefined nodes to the document as admins - for _, n := range s.nodes { - err = builder.UserAdd(n.SigningKeyString, n.EncryptionKey, aclpb.ACLChange_Admin) - if err != nil { - return err - } - } - return nil - }, s.storage.CreateTreeStorage) - - id, err = t.TreeID() - if err != nil { - return "", err - } - - header, err = t.Header() - if err != nil { - return "", err - } - - heads = []string{header.FirstChangeId} - snapshotPath = []string{header.FirstChangeId} - ch, err = t.GetChange(ctx, header.FirstChangeId) - if err != nil { - return "", err - } - - if err != nil { - return "", err - } - - err = s.messageService.SendToSpaceAsync("", syncproto.WrapHeadUpdate(&syncproto.SyncHeadUpdate{ - Heads: heads, - Changes: []*aclpb.RawChange{ch}, - SnapshotPath: snapshotPath, - }, header, id)) - return id, nil +func (s *service) importACLList(ctx context.Context) (err error) { + panic("not implemented") } -func (s *service) CreateDocumentTree(ctx context.Context, aclTreeId string, text string) (id string, err error) { +func (s *service) CreateDocumentTree(ctx context.Context, aclListId string, text string) (id string, err error) { acc := s.account.Account() var ( ch *aclpb.RawChange - header *treepb.TreeHeader + header *aclpb.Header snapshotPath []string heads []string ) - err = s.treeCache.Do(ctx, aclTreeId, func(obj interface{}) error { - t := obj.(tree.ACLTree) + err = s.treeCache.Do(ctx, aclListId, func(obj interface{}) error { + t := obj.(list.ACLList) t.RLock() defer t.RUnlock() @@ -205,9 +154,9 @@ func (s *service) CreateDocumentTree(ctx context.Context, aclTreeId string, text return err } - heads = []string{header.FirstChangeId} - snapshotPath = []string{header.FirstChangeId} - ch, err = doc.GetRawChange(ctx, header.FirstChangeId) + heads = []string{header.FirstId} + snapshotPath = []string{header.FirstId} + ch, err = doc.GetRawChange(ctx, header.FirstId) if err != nil { return err } @@ -233,26 +182,26 @@ func (s *service) CreateDocumentTree(ctx context.Context, aclTreeId string, text } func createInitialTextChange(text string) proto.Marshaler { - return &testchangepb.PlainTextChangeData{ - Content: []*testchangepb.PlainTextChangeContent{ + return &testchanges.PlainTextChangeData{ + Content: []*testchanges.PlainTextChangeContent{ createAppendTextChangeContent(text), }, - Snapshot: &testchangepb.PlainTextChangeSnapshot{Text: text}, + Snapshot: &testchanges.PlainTextChangeSnapshot{Text: text}, } } func createAppendTextChange(text string) proto.Marshaler { - return &testchangepb.PlainTextChangeData{ - Content: []*testchangepb.PlainTextChangeContent{ + return &testchanges.PlainTextChangeData{ + Content: []*testchanges.PlainTextChangeContent{ createAppendTextChangeContent(text), }, } } -func createAppendTextChangeContent(text string) *testchangepb.PlainTextChangeContent { - return &testchangepb.PlainTextChangeContent{ - Value: &testchangepb.PlainTextChangeContentValueOfTextAppend{ - TextAppend: &testchangepb.PlainTextChangeTextAppend{ +func createAppendTextChangeContent(text string) *testchanges.PlainTextChangeContent { + return &testchanges.PlainTextChangeContent{ + Value: &testchanges.PlainTextChangeContentValueOfTextAppend{ + TextAppend: &testchanges.PlainTextChangeTextAppend{ Text: text, }, }, diff --git a/service/storage/service.go b/service/storage/service.go index 1f495034..5ee9efa4 100644 --- a/service/storage/service.go +++ b/service/storage/service.go @@ -4,14 +4,13 @@ import ( "context" "github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/treepb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" ) var CName = "storage" type Service interface { - treestorage.Provider + storage.Provider } func New() app.Component { @@ -19,19 +18,19 @@ func New() app.Component { } type service struct { - storageProvider treestorage.Provider + storageProvider storage.Provider } func (s *service) Init(ctx context.Context, a *app.App) (err error) { - s.storageProvider = treestorage.NewInMemoryTreeStorageProvider() + s.storageProvider = storage.NewInMemoryTreeStorageProvider() return nil } -func (s *service) TreeStorage(treeId string) (treestorage.TreeStorage, error) { - return s.storageProvider.TreeStorage(treeId) +func (s *service) Storage(treeId string) (storage.Storage, error) { + return s.storageProvider.Storage(treeId) } -func (s *service) CreateTreeStorage(treeId string, header *treepb.TreeHeader, changes []*aclpb.RawChange) (treestorage.TreeStorage, error) { +func (s *service) CreateTreeStorage(treeId string, header *aclpb.Header, changes []*aclpb.RawChange) (storage.TreeStorage, error) { return s.storageProvider.CreateTreeStorage(treeId, header, changes) } diff --git a/service/sync/message/service.go b/service/sync/message/service.go index 78a4829c..423f7393 100644 --- a/service/sync/message/service.go +++ b/service/sync/message/service.go @@ -119,6 +119,6 @@ func msgInfo(content *syncproto.Sync) (syncMethod string) { case msg.GetHeadUpdate() != nil: syncMethod = "HeadUpdate" } - syncMethod = fmt.Sprintf("method: %s, treeType: %s", syncMethod, content.TreeHeader.Type.String()) + syncMethod = fmt.Sprintf("method: %s, treeType: %s", syncMethod, content.TreeHeader.DocType.String()) return } diff --git a/service/sync/requesthandler/requesthandler.go b/service/sync/requesthandler/requesthandler.go index 4600ab96..e4938554 100644 --- a/service/sync/requesthandler/requesthandler.go +++ b/service/sync/requesthandler/requesthandler.go @@ -6,9 +6,9 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/treepb" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/treecache" "github.com/anytypeio/go-anytype-infrastructure-experiments/syncproto" @@ -77,7 +77,7 @@ func (r *requestHandler) HandleHeadUpdate( ctx context.Context, senderId string, update *syncproto.SyncHeadUpdate, - header *treepb.TreeHeader, + header *aclpb.Header, treeId string) (err error) { var ( @@ -88,81 +88,41 @@ func (r *requestHandler) HandleHeadUpdate( log.With(zap.String("peerId", senderId), zap.String("treeId", treeId)). Debug("processing head update") - updateACLTree := func() { - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - t := obj.(tree.ACLTree) - t.Lock() - defer t.Unlock() + err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { + docTree := obj.(tree.DocTree) + docTree.Lock() + defer docTree.Unlock() - if slice.UnsortedEquals(update.Heads, t.Heads()) { - return nil - } + if slice.UnsortedEquals(update.Heads, docTree.Heads()) { + return nil + } + + return r.treeCache.Do(ctx, docTree.Header().AclListId, func(obj interface{}) error { + aclTree := obj.(list.ACLList) + aclTree.RLock() + defer aclTree.RUnlock() // TODO: check if we already have those changes - result, err = t.AddRawChanges(ctx, update.Changes...) + result, err = docTree.AddRawChanges(ctx, aclTree, update.Changes...) if err != nil { return err } - log.With(zap.Strings("update heads", update.Heads), zap.Strings("tree heads", t.Heads())). + log.With(zap.Strings("update heads", update.Heads), zap.Strings("tree heads", docTree.Heads())). Debug("comparing heads after head update") - shouldFullSync := !slice.UnsortedEquals(update.Heads, t.Heads()) - snapshotPath = t.SnapshotPath() + shouldFullSync := !slice.UnsortedEquals(update.Heads, docTree.Heads()) + snapshotPath = docTree.SnapshotPath() if shouldFullSync { - fullRequest, err = r.prepareFullSyncRequest(treeId, header, update.SnapshotPath, t) + fullRequest, err = r.prepareFullSyncRequest(update.SnapshotPath, docTree) if err != nil { return err } } return nil }) - } - - updateDocTree := func() { - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - docTree := obj.(tree.DocTree) - docTree.Lock() - defer docTree.Unlock() - - if slice.UnsortedEquals(update.Heads, docTree.Heads()) { - return nil - } - - return r.treeCache.Do(ctx, docTree.Header().AclTreeId, func(obj interface{}) error { - aclTree := obj.(tree.ACLTree) - aclTree.RLock() - defer aclTree.RUnlock() - - // TODO: check if we already have those changes - result, err = docTree.AddRawChanges(ctx, aclTree, update.Changes...) - if err != nil { - return err - } - log.With(zap.Strings("update heads", update.Heads), zap.Strings("tree heads", docTree.Heads())). - Debug("comparing heads after head update") - shouldFullSync := !slice.UnsortedEquals(update.Heads, docTree.Heads()) - snapshotPath = docTree.SnapshotPath() - if shouldFullSync { - fullRequest, err = r.prepareFullSyncRequest(treeId, header, update.SnapshotPath, docTree) - if err != nil { - return err - } - } - return nil - }) - }) - } - - switch header.Type { - case treepb.TreeHeader_ACLTree: - updateACLTree() - case treepb.TreeHeader_DocTree: - updateDocTree() - default: - return ErrIncorrectDocType - } + }) // if there are no such tree - if err == treestorage.ErrUnknownTreeId { + if err == storage.ErrUnknownTreeId { // TODO: maybe we can optimize this by sending the header and stuff right away, so when the tree is created we are able to add it on first request fullRequest = &syncproto.SyncFullRequest{} } @@ -188,7 +148,7 @@ func (r *requestHandler) HandleFullSyncRequest( ctx context.Context, senderId string, request *syncproto.SyncFullRequest, - header *treepb.TreeHeader, + header *aclpb.Header, treeId string) (err error) { var ( @@ -199,74 +159,36 @@ func (r *requestHandler) HandleFullSyncRequest( log.With(zap.String("peerId", senderId), zap.String("treeId", treeId)). Debug("processing full sync request") - requestACLTree := func() { - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - t := obj.(tree.ACLTree) - t.Lock() - defer t.Unlock() - - //if slice.UnsortedEquals(request.Heads, t.Heads()) { - // return nil - //} + log.Info("getting doc tree from treeCache", zap.String("treeId", treeId)) + err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { + docTree := obj.(tree.DocTree) + docTree.Lock() + defer docTree.Unlock() + //if slice.UnsortedEquals(request.Heads, docTree.Heads()) { + // return nil + //} + log.Info("getting tree from treeCache", zap.String("aclId", docTree.Header().AclListId)) + return r.treeCache.Do(ctx, docTree.Header().AclListId, func(obj interface{}) error { + aclTree := obj.(list.ACLList) + aclTree.RLock() + defer aclTree.RUnlock() // TODO: check if we already have those changes // if we have non-empty request if len(request.Heads) != 0 { - result, err = t.AddRawChanges(ctx, request.Changes...) + result, err = docTree.AddRawChanges(ctx, aclTree, request.Changes...) if err != nil { return err } } - snapshotPath = t.SnapshotPath() - fullResponse, err = r.prepareFullSyncResponse(treeId, request.SnapshotPath, request.Changes, t) + snapshotPath = docTree.SnapshotPath() + fullResponse, err = r.prepareFullSyncResponse(treeId, request.SnapshotPath, request.Changes, docTree) if err != nil { return err } return nil }) - } - - requestDocTree := func() { - log.Info("getting doc tree from treeCache", zap.String("treeId", treeId)) - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - docTree := obj.(tree.DocTree) - docTree.Lock() - defer docTree.Unlock() - - //if slice.UnsortedEquals(request.Heads, docTree.Heads()) { - // return nil - //} - log.Info("getting tree from treeCache", zap.String("aclId", docTree.Header().AclTreeId)) - return r.treeCache.Do(ctx, docTree.Header().AclTreeId, func(obj interface{}) error { - aclTree := obj.(tree.ACLTree) - aclTree.RLock() - defer aclTree.RUnlock() - // TODO: check if we already have those changes - // if we have non-empty request - if len(request.Heads) != 0 { - result, err = docTree.AddRawChanges(ctx, aclTree, request.Changes...) - if err != nil { - return err - } - } - snapshotPath = docTree.SnapshotPath() - fullResponse, err = r.prepareFullSyncResponse(treeId, request.SnapshotPath, request.Changes, docTree) - if err != nil { - return err - } - return nil - }) - }) - } - - switch header.Type { - case treepb.TreeHeader_ACLTree: - requestACLTree() - case treepb.TreeHeader_DocTree: - requestDocTree() - default: - return ErrIncorrectDocType - } + }) if err != nil { return err @@ -290,7 +212,7 @@ func (r *requestHandler) HandleFullSyncResponse( ctx context.Context, senderId string, response *syncproto.SyncFullResponse, - header *treepb.TreeHeader, + header *aclpb.Header, treeId string) (err error) { var ( @@ -300,66 +222,35 @@ func (r *requestHandler) HandleFullSyncResponse( log.With(zap.String("peerId", senderId), zap.String("treeId", treeId)). Debug("processing full sync response") - responseACLTree := func() { - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - t := obj.(tree.ACLTree) - t.Lock() - defer t.Unlock() + err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { + docTree := obj.(tree.DocTree) + docTree.Lock() + defer docTree.Unlock() - if slice.UnsortedEquals(response.Heads, t.Heads()) { - return nil - } + if slice.UnsortedEquals(response.Heads, docTree.Heads()) { + return nil + } + return r.treeCache.Do(ctx, docTree.Header().AclListId, func(obj interface{}) error { + aclTree := obj.(list.ACLList) + aclTree.RLock() + defer aclTree.RUnlock() // TODO: check if we already have those changes - result, err = t.AddRawChanges(ctx, response.Changes...) + result, err = docTree.AddRawChanges(ctx, aclTree, response.Changes...) if err != nil { return err } - snapshotPath = t.SnapshotPath() + snapshotPath = docTree.SnapshotPath() return nil }) - } - - responseDocTree := func() { - err = r.treeCache.Do(ctx, treeId, func(obj interface{}) error { - docTree := obj.(tree.DocTree) - docTree.Lock() - defer docTree.Unlock() - - if slice.UnsortedEquals(response.Heads, docTree.Heads()) { - return nil - } - - return r.treeCache.Do(ctx, docTree.Header().AclTreeId, func(obj interface{}) error { - aclTree := obj.(tree.ACLTree) - aclTree.RLock() - defer aclTree.RUnlock() - // TODO: check if we already have those changes - result, err = docTree.AddRawChanges(ctx, aclTree, response.Changes...) - if err != nil { - return err - } - snapshotPath = docTree.SnapshotPath() - return nil - }) - }) - } - - switch header.Type { - case treepb.TreeHeader_ACLTree: - responseACLTree() - case treepb.TreeHeader_DocTree: - responseDocTree() - default: - return ErrIncorrectDocType - } + }) // if error or nothing has changed - if (err != nil || len(result.Added) == 0) && err != treestorage.ErrUnknownTreeId { + if (err != nil || len(result.Added) == 0) && err != storage.ErrUnknownTreeId { return err } // if we have a new tree - if err == treestorage.ErrUnknownTreeId { + if err == storage.ErrUnknownTreeId { err = r.createTree(ctx, response, header, treeId) if err != nil { return err @@ -379,7 +270,7 @@ func (r *requestHandler) HandleFullSyncResponse( return r.messageService.SendToSpaceAsync("", syncproto.WrapHeadUpdate(newUpdate, header, treeId)) } -func (r *requestHandler) prepareFullSyncRequest(treeId string, header *treepb.TreeHeader, theirPath []string, t tree.CommonTree) (*syncproto.SyncFullRequest, error) { +func (r *requestHandler) prepareFullSyncRequest(theirPath []string, t tree.CommonTree) (*syncproto.SyncFullRequest, error) { ourChanges, err := t.ChangesAfterCommonSnapshot(theirPath) if err != nil { return nil, err @@ -426,7 +317,7 @@ func (r *requestHandler) prepareFullSyncResponse( func (r *requestHandler) createTree( ctx context.Context, response *syncproto.SyncFullResponse, - header *treepb.TreeHeader, + header *aclpb.Header, treeId string) error { return r.treeCache.Add( diff --git a/service/treecache/service.go b/service/treecache/service.go index ec6cae8a..c94d1fb6 100644 --- a/service/treecache/service.go +++ b/service/treecache/service.go @@ -7,6 +7,7 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" + aclstorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache" "github.com/anytypeio/go-anytype-infrastructure-experiments/service/account" @@ -17,13 +18,13 @@ import ( const CName = "treecache" // TODO: add context -type TreeFunc = func(tree interface{}) error +type ObjFunc = func(obj interface{}) error var log = logger.NewNamed("treecache") type Service interface { - Do(ctx context.Context, treeId string, f TreeFunc) error - Add(ctx context.Context, treeId string, header *aclpb.Header, changes []*aclpb.RawChange, f TreeFunc) error + Do(ctx context.Context, treeId string, f ObjFunc) error + Add(ctx context.Context, treeId string, header *aclpb.Header, changes []*aclpb.RawChange, f ObjFunc) error } type service struct { @@ -36,7 +37,7 @@ func New() app.ComponentRunnable { return &service{} } -func (s *service) Do(ctx context.Context, treeId string, f TreeFunc) error { +func (s *service) Do(ctx context.Context, treeId string, f ObjFunc) error { log. With(zap.String("treeId", treeId)). Debug("requesting tree from cache to perform operation") @@ -49,7 +50,7 @@ func (s *service) Do(ctx context.Context, treeId string, f TreeFunc) error { return f(t) } -func (s *service) Add(ctx context.Context, treeId string, header *treepb.TreeHeader, changes []*aclpb.RawChange, f TreeFunc) error { +func (s *service) Add(ctx context.Context, treeId string, header *aclpb.Header, changes []*aclpb.RawChange, f ObjFunc) error { log. With(zap.String("treeId", treeId), zap.Int("len(changes)", len(changes))). Debug("adding tree with changes") @@ -82,7 +83,7 @@ func (s *service) Close(ctx context.Context) (err error) { } func (s *service) loadTree(ctx context.Context, id string) (ocache.Object, error) { - t, err := s.storage.TreeStorage(id) + t, err := s.storage.Storage(id) if err != nil { return nil, err } @@ -93,7 +94,7 @@ func (s *service) loadTree(ctx context.Context, id string) (ocache.Object, error switch header.DocType { case aclpb.Header_ACL: - return list.BuildACLListWithIdentity(acc) + return list.BuildACLListWithIdentity(s.account.Account(), t.(aclstorage.ListStorage)) case aclpb.Header_DocTree: break default: @@ -101,13 +102,13 @@ func (s *service) loadTree(ctx context.Context, id string) (ocache.Object, error } log.Info("got header", zap.String("header", header.String())) var docTree tree.DocTree - // TODO: it is a question if we need to use ACLTree on the first tree build, because we can think that the tree is already validated - err = s.Do(ctx, header.AclTreeId, func(obj interface{}) error { - aclTree := obj.(tree.ACLTree) + // TODO: it is a question if we need to use ACLList on the first tree build, because we can think that the tree is already validated + err = s.Do(ctx, header.AclListId, func(obj interface{}) error { + aclTree := obj.(list.ACLList) aclTree.RLock() defer aclTree.RUnlock() - docTree, err = tree.BuildDocTreeWithIdentity(t, s.account.Account(), nil, aclTree) + docTree, err = tree.BuildDocTreeWithIdentity(t.(aclstorage.TreeStorage), s.account.Account(), nil, aclTree) if err != nil { return err } diff --git a/syncproto/helpers.go b/syncproto/helpers.go index 38bd5cf1..9fe94914 100644 --- a/syncproto/helpers.go +++ b/syncproto/helpers.go @@ -1,6 +1,6 @@ package syncproto -import "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/treepb" +import "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage/treepb" func WrapHeadUpdate(update *SyncHeadUpdate, header *treepb.TreeHeader, treeId string) *Sync { return &Sync{ diff --git a/syncproto/proto/sync.proto b/syncproto/proto/sync.proto index f83aef9a..c71848e4 100644 --- a/syncproto/proto/sync.proto +++ b/syncproto/proto/sync.proto @@ -3,7 +3,6 @@ package anytype; option go_package = "/syncproto"; import "pkg/acl/aclchanges/aclpb/protos/aclchanges.proto"; -import "pkg/acl/treestorage/treepb/protos/tree.proto"; message Message { Header header = 1; @@ -64,7 +63,7 @@ message Subscription { message Sync { string spaceId = 1; ContentValue message = 2; - tree.TreeHeader treeHeader = 3; + acl.Header treeHeader = 3; string treeId = 4; message ContentValue { diff --git a/syncproto/sync.pb.go b/syncproto/sync.pb.go index bf090662..f047edb3 100644 --- a/syncproto/sync.pb.go +++ b/syncproto/sync.pb.go @@ -6,7 +6,6 @@ package syncproto import ( fmt "fmt" aclpb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclchanges/aclpb" - treepb "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treestorage/treepb" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -590,10 +589,10 @@ func (m *SubscriptionUnsubscribeSpace) GetSpaceId() string { } type Sync struct { - SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` - Message *SyncContentValue `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` - TreeHeader *treepb.TreeHeader `protobuf:"bytes,3,opt,name=treeHeader,proto3" json:"treeHeader,omitempty"` - TreeId string `protobuf:"bytes,4,opt,name=treeId,proto3" json:"treeId,omitempty"` + SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` + Message *SyncContentValue `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + TreeHeader *aclpb.Header `protobuf:"bytes,3,opt,name=treeHeader,proto3" json:"treeHeader,omitempty"` + TreeId string `protobuf:"bytes,4,opt,name=treeId,proto3" json:"treeId,omitempty"` } func (m *Sync) Reset() { *m = Sync{} } @@ -643,7 +642,7 @@ func (m *Sync) GetMessage() *SyncContentValue { return nil } -func (m *Sync) GetTreeHeader() *treepb.TreeHeader { +func (m *Sync) GetTreeHeader() *aclpb.Header { if m != nil { return m.TreeHeader } @@ -996,61 +995,60 @@ func init() { func init() { proto.RegisterFile("syncproto/proto/sync.proto", fileDescriptor_4b28dfdd48a89166) } var fileDescriptor_4b28dfdd48a89166 = []byte{ - // 858 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xd1, 0x8e, 0xda, 0x46, - 0x14, 0xc5, 0x60, 0x20, 0x5c, 0x10,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xe2, 0x8d, 0x59, 0x93, - 0x69, 0x6e, 0x61, 0xd6, 0xbf, 0x1a, 0xe8, 0xc2, 0xa0, 0x75, 0x05, 0xcd, 0xac, 0xb3, 0x0f, 0x51, - 0x97, 0xc1, 0x9d, 0xac, 0xfd, 0x0f, 0x51, 0xef, 0xf1, 0x25, 0xb4, 0x0b, 0xc3, 0x1d, 0xdd, 0x87, - 0x8f, 0x0a, 0xa1, 0x1a, 0x40, 0x46, 0x05, 0x3d, 0x80, 0x4f, 0x8a, 0x70, 0xe1, 0x8e, 0x1a, 0x1a, - 0xba, 0x0b, 0x27, 0xb7, 0x34, 0xcc, 0x35, 0xaa, 0x2f, 0x1e, 0xfd, 0x75, 0xdd, 0xd3, 0xde, 0x5e, - 0xf7, 0xb4, 0x7f, 0xae, 0x7b, 0xda, 0x9b, 0x9b, 0x5e, 0xe5, 0xed, 0x4d, 0xaf, 0xf2, 0xf7, 0x4d, - 0xaf, 0xf2, 0x13, 0x9c, 0x1e, 0x5e, 0xc7, 0xab, 0x86, 0xfc, 0xf9, 0xea, 0xff, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x6a, 0x04, 0xc0, 0x87, 0xa2, 0x07, 0x00, 0x00, + // 840 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xd1, 0x8e, 0xdb, 0x44, + 0x14, 0x8d, 0x13, 0x27, 0x69, 0x6e, 0xa2, 0xac, 0x99, 0xb6, 0x60, 0xdc, 0x2a, 0xb2, 0xac, 0x02, + 0x56, 0x8b, 0xbc, 0x28, 0x50, 0x21, 0xf1, 0xd6, 0x2e, 0xbb, 0x4a, 0x44, 0x49, 0xa2, 0xc9, 0x66, + 0x91, 0x78, 0xa9, 0x26, 0xf6, 0x34, 0x89, 0xe2, 0x1d, 0x1b, 0x8f, 0x0d, 0xe4, 0x17, 0x78, 0xea, + 0x37, 0xf0, 0x0d, 0x7c, 0x04, 0x8f, 0x7d, 0xe4, 0x09, 0xa1, 0x5d, 0xc1, 0x77, 0xa0, 0x99, 0xb1, + 0x13, 0xaf, 0xbb, 0x7d, 0xed, 0x43, 0x92, 0xb9, 0xf7, 0x9e, 0x73, 0xe6, 0x5c, 0x8f, 0xef, 0x04, + 0x2c, 0xbe, 0x63, 0x7e, 0x9c, 0x44, 0x69, 0x74, 0xac, 0xbe, 0x45, 0xec, 0xc9, 0x25, 0x6a, 0x13, + 0xb6, 0x4b, 0x77, 0x31, 0xb5, 0xbe, 0x88, 0xb7, 0xab, 0x63, 0xe2, 0x87, 0xe2, 0xe3, 0xaf, 0x09, + 0x5b, 0x51, 0x2e, 0x96, 0xf1, 0x52, 0x71, 0x78, 0x29, 0xaf, 0xa8, 0xce, 0x19, 0xb4, 0xbf, 0xa7, + 0x9c, 0x93, 0x15, 0x45, 0x9f, 0x41, 0x6b, 0x4d, 0x49, 0x40, 0x13, 0x53, 0xb3, 0x35, 0xb7, 0x3b, + 0x3c, 0xf2, 0x72, 0x59, 0x6f, 0x24, 0xd3, 0x38, 0x2f, 0x23, 0x04, 0x7a, 0x40, 0x52, 0x62, 0xd6, + 0x6d, 0xcd, 0xed, 0x61, 0xb9, 0x76, 0x7e, 0xd7, 0xa0, 0xa5, 0x60, 0xc8, 0x84, 0x76, 0x9a, 0x10, + 0x9f, 0x8e, 0x03, 0x29, 0xd4, 0xc3, 0x45, 0x88, 0x1e, 0x42, 0x27, 0xa1, 0x3f, 0x65, 0x94, 0xa7, + 0xe3, 0x40, 0xb2, 0x75, 0x7c, 0x48, 0x08, 0x5e, 0x42, 0xe3, 0x70, 0x37, 0x0e, 0xcc, 0x86, 0xac, + 0x15, 0x21, 0x72, 0x41, 0x17, 0x3e, 0x4c, 0xdd, 0xd6, 0xdc, 0xfe, 0xf0, 0xde, 0xde, 0x57, 0xee, + 0xfc, 0x7c, 0x17, 0x53, 0x2c, 0x11, 0x62, 0x87, 0x80, 0x2e, 0xb3, 0xd5, 0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xbd, 0xb9, 0x1a, 0x68, + 0xff, 0x5c, 0x0d, 0xb4, 0xd7, 0xd7, 0x83, 0xda, 0x9b, 0xeb, 0x41, 0xed, 0xaf, 0xeb, 0x41, 0xed, + 0x47, 0x38, 0xde, 0xff, 0xb7, 0x2e, 0x5b, 0xf2, 0xe7, 0xcb, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, + 0x34, 0xaa, 0x76, 0x9b, 0x6f, 0x07, 0x00, 0x00, } func (m *Message) Marshal() (dAtA []byte, err error) { @@ -3328,7 +3326,7 @@ func (m *Sync) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.TreeHeader == nil { - m.TreeHeader = &treepb.TreeHeader{} + m.TreeHeader = &aclpb.Header{} } if err := m.TreeHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err