More fixes to synctree and objecttree

This commit is contained in:
mcrakhman 2022-12-15 21:53:58 +01:00
parent c064f89988
commit 8a6a5a6bc1
No known key found for this signature in database
GPG Key ID: DED12CFEF5B8396B
6 changed files with 14 additions and 6 deletions

View File

@ -129,9 +129,7 @@ func (d *diffSyncer) pingTreesInCache(ctx context.Context, trees []string) {
// it may be already there (i.e. loaded)
// and build func will not be called, thus we won't sync the tree
// therefore we just do it manually
syncTree.Lock()
syncTree.Ping()
syncTree.Unlock()
}
}

View File

@ -313,7 +313,9 @@ func (s *syncTree) checkAlive() (err error) {
}
func (s *syncTree) Ping() (err error) {
s.Lock()
headUpdate := s.syncClient.CreateHeadUpdate(s, nil)
s.Unlock()
return s.syncClient.BroadcastAsyncOrSendResponsible(headUpdate)
}

View File

@ -42,7 +42,7 @@ func (s *syncTreeHandler) HandleMessage(ctx context.Context, senderId string, ms
if err != nil {
return
}
s.handlerLock.Lock()
queue := s.handlerMap[senderId]
queueFull := len(queue) >= maxQueueSize

View File

@ -246,7 +246,7 @@ func (st *ACLState) applyChangeData(changeData *aclrecordproto.ACLData, hash uin
return
}
if !st.hasPermission(identity, aclrecordproto.ACLUserPermissions_Admin) {
if !st.HasPermission(identity, aclrecordproto.ACLUserPermissions_Admin) {
err = fmt.Errorf("user %s must have admin permissions", identity)
return
}
@ -413,7 +413,7 @@ func (st *ACLState) decryptReadKeyAndHash(msg []byte) (*symmetric.Key, uint64, e
return key, hasher.Sum64(), nil
}
func (st *ACLState) hasPermission(identity []byte, permission aclrecordproto.ACLUserPermissions) bool {
func (st *ACLState) HasPermission(identity []byte, permission aclrecordproto.ACLUserPermissions) bool {
state, exists := st.userStates[string(identity)]
if !exists {
return false

View File

@ -4,6 +4,7 @@ package tree
import (
"context"
"errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
list "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
@ -197,6 +198,13 @@ func (ot *objectTree) prepareBuilderContent(content SignableChangeContent) (cnt
readKey *symmetric.Key
readKeyHash uint64
)
canWrite := state.HasPermission(content.Identity, aclrecordproto.ACLUserPermissions_Writer) ||
state.HasPermission(content.Identity, aclrecordproto.ACLUserPermissions_Admin)
if !canWrite {
err = list.ErrInsufficientPermissions
return
}
if content.IsEncrypted {
readKeyHash = state.CurrentReadKeyHash()
readKey, err = state.CurrentReadKey()

View File

@ -58,7 +58,7 @@ func (s *service) registerScripts() {
}
for _, p := range addresses {
wg.Add(1)
createMany(p)
go createMany(p)
}
wg.Wait()
if mError.Err() != nil {