acl service wip

This commit is contained in:
Sergey Cherepanov 2022-10-31 11:25:58 +03:00 committed by Mikhail Iudin
parent 41a3f0502e
commit cb8a288773
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
10 changed files with 264 additions and 235 deletions

View File

@ -42,7 +42,7 @@ func (s *service) Init(a *app.App) (err error) {
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider) s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
s.spaceCache = ocache.New( s.spaceCache = ocache.New(
func(ctx context.Context, id string) (value ocache.Object, err error) { func(ctx context.Context, id string) (value ocache.Object, err error) {
return s.commonSpace.GetSpace(ctx, id) return s.commonSpace.NewSpace(ctx, id)
}, },
ocache.WithLogger(log.Sugar()), ocache.WithLogger(log.Sugar()),
ocache.WithGCPeriod(time.Minute), ocache.WithGCPeriod(time.Minute),

View File

@ -25,7 +25,7 @@ func New() Service {
type Service interface { type Service interface {
DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (string, error)
CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error) CreateSpace(ctx context.Context, payload SpaceCreatePayload) (string, error)
GetSpace(ctx context.Context, id string) (sp Space, err error) NewSpace(ctx context.Context, id string) (sp Space, err error)
app.Component app.Component
} }
@ -78,7 +78,7 @@ func (s *service) DeriveSpace(ctx context.Context, payload SpaceDerivePayload) (
return store.Id(), nil return store.Id(), nil
} }
func (s *service) GetSpace(ctx context.Context, id string) (Space, error) { func (s *service) NewSpace(ctx context.Context, id string) (Space, error) {
st, err := s.storageProvider.SpaceStorage(id) st, err := s.storageProvider.SpaceStorage(id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -97,8 +97,5 @@ func (s *service) GetSpace(ctx context.Context, id string) (Space, error) {
configuration: lastConfiguration, configuration: lastConfiguration,
storage: st, storage: st,
} }
if err := sp.Init(ctx); err != nil {
return nil, err
}
return sp, nil return sp, nil
} }

View File

@ -15,9 +15,10 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/treegetter"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
tree "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -58,6 +59,8 @@ func NewSpaceId(id string, repKey uint64) string {
type Space interface { type Space interface {
Id() string Id() string
Init(ctx context.Context) error
StoredIds() []string StoredIds() []string
Description() SpaceDescription Description() SpaceDescription
@ -206,7 +209,18 @@ func (s *space) Close() error {
s.isClosed.Store(true) s.isClosed.Store(true)
log.With(zap.String("id", s.id)).Debug("space closed") log.With(zap.String("id", s.id)).Debug("space closed")
}() }()
s.diffService.Close() var mError errs.Group
s.syncService.Close() if err := s.diffService.Close(); err != nil {
return s.storage.Close() mError.Add(err)
}
if err := s.syncService.Close(); err != nil {
mError.Add(err)
}
if err := s.aclList.Close(); err != nil {
mError.Add(err)
}
if err := s.storage.Close(); err != nil {
mError.Add(err)
}
return mError.Err()
} }

View File

