diff --git a/Makefile b/Makefile index e9143f01..53ddd25b 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ proto: $(GOGO_START) protoc --gogofaster_out=:. $(P_ACL_RECORDS_PATH_PB)/protos/*.proto $(GOGO_START) protoc --gogofaster_out=:. $(P_TREE_CHANGES_PATH_PB)/protos/*.proto $(GOGO_START) protoc --gogofaster_out=:. $(P_TEST_CHANGES_PATH_PB)/proto/*.proto - $(eval PKGMAP := $$(P_TREE_CHANGES)) + $(eval PKGMAP := $$(P_TREE_CHANGES),$$(P_ACL_RECORDS)) $(GOGO_START) protoc --gogofaster_out=$(PKGMAP):. --go-drpc_out=protolib=github.com/gogo/protobuf:. common/commonspace/spacesyncproto/protos/*.proto diff --git a/cmd/node/node.go b/cmd/node/node.go index 3a0e0f64..47d0c3e5 100644 --- a/cmd/node/node.go +++ b/cmd/node/node.go @@ -89,6 +89,7 @@ func main() { func Bootstrap(a *app.App) { a.Register(account.New()). + // TODO: add space storage provider from node side Register(nodeconf.New()). Register(secure.New()). Register(dialer.New()). diff --git a/common/commonspace/diffservice/diffservice.go b/common/commonspace/diffservice/diffservice.go index b530d05f..71cf36ce 100644 --- a/common/commonspace/diffservice/diffservice.go +++ b/common/commonspace/diffservice/diffservice.go @@ -27,7 +27,7 @@ type DiffService interface { type diffService struct { spaceId string periodicSync *periodicSync - storage storage.Storage + storage storage.SpaceStorage nconf nodeconf.Configuration diff ldiff.Diff cache cache.TreeCache @@ -39,7 +39,7 @@ type diffService struct { func NewDiffService( spaceId string, syncPeriod int, - storage storage.Storage, + storage storage.SpaceStorage, nconf nodeconf.Configuration, cache cache.TreeCache, log *zap.Logger) DiffService { diff --git a/common/commonspace/service.go b/common/commonspace/service.go index ae1edd99..f5b10591 100644 --- a/common/commonspace/service.go +++ b/common/commonspace/service.go @@ -6,10 +6,17 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice" + "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf" "github.com/anytypeio/go-anytype-infrastructure-experiments/config" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" + "github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" + "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" + "hash/fnv" + "math/rand" + "time" ) const CName = "common.commonspace" @@ -21,22 +28,21 @@ func New() Service { } type Service interface { - CreateSpace(ctx context.Context, id string, deps SpaceDeps) (sp Space, err error) + CreateSpace(ctx context.Context, cache cache.TreeCache, payload SpaceCreatePayload) (Space, error) + DeriveSpace(ctx context.Context, cache cache.TreeCache, payload SpaceDerivePayload) (Space, error) + GetSpace(ctx context.Context, id string, cache cache.TreeCache) (sp Space, err error) app.Component } type service struct { config config.Space configurationService nodeconf.Service -} - -type SpaceDeps struct { - Cache cache.TreeCache - Storage storage.Storage + storageProvider storage.SpaceStorageProvider } func (s *service) Init(a *app.App) (err error) { s.config = a.MustComponent(config.CName).(*config.Config).Space + s.storageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider) s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service) return nil } @@ -45,19 +51,222 @@ func (s *service) Name() (name string) { return CName } -func (s *service) CreateSpace(ctx context.Context, id string, deps SpaceDeps) (Space, error) { +func (s *service) CreateSpace( + ctx context.Context, + cache cache.TreeCache, + payload SpaceCreatePayload) (sp Space, err error) { + + // unmarshalling signing and encryption keys + identity, err := payload.SigningKey.GetPublic().Raw() + if err != nil { + return + } + encPubKey, err := payload.EncryptionKey.GetPublic().Raw() + if err != nil { + return + } + + // preparing header and space id + bytes := make([]byte, 32) + _, err = rand.Read(bytes) + if err != nil { + return + } + header := &spacesyncproto.SpaceHeader{ + Identity: identity, + Timestamp: time.Now().UnixNano(), + SpaceType: payload.SpaceType, + ReplicationKey: payload.ReplicationKey, + Seed: bytes, + } + marshalled, err := header.Marshal() + if err != nil { + return + } + id, err := cid.NewCIDFromBytes(marshalled) + if err != nil { + return + } + spaceId := NewSpaceId(id, payload.ReplicationKey) + + // encrypting read key + hasher := fnv.New64() + _, err = hasher.Write(payload.ReadKey) + if err != nil { + return + } + readKeyHash := hasher.Sum64() + encReadKey, err := payload.EncryptionKey.GetPublic().Encrypt(payload.ReadKey) + if err != nil { + return + } + + // preparing acl + aclRoot := &aclrecordproto.ACLRoot{ + Identity: identity, + EncryptionKey: encPubKey, + SpaceId: spaceId, + EncryptedReadKey: encReadKey, + DerivationScheme: "", + CurrentReadKeyHash: readKeyHash, + Timestamp: time.Now().UnixNano(), + } + rawWithId, err := marshalACLRoot(aclRoot, payload.SigningKey) + if err != nil { + return + } + + // creating storage + storageCreate := storage.SpaceStorageCreatePayload{ + RecWithId: rawWithId, + SpaceHeader: header, + Id: id, + } + _, err = s.storageProvider.CreateSpaceStorage(storageCreate) + if err != nil { + return + } + + return s.GetSpace(ctx, spaceId, cache) +} + +func (s *service) DeriveSpace( + ctx context.Context, + cache cache.TreeCache, + payload SpaceDerivePayload) (sp Space, err error) { + + // unmarshalling signing and encryption keys + identity, err := payload.SigningKey.GetPublic().Raw() + if err != nil { + return + } + signPrivKey, err := payload.SigningKey.Raw() + if err != nil { + return + } + encPubKey, err := payload.EncryptionKey.GetPublic().Raw() + if err != nil { + return + } + encPrivKey, err := payload.EncryptionKey.Raw() + if err != nil { + return + } + + // preparing replication key + hasher := fnv.New64() + _, err = hasher.Write(identity) + if err != nil { + return + } + repKey := hasher.Sum64() + + // preparing header and space id + header := &spacesyncproto.SpaceHeader{ + Identity: identity, + SpaceType: SpaceTypeDerived, + ReplicationKey: repKey, + } + marshalled, err := header.Marshal() + if err != nil { + return + } + id, err := cid.NewCIDFromBytes(marshalled) + if err != nil { + return + } + spaceId := NewSpaceId(id, repKey) + + // deriving and encrypting read key + readKey, err := aclrecordproto.ACLReadKeyDerive(signPrivKey, encPrivKey) + if err != nil { + return + } + hasher = fnv.New64() + _, err = hasher.Write(readKey.Bytes()) + if err != nil { + return + } + readKeyHash := hasher.Sum64() + encReadKey, err := payload.EncryptionKey.GetPublic().Encrypt(readKey.Bytes()) + if err != nil { + return + } + + // preparing acl + aclRoot := &aclrecordproto.ACLRoot{ + Identity: identity, + EncryptionKey: encPubKey, + SpaceId: spaceId, + EncryptedReadKey: encReadKey, + DerivationScheme: "", + CurrentReadKeyHash: readKeyHash, + Timestamp: time.Now().UnixNano(), + } + rawWithId, err := marshalACLRoot(aclRoot, payload.SigningKey) + if err != nil { + return + } + + // creating storage + storageCreate := storage.SpaceStorageCreatePayload{ + RecWithId: rawWithId, + SpaceHeader: header, + Id: id, + } + _, err = s.storageProvider.CreateSpaceStorage(storageCreate) + if err != nil { + return + } + + return s.GetSpace(ctx, spaceId, cache) +} + +func (s *service) GetSpace(ctx context.Context, id string, cache cache.TreeCache) (Space, error) { + st, err := s.storageProvider.SpaceStorage(id) + if err != nil { + return nil, err + } lastConfiguration := s.configurationService.GetLast() - diffService := diffservice.NewDiffService(id, s.config.SyncPeriod, deps.Storage, lastConfiguration, deps.Cache, log) - syncService := syncservice.NewSyncService(id, diffService, deps.Cache, lastConfiguration) + diffService := diffservice.NewDiffService(id, s.config.SyncPeriod, st, lastConfiguration, cache, log) + syncService := syncservice.NewSyncService(id, diffService, cache, lastConfiguration) sp := &space{ id: id, syncService: syncService, diffService: diffService, - cache: deps.Cache, - storage: deps.Storage, + cache: cache, + storage: st, } if err := sp.Init(ctx); err != nil { return nil, err } return sp, nil } + +func marshalACLRoot(aclRoot *aclrecordproto.ACLRoot, key signingkey.PrivKey) (rawWithId *aclrecordproto.RawACLRecordWithId, err error) { + marshalledRoot, err := aclRoot.Marshal() + if err != nil { + return + } + signature, err := key.Sign(marshalledRoot) + if err != nil { + return + } + raw := &aclrecordproto.RawACLRecord{ + Payload: marshalledRoot, + Signature: signature, + } + marshalledRaw, err := raw.Marshal() + if err != nil { + return + } + aclHeadId, err := cid.NewCIDFromBytes(marshalledRaw) + if err != nil { + return + } + rawWithId = &aclrecordproto.RawACLRecordWithId{ + Payload: marshalledRaw, + Id: aclHeadId, + } + return +} diff --git a/common/commonspace/space.go b/common/commonspace/space.go index 07dac8f6..31c2fdfa 100644 --- a/common/commonspace/space.go +++ b/common/commonspace/space.go @@ -2,6 +2,7 @@ package commonspace import ( "context" + "fmt" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" @@ -11,9 +12,30 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" treestorage "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/util/keys/asymmetric/encryptionkey" + "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "sync" ) +type SpaceCreatePayload struct { + SigningKey signingkey.PrivKey + EncryptionKey encryptionkey.PrivKey + SpaceType string + ReadKey []byte + ReplicationKey uint64 +} + +const SpaceTypeDerived = "derived.space" + +type SpaceDerivePayload struct { + SigningKey signingkey.PrivKey + EncryptionKey encryptionkey.PrivKey +} + +func NewSpaceId(id string, repKey uint64) string { + return fmt.Sprintf("%s.%d", id, repKey) +} + type Space interface { Id() string @@ -21,6 +43,7 @@ type Space interface { SyncService() syncservice.SyncService DiffService() diffservice.DiffService + DeriveTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener synctree.UpdateListener) (tree.ObjectTree, error) CreateTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener synctree.UpdateListener) (tree.ObjectTree, error) BuildTree(ctx context.Context, id string, listener synctree.UpdateListener) (tree.ObjectTree, error) @@ -35,7 +58,7 @@ type space struct { syncService syncservice.SyncService diffService diffservice.DiffService - storage storage.Storage + storage storage.SpaceStorage cache cache.TreeCache aclList list.ACLList } @@ -69,6 +92,10 @@ func (s *space) DiffService() diffservice.DiffService { return s.diffService } +func (s *space) DeriveTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener synctree.UpdateListener) (tree.ObjectTree, error) { + return synctree.DeriveSyncTree(ctx, payload, s.syncService, listener, s.aclList, s.storage.CreateTreeStorage) +} + func (s *space) CreateTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener synctree.UpdateListener) (tree.ObjectTree, error) { return synctree.CreateSyncTree(ctx, payload, s.syncService, listener, s.aclList, s.storage.CreateTreeStorage) } diff --git a/common/commonspace/spacesyncproto/protos/spacesync.proto b/common/commonspace/spacesyncproto/protos/spacesync.proto index d4d65733..8131db4f 100644 --- a/common/commonspace/spacesyncproto/protos/spacesync.proto +++ b/common/commonspace/spacesyncproto/protos/spacesync.proto @@ -3,6 +3,7 @@ package anySpace; option go_package = "common/commonspace/spacesyncproto"; import "pkg/acl/treechangeproto/protos/treechange.proto"; +import "pkg/acl/aclrecordproto/protos/aclrecord.proto"; enum ErrCodes { Unexpected = 0; @@ -11,6 +12,9 @@ enum ErrCodes { service Space { // HeadSync compares all objects and their hashes in a space rpc HeadSync(HeadSyncRequest) returns (HeadSyncResponse); + // PushSpace sends new space to the node + rpc PushSpace(PushSpaceRequest) returns (PushSpaceResponse); + // Stream opens object sync stream with node or client rpc Stream(stream ObjectSyncMessage) returns (stream ObjectSyncMessage); } @@ -52,9 +56,9 @@ message ObjectSyncMessage { treechange.RawTreeChangeWithId rootChange = 3; string treeId = 4; string trackingId = 5; -// -// string identity = 5; -// string peerSignature = 6; + +// string identity = 5; +// string peerSignature = 6; } // ObjectSyncContentValue provides different types for object sync @@ -88,10 +92,22 @@ message ObjectFullSyncResponse { repeated string snapshotPath = 3; } +// ObjectErrorResponse is an error sent as a response for a full sync request message ObjectErrorResponse { string error = 1; } +// PushSpaceRequest is a request to add space on a node containing only one acl record +message PushSpaceRequest { + string spaceId = 1; + SpaceHeader spaceHeader = 2; + aclrecord.RawACLRecordWithId aclRoot = 3; +} + +// PushSpaceResponse is an empty response +message PushSpaceResponse {} + +// SpaceHeader is a header for a space message SpaceHeader { bytes identity = 1; int64 timestamp = 2; diff --git a/common/commonspace/spacesyncproto/spacesync.pb.go b/common/commonspace/spacesyncproto/spacesync.pb.go index 6cbcba84..8cffa076 100644 --- a/common/commonspace/spacesyncproto/spacesync.pb.go +++ b/common/commonspace/spacesyncproto/spacesync.pb.go @@ -5,6 +5,7 @@ package spacesyncproto import ( fmt "fmt" + aclrecordproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" treechangeproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -690,6 +691,7 @@ func (m *ObjectFullSyncResponse) GetSnapshotPath() []string { return nil } +// ObjectErrorResponse is an error sent as a response for a full sync request type ObjectErrorResponse struct { Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` } @@ -734,6 +736,105 @@ func (m *ObjectErrorResponse) GetError() string { return "" } +// 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"` + AclRoot *aclrecordproto.RawACLRecordWithId `protobuf:"bytes,3,opt,name=aclRoot,proto3" json:"aclRoot,omitempty"` +} + +func (m *PushSpaceRequest) Reset() { *m = PushSpaceRequest{} } +func (m *PushSpaceRequest) String() string { return proto.CompactTextString(m) } +func (*PushSpaceRequest) ProtoMessage() {} +func (*PushSpaceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_5855f4ef9cf24cdb, []int{11} +} +func (m *PushSpaceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PushSpaceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PushSpaceRequest.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 *PushSpaceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_PushSpaceRequest.Merge(m, src) +} +func (m *PushSpaceRequest) XXX_Size() int { + return m.Size() +} +func (m *PushSpaceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_PushSpaceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_PushSpaceRequest proto.InternalMessageInfo + +func (m *PushSpaceRequest) GetSpaceId() string { + if m != nil { + return m.SpaceId + } + return "" +} + +func (m *PushSpaceRequest) GetSpaceHeader() *SpaceHeader { + if m != nil { + return m.SpaceHeader + } + return nil +} + +func (m *PushSpaceRequest) GetAclRoot() *aclrecordproto.RawACLRecordWithId { + if m != nil { + return m.AclRoot + } + return nil +} + +// PushSpaceResponse is an empty response +type PushSpaceResponse struct { +} + +func (m *PushSpaceResponse) Reset() { *m = PushSpaceResponse{} } +func (m *PushSpaceResponse) String() string { return proto.CompactTextString(m) } +func (*PushSpaceResponse) ProtoMessage() {} +func (*PushSpaceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_5855f4ef9cf24cdb, []int{12} +} +func (m *PushSpaceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PushSpaceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PushSpaceResponse.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 *PushSpaceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_PushSpaceResponse.Merge(m, src) +} +func (m *PushSpaceResponse) XXX_Size() int { + return m.Size() +} +func (m *PushSpaceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_PushSpaceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_PushSpaceResponse proto.InternalMessageInfo + +// SpaceHeader is a header for a space type SpaceHeader struct { Identity []byte `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` @@ -746,7 +847,7 @@ func (m *SpaceHeader) Reset() { *m = SpaceHeader{} } func (m *SpaceHeader) String() string { return proto.CompactTextString(m) } func (*SpaceHeader) ProtoMessage() {} func (*SpaceHeader) Descriptor() ([]byte, []int) { - return fileDescriptor_5855f4ef9cf24cdb, []int{11} + return fileDescriptor_5855f4ef9cf24cdb, []int{13} } func (m *SpaceHeader) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -823,6 +924,8 @@ func init() { proto.RegisterType((*ObjectFullSyncRequest)(nil), "anySpace.ObjectFullSyncRequest") proto.RegisterType((*ObjectFullSyncResponse)(nil), "anySpace.ObjectFullSyncResponse") proto.RegisterType((*ObjectErrorResponse)(nil), "anySpace.ObjectErrorResponse") + proto.RegisterType((*PushSpaceRequest)(nil), "anySpace.PushSpaceRequest") + proto.RegisterType((*PushSpaceResponse)(nil), "anySpace.PushSpaceResponse") proto.RegisterType((*SpaceHeader)(nil), "anySpace.SpaceHeader") } @@ -831,57 +934,63 @@ func init() { } var fileDescriptor_5855f4ef9cf24cdb = []byte{ - // 793 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xcd, 0x8e, 0x1b, 0x45, - 0x10, 0x9e, 0xf1, 0x7a, 0xd7, 0x76, 0xed, 0xae, 0x63, 0x1a, 0x12, 0x06, 0x03, 0x8e, 0x99, 0x03, - 0xb2, 0x40, 0x5a, 0x23, 0x73, 0x01, 0x16, 0x09, 0x91, 0x95, 0x57, 0xb6, 0x22, 0x7e, 0xd4, 0x9b, - 0x80, 0x84, 0xb8, 0x74, 0x66, 0x2a, 0xf6, 0x90, 0x99, 0xe9, 0xa1, 0xbb, 0x4d, 0xf0, 0x13, 0x70, - 0x01, 0x09, 0xf1, 0x06, 0x3c, 0x0b, 0x17, 0x8e, 0x39, 0x72, 0x44, 0xde, 0x17, 0x41, 0x5d, 0xe3, - 0xf1, 0xd8, 0x66, 0x92, 0x1c, 0xf7, 0xe2, 0xe9, 0xaa, 0xfe, 0xbe, 0xea, 0xaf, 0xab, 0xaa, 0xcb, - 0xf0, 0x51, 0x20, 0x93, 0x44, 0xa6, 0xc3, 0xfc, 0xa3, 0x33, 0x11, 0xe0, 0x90, 0x7e, 0xf5, 0x32, - 0x0d, 0x32, 0x25, 0x8d, 0x1c, 0xd2, 0xaf, 0x2e, 0xbd, 0x67, 0xe4, 0x60, 0x4d, 0x91, 0x2e, 0xaf, - 0xac, 0xaf, 0x3b, 0xcc, 0x9e, 0xcc, 0x86, 0x22, 0x88, 0x87, 0x46, 0x21, 0x06, 0x73, 0x91, 0xce, - 0x70, 0x87, 0x59, 0xba, 0x73, 0xaa, 0x3f, 0x85, 0xd3, 0x09, 0x8a, 0xf0, 0x6a, 0x99, 0x06, 0xdc, - 0xba, 0x19, 0x83, 0xfa, 0x63, 0x25, 0x13, 0xcf, 0xed, 0xbb, 0x83, 0x3a, 0xa7, 0x35, 0x6b, 0x43, - 0xcd, 0x48, 0xaf, 0x46, 0x9e, 0x9a, 0x91, 0xec, 0x35, 0x38, 0x8c, 0xa3, 0x24, 0x32, 0xde, 0x41, - 0xdf, 0x1d, 0x9c, 0xf2, 0xdc, 0xf0, 0x9f, 0x42, 0x7b, 0x13, 0x0a, 0xf5, 0x22, 0x36, 0x36, 0xd6, - 0x5c, 0xe8, 0x39, 0xc5, 0x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f, 0x57, 0x3d, 0xf7, 0xf7, 0xeb, 0x9e, 0xf3, 0xec, 0xba, 0xe7, 0xfc, 0x73, 0xdd, 0x73, - 0xbe, 0x7b, 0xe7, 0xa5, 0xff, 0xc5, 0x8f, 0x8e, 0xe8, 0xf3, 0xe1, 0x7f, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x33, 0xca, 0x5b, 0xe5, 0xb7, 0x07, 0x00, 0x00, + // 887 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0x3a, 0x4e, 0x6c, 0x3f, 0x27, 0xa9, 0x3b, 0x25, 0x65, 0x71, 0xa9, 0x6b, 0xf6, 0x80, + 0x22, 0x10, 0x31, 0x32, 0x87, 0x02, 0x41, 0x42, 0x6d, 0x48, 0x64, 0xab, 0xfc, 0xa9, 0x26, 0x2d, + 0x48, 0x88, 0xcb, 0x74, 0xf7, 0x35, 0x5e, 0xba, 0xde, 0x59, 0x66, 0xc7, 0x04, 0x7f, 0x02, 0x2e, + 0x20, 0xf1, 0x09, 0x90, 0xf8, 0x2c, 0x5c, 0x38, 0xf6, 0xd8, 0x23, 0x4a, 0xbe, 0x08, 0x9a, 0x37, + 0xbb, 0xde, 0xb5, 0xd9, 0x36, 0xc7, 0x5e, 0xbc, 0xf3, 0xde, 0xfb, 0xbd, 0x37, 0xbf, 0xf7, 0x67, + 0x66, 0x0c, 0x1f, 0xfb, 0x72, 0x36, 0x93, 0xf1, 0xd0, 0x7e, 0xd2, 0x44, 0xf8, 0x38, 0xa4, 0xdf, + 0x74, 0x11, 0xfb, 0x89, 0x92, 0x5a, 0x0e, 0xe9, 0x37, 0x2d, 0xb4, 0x07, 0xa4, 0x60, 0x2d, 0x11, + 0x2f, 0x4e, 0x8d, 0xae, 0x37, 0x4c, 0x9e, 0x9d, 0x0d, 0x85, 0x1f, 0x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e, 0x6d, 0x79, 0xb2, 0x45, 0x9f, 0x8f, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x7d, + 0x4c, 0x93, 0xdc, 0xe2, 0x08, 0x00, 0x00, } func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { @@ -1468,6 +1577,83 @@ func (m *ObjectErrorResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *PushSpaceRequest) 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 *PushSpaceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PushSpaceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AclRoot != nil { + { + size, err := m.AclRoot.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSpacesync(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if m.SpaceHeader != nil { + { + size, err := m.SpaceHeader.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintSpacesync(dAtA, i, uint64(size)) + } + 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 +} + +func (m *PushSpaceResponse) 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 *PushSpaceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PushSpaceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *SpaceHeader) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1807,6 +1993,36 @@ func (m *ObjectErrorResponse) Size() (n int) { return n } +func (m *PushSpaceRequest) Size() (n int) { + if m == nil { + return 0 + } + 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)) + } + if m.AclRoot != nil { + l = m.AclRoot.Size() + n += 1 + l + sovSpacesync(uint64(l)) + } + return n +} + +func (m *PushSpaceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *SpaceHeader) Size() (n int) { if m == nil { return 0 @@ -3332,6 +3548,210 @@ func (m *ObjectErrorResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *PushSpaceRequest) 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: PushSpaceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + 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) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSpacesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.SpaceHeader == nil { + m.SpaceHeader = &SpaceHeader{} + } + if err := m.SpaceHeader.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AclRoot", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSpacesync + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthSpacesync + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthSpacesync + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.AclRoot == nil { + m.AclRoot = &aclrecordproto.RawACLRecordWithId{} + } + if err := m.AclRoot.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *PushSpaceResponse) 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: PushSpaceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PushSpaceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + 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 *SpaceHeader) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/common/commonspace/spacesyncproto/spacesync_drpc.pb.go b/common/commonspace/spacesyncproto/spacesync_drpc.pb.go index 9f984b1e..d17223ae 100644 --- a/common/commonspace/spacesyncproto/spacesync_drpc.pb.go +++ b/common/commonspace/spacesyncproto/spacesync_drpc.pb.go @@ -41,6 +41,7 @@ type DRPCSpaceClient interface { DRPCConn() drpc.Conn HeadSync(ctx context.Context, in *HeadSyncRequest) (*HeadSyncResponse, error) + PushSpace(ctx context.Context, in *PushSpaceRequest) (*PushSpaceResponse, error) Stream(ctx context.Context) (DRPCSpace_StreamClient, error) } @@ -63,6 +64,15 @@ func (c *drpcSpaceClient) HeadSync(ctx context.Context, in *HeadSyncRequest) (*H return out, nil } +func (c *drpcSpaceClient) PushSpace(ctx context.Context, in *PushSpaceRequest) (*PushSpaceResponse, error) { + out := new(PushSpaceResponse) + err := c.cc.Invoke(ctx, "/anySpace.Space/PushSpace", drpcEncoding_File_common_commonspace_spacesyncproto_protos_spacesync_proto{}, in, out) + if err != nil { + return nil, err + } + return out, nil +} + func (c *drpcSpaceClient) Stream(ctx context.Context) (DRPCSpace_StreamClient, error) { stream, err := c.cc.NewStream(ctx, "/anySpace.Space/Stream", drpcEncoding_File_common_commonspace_spacesyncproto_protos_spacesync_proto{}) if err != nil { @@ -100,6 +110,7 @@ func (x *drpcSpace_StreamClient) RecvMsg(m *ObjectSyncMessage) error { type DRPCSpaceServer interface { HeadSync(context.Context, *HeadSyncRequest) (*HeadSyncResponse, error) + PushSpace(context.Context, *PushSpaceRequest) (*PushSpaceResponse, error) Stream(DRPCSpace_StreamStream) error } @@ -109,13 +120,17 @@ func (s *DRPCSpaceUnimplementedServer) HeadSync(context.Context, *HeadSyncReques return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } +func (s *DRPCSpaceUnimplementedServer) PushSpace(context.Context, *PushSpaceRequest) (*PushSpaceResponse, error) { + return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) +} + func (s *DRPCSpaceUnimplementedServer) Stream(DRPCSpace_StreamStream) error { return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented) } type DRPCSpaceDescription struct{} -func (DRPCSpaceDescription) NumMethods() int { return 2 } +func (DRPCSpaceDescription) NumMethods() int { return 3 } func (DRPCSpaceDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) { switch n { @@ -129,6 +144,15 @@ func (DRPCSpaceDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, ) }, DRPCSpaceServer.HeadSync, true case 1: + return "/anySpace.Space/PushSpace", drpcEncoding_File_common_commonspace_spacesyncproto_protos_spacesync_proto{}, + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCSpaceServer). + PushSpace( + ctx, + in1.(*PushSpaceRequest), + ) + }, DRPCSpaceServer.PushSpace, true + case 2: return "/anySpace.Space/Stream", drpcEncoding_File_common_commonspace_spacesyncproto_protos_spacesync_proto{}, func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { return nil, srv.(DRPCSpaceServer). @@ -161,6 +185,22 @@ func (x *drpcSpace_HeadSyncStream) SendAndClose(m *HeadSyncResponse) error { return x.CloseSend() } +type DRPCSpace_PushSpaceStream interface { + drpc.Stream + SendAndClose(*PushSpaceResponse) error +} + +type drpcSpace_PushSpaceStream struct { + drpc.Stream +} + +func (x *drpcSpace_PushSpaceStream) SendAndClose(m *PushSpaceResponse) error { + if err := x.MsgSend(m, drpcEncoding_File_common_commonspace_spacesyncproto_protos_spacesync_proto{}); err != nil { + return err + } + return x.CloseSend() +} + type DRPCSpace_StreamStream interface { drpc.Stream Send(*ObjectSyncMessage) error diff --git a/common/commonspace/storage/storage.go b/common/commonspace/storage/storage.go index fb67e1df..d2869680 100644 --- a/common/commonspace/storage/storage.go +++ b/common/commonspace/storage/storage.go @@ -1,12 +1,27 @@ package storage import ( + "github.com/anytypeio/go-anytype-infrastructure-experiments/app" + "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" + "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" ) const CName = "commonspace.storage" -type Storage interface { +type SpaceStorage interface { storage.Provider StoredIds() ([]string, error) } + +type SpaceStorageCreatePayload struct { + RecWithId *aclrecordproto.RawACLRecordWithId + SpaceHeader *spacesyncproto.SpaceHeader + Id string +} + +type SpaceStorageProvider interface { + app.Component + SpaceStorage(id string) (SpaceStorage, error) + CreateSpaceStorage(payload SpaceStorageCreatePayload) (SpaceStorage, error) +} diff --git a/common/commonspace/syncservice/syncservice.go b/common/commonspace/syncservice/syncservice.go index ecf43dfe..4ba8c08b 100644 --- a/common/commonspace/syncservice/syncservice.go +++ b/common/commonspace/syncservice/syncservice.go @@ -101,7 +101,8 @@ func (s *syncService) responsibleStreamCheckLoop(ctx context.Context) { if err != nil { continue } - + // sending empty message for the server to understand from which space is it coming + stream.Send(&spacesyncproto.ObjectSyncMessage{SpaceId: s.spaceId}) s.streamPool.AddAndReadStreamAsync(stream) } } diff --git a/common/commonspace/synctree/synctree.go b/common/commonspace/synctree/synctree.go index 68ea48f4..a339b6fb 100644 --- a/common/commonspace/synctree/synctree.go +++ b/common/commonspace/synctree/synctree.go @@ -22,6 +22,30 @@ type SyncTree struct { listener UpdateListener } +func DeriveSyncTree( + ctx context.Context, + payload tree.ObjectTreeCreatePayload, + syncService syncservice.SyncService, + listener UpdateListener, + aclList list.ACLList, + createStorage storage.TreeStorageCreatorFunc) (t tree.ObjectTree, err error) { + t, err = tree.CreateDerivedObjectTree(payload, aclList, createStorage) + if err != nil { + return + } + t = &SyncTree{ + ObjectTree: t, + syncService: syncService, + listener: listener, + } + + err = syncService.NotifyHeadUpdate(ctx, t.ID(), t.Header(), &spacesyncproto.ObjectHeadUpdate{ + Heads: t.Heads(), + SnapshotPath: t.SnapshotPath(), + }) + return +} + func CreateSyncTree( ctx context.Context, payload tree.ObjectTreeCreatePayload, diff --git a/node/nodespace/rpchandler.go b/node/nodespace/rpchandler.go index 082e7b90..1c4e49d7 100644 --- a/node/nodespace/rpchandler.go +++ b/node/nodespace/rpchandler.go @@ -9,6 +9,10 @@ type rpcHandler struct { s *service } +func (r *rpcHandler) PushSpace(ctx context.Context, request *spacesyncproto.PushSpaceRequest) (*spacesyncproto.PushSpaceResponse, error) { + return nil, nil +} + func (r *rpcHandler) HeadSync(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (*spacesyncproto.HeadSyncResponse, error) { sp, err := r.s.GetSpace(ctx, req.SpaceId) if err != nil { diff --git a/node/nodespace/service.go b/node/nodespace/service.go index 9602a18b..9b3990c8 100644 --- a/node/nodespace/service.go +++ b/node/nodespace/service.go @@ -9,7 +9,6 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server" "github.com/anytypeio/go-anytype-infrastructure-experiments/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache" - "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache" "time" ) @@ -38,11 +37,7 @@ func (s *service) Init(a *app.App) (err error) { s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service) s.spaceCache = ocache.New( func(ctx context.Context, id string) (value ocache.Object, err error) { - deps := commonspace.SpaceDeps{ - Cache: nodecache.NewNodeCache(s.conf.GCTTL), - Storage: storage.NewInMemoryTreeStorageProvider(), - } - return s.commonSpace.CreateSpace(ctx, id, deps) + return s.commonSpace.GetSpace(ctx, id, nodecache.NewNodeCache(s.conf.GCTTL)) }, ocache.WithLogger(log.Sugar()), ocache.WithGCPeriod(time.Minute), diff --git a/pkg/acl/tree/changebuilder.go b/pkg/acl/tree/changebuilder.go index 1a2e207b..885dff34 100644 --- a/pkg/acl/tree/changebuilder.go +++ b/pkg/acl/tree/changebuilder.go @@ -32,6 +32,7 @@ type InitialContent struct { SpaceId string Seed []byte ChangeType string + Timestamp int64 } type ChangeBuilder interface { @@ -100,7 +101,7 @@ func (c *changeBuilder) SetRootRawChange(rawIdChange *treechangeproto.RawTreeCha func (c *changeBuilder) BuildInitialContent(payload InitialContent) (ch *Change, rawIdChange *treechangeproto.RawTreeChangeWithId, err error) { change := &treechangeproto.RootChange{ AclHeadId: payload.AclHeadId, - Timestamp: int64(time.Now().Nanosecond()), + Timestamp: payload.Timestamp, Identity: payload.Identity, ChangeType: payload.ChangeType, SpaceId: payload.SpaceId, diff --git a/pkg/acl/tree/objecttreefactory.go b/pkg/acl/tree/objecttreefactory.go index 3a65fde8..61631412 100644 --- a/pkg/acl/tree/objecttreefactory.go +++ b/pkg/acl/tree/objecttreefactory.go @@ -8,12 +8,13 @@ import ( "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" "github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "go.uber.org/zap" + "math/rand" + "time" ) type ObjectTreeCreatePayload struct { SignKey signingkey.PrivKey ChangeType string - Seed []byte SpaceId string Identity []byte } @@ -27,10 +28,31 @@ func BuildObjectTree(treeStorage storage.TreeStorage, aclList list.ACLList) (Obj return buildObjectTree(deps) } +func CreateDerivedObjectTree( + payload ObjectTreeCreatePayload, + aclList list.ACLList, + createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { + return createObjectTree(payload, 0, nil, aclList, createStorage) +} + func CreateObjectTree( payload ObjectTreeCreatePayload, aclList list.ACLList, createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { + bytes := make([]byte, 32) + _, err = rand.Read(bytes) + if err != nil { + return + } + return createObjectTree(payload, time.Now().UnixNano(), bytes, aclList, createStorage) +} + +func createObjectTree( + payload ObjectTreeCreatePayload, + timestamp int64, + seed []byte, + aclList list.ACLList, + createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { aclList.RLock() var ( deps = defaultObjectTreeDeps(nil, nil, aclList) @@ -46,8 +68,9 @@ func CreateObjectTree( Identity: payload.Identity, SigningKey: payload.SignKey, SpaceId: payload.SpaceId, - Seed: payload.Seed, ChangeType: payload.ChangeType, + Timestamp: timestamp, + Seed: seed, } _, raw, err := deps.changeBuilder.BuildInitialContent(cnt)