@ -51,8 +51,10 @@ func (ACLUserPermissions) EnumDescriptor() ([]byte, []int) {
} }
type RawACLRecord struct { type RawACLRecord struct {
Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"`
AcceptorIdentity []byte `protobuf:"bytes,3,opt,name=acceptorIdentity,proto3" json:"acceptorIdentity,omitempty"`
AcceptorSignature []byte `protobuf:"bytes,4,opt,name=acceptorSignature,proto3" json:"acceptorSignature,omitempty"`
} }
func (m *RawACLRecord) Reset() { *m = RawACLRecord{} } func (m *RawACLRecord) Reset() { *m = RawACLRecord{} }
@ -102,11 +104,23 @@ func (m *RawACLRecord) GetSignature() []byte {
return nil return nil
} }
func (m *RawACLRecord) GetAcceptorIdentity() []byte {
if m != nil {
return m.AcceptorIdentity
}
return nil
}
func (m *RawACLRecord) GetAcceptorSignature() []byte {
if m != nil {
return m.AcceptorSignature
}
return nil
}
type RawACLRecordWithId struct { type RawACLRecordWithId struct {
Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
AcceptorIdentity []byte `protobuf:"bytes,3,opt,name=acceptorIdentity,proto3" json:"acceptorIdentity,omitempty"`
AcceptorSignature []byte `protobuf:"bytes,4,opt,name=acceptorSignature,proto3" json:"acceptorSignature,omitempty"`
} }
func (m *RawACLRecordWithId) Reset() { *m = RawACLRecordWithId{} } func (m *RawACLRecordWithId) Reset() { *m = RawACLRecordWithId{} }
@ -156,20 +170,6 @@ func (m *RawACLRecordWithId) GetId() string {
return "" return ""
} }
func (m *RawACLRecordWithId) GetAcceptorIdentity() []byte {
if m != nil {
return m.AcceptorIdentity
}
return nil
}
func (m *RawACLRecordWithId) GetAcceptorSignature() []byte {
if m != nil {
return m.AcceptorSignature
}
return nil
}
type ACLRecord struct { type ACLRecord struct {
PrevId string `protobuf:"bytes,1,opt,name=prevId,proto3" json:"prevId,omitempty"` PrevId string `protobuf:"bytes,1,opt,name=prevId,proto3" json:"prevId,omitempty"`
Identity []byte `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` Identity []byte `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"`
@ -1203,66 +1203,66 @@ func init() {
var fileDescriptor_14abe0d1b4206d54 = []byte{ var fileDescriptor_14abe0d1b4206d54 = []byte{
// 959 bytes of a gzipped FileDescriptorProto // 959 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcf, 0x6f, 0x1b, 0x45, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x4f, 0x6f, 0x1b, 0x45,
0x14, 0xf6, 0xac, 0x9d, 0x38, 0x7e, 0x76, 0x13, 0x67, 0x80, 0xd4, 0x8a, 0x8a, 0x15, 0xad, 0x38, 0x14, 0xf7, 0xac, 0x9d, 0x38, 0x7e, 0x76, 0x13, 0x67, 0x80, 0xd4, 0x8a, 0x8a, 0x15, 0xad, 0x38,
0x44, 0x55, 0x71, 0xc1, 0x20, 0xa5, 0xca, 0x05, 0xb9, 0xa6, 0x95, 0xdd, 0x04, 0xa9, 0x9a, 0x00, 0x44, 0x55, 0x71, 0xc1, 0x20, 0xa5, 0xca, 0x01, 0xe4, 0x9a, 0x22, 0xbb, 0x09, 0x52, 0x35, 0x01,
0x45, 0xbd, 0x4d, 0x77, 0x47, 0xc9, 0xa8, 0xf6, 0xee, 0x6a, 0x66, 0x6c, 0xe4, 0x23, 0x67, 0x2e, 0x8a, 0x7a, 0x9b, 0xee, 0x8e, 0x92, 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x57, 0x45, 0xc1, 0x2d, 0xd8, 0x18, 0xf9, 0x73, 0x1e, 0x74, 0x6b, 0x18, 0x60,
0xf3, 0x85, 0xe0, 0x8a, 0x89, 0x2e, 0xd2, 0xcf, 0xba, 0x42, 0x4c, 0x74, 0x9d, 0xc7, 0x9f, 0xfc, 0xf3, 0xb9, 0xe0, 0x8a, 0x89, 0x2e, 0xd2, 0x6b, 0x5d, 0x21, 0x26, 0xba, 0xce, 0xe3, 0x8f, 0xfe,
0x71, 0xd9, 0x47, 0x6f, 0x2e, 0xfb, 0xe8, 0xef, 0xcb, 0x3e, 0xfa, 0xe9, 0xaa, 0x5f, 0x7b, 0x73, 0xb8, 0xec, 0xa3, 0xd7, 0x97, 0x7d, 0xf4, 0xf7, 0x65, 0x1f, 0xfd, 0x74, 0xd5, 0xaf, 0xbd, 0xbe,
0xd5, 0xaf, 0xfd, 0x75, 0xd5, 0xaf, 0xbd, 0xdc, 0x5b, 0xff, 0xb9, 0xfc, 0x6a, 0xd3, 0xfc, 0x7c, 0xea, 0xd7, 0xfe, 0xba, 0xea, 0xd7, 0x5e, 0xec, 0xad, 0xff, 0x5c, 0x7e, 0xb9, 0x69, 0xfe, 0x7c,
0xf6, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x04, 0x6d, 0x2c, 0x1d, 0x4f, 0x0b, 0x00, 0x00, 0xf2, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x9d, 0x20, 0x5d, 0x4f, 0x0b, 0x00, 0x00,
} }
func (m *RawACLRecord) Marshal() (dAtA []byte, err error) { func (m *RawACLRecord) Marshal() (dAtA []byte, err error) {
@ -1285,6 +1285,20 @@ func (m *RawACLRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i _ = i
var l int var l int
_ = l _ = l
if len(m.AcceptorSignature) > 0 {
i -= len(m.AcceptorSignature)
copy(dAtA[i:], m.AcceptorSignature)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptorSignature)))
i--
dAtA[i] = 0x22
}
if len(m.AcceptorIdentity) > 0 {
i -= len(m.AcceptorIdentity)
copy(dAtA[i:], m.AcceptorIdentity)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptorIdentity)))
i--
dAtA[i] = 0x1a
}
if len(m.Signature) > 0 { if len(m.Signature) > 0 {
i -= len(m.Signature) i -= len(m.Signature)
copy(dAtA[i:], m.Signature) copy(dAtA[i:], m.Signature)
@ -1322,20 +1336,6 @@ func (m *RawACLRecordWithId) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i _ = i
var l int var l int
_ = l _ = l
if len(m.AcceptorSignature) > 0 {
i -= len(m.AcceptorSignature)
copy(dAtA[i:], m.AcceptorSignature)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptorSignature)))
i--
dAtA[i] = 0x22
}
if len(m.AcceptorIdentity) > 0 {
i -= len(m.AcceptorIdentity)
copy(dAtA[i:], m.AcceptorIdentity)
i = encodeVarintAclrecord(dAtA, i, uint64(len(m.AcceptorIdentity)))
i--
dAtA[i] = 0x1a
}
if len(m.Id) > 0 { if len(m.Id) > 0 {
i -= len(m.Id) i -= len(m.Id)
copy(dAtA[i:], m.Id) copy(dAtA[i:], m.Id)
@ -2214,6 +2214,14 @@ func (m *RawACLRecord) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovAclrecord(uint64(l)) n += 1 + l + sovAclrecord(uint64(l))
} }
l = len(m.AcceptorIdentity)
if l > 0 {
n += 1 + l + sovAclrecord(uint64(l))
}
l = len(m.AcceptorSignature)
if l > 0 {
n += 1 + l + sovAclrecord(uint64(l))
}
return n return n
} }
@ -2231,14 +2239,6 @@ func (m *RawACLRecordWithId) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovAclrecord(uint64(l)) n += 1 + l + sovAclrecord(uint64(l))
} }
l = len(m.AcceptorIdentity)
if l > 0 {
n += 1 + l + sovAclrecord(uint64(l))
}
l = len(m.AcceptorSignature)
if l > 0 {
n += 1 + l + sovAclrecord(uint64(l))
}
return n return n
} }
@ -2744,6 +2744,74 @@ func (m *RawACLRecord) Unmarshal(dAtA []byte) error {
m.Signature = []byte{} m.Signature = []byte{}
} }
iNdEx = postIndex iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptorIdentity", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAclrecord
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthAclrecord
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthAclrecord
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.AcceptorIdentity = append(m.AcceptorIdentity[:0], dAtA[iNdEx:postIndex]...)
if m.AcceptorIdentity == nil {
m.AcceptorIdentity = []byte{}
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptorSignature", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAclrecord
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthAclrecord
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthAclrecord
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.AcceptorSignature = append(m.AcceptorSignature[:0], dAtA[iNdEx:postIndex]...)
if m.AcceptorSignature == nil {
m.AcceptorSignature = []byte{}
}
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipAclrecord(dAtA[iNdEx:]) skippy, err := skipAclrecord(dAtA[iNdEx:])
@ -2860,74 +2928,6 @@ func (m *RawACLRecordWithId) Unmarshal(dAtA []byte) error {
} }
m.Id = string(dAtA[iNdEx:postIndex]) m.Id = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptorIdentity", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAclrecord
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthAclrecord
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthAclrecord
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.AcceptorIdentity = append(m.AcceptorIdentity[:0], dAtA[iNdEx:postIndex]...)
if m.AcceptorIdentity == nil {
m.AcceptorIdentity = []byte{}
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field AcceptorSignature", wireType)
}
var byteLen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAclrecord
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
byteLen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if byteLen < 0 {
return ErrInvalidLengthAclrecord
}
postIndex := iNdEx + byteLen
if postIndex < 0 {
return ErrInvalidLengthAclrecord
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.AcceptorSignature = append(m.AcceptorSignature[:0], dAtA[iNdEx:postIndex]...)
if m.AcceptorSignature == nil {
m.AcceptorSignature = []byte{}
}
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipAclrecord(dAtA[iNdEx:]) skippy, err := skipAclrecord(dAtA[iNdEx:])

View File

@ -5,13 +5,13 @@ option go_package = "pkg/acl/aclrecordproto";
message RawACLRecord { message RawACLRecord {
bytes payload = 1; bytes payload = 1;
bytes signature = 2; bytes signature = 2;
bytes acceptorIdentity = 3;
bytes acceptorSignature = 4;
} }
message RawACLRecordWithId { message RawACLRecordWithId {
bytes payload = 1; bytes payload = 1;
string id = 2; string id = 2;
bytes acceptorIdentity = 3;
bytes acceptorSignature = 4;
} }
message ACLRecord { message ACLRecord {

View File

@ -3,14 +3,14 @@ package tree
import ( import (
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
list2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
) )
type ObjectTreeValidator interface { type ObjectTreeValidator interface {
// ValidateFullTree should always be entered while holding a read lock on ACLList // ValidateFullTree should always be entered while holding a read lock on ACLList
ValidateFullTree(tree *Tree, aclList list2.ACLList) error ValidateFullTree(tree *Tree, aclList list.ACLList) error
// ValidateNewChanges should always be entered while holding a read lock on ACLList // ValidateNewChanges should always be entered while holding a read lock on ACLList
ValidateNewChanges(tree *Tree, aclList list2.ACLList, newChanges []*Change) error ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) error
} }
type objectTreeValidator struct{} type objectTreeValidator struct{}
@ -19,7 +19,7 @@ func newTreeValidator() ObjectTreeValidator {
return &objectTreeValidator{} return &objectTreeValidator{}
} }
func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list2.ACLList) (err error) { func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list.ACLList) (err error) {
tree.Iterate(tree.RootId(), func(c *Change) (isContinue bool) { tree.Iterate(tree.RootId(), func(c *Change) (isContinue bool) {
err = v.validateChange(tree, aclList, c) err = v.validateChange(tree, aclList, c)
return err == nil return err == nil
@ -27,7 +27,7 @@ func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list2.ACLList
return err return err
} }
func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list2.ACLList, newChanges []*Change) (err error) { func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) (err error) {
for _, c := range newChanges { for _, c := range newChanges {
err = v.validateChange(tree, aclList, c) err = v.validateChange(tree, aclList, c)
if err != nil { if err != nil {
@ -37,9 +37,9 @@ func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list2.ACLLi
return return
} }
func (v *objectTreeValidator) validateChange(tree *Tree, aclList list2.ACLList, c *Change) (err error) { func (v *objectTreeValidator) validateChange(tree *Tree, aclList list.ACLList, c *Change) (err error) {
var ( var (
perm list2.UserPermissionPair perm list.UserPermissionPair
state = aclList.ACLState() state = aclList.ACLState()
) )
// checking if the user could write // checking if the user could write
@ -49,7 +49,7 @@ func (v *objectTreeValidator) validateChange(tree *Tree, aclList list2.ACLList,
} }
if perm.Permission != aclrecordproto.ACLUserPermissions_Writer && perm.Permission != aclrecordproto.ACLUserPermissions_Admin { if perm.Permission != aclrecordproto.ACLUserPermissions_Writer && perm.Permission != aclrecordproto.ACLUserPermissions_Admin {
err = list2.ErrInsufficientPermissions err = list.ErrInsufficientPermissions
return return
} }

View File

@ -44,11 +44,6 @@ func (s *service) CreateLog(ctx context.Context, aclId string, rec *aclrecordpro
if err != nil { if err != nil {
return return
} }
acc := s.account.Account()
rec.AcceptorIdentity = acc.Identity
if rec.AcceptorSignature, err = acc.SignKey.Sign(rec.Payload); err != nil {
return
}
recPayload, err := rec.Marshal() recPayload, err := rec.Marshal()
if err != nil { if err != nil {
return return
@ -74,11 +69,7 @@ func (s *service) AddRecord(ctx context.Context, aclId string, rec *aclrecordpro
if err != nil { if err != nil {
return return
} }
acc := s.account.Account()
rec.AcceptorIdentity = acc.Identity
if rec.AcceptorSignature, err = acc.SignKey.Sign(rec.Payload); err != nil {
return
}
recPayload, err := rec.Marshal() recPayload, err := rec.Marshal()
if err != nil { if err != nil {
return return

View File

@ -2,43 +2,42 @@ package nodespace
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" "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/pkg/acl/aclrecordproto"
) )
type rpcHandler struct { type rpcHandler struct {
s *service s *service
} }
func (r *rpcHandler) PullSpace(ctx context.Context, request *spacesyncproto.PullSpaceRequest) (resp *spacesyncproto.PullSpaceResponse, err error) { func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpaceRequest) (resp *spacesyncproto.PushSpaceResponse, err error) {
sp, err := r.s.GetSpace(ctx, request.Id) _, err = r.s.GetSpace(ctx, req.SpaceHeader.Id)
if err == nil {
err = spacesyncproto.ErrSpaceExists
return
}
if err != storage.ErrSpaceStorageMissing {
err = spacesyncproto.ErrUnexpected
return
}
payload := storage.SpaceStorageCreatePayload{
RecWithId: &aclrecordproto.RawACLRecordWithId{
Payload: req.AclPayload,
Id: req.AclPayloadId,
},
SpaceHeaderWithId: req.SpaceHeader,
}
st, err := r.s.spaceStorageProvider.CreateSpaceStorage(payload)
if err != nil { if err != nil {
if err != spacesyncproto.ErrSpaceMissing { err = spacesyncproto.ErrUnexpected
err = spacesyncproto.ErrUnexpected if err == storage.ErrSpaceStorageExists {
err = spacesyncproto.ErrSpaceExists
} }
return return
} }
err = st.Close()
description := sp.Description()
resp = &spacesyncproto.PullSpaceResponse{
SpaceHeader: description.SpaceHeader,
AclPayload: description.AclPayload,
AclPayloadId: description.AclId,
}
return
}
func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpaceRequest) (resp *spacesyncproto.PushSpaceResponse, err error) {
description := commonspace.SpaceDescription{
SpaceHeader: req.SpaceHeader,
AclId: req.AclPayloadId,
AclPayload: req.AclPayload,
}
err = r.s.AddSpace(ctx, description)
if err != nil {
return
}
resp = &spacesyncproto.PushSpaceResponse{}
return return
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" "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/storage"
config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache"
"time" "time"
@ -22,26 +22,23 @@ func New() Service {
} }
type Service interface { type Service interface {
AddSpace(ctx context.Context, description commonspace.SpaceDescription) (err error)
GetSpace(ctx context.Context, id string) (commonspace.Space, error) GetSpace(ctx context.Context, id string) (commonspace.Space, error)
app.ComponentRunnable app.ComponentRunnable
} }
type service struct { type service struct {
conf config2.Space conf config.Space
spaceCache ocache.OCache spaceCache ocache.OCache
commonSpace commonspace.Service commonSpace commonspace.Service
spaceStorageProvider storage.SpaceStorageProvider spaceStorageProvider storage.SpaceStorageProvider
} }
func (s *service) Init(a *app.App) (err error) { func (s *service) Init(a *app.App) (err error) {
s.conf = a.MustComponent(config2.CName).(*config2.Config).Space s.conf = a.MustComponent(config.CName).(*config.Config).Space
s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service) s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service)
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider) s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
s.spaceCache = ocache.New( s.spaceCache = ocache.New(
func(ctx context.Context, id string) (value ocache.Object, err error) { s.loadSpace,
return s.commonSpace.GetSpace(ctx, id)
},
ocache.WithLogger(log.Sugar()), ocache.WithLogger(log.Sugar()),
ocache.WithGCPeriod(time.Minute), ocache.WithGCPeriod(time.Minute),
ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second), ocache.WithTTL(time.Duration(s.conf.GCTTL)*time.Second),
@ -54,10 +51,6 @@ func (s *service) Name() (name string) {
} }
func (s *service) Run(ctx context.Context) (err error) { func (s *service) Run(ctx context.Context) (err error) {
go func() {
time.Sleep(time.Second * 5)
_, _ = s.GetSpace(ctx, "testDSpace")
}()
return return
} }
@ -69,8 +62,19 @@ func (s *service) GetSpace(ctx context.Context, id string) (commonspace.Space, e
return v.(commonspace.Space), nil return v.(commonspace.Space), nil
} }
func (s *service) AddSpace(ctx context.Context, description commonspace.SpaceDescription) (err error) { func (s *service) loadSpace(ctx context.Context, id string) (value ocache.Object, err error) {
return s.commonSpace.AddSpace(ctx, description) cc, err := s.commonSpace.NewSpace(ctx, id)
if err != nil {
return
}
ns, err := newNodeSpace(cc)
if err != nil {
return
}
if err = ns.Init(ctx); err != nil {
return
}
return ns, nil
} }
func (s *service) Close(ctx context.Context) (err error) { func (s *service) Close(ctx context.Context) (err error) {

24
node/nodespace/space.go Normal file
View File

@ -0,0 +1,24 @@
package nodespace
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
)
func newNodeSpace(cc commonspace.Space) (commonspace.Space, error) {
return &nodeSpace{cc}, nil
}
type nodeSpace struct {
commonspace.Space
}
func (s *nodeSpace) Init(ctx context.Context) (err error) {
// try to push acl to consensus node
//
return s.Space.Init(ctx)
}
func (s *nodeSpace) Close() (err error) {
return s.Space.Close()
}