move pkgs

This commit is contained in:
Sergey Cherepanov 2022-10-17 14:11:55 +03:00 committed by Mikhail Iudin
parent 5689863046
commit daa9bb1df0
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
152 changed files with 569 additions and 1771 deletions

View File

@ -34,9 +34,9 @@ proto:
build: build:
@$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/app)) @$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/common/app))
go build -v -o bin/anytype-node -ldflags "$(FLAGS)" cmd/node/node.go go build -v -o bin/anytype-node -ldflags "$(FLAGS)" cmd/node/node.go
build-consensus: build-consensus:
@$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/app)) @$(eval FLAGS := $$(shell govvv -flags -pkg github.com/anytypeio/go-anytype-infrastructure-experiments/common/app))
go build -v -o bin/consensus-node -ldflags "$(FLAGS)" github.com/anytypeio/go-anytype-infrastructure-experiments/cmd/consensusnode go build -v -o bin/consensus-node -ldflags "$(FLAGS)" github.com/anytypeio/go-anytype-infrastructure-experiments/cmd/consensusnode

View File

@ -1,13 +1,13 @@
package account package account
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/account" commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
) )
type service struct { type service struct {

View File

@ -2,8 +2,8 @@ package badgerprovider
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
) )

View File

@ -3,11 +3,11 @@ package clientcache
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace" "github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache"
"time" "time"
) )

View File

@ -2,14 +2,14 @@ package clientspace
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"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/net/rpc/server" "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/common/pkg/ocache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache"
"time" "time"
) )
@ -29,14 +29,14 @@ type Service interface {
} }
type service struct { type service struct {
conf config.Space conf config2.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(config.CName).(*config.Config).Space s.conf = a.MustComponent(config2.CName).(*config2.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(

View File

@ -1,6 +1,6 @@
package document package document
import "github.com/anytypeio/go-anytype-infrastructure-experiments/app" import "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
type Service interface { type Service interface {
app.Component app.Component

View File

@ -1,7 +1,7 @@
package storage package storage
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
) )
type aclKeys struct { type aclKeys struct {

View File

@ -3,8 +3,8 @@ package storage
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
) )

View File

@ -3,7 +3,7 @@ package storage
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
spacestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" spacestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
"sync" "sync"
) )
@ -12,7 +12,7 @@ type spaceStorage struct {
spaceId string spaceId string
objDb *badger.DB objDb *badger.DB
keys spaceKeys keys spaceKeys
aclStorage storage.ListStorage aclStorage storage2.ListStorage
header *spacesyncproto.RawSpaceHeaderWithId header *spacesyncproto.RawSpaceHeaderWithId
mx sync.Mutex mx sync.Mutex
} }
@ -81,11 +81,11 @@ func (s *spaceStorage) ID() (string, error) {
return s.spaceId, nil return s.spaceId, nil
} }
func (s *spaceStorage) TreeStorage(id string) (storage.TreeStorage, error) { func (s *spaceStorage) TreeStorage(id string) (storage2.TreeStorage, error) {
return newTreeStorage(s.objDb, s.spaceId, id) return newTreeStorage(s.objDb, s.spaceId, id)
} }
func (s *spaceStorage) CreateTreeStorage(payload storage.TreeStorageCreatePayload) (ts storage.TreeStorage, err error) { func (s *spaceStorage) CreateTreeStorage(payload storage2.TreeStorageCreatePayload) (ts storage2.TreeStorage, err error) {
// we have mutex here, so we prevent overwriting the heads of a tree on concurrent creation // we have mutex here, so we prevent overwriting the heads of a tree on concurrent creation
s.mx.Lock() s.mx.Lock()
defer s.mx.Unlock() defer s.mx.Unlock()
@ -93,7 +93,7 @@ func (s *spaceStorage) CreateTreeStorage(payload storage.TreeStorageCreatePayloa
return createTreeStorage(s.objDb, s.spaceId, payload) return createTreeStorage(s.objDb, s.spaceId, payload)
} }
func (s *spaceStorage) ACLStorage() (storage.ListStorage, error) { func (s *spaceStorage) ACLStorage() (storage2.ListStorage, error) {
return s.aclStorage, nil return s.aclStorage, nil
} }

View File

@ -1,7 +1,7 @@
package storage package storage
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/badgerprovider" "github.com/anytypeio/go-anytype-infrastructure-experiments/client/badgerprovider"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"

View File

@ -2,8 +2,8 @@ package storage
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/dgraph-io/badger/v3" "github.com/dgraph-io/badger/v3"
) )
@ -14,7 +14,7 @@ type treeStorage struct {
root *treechangeproto.RawTreeChangeWithId root *treechangeproto.RawTreeChangeWithId
} }
func newTreeStorage(db *badger.DB, spaceId, treeId string) (ts storage.TreeStorage, err error) { func newTreeStorage(db *badger.DB, spaceId, treeId string) (ts storage2.TreeStorage, err error) {
keys := newTreeKeys(spaceId, treeId) keys := newTreeKeys(spaceId, treeId)
err = db.View(func(txn *badger.Txn) error { err = db.View(func(txn *badger.Txn) error {
_, err := txn.Get(keys.RootIdKey()) _, err := txn.Get(keys.RootIdKey())
@ -43,14 +43,14 @@ func newTreeStorage(db *badger.DB, spaceId, treeId string) (ts storage.TreeStora
return return
} }
func createTreeStorage(db *badger.DB, spaceId string, payload storage.TreeStorageCreatePayload) (ts storage.TreeStorage, err error) { func createTreeStorage(db *badger.DB, spaceId string, payload storage2.TreeStorageCreatePayload) (ts storage2.TreeStorage, err error) {
keys := newTreeKeys(spaceId, payload.TreeId) keys := newTreeKeys(spaceId, payload.TreeId)
if hasDB(db, keys.RootIdKey()) { if hasDB(db, keys.RootIdKey()) {
err = storage.ErrTreeExists err = storage2.ErrTreeExists
return return
} }
err = db.Update(func(txn *badger.Txn) error { err = db.Update(func(txn *badger.Txn) error {
heads := storage.CreateHeadsPayload(payload.Heads) heads := storage2.CreateHeadsPayload(payload.Heads)
for _, ch := range payload.Changes { for _, ch := range payload.Changes {
err = txn.Set(keys.RawChangeKey(ch.Id), ch.GetRawChange()) err = txn.Set(keys.RawChangeKey(ch.Id), ch.GetRawChange())
@ -97,16 +97,16 @@ func (t *treeStorage) Heads() (heads []string, err error) {
headsBytes, err := getDB(t.db, t.keys.HeadsKey()) headsBytes, err := getDB(t.db, t.keys.HeadsKey())
if err != nil { if err != nil {
if err == badger.ErrKeyNotFound { if err == badger.ErrKeyNotFound {
err = storage.ErrUnknownTreeId err = storage2.ErrUnknownTreeId
} }
return return
} }
heads = storage.ParseHeads(headsBytes) heads = storage2.ParseHeads(headsBytes)
return return
} }
func (t *treeStorage) SetHeads(heads []string) (err error) { func (t *treeStorage) SetHeads(heads []string) (err error) {
payload := storage.CreateHeadsPayload(heads) payload := storage2.CreateHeadsPayload(heads)
return putDB(t.db, t.keys.HeadsKey(), payload) return putDB(t.db, t.keys.HeadsKey(), payload)
} }
@ -118,7 +118,7 @@ func (t *treeStorage) GetRawChange(ctx context.Context, id string) (raw *treecha
res, err := getDB(t.db, t.keys.RawChangeKey(id)) res, err := getDB(t.db, t.keys.RawChangeKey(id))
if err != nil { if err != nil {
if err == badger.ErrKeyNotFound { if err == badger.ErrKeyNotFound {
err = storage.ErrUnknownTreeId err = storage2.ErrUnknownTreeId
} }
return return
} }

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric"
"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/net/secure" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"

View File

@ -5,13 +5,13 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"
"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/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusclient" "github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusclient"
"github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusproto/consensuserr" "github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/consensusproto/consensuserr"

View File

@ -4,15 +4,15 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"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/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool"
"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/net/secure" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"
"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/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache" "github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache"

View File

@ -3,12 +3,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
"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/peer"
cconfig "github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/config" cconfig "github.com/anytypeio/go-anytype-infrastructure-experiments/consensus/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/peer"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"io/ioutil" "io/ioutil"
"os" "os"
@ -42,8 +42,8 @@ func main() {
} }
flag.Parse() flag.Parse()
var configs []config.Config var configs []config2.Config
var nodes []config.Node var nodes []config2.Node
for _, n := range nodesMap.Nodes { for _, n := range nodesMap.Nodes {
cfg, err := genNodeConfig(n.Addresses, n.APIPort) cfg, err := genNodeConfig(n.Addresses, n.APIPort)
if err != nil { if err != nil {
@ -51,7 +51,7 @@ func main() {
} }
configs = append(configs, cfg) configs = append(configs, cfg)
node := config.Node{ node := config2.Node{
PeerId: cfg.Account.PeerId, PeerId: cfg.Account.PeerId,
Address: cfg.GrpcServer.ListenAddrs[0], Address: cfg.GrpcServer.ListenAddrs[0],
SigningKey: cfg.Account.SigningKey, SigningKey: cfg.Account.SigningKey,
@ -68,7 +68,7 @@ func main() {
} }
consConfigs = append(consConfigs, cfg) consConfigs = append(consConfigs, cfg)
node := config.Node{ node := config2.Node{
PeerId: cfg.Account.PeerId, PeerId: cfg.Account.PeerId,
Address: cfg.GrpcServer.ListenAddrs[0], Address: cfg.GrpcServer.ListenAddrs[0],
SigningKey: cfg.Account.SigningKey, SigningKey: cfg.Account.SigningKey,
@ -124,48 +124,48 @@ func main() {
} }
} }
func genNodeConfig(addresses []string, apiPort string) (config.Config, error) { func genNodeConfig(addresses []string, apiPort string) (config2.Config, error) {
encKey, _, err := encryptionkey.GenerateRandomRSAKeyPair(2048) encKey, _, err := encryptionkey.GenerateRandomRSAKeyPair(2048)
if err != nil { if err != nil {
return config.Config{}, err return config2.Config{}, err
} }
signKey, _, err := signingkey.GenerateRandomEd25519KeyPair() signKey, _, err := signingkey.GenerateRandomEd25519KeyPair()
if err != nil { if err != nil {
return config.Config{}, err return config2.Config{}, err
} }
encEncKey, err := keys.EncodeKeyToString(encKey) encEncKey, err := keys.EncodeKeyToString(encKey)
if err != nil { if err != nil {
return config.Config{}, err return config2.Config{}, err
} }
encSignKey, err := keys.EncodeKeyToString(signKey) encSignKey, err := keys.EncodeKeyToString(signKey)
if err != nil { if err != nil {
return config.Config{}, err return config2.Config{}, err
} }
peerID, err := peer.IDFromSigningPubKey(signKey.GetPublic()) peerID, err := peer.IDFromSigningPubKey(signKey.GetPublic())
if err != nil { if err != nil {
return config.Config{}, err return config2.Config{}, err
} }
return config.Config{ return config2.Config{
Anytype: config.Anytype{SwarmKey: "/key/swarm/psk/1.0.0/base16/209992e611c27d5dce8fbd2e7389f6b51da9bee980992ef60739460b536139ec"}, Anytype: config2.Anytype{SwarmKey: "/key/swarm/psk/1.0.0/base16/209992e611c27d5dce8fbd2e7389f6b51da9bee980992ef60739460b536139ec"},
GrpcServer: config.GrpcServer{ GrpcServer: config2.GrpcServer{
ListenAddrs: addresses, ListenAddrs: addresses,
TLS: false, TLS: false,
}, },
Storage: config.Storage{Path: "db"}, Storage: config2.Storage{Path: "db"},
Account: config.Account{ Account: config2.Account{
PeerId: peerID.String(), PeerId: peerID.String(),
SigningKey: encSignKey, SigningKey: encSignKey,
EncryptionKey: encEncKey, EncryptionKey: encEncKey,
}, },
APIServer: config.APIServer{ APIServer: config2.APIServer{
Port: apiPort, Port: apiPort,
}, },
Space: config.Space{ Space: config2.Space{
GCTTL: 60, GCTTL: 60,
SyncPeriod: 10, SyncPeriod: 10,
}, },
@ -199,11 +199,11 @@ func genConsensusConfig(addresses []string) (cconfig.Config, error) {
} }
return cconfig.Config{ return cconfig.Config{
GrpcServer: config.GrpcServer{ GrpcServer: config2.GrpcServer{
ListenAddrs: addresses, ListenAddrs: addresses,
TLS: false, TLS: false,
}, },
Account: config.Account{ Account: config2.Account{
PeerId: peerID.String(), PeerId: peerID.String(),
SigningKey: encSignKey, SigningKey: encSignKey,
EncryptionKey: encEncKey, EncryptionKey: encEncKey,

View File

@ -1,9 +1,9 @@
package account package account
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/account"
) )
const CName = "common.account" const CName = "common.account"

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"go.uber.org/zap" "go.uber.org/zap"
"os" "os"
"runtime" "runtime"

View File

@ -8,7 +8,7 @@ import (
context "context" context "context"
reflect "reflect" reflect "reflect"
app "github.com/anytypeio/go-anytype-infrastructure-experiments/app" app "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
cache "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" cache "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )

View File

@ -4,9 +4,9 @@ package cache
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
) )
const CName = "commonspace.cache" const CName = "commonspace.cache"

View File

@ -8,7 +8,7 @@ import (
"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"
"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/pkg/ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff"
"go.uber.org/zap" "go.uber.org/zap"
"strings" "strings"
) )

View File

@ -1,12 +1,12 @@
package diffservice package diffservice
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice/mock_diffservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice/mock_diffservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage/mock_storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage/mock_storage"
mock_storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage/mock_storage" mock_storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage/mock_storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff/mock_ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff/mock_ldiff"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"testing" "testing"
) )

View File

@ -9,7 +9,7 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpcerr" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpcerr"
"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/pkg/ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff"
"go.uber.org/zap" "go.uber.org/zap"
"time" "time"
) )

View File

@ -3,7 +3,7 @@ package diffservice
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache/mock_cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache/mock_cache"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/remotediff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/remotediff"
@ -12,9 +12,9 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage/mock_storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage/mock_storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf/mock_nodeconf" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf/mock_nodeconf"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
mock_aclstorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage/mock_storage" mock_aclstorage "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage/mock_storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff/mock_ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff/mock_ldiff"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"storj.io/drpc" "storj.io/drpc"

View File

@ -1,7 +1,7 @@
package diffservice package diffservice
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice/mock_diffservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice/mock_diffservice"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"testing" "testing"

View File

@ -3,9 +3,9 @@ package commonspace
import ( import (
"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"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" aclrecordproto2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/cid"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"hash/fnv" "hash/fnv"
"math/rand" "math/rand"
"time" "time"
@ -68,7 +68,7 @@ func storagePayloadForSpaceCreate(payload SpaceCreatePayload) (storagePayload st
} }
// preparing acl // preparing acl
aclRoot := &aclrecordproto.ACLRoot{ aclRoot := &aclrecordproto2.ACLRoot{
Identity: identity, Identity: identity,
EncryptionKey: encPubKey, EncryptionKey: encPubKey,
SpaceId: spaceId, SpaceId: spaceId,
@ -144,7 +144,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload st
} }
// deriving and encrypting read key // deriving and encrypting read key
readKey, err := aclrecordproto.ACLReadKeyDerive(signPrivKey, encPrivKey) readKey, err := aclrecordproto2.ACLReadKeyDerive(signPrivKey, encPrivKey)
if err != nil { if err != nil {
return return
} }
@ -160,7 +160,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload st
} }
// preparing acl // preparing acl
aclRoot := &aclrecordproto.ACLRoot{ aclRoot := &aclrecordproto2.ACLRoot{
Identity: identity, Identity: identity,
EncryptionKey: encPubKey, EncryptionKey: encPubKey,
SpaceId: spaceId, SpaceId: spaceId,
@ -182,7 +182,7 @@ func storagePayloadForSpaceDerive(payload SpaceDerivePayload) (storagePayload st
return return
} }
func marshalACLRoot(aclRoot *aclrecordproto.ACLRoot, key signingkey.PrivKey) (rawWithId *aclrecordproto.RawACLRecordWithId, err error) { func marshalACLRoot(aclRoot *aclrecordproto2.ACLRoot, key signingkey.PrivKey) (rawWithId *aclrecordproto2.RawACLRecordWithId, err error) {
marshalledRoot, err := aclRoot.Marshal() marshalledRoot, err := aclRoot.Marshal()
if err != nil { if err != nil {
return return
@ -191,7 +191,7 @@ func marshalACLRoot(aclRoot *aclrecordproto.ACLRoot, key signingkey.PrivKey) (ra
if err != nil { if err != nil {
return return
} }
raw := &aclrecordproto.RawACLRecord{ raw := &aclrecordproto2.RawACLRecord{
Payload: marshalledRoot, Payload: marshalledRoot,
Signature: signature, Signature: signature,
} }
@ -203,7 +203,7 @@ func marshalACLRoot(aclRoot *aclrecordproto.ACLRoot, key signingkey.PrivKey) (ra
if err != nil { if err != nil {
return return
} }
rawWithId = &aclrecordproto.RawACLRecordWithId{ rawWithId = &aclrecordproto2.RawACLRecordWithId{
Payload: marshalledRaw, Payload: marshalledRaw,
Id: aclHeadId, Id: aclHeadId,
} }

View File

@ -3,7 +3,7 @@ package remotediff
import ( import (
"context" "context"
"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/pkg/ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff"
) )
type Client interface { type Client interface {

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"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/pkg/ldiff" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ldiff"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"

View File

@ -2,15 +2,15 @@ package commonspace
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "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/diffservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" "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/commonspace/syncservice"
config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/pool"
"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/config"
) )
const CName = "common.commonspace" const CName = "common.commonspace"
@ -29,7 +29,7 @@ type Service interface {
} }
type service struct { type service struct {
config config.Space config config2.Space
configurationService nodeconf.Service configurationService nodeconf.Service
storageProvider storage.SpaceStorageProvider storageProvider storage.SpaceStorageProvider
cache cache.TreeCache cache cache.TreeCache
@ -37,7 +37,7 @@ type service struct {
} }
func (s *service) Init(a *app.App) (err error) { func (s *service) Init(a *app.App) (err error) {
s.config = a.MustComponent(config.CName).(*config.Config).Space s.config = a.MustComponent(config2.CName).(*config2.Config).Space
s.storageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider) s.storageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service) s.configurationService = a.MustComponent(nodeconf.CName).(nodeconf.Service)
s.cache = a.MustComponent(cache.CName).(cache.TreeCache) s.cache = a.MustComponent(cache.CName).(cache.TreeCache)

View File

@ -10,11 +10,11 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
treestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" tree2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"sync" "sync"
) )
@ -47,9 +47,9 @@ type Space interface {
SpaceSyncRpc() RpcHandler SpaceSyncRpc() RpcHandler
DeriveTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree.ObjectTree, error) DeriveTree(ctx context.Context, payload tree2.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree2.ObjectTree, error)
CreateTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree.ObjectTree, error) CreateTree(ctx context.Context, payload tree2.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree2.ObjectTree, error)
BuildTree(ctx context.Context, id string, listener updatelistener.UpdateListener) (tree.ObjectTree, error) BuildTree(ctx context.Context, id string, listener updatelistener.UpdateListener) (tree2.ObjectTree, error)
Close() error Close() error
} }
@ -94,15 +94,15 @@ func (s *space) DiffService() diffservice.DiffService {
return s.diffService return s.diffService
} }
func (s *space) DeriveTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree.ObjectTree, error) { func (s *space) DeriveTree(ctx context.Context, payload tree2.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree2.ObjectTree, error) {
return synctree.DeriveSyncTree(ctx, payload, s.syncService.SyncClient(), listener, s.aclList, s.storage.CreateTreeStorage) return synctree.DeriveSyncTree(ctx, payload, s.syncService.SyncClient(), listener, s.aclList, s.storage.CreateTreeStorage)
} }
func (s *space) CreateTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree.ObjectTree, error) { func (s *space) CreateTree(ctx context.Context, payload tree2.ObjectTreeCreatePayload, listener updatelistener.UpdateListener) (tree2.ObjectTree, error) {
return synctree.CreateSyncTree(ctx, payload, s.syncService.SyncClient(), listener, s.aclList, s.storage.CreateTreeStorage) return synctree.CreateSyncTree(ctx, payload, s.syncService.SyncClient(), listener, s.aclList, s.storage.CreateTreeStorage)
} }
func (s *space) BuildTree(ctx context.Context, id string, listener updatelistener.UpdateListener) (t tree.ObjectTree, err error) { func (s *space) BuildTree(ctx context.Context, id string, listener updatelistener.UpdateListener) (t tree2.ObjectTree, err error) {
getTreeRemote := func() (*spacesyncproto.ObjectSyncMessage, error) { getTreeRemote := func() (*spacesyncproto.ObjectSyncMessage, error) {
// TODO: add empty context handling (when this is not happening due to head update) // TODO: add empty context handling (when this is not happening due to head update)
peerId, err := syncservice.GetPeerIdFromStreamContext(ctx) peerId, err := syncservice.GetPeerIdFromStreamContext(ctx)
@ -116,11 +116,11 @@ func (s *space) BuildTree(ctx context.Context, id string, listener updatelistene
} }
store, err := s.storage.TreeStorage(id) store, err := s.storage.TreeStorage(id)
if err != nil && err != treestorage.ErrUnknownTreeId { if err != nil && err != storage2.ErrUnknownTreeId {
return return
} }
if err == treestorage.ErrUnknownTreeId { if err == storage2.ErrUnknownTreeId {
var resp *spacesyncproto.ObjectSyncMessage var resp *spacesyncproto.ObjectSyncMessage
resp, err = getTreeRemote() resp, err = getTreeRemote()
if err != nil { if err != nil {
@ -128,7 +128,7 @@ func (s *space) BuildTree(ctx context.Context, id string, listener updatelistene
} }
fullSyncResp := resp.GetContent().GetFullSyncResponse() fullSyncResp := resp.GetContent().GetFullSyncResponse()
payload := treestorage.TreeStorageCreatePayload{ payload := storage2.TreeStorageCreatePayload{
TreeId: resp.TreeId, TreeId: resp.TreeId,
RootRawChange: resp.RootChange, RootRawChange: resp.RootChange,
Changes: fullSyncResp.Changes, Changes: fullSyncResp.Changes,
@ -136,7 +136,7 @@ func (s *space) BuildTree(ctx context.Context, id string, listener updatelistene
} }
// basically building tree with inmemory storage and validating that it was without errors // basically building tree with inmemory storage and validating that it was without errors
err = tree.ValidateRawTree(payload, s.aclList) err = tree2.ValidateRawTree(payload, s.aclList)
if err != nil { if err != nil {
return return
} }
@ -146,7 +146,7 @@ func (s *space) BuildTree(ctx context.Context, id string, listener updatelistene
return return
} }
} }
return synctree.BuildSyncTree(ctx, s.syncService.SyncClient(), store.(treestorage.TreeStorage), listener, s.aclList) return synctree.BuildSyncTree(ctx, s.syncService.SyncClient(), store.(storage2.TreeStorage), listener, s.aclList)
} }
func (s *space) Close() error { func (s *space) Close() error {

View File

@ -2,7 +2,7 @@
package spacesyncproto package spacesyncproto
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"storj.io/drpc" "storj.io/drpc"
) )

View File

@ -5,8 +5,8 @@ package spacesyncproto
import ( import (
fmt "fmt" fmt "fmt"
aclrecordproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
treechangeproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
proto "github.com/gogo/protobuf/proto" proto "github.com/gogo/protobuf/proto"
io "io" io "io"
math "math" math "math"

View File

@ -5,12 +5,12 @@
package mock_storage package mock_storage
import ( import (
storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
reflect "reflect" reflect "reflect"
app "github.com/anytypeio/go-anytype-infrastructure-experiments/app" app "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
spacesyncproto "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" spacesyncproto "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
storage "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage" storage "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
storage0 "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )
@ -119,10 +119,10 @@ func (m *MockSpaceStorage) EXPECT() *MockSpaceStorageMockRecorder {
} }
// ACLStorage mocks base method. // ACLStorage mocks base method.
func (m *MockSpaceStorage) ACLStorage() (storage0.ListStorage, error) { func (m *MockSpaceStorage) ACLStorage() (storage2.ListStorage, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ACLStorage") ret := m.ctrl.Call(m, "ACLStorage")
ret0, _ := ret[0].(storage0.ListStorage) ret0, _ := ret[0].(storage2.ListStorage)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@ -148,10 +148,10 @@ func (mr *MockSpaceStorageMockRecorder) Close() *gomock.Call {
} }
// CreateTreeStorage mocks base method. // CreateTreeStorage mocks base method.
func (m *MockSpaceStorage) CreateTreeStorage(arg0 storage0.TreeStorageCreatePayload) (storage0.TreeStorage, error) { func (m *MockSpaceStorage) CreateTreeStorage(arg0 storage2.TreeStorageCreatePayload) (storage2.TreeStorage, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CreateTreeStorage", arg0) ret := m.ctrl.Call(m, "CreateTreeStorage", arg0)
ret0, _ := ret[0].(storage0.TreeStorage) ret0, _ := ret[0].(storage2.TreeStorage)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@ -208,10 +208,10 @@ func (mr *MockSpaceStorageMockRecorder) StoredIds() *gomock.Call {
} }
// TreeStorage mocks base method. // TreeStorage mocks base method.
func (m *MockSpaceStorage) TreeStorage(arg0 string) (storage0.TreeStorage, error) { func (m *MockSpaceStorage) TreeStorage(arg0 string) (storage2.TreeStorage, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "TreeStorage", arg0) ret := m.ctrl.Call(m, "TreeStorage", arg0)
ret0, _ := ret[0].(storage0.TreeStorage) ret0, _ := ret[0].(storage2.TreeStorage)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }

View File

@ -3,10 +3,10 @@ package storage
import ( import (
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"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/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
) )
const CName = "commonspace.storage" const CName = "commonspace.storage"
@ -15,9 +15,9 @@ var ErrSpaceStorageExists = errors.New("space storage exists")
var ErrSpaceStorageMissing = errors.New("space storage missing") var ErrSpaceStorageMissing = errors.New("space storage missing")
type SpaceStorage interface { type SpaceStorage interface {
storage.Storage storage2.Storage
storage.Provider storage2.Provider
ACLStorage() (storage.ListStorage, error) ACLStorage() (storage2.ListStorage, error)
SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error) SpaceHeader() (*spacesyncproto.RawSpaceHeaderWithId, error)
StoredIds() ([]string, error) StoredIds() ([]string, error)
Close() error Close() error

View File

@ -5,11 +5,11 @@
package mock_syncservice package mock_syncservice
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
reflect "reflect" reflect "reflect"
spacesyncproto "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto" spacesyncproto "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
tree "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
treechangeproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )

View File

@ -3,9 +3,9 @@ package syncservice
import ( import (
"fmt" "fmt"
"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/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/slice"
) )
type RequestFactory interface { type RequestFactory interface {

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
"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/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/slice"
) )
type syncHandler struct { type syncHandler struct {

View File

@ -7,9 +7,9 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache/mock_cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache/mock_cache"
"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/syncservice/mock_syncservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice/mock_syncservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
mock_tree "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree/mock_objecttree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree/mock_objecttree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"sync" "sync"

View File

@ -3,7 +3,7 @@ package syncservice
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
"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/net/rpc/rpcerr" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpcerr"

View File

@ -4,30 +4,30 @@ import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" tree2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
) )
// SyncTree sends head updates to sync service and also sends new changes to update listener // SyncTree sends head updates to sync service and also sends new changes to update listener
type SyncTree struct { type SyncTree struct {
tree.ObjectTree tree2.ObjectTree
syncClient syncservice.SyncClient syncClient syncservice.SyncClient
listener updatelistener.UpdateListener listener updatelistener.UpdateListener
} }
var createDerivedObjectTree = tree.CreateDerivedObjectTree var createDerivedObjectTree = tree2.CreateDerivedObjectTree
var createObjectTree = tree.CreateObjectTree var createObjectTree = tree2.CreateObjectTree
var buildObjectTree = tree.BuildObjectTree var buildObjectTree = tree2.BuildObjectTree
func DeriveSyncTree( func DeriveSyncTree(
ctx context.Context, ctx context.Context,
payload tree.ObjectTreeCreatePayload, payload tree2.ObjectTreeCreatePayload,
syncClient syncservice.SyncClient, syncClient syncservice.SyncClient,
listener updatelistener.UpdateListener, listener updatelistener.UpdateListener,
aclList list.ACLList, aclList list.ACLList,
createStorage storage.TreeStorageCreatorFunc) (t tree.ObjectTree, err error) { createStorage storage.TreeStorageCreatorFunc) (t tree2.ObjectTree, err error) {
t, err = createDerivedObjectTree(payload, aclList, createStorage) t, err = createDerivedObjectTree(payload, aclList, createStorage)
if err != nil { if err != nil {
return return
@ -45,11 +45,11 @@ func DeriveSyncTree(
func CreateSyncTree( func CreateSyncTree(
ctx context.Context, ctx context.Context,
payload tree.ObjectTreeCreatePayload, payload tree2.ObjectTreeCreatePayload,
syncClient syncservice.SyncClient, syncClient syncservice.SyncClient,
listener updatelistener.UpdateListener, listener updatelistener.UpdateListener,
aclList list.ACLList, aclList list.ACLList,
createStorage storage.TreeStorageCreatorFunc) (t tree.ObjectTree, err error) { createStorage storage.TreeStorageCreatorFunc) (t tree2.ObjectTree, err error) {
t, err = createObjectTree(payload, aclList, createStorage) t, err = createObjectTree(payload, aclList, createStorage)
if err != nil { if err != nil {
return return
@ -70,7 +70,7 @@ func BuildSyncTree(
syncClient syncservice.SyncClient, syncClient syncservice.SyncClient,
treeStorage storage.TreeStorage, treeStorage storage.TreeStorage,
listener updatelistener.UpdateListener, listener updatelistener.UpdateListener,
aclList list.ACLList) (t tree.ObjectTree, err error) { aclList list.ACLList) (t tree2.ObjectTree, err error) {
return buildSyncTree(ctx, syncClient, treeStorage, listener, aclList) return buildSyncTree(ctx, syncClient, treeStorage, listener, aclList)
} }
@ -79,7 +79,7 @@ func buildSyncTree(
syncClient syncservice.SyncClient, syncClient syncservice.SyncClient,
treeStorage storage.TreeStorage, treeStorage storage.TreeStorage,
listener updatelistener.UpdateListener, listener updatelistener.UpdateListener,
aclList list.ACLList) (t tree.ObjectTree, err error) { aclList list.ACLList) (t tree2.ObjectTree, err error) {
t, err = buildObjectTree(treeStorage, aclList) t, err = buildObjectTree(treeStorage, aclList)
if err != nil { if err != nil {
return return
@ -96,7 +96,7 @@ func buildSyncTree(
return return
} }
func (s *SyncTree) AddContent(ctx context.Context, content tree.SignableChangeContent) (res tree.AddResult, err error) { func (s *SyncTree) AddContent(ctx context.Context, content tree2.SignableChangeContent) (res tree2.AddResult, err error) {
res, err = s.ObjectTree.AddContent(ctx, content) res, err = s.ObjectTree.AddContent(ctx, content)
if err != nil { if err != nil {
return return
@ -106,17 +106,17 @@ func (s *SyncTree) AddContent(ctx context.Context, content tree.SignableChangeCo
return return
} }
func (s *SyncTree) AddRawChanges(ctx context.Context, changes ...*treechangeproto.RawTreeChangeWithId) (res tree.AddResult, err error) { func (s *SyncTree) AddRawChanges(ctx context.Context, changes ...*treechangeproto.RawTreeChangeWithId) (res tree2.AddResult, err error) {
res, err = s.ObjectTree.AddRawChanges(ctx, changes...) res, err = s.ObjectTree.AddRawChanges(ctx, changes...)
if err != nil { if err != nil {
return return
} }
switch res.Mode { switch res.Mode {
case tree.Nothing: case tree2.Nothing:
return return
case tree.Append: case tree2.Append:
s.listener.Update(s) s.listener.Update(s)
case tree.Rebuild: case tree2.Rebuild:
s.listener.Rebuild(s) s.listener.Rebuild(s)
} }
@ -125,6 +125,6 @@ func (s *SyncTree) AddRawChanges(ctx context.Context, changes ...*treechangeprot
return return
} }
func (s *SyncTree) Tree() tree.ObjectTree { func (s *SyncTree) Tree() tree2.ObjectTree {
return s return s
} }

View File

@ -7,20 +7,20 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice/mock_syncservice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/syncservice/mock_syncservice"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener/mock_updatelistener" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener/mock_updatelistener"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list/mock_list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list/mock_list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage/mock_storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage/mock_storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" tree2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
mock_tree "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree/mock_objecttree" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree/mock_objecttree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
) )
type syncTreeMatcher struct { type syncTreeMatcher struct {
objTree tree.ObjectTree objTree tree2.ObjectTree
client syncservice.SyncClient client syncservice.SyncClient
listener updatelistener.UpdateListener listener updatelistener.UpdateListener
} }
@ -45,11 +45,11 @@ func Test_DeriveSyncTree(t *testing.T) {
updateListenerMock := mock_updatelistener.NewMockUpdateListener(ctrl) updateListenerMock := mock_updatelistener.NewMockUpdateListener(ctrl)
syncClientMock := mock_syncservice.NewMockSyncClient(ctrl) syncClientMock := mock_syncservice.NewMockSyncClient(ctrl)
aclListMock := mock_list.NewMockACLList(ctrl) aclListMock := mock_list.NewMockACLList(ctrl)
createStorage := storage.TreeStorageCreatorFunc(func(payload storage.TreeStorageCreatePayload) (storage.TreeStorage, error) { createStorage := storage2.TreeStorageCreatorFunc(func(payload storage2.TreeStorageCreatePayload) (storage2.TreeStorage, error) {
return nil, nil return nil, nil
}) })
objTreeMock := mock_tree.NewMockObjectTree(ctrl) objTreeMock := mock_tree.NewMockObjectTree(ctrl)
createDerivedObjectTree = func(payload tree.ObjectTreeCreatePayload, l list.ACLList, create storage.TreeStorageCreatorFunc) (objTree tree.ObjectTree, err error) { createDerivedObjectTree = func(payload tree2.ObjectTreeCreatePayload, l list.ACLList, create storage2.TreeStorageCreatorFunc) (objTree tree2.ObjectTree, err error) {
require.Equal(t, l, aclListMock) require.Equal(t, l, aclListMock)
return objTreeMock, nil return objTreeMock, nil
} }
@ -57,7 +57,7 @@ func Test_DeriveSyncTree(t *testing.T) {
syncClientMock.EXPECT().CreateHeadUpdate(syncTreeMatcher{objTreeMock, syncClientMock, updateListenerMock}, gomock.Nil()).Return(headUpdate) syncClientMock.EXPECT().CreateHeadUpdate(syncTreeMatcher{objTreeMock, syncClientMock, updateListenerMock}, gomock.Nil()).Return(headUpdate)
syncClientMock.EXPECT().BroadcastAsync(gomock.Eq(headUpdate)).Return(nil) syncClientMock.EXPECT().BroadcastAsync(gomock.Eq(headUpdate)).Return(nil)
_, err := DeriveSyncTree(ctx, tree.ObjectTreeCreatePayload{}, syncClientMock, updateListenerMock, aclListMock, createStorage) _, err := DeriveSyncTree(ctx, tree2.ObjectTreeCreatePayload{}, syncClientMock, updateListenerMock, aclListMock, createStorage)
require.NoError(t, err) require.NoError(t, err)
} }
@ -69,11 +69,11 @@ func Test_CreateSyncTree(t *testing.T) {
updateListenerMock := mock_updatelistener.NewMockUpdateListener(ctrl) updateListenerMock := mock_updatelistener.NewMockUpdateListener(ctrl)
syncClientMock := mock_syncservice.NewMockSyncClient(ctrl) syncClientMock := mock_syncservice.NewMockSyncClient(ctrl)
aclListMock := mock_list.NewMockACLList(ctrl) aclListMock := mock_list.NewMockACLList(ctrl)
createStorage := storage.TreeStorageCreatorFunc(func(payload storage.TreeStorageCreatePayload) (storage.TreeStorage, error) { createStorage := storage2.TreeStorageCreatorFunc(func(payload storage2.TreeStorageCreatePayload) (storage2.TreeStorage, error) {
return nil, nil return nil, nil
}) })
objTreeMock := mock_tree.NewMockObjectTree(ctrl) objTreeMock := mock_tree.NewMockObjectTree(ctrl)
createObjectTree = func(payload tree.ObjectTreeCreatePayload, l list.ACLList, create storage.TreeStorageCreatorFunc) (objTree tree.ObjectTree, err error) { createObjectTree = func(payload tree2.ObjectTreeCreatePayload, l list.ACLList, create storage2.TreeStorageCreatorFunc) (objTree tree2.ObjectTree, err error) {
require.Equal(t, l, aclListMock) require.Equal(t, l, aclListMock)
return objTreeMock, nil return objTreeMock, nil
} }
@ -81,7 +81,7 @@ func Test_CreateSyncTree(t *testing.T) {
syncClientMock.EXPECT().CreateHeadUpdate(syncTreeMatcher{objTreeMock, syncClientMock, updateListenerMock}, gomock.Nil()).Return(headUpdate) syncClientMock.EXPECT().CreateHeadUpdate(syncTreeMatcher{objTreeMock, syncClientMock, updateListenerMock}, gomock.Nil()).Return(headUpdate)
syncClientMock.EXPECT().BroadcastAsync(gomock.Eq(headUpdate)).Return(nil) syncClientMock.EXPECT().BroadcastAsync(gomock.Eq(headUpdate)).Return(nil)
_, err := CreateSyncTree(ctx, tree.ObjectTreeCreatePayload{}, syncClientMock, updateListenerMock, aclListMock, createStorage) _, err := CreateSyncTree(ctx, tree2.ObjectTreeCreatePayload{}, syncClientMock, updateListenerMock, aclListMock, createStorage)
require.NoError(t, err) require.NoError(t, err)
} }
@ -95,7 +95,7 @@ func Test_BuildSyncTree(t *testing.T) {
aclListMock := mock_list.NewMockACLList(ctrl) aclListMock := mock_list.NewMockACLList(ctrl)
storageMock := mock_storage.NewMockTreeStorage(ctrl) storageMock := mock_storage.NewMockTreeStorage(ctrl)
objTreeMock := mock_tree.NewMockObjectTree(ctrl) objTreeMock := mock_tree.NewMockObjectTree(ctrl)
buildObjectTree = func(store storage.TreeStorage, l list.ACLList) (objTree tree.ObjectTree, err error) { buildObjectTree = func(store storage2.TreeStorage, l list.ACLList) (objTree tree2.ObjectTree, err error) {
require.Equal(t, aclListMock, l) require.Equal(t, aclListMock, l)
require.Equal(t, store, storageMock) require.Equal(t, store, storageMock)
return objTreeMock, nil return objTreeMock, nil
@ -109,9 +109,9 @@ func Test_BuildSyncTree(t *testing.T) {
t.Run("AddRawChanges update", func(t *testing.T) { t.Run("AddRawChanges update", func(t *testing.T) {
changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}} changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}}
expectedRes := tree.AddResult{ expectedRes := tree2.AddResult{
Added: changes, Added: changes,
Mode: tree.Append, Mode: tree2.Append,
} }
objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)). objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)).
Return(expectedRes, nil) Return(expectedRes, nil)
@ -126,9 +126,9 @@ func Test_BuildSyncTree(t *testing.T) {
t.Run("AddRawChanges rebuild", func(t *testing.T) { t.Run("AddRawChanges rebuild", func(t *testing.T) {
changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}} changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}}
expectedRes := tree.AddResult{ expectedRes := tree2.AddResult{
Added: changes, Added: changes,
Mode: tree.Rebuild, Mode: tree2.Rebuild,
} }
objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)). objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)).
Return(expectedRes, nil) Return(expectedRes, nil)
@ -143,9 +143,9 @@ func Test_BuildSyncTree(t *testing.T) {
t.Run("AddRawChanges nothing", func(t *testing.T) { t.Run("AddRawChanges nothing", func(t *testing.T) {
changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}} changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}}
expectedRes := tree.AddResult{ expectedRes := tree2.AddResult{
Added: changes, Added: changes,
Mode: tree.Nothing, Mode: tree2.Nothing,
} }
objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)). objTreeMock.EXPECT().AddRawChanges(gomock.Any(), gomock.Eq(changes)).
Return(expectedRes, nil) Return(expectedRes, nil)
@ -157,11 +157,11 @@ func Test_BuildSyncTree(t *testing.T) {
t.Run("AddContent", func(t *testing.T) { t.Run("AddContent", func(t *testing.T) {
changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}} changes := []*treechangeproto.RawTreeChangeWithId{{Id: "some"}}
content := tree.SignableChangeContent{ content := tree2.SignableChangeContent{
Data: []byte("abcde"), Data: []byte("abcde"),
} }
expectedRes := tree.AddResult{ expectedRes := tree2.AddResult{
Mode: tree.Append, Mode: tree2.Append,
Added: changes, Added: changes,
} }
objTreeMock.EXPECT().AddContent(gomock.Any(), gomock.Eq(content)). objTreeMock.EXPECT().AddContent(gomock.Any(), gomock.Eq(content)).

View File

@ -5,9 +5,9 @@
package mock_updatelistener package mock_updatelistener
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
reflect "reflect" reflect "reflect"
tree "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )

View File

@ -1,7 +1,9 @@
//go:generate mockgen -destination mock_updatelistener/mock_updatelistener.go github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener UpdateListener //go:generate mockgen -destination mock_updatelistener/mock_updatelistener.go github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/synctree/updatelistener UpdateListener
package updatelistener package updatelistener
import "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree" import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
)
type UpdateListener interface { type UpdateListener interface {
Update(tree tree.ObjectTree) Update(tree tree.ObjectTree)

View File

@ -2,8 +2,8 @@ package config
import ( import (
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"io/ioutil" "io/ioutil"
) )

View File

@ -1,7 +1,7 @@
package config package config
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"go.uber.org/zap" "go.uber.org/zap"
) )

View File

@ -2,8 +2,8 @@ package metric
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -24,16 +24,16 @@ type Metric interface {
type metric struct { type metric struct {
registry *prometheus.Registry registry *prometheus.Registry
config config.Metric config config2.Metric
} }
type configSource interface { type configSource interface {
GetMetric() config.Metric GetMetric() config2.Metric
} }
func (m *metric) Init(a *app.App) (err error) { func (m *metric) Init(a *app.App) (err error) {
m.registry = prometheus.NewRegistry() m.registry = prometheus.NewRegistry()
m.config = a.MustComponent(config.CName).(configSource).GetMetric() m.config = a.MustComponent(config2.CName).(configSource).GetMetric()
return nil return nil
} }

View File

@ -3,11 +3,11 @@ package dialer
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/libp2p/go-libp2p-core/sec" "github.com/libp2p/go-libp2p-core/sec"
"go.uber.org/zap" "go.uber.org/zap"
"net" "net"

View File

@ -3,11 +3,11 @@ package pool
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/ocache"
"math/rand" "math/rand"
"time" "time"
) )

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/dialer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"

View File

@ -2,11 +2,11 @@ package server
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/metric"
secure2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure" secure2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
@ -32,11 +32,11 @@ type DRPCServer interface {
} }
type configGetter interface { type configGetter interface {
GetGRPCServer() config.GrpcServer GetGRPCServer() config2.GrpcServer
} }
type drpcServer struct { type drpcServer struct {
config config.GrpcServer config config2.GrpcServer
drpcServer *drpcserver.Server drpcServer *drpcserver.Server
transport secure2.Service transport secure2.Service
listeners []secure2.ContextListener listeners []secure2.ContextListener
@ -46,7 +46,7 @@ type drpcServer struct {
} }
func (s *drpcServer) Init(a *app.App) (err error) { func (s *drpcServer) Init(a *app.App) (err error) {
s.config = a.MustComponent(config.CName).(configGetter).GetGRPCServer() s.config = a.MustComponent(config2.CName).(configGetter).GetGRPCServer()
s.transport = a.MustComponent(secure2.CName).(secure2.Service) s.transport = a.MustComponent(secure2.CName).(secure2.Service)
s.metric = a.MustComponent(metric.CName).(metric.Metric) s.metric = a.MustComponent(metric.CName).(metric.Metric)
return nil return nil

View File

@ -2,11 +2,11 @@ package secure
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/account" commonaccount "github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
"github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/sec" "github.com/libp2p/go-libp2p-core/sec"
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"

View File

@ -1,12 +1,12 @@
package nodeconf package nodeconf
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config" config2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" encryptionkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" signingkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-chash" "github.com/anytypeio/go-chash"
) )
@ -36,8 +36,8 @@ type service struct {
type Node struct { type Node struct {
Address string Address string
PeerId string PeerId string
SigningKey signingkey.PubKey SigningKey signingkey2.PubKey
EncryptionKey encryptionkey.PubKey EncryptionKey encryptionkey2.PubKey
} }
func (n *Node) Id() string { func (n *Node) Id() string {
@ -49,7 +49,7 @@ func (n *Node) Capacity() float64 {
} }
func (s *service) Init(a *app.App) (err error) { func (s *service) Init(a *app.App) (err error) {
conf := a.MustComponent(config.CName).(*config.Config) conf := a.MustComponent(config2.CName).(*config2.Config)
s.accountId = conf.Account.PeerId s.accountId = conf.Account.PeerId
config := &configuration{ config := &configuration{
@ -100,10 +100,10 @@ func (s *service) ConsensusPeers() []string {
} }
func nodeFromConfigNode( func nodeFromConfigNode(
n config.Node) (*Node, error) { n config2.Node) (*Node, error) {
decodedSigningKey, err := keys.DecodeKeyFromString( decodedSigningKey, err := keys.DecodeKeyFromString(
n.SigningKey, n.SigningKey,
signingkey.UnmarshalEd25519PrivateKey, signingkey2.UnmarshalEd25519PrivateKey,
nil) nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -111,7 +111,7 @@ func nodeFromConfigNode(
decodedEncryptionKey, err := keys.DecodeKeyFromString( decodedEncryptionKey, err := keys.DecodeKeyFromString(
n.EncryptionKey, n.EncryptionKey,
encryptionkey.NewEncryptionRsaPrivKeyFromBytes, encryptionkey2.NewEncryptionRsaPrivKeyFromBytes,
nil) nil)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -0,0 +1,12 @@
package account
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
)
type AccountData struct { // TODO: create a convenient constructor for this
Identity []byte // public key
SignKey signingkey.PrivKey
EncKey encryptionkey.PrivKey
}

View File

@ -1,6 +1,8 @@
package aclrecordproto package aclrecordproto
import "github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
)
func ACLReadKeyDerive(signKey []byte, encKey []byte) (*symmetric.Key, error) { func ACLReadKeyDerive(signKey []byte, encKey []byte) (*symmetric.Key, error) {
concBuf := make([]byte, 0, len(signKey)+len(encKey)) concBuf := make([]byte, 0, len(signKey)+len(encKey))

View File

@ -0,0 +1,28 @@
package common
import (
signingkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
)
type Keychain struct {
keys map[string]signingkey2.PubKey
}
func NewKeychain() *Keychain {
return &Keychain{
keys: make(map[string]signingkey2.PubKey),
}
}
func (k *Keychain) GetOrAdd(identity string) (signingkey2.PubKey, error) {
if key, exists := k.keys[identity]; exists {
return key, nil
}
res, err := signingkey2.NewSigningEd25519PubKeyFromBytes([]byte(identity))
if err != nil {
return nil, err
}
k.keys[identity] = res.(signingkey2.PubKey)
return res.(signingkey2.PubKey), nil
}

View File

@ -1,9 +1,9 @@
package list package list
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/cid"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
) )

View File

@ -4,12 +4,12 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" aclrecordproto2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" signingkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"go.uber.org/zap" "go.uber.org/zap"
"hash/fnv" "hash/fnv"
@ -30,17 +30,17 @@ var ErrIncorrectRoot = errors.New("incorrect root")
type UserPermissionPair struct { type UserPermissionPair struct {
Identity string Identity string
Permission aclrecordproto.ACLUserPermissions Permission aclrecordproto2.ACLUserPermissions
} }
type ACLState struct { type ACLState struct {
id string id string
currentReadKeyHash uint64 currentReadKeyHash uint64
userReadKeys map[uint64]*symmetric.Key userReadKeys map[uint64]*symmetric.Key
userStates map[string]*aclrecordproto.ACLUserState userStates map[string]*aclrecordproto2.ACLUserState
userInvites map[string]*aclrecordproto.ACLUserInvite userInvites map[string]*aclrecordproto2.ACLUserInvite
encryptionKey encryptionkey.PrivKey encryptionKey encryptionkey.PrivKey
signingKey signingkey.PrivKey signingKey signingkey2.PrivKey
identity string identity string
permissionsAtRecord map[string][]UserPermissionPair permissionsAtRecord map[string][]UserPermissionPair
@ -50,7 +50,7 @@ type ACLState struct {
func newACLStateWithKeys( func newACLStateWithKeys(
id string, id string,
signingKey signingkey.PrivKey, signingKey signingkey2.PrivKey,
encryptionKey encryptionkey.PrivKey) (*ACLState, error) { encryptionKey encryptionkey.PrivKey) (*ACLState, error) {
identity, err := signingKey.Raw() identity, err := signingKey.Raw()
if err != nil { if err != nil {
@ -62,8 +62,8 @@ func newACLStateWithKeys(
signingKey: signingKey, signingKey: signingKey,
encryptionKey: encryptionKey, encryptionKey: encryptionKey,
userReadKeys: make(map[uint64]*symmetric.Key), userReadKeys: make(map[uint64]*symmetric.Key),
userStates: make(map[string]*aclrecordproto.ACLUserState), userStates: make(map[string]*aclrecordproto2.ACLUserState),
userInvites: make(map[string]*aclrecordproto.ACLUserInvite), userInvites: make(map[string]*aclrecordproto2.ACLUserInvite),
permissionsAtRecord: make(map[string][]UserPermissionPair), permissionsAtRecord: make(map[string][]UserPermissionPair),
}, nil }, nil
} }
@ -72,8 +72,8 @@ func newACLState(id string) *ACLState {
return &ACLState{ return &ACLState{
id: id, id: id,
userReadKeys: make(map[uint64]*symmetric.Key), userReadKeys: make(map[uint64]*symmetric.Key),
userStates: make(map[string]*aclrecordproto.ACLUserState), userStates: make(map[string]*aclrecordproto2.ACLUserState),
userInvites: make(map[string]*aclrecordproto.ACLUserInvite), userInvites: make(map[string]*aclrecordproto2.ACLUserInvite),
permissionsAtRecord: make(map[string][]UserPermissionPair), permissionsAtRecord: make(map[string][]UserPermissionPair),
} }
} }
@ -111,16 +111,16 @@ func (st *ACLState) PermissionsAtRecord(id string, identity string) (UserPermiss
func (st *ACLState) applyRecord(record *ACLRecord) (err error) { func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
if record.Id == st.id { if record.Id == st.id {
root, ok := record.Model.(*aclrecordproto.ACLRoot) root, ok := record.Model.(*aclrecordproto2.ACLRoot)
if !ok { if !ok {
return ErrIncorrectRoot return ErrIncorrectRoot
} }
return st.applyRoot(root) return st.applyRoot(root)
} }
aclData := &aclrecordproto.ACLData{} aclData := &aclrecordproto2.ACLData{}
if record.Model != nil { if record.Model != nil {
aclData = record.Model.(*aclrecordproto.ACLData) aclData = record.Model.(*aclrecordproto2.ACLData)
} else { } else {
err = proto.Unmarshal(record.Data, aclData) err = proto.Unmarshal(record.Data, aclData)
if err != nil { if err != nil {
@ -148,7 +148,7 @@ func (st *ACLState) applyRecord(record *ACLRecord) (err error) {
return nil return nil
} }
func (st *ACLState) applyRoot(root *aclrecordproto.ACLRoot) (err error) { func (st *ACLState) applyRoot(root *aclrecordproto2.ACLRoot) (err error) {
if st.signingKey != nil && st.encryptionKey != nil { if st.signingKey != nil && st.encryptionKey != nil {
err = st.saveReadKeyFromRoot(root) err = st.saveReadKeyFromRoot(root)
if err != nil { if err != nil {
@ -157,16 +157,16 @@ func (st *ACLState) applyRoot(root *aclrecordproto.ACLRoot) (err error) {
} }
// adding user to the list // adding user to the list
userState := &aclrecordproto.ACLUserState{ userState := &aclrecordproto2.ACLUserState{
Identity: root.Identity, Identity: root.Identity,
EncryptionKey: root.EncryptionKey, EncryptionKey: root.EncryptionKey,
Permissions: aclrecordproto.ACLUserPermissions_Admin, Permissions: aclrecordproto2.ACLUserPermissions_Admin,
} }
st.userStates[string(root.Identity)] = userState st.userStates[string(root.Identity)] = userState
return return
} }
func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto.ACLRoot) (err error) { func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto2.ACLRoot) (err error) {
var readKey *symmetric.Key var readKey *symmetric.Key
if len(root.GetDerivationScheme()) != 0 { if len(root.GetDerivationScheme()) != 0 {
var encPubKey []byte var encPubKey []byte
@ -175,7 +175,7 @@ func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto.ACLRoot) (err error
return return
} }
readKey, err = aclrecordproto.ACLReadKeyDerive([]byte(st.identity), encPubKey) readKey, err = aclrecordproto2.ACLReadKeyDerive([]byte(st.identity), encPubKey)
if err != nil { if err != nil {
return return
} }
@ -199,7 +199,7 @@ func (st *ACLState) saveReadKeyFromRoot(root *aclrecordproto.ACLRoot) (err error
return return
} }
func (st *ACLState) applyChangeData(changeData *aclrecordproto.ACLData, hash uint64, identity []byte) (err error) { func (st *ACLState) applyChangeData(changeData *aclrecordproto2.ACLData, hash uint64, identity []byte) (err error) {
defer func() { defer func() {
if err != nil { if err != nil {
return return
@ -214,7 +214,7 @@ func (st *ACLState) applyChangeData(changeData *aclrecordproto.ACLData, hash uin
return return
} }
if !st.hasPermission(identity, aclrecordproto.ACLUserPermissions_Admin) { if !st.hasPermission(identity, aclrecordproto2.ACLUserPermissions_Admin) {
err = fmt.Errorf("user %s must have admin permissions", identity) err = fmt.Errorf("user %s must have admin permissions", identity)
return return
} }
@ -230,7 +230,7 @@ func (st *ACLState) applyChangeData(changeData *aclrecordproto.ACLData, hash uin
return nil return nil
} }
func (st *ACLState) applyChangeContent(ch *aclrecordproto.ACLContentValue) error { func (st *ACLState) applyChangeContent(ch *aclrecordproto2.ACLContentValue) error {
switch { switch {
case ch.GetUserPermissionChange() != nil: case ch.GetUserPermissionChange() != nil:
return st.applyUserPermissionChange(ch.GetUserPermissionChange()) return st.applyUserPermissionChange(ch.GetUserPermissionChange())
@ -247,7 +247,7 @@ func (st *ACLState) applyChangeContent(ch *aclrecordproto.ACLContentValue) error
} }
} }
func (st *ACLState) applyUserPermissionChange(ch *aclrecordproto.ACLUserPermissionChange) error { func (st *ACLState) applyUserPermissionChange(ch *aclrecordproto2.ACLUserPermissionChange) error {
chIdentity := string(ch.Identity) chIdentity := string(ch.Identity)
state, exists := st.userStates[chIdentity] state, exists := st.userStates[chIdentity]
if !exists { if !exists {
@ -258,12 +258,12 @@ func (st *ACLState) applyUserPermissionChange(ch *aclrecordproto.ACLUserPermissi
return nil return nil
} }
func (st *ACLState) applyUserInvite(ch *aclrecordproto.ACLUserInvite) error { func (st *ACLState) applyUserInvite(ch *aclrecordproto2.ACLUserInvite) error {
st.userInvites[ch.InviteId] = ch st.userInvites[ch.InviteId] = ch
return nil return nil
} }
func (st *ACLState) applyUserJoin(ch *aclrecordproto.ACLUserJoin) error { func (st *ACLState) applyUserJoin(ch *aclrecordproto2.ACLUserJoin) error {
invite, exists := st.userInvites[ch.InviteId] invite, exists := st.userInvites[ch.InviteId]
if !exists { if !exists {
return fmt.Errorf("no such invite with id %s", ch.InviteId) return fmt.Errorf("no such invite with id %s", ch.InviteId)
@ -276,12 +276,12 @@ func (st *ACLState) applyUserJoin(ch *aclrecordproto.ACLUserJoin) error {
// validating signature // validating signature
signature := ch.GetAcceptSignature() signature := ch.GetAcceptSignature()
verificationKey, err := signingkey.NewSigningEd25519PubKeyFromBytes(invite.AcceptPublicKey) verificationKey, err := signingkey2.NewSigningEd25519PubKeyFromBytes(invite.AcceptPublicKey)
if err != nil { if err != nil {
return fmt.Errorf("public key verifying invite accepts is given in incorrect format: %v", err) return fmt.Errorf("public key verifying invite accepts is given in incorrect format: %v", err)
} }
res, err := verificationKey.(signingkey.PubKey).Verify(ch.Identity, signature) res, err := verificationKey.(signingkey2.PubKey).Verify(ch.Identity, signature)
if err != nil { if err != nil {
return fmt.Errorf("verification returned error: %w", err) return fmt.Errorf("verification returned error: %w", err)
} }
@ -302,7 +302,7 @@ func (st *ACLState) applyUserJoin(ch *aclrecordproto.ACLUserJoin) error {
} }
// adding user to the list // adding user to the list
userState := &aclrecordproto.ACLUserState{ userState := &aclrecordproto2.ACLUserState{
Identity: ch.Identity, Identity: ch.Identity,
EncryptionKey: ch.EncryptionKey, EncryptionKey: ch.EncryptionKey,
Permissions: invite.Permissions, Permissions: invite.Permissions,
@ -311,13 +311,13 @@ func (st *ACLState) applyUserJoin(ch *aclrecordproto.ACLUserJoin) error {
return nil return nil
} }
func (st *ACLState) applyUserAdd(ch *aclrecordproto.ACLUserAdd) error { func (st *ACLState) applyUserAdd(ch *aclrecordproto2.ACLUserAdd) error {
chIdentity := string(ch.Identity) chIdentity := string(ch.Identity)
if _, exists := st.userStates[chIdentity]; exists { if _, exists := st.userStates[chIdentity]; exists {
return ErrUserAlreadyExists return ErrUserAlreadyExists
} }
st.userStates[chIdentity] = &aclrecordproto.ACLUserState{ st.userStates[chIdentity] = &aclrecordproto2.ACLUserState{
Identity: ch.Identity, Identity: ch.Identity,
EncryptionKey: ch.EncryptionKey, EncryptionKey: ch.EncryptionKey,
Permissions: ch.Permissions, Permissions: ch.Permissions,
@ -337,7 +337,7 @@ func (st *ACLState) applyUserAdd(ch *aclrecordproto.ACLUserAdd) error {
return nil return nil
} }
func (st *ACLState) applyUserRemove(ch *aclrecordproto.ACLUserRemove) error { func (st *ACLState) applyUserRemove(ch *aclrecordproto2.ACLUserRemove) error {
chIdentity := string(ch.Identity) chIdentity := string(ch.Identity)
if chIdentity == st.identity { if chIdentity == st.identity {
return ErrDocumentForbidden return ErrDocumentForbidden
@ -381,7 +381,7 @@ func (st *ACLState) decryptReadKeyAndHash(msg []byte) (*symmetric.Key, uint64, e
return key, hasher.Sum64(), nil return key, hasher.Sum64(), nil
} }
func (st *ACLState) hasPermission(identity []byte, permission aclrecordproto.ACLUserPermissions) bool { func (st *ACLState) hasPermission(identity []byte, permission aclrecordproto2.ACLUserPermissions) bool {
state, exists := st.userStates[string(identity)] state, exists := st.userStates[string(identity)]
if !exists { if !exists {
return false return false
@ -390,17 +390,17 @@ func (st *ACLState) hasPermission(identity []byte, permission aclrecordproto.ACL
return state.Permissions == permission return state.Permissions == permission
} }
func (st *ACLState) isUserJoin(data *aclrecordproto.ACLData) bool { func (st *ACLState) isUserJoin(data *aclrecordproto2.ACLData) bool {
// if we have a UserJoin, then it should always be the first one applied // if we have a UserJoin, then it should always be the first one applied
return data.GetAclContent() != nil && data.GetAclContent()[0].GetUserJoin() != nil return data.GetAclContent() != nil && data.GetAclContent()[0].GetUserJoin() != nil
} }
func (st *ACLState) isUserAdd(data *aclrecordproto.ACLData, identity []byte) bool { func (st *ACLState) isUserAdd(data *aclrecordproto2.ACLData, identity []byte) bool {
// if we have a UserAdd, then it should always be the first one applied // if we have a UserAdd, then it should always be the first one applied
userAdd := data.GetAclContent()[0].GetUserAdd() userAdd := data.GetAclContent()[0].GetUserAdd()
return data.GetAclContent() != nil && userAdd != nil && bytes.Compare(userAdd.GetIdentity(), identity) == 0 return data.GetAclContent() != nil && userAdd != nil && bytes.Compare(userAdd.GetIdentity(), identity) == 0
} }
func (st *ACLState) GetUserStates() map[string]*aclrecordproto.ACLUserState { func (st *ACLState) GetUserStates() map[string]*aclrecordproto2.ACLUserState {
return st.userStates return st.userStates
} }

View File

@ -1,9 +1,9 @@
package list package list
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
) )
type aclStateBuilder struct { type aclStateBuilder struct {

View File

@ -5,10 +5,10 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"sync" "sync"
) )

View File

@ -1,8 +1,8 @@
package list package list
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/acllistbuilder" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/testutils/acllistbuilder"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"

View File

@ -5,10 +5,10 @@
package mock_list package mock_list
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
list2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
reflect "reflect" reflect "reflect"
aclrecordproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
list "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )
@ -36,10 +36,10 @@ func (m *MockACLList) EXPECT() *MockACLListMockRecorder {
} }
// ACLState mocks base method. // ACLState mocks base method.
func (m *MockACLList) ACLState() *list.ACLState { func (m *MockACLList) ACLState() *list2.ACLState {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ACLState") ret := m.ctrl.Call(m, "ACLState")
ret0, _ := ret[0].(*list.ACLState) ret0, _ := ret[0].(*list2.ACLState)
return ret0 return ret0
} }
@ -64,10 +64,10 @@ func (mr *MockACLListMockRecorder) Close() *gomock.Call {
} }
// Get mocks base method. // Get mocks base method.
func (m *MockACLList) Get(arg0 string) (*list.ACLRecord, error) { func (m *MockACLList) Get(arg0 string) (*list2.ACLRecord, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Get", arg0) ret := m.ctrl.Call(m, "Get", arg0)
ret0, _ := ret[0].(*list.ACLRecord) ret0, _ := ret[0].(*list2.ACLRecord)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@ -79,10 +79,10 @@ func (mr *MockACLListMockRecorder) Get(arg0 interface{}) *gomock.Call {
} }
// Head mocks base method. // Head mocks base method.
func (m *MockACLList) Head() *list.ACLRecord { func (m *MockACLList) Head() *list2.ACLRecord {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Head") ret := m.ctrl.Call(m, "Head")
ret0, _ := ret[0].(*list.ACLRecord) ret0, _ := ret[0].(*list2.ACLRecord)
return ret0 return ret0
} }
@ -122,7 +122,7 @@ func (mr *MockACLListMockRecorder) IsAfter(arg0, arg1 interface{}) *gomock.Call
} }
// Iterate mocks base method. // Iterate mocks base method.
func (m *MockACLList) Iterate(arg0 func(*list.ACLRecord) bool) { func (m *MockACLList) Iterate(arg0 func(*list2.ACLRecord) bool) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "Iterate", arg0) m.ctrl.Call(m, "Iterate", arg0)
} }
@ -134,7 +134,7 @@ func (mr *MockACLListMockRecorder) Iterate(arg0 interface{}) *gomock.Call {
} }
// IterateFrom mocks base method. // IterateFrom mocks base method.
func (m *MockACLList) IterateFrom(arg0 string, arg1 func(*list.ACLRecord) bool) { func (m *MockACLList) IterateFrom(arg0 string, arg1 func(*list2.ACLRecord) bool) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateFrom", arg0, arg1) m.ctrl.Call(m, "IterateFrom", arg0, arg1)
} }
@ -182,10 +182,10 @@ func (mr *MockACLListMockRecorder) RUnlock() *gomock.Call {
} }
// Records mocks base method. // Records mocks base method.
func (m *MockACLList) Records() []*list.ACLRecord { func (m *MockACLList) Records() []*list2.ACLRecord {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Records") ret := m.ctrl.Call(m, "Records")
ret0, _ := ret[0].([]*list.ACLRecord) ret0, _ := ret[0].([]*list2.ACLRecord)
return ret0 return ret0
} }

View File

@ -3,8 +3,8 @@ package storage
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"sync" "sync"
) )

View File

@ -4,7 +4,7 @@ package storage
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
) )
var ErrUnknownACLId = errors.New("acl does not exist") var ErrUnknownACLId = errors.New("acl does not exist")

View File

@ -6,10 +6,10 @@ package mock_storage
import ( import (
context "context" context "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
reflect "reflect" reflect "reflect"
aclrecordproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
treechangeproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )

View File

@ -2,7 +2,7 @@ package storage
import ( import (
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
) )
var ErrUnknownTreeId = errors.New("tree does not exist") var ErrUnknownTreeId = errors.New("tree does not exist")

View File

@ -2,7 +2,7 @@ package storage
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
) )
type TreeStorage interface { type TreeStorage interface {

View File

@ -1,14 +1,13 @@
package acllistbuilder package acllistbuilder
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" encryptionkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" signingkey2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"hash/fnv" "hash/fnv"
"strings" "strings"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric"
) )
type SymKey struct { type SymKey struct {
@ -17,9 +16,9 @@ type SymKey struct {
} }
type YAMLKeychain struct { type YAMLKeychain struct {
SigningKeysByYAMLIdentity map[string]signingkey.PrivKey SigningKeysByYAMLIdentity map[string]signingkey2.PrivKey
SigningKeysByRealIdentity map[string]signingkey.PrivKey SigningKeysByRealIdentity map[string]signingkey2.PrivKey
EncryptionKeysByYAMLIdentity map[string]encryptionkey.PrivKey EncryptionKeysByYAMLIdentity map[string]encryptionkey2.PrivKey
ReadKeysByYAMLIdentity map[string]*SymKey ReadKeysByYAMLIdentity map[string]*SymKey
ReadKeysByHash map[uint64]*SymKey ReadKeysByHash map[uint64]*SymKey
GeneratedIdentities map[string]string GeneratedIdentities map[string]string
@ -28,9 +27,9 @@ type YAMLKeychain struct {
func NewKeychain() *YAMLKeychain { func NewKeychain() *YAMLKeychain {
return &YAMLKeychain{ return &YAMLKeychain{
SigningKeysByYAMLIdentity: map[string]signingkey.PrivKey{}, SigningKeysByYAMLIdentity: map[string]signingkey2.PrivKey{},
SigningKeysByRealIdentity: map[string]signingkey.PrivKey{}, SigningKeysByRealIdentity: map[string]signingkey2.PrivKey{},
EncryptionKeysByYAMLIdentity: map[string]encryptionkey.PrivKey{}, EncryptionKeysByYAMLIdentity: map[string]encryptionkey2.PrivKey{},
GeneratedIdentities: map[string]string{}, GeneratedIdentities: map[string]string{},
ReadKeysByYAMLIdentity: map[string]*SymKey{}, ReadKeysByYAMLIdentity: map[string]*SymKey{},
ReadKeysByHash: map[uint64]*SymKey{}, ReadKeysByHash: map[uint64]*SymKey{},
@ -57,16 +56,16 @@ func (k *YAMLKeychain) AddEncryptionKey(key *Key) {
return return
} }
var ( var (
newPrivKey encryptionkey.PrivKey newPrivKey encryptionkey2.PrivKey
err error err error
) )
if key.Value == "generated" { if key.Value == "generated" {
newPrivKey, _, err = encryptionkey.GenerateRandomRSAKeyPair(2048) newPrivKey, _, err = encryptionkey2.GenerateRandomRSAKeyPair(2048)
if err != nil { if err != nil {
panic(err) panic(err)
} }
} else { } else {
newPrivKey, err = keys.DecodeKeyFromString(key.Value, encryptionkey.NewEncryptionRsaPrivKeyFromBytes, nil) newPrivKey, err = keys.DecodeKeyFromString(key.Value, encryptionkey2.NewEncryptionRsaPrivKeyFromBytes, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -79,17 +78,17 @@ func (k *YAMLKeychain) AddSigningKey(key *Key) {
return return
} }
var ( var (
newPrivKey signingkey.PrivKey newPrivKey signingkey2.PrivKey
pubKey signingkey.PubKey pubKey signingkey2.PubKey
err error err error
) )
if key.Value == "generated" { if key.Value == "generated" {
newPrivKey, pubKey, err = signingkey.GenerateRandomEd25519KeyPair() newPrivKey, pubKey, err = signingkey2.GenerateRandomEd25519KeyPair()
if err != nil { if err != nil {
panic(err) panic(err)
} }
} else { } else {
newPrivKey, err = keys.DecodeKeyFromString(key.Value, signingkey.NewSigningEd25519PrivKeyFromBytes, nil) newPrivKey, err = keys.DecodeKeyFromString(key.Value, signingkey2.NewSigningEd25519PrivKeyFromBytes, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -3,12 +3,12 @@ package acllistbuilder
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" aclrecordproto2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/yamltests" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/testutils/yamltests"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/cid"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"hash/fnv" "hash/fnv"
"io/ioutil" "io/ioutil"
"path" "path"
@ -20,18 +20,18 @@ import (
type ACLListStorageBuilder struct { type ACLListStorageBuilder struct {
aclList string aclList string
records []*aclrecordproto.ACLRecord records []*aclrecordproto2.ACLRecord
rawRecords []*aclrecordproto.RawACLRecordWithId rawRecords []*aclrecordproto2.RawACLRecordWithId
indexes map[string]int indexes map[string]int
keychain *YAMLKeychain keychain *YAMLKeychain
rawRoot *aclrecordproto.RawACLRecordWithId rawRoot *aclrecordproto2.RawACLRecordWithId
root *aclrecordproto.ACLRoot root *aclrecordproto2.ACLRoot
id string id string
} }
func NewACLListStorageBuilder(keychain *YAMLKeychain) *ACLListStorageBuilder { func NewACLListStorageBuilder(keychain *YAMLKeychain) *ACLListStorageBuilder {
return &ACLListStorageBuilder{ return &ACLListStorageBuilder{
records: make([]*aclrecordproto.ACLRecord, 0), records: make([]*aclrecordproto2.ACLRecord, 0),
indexes: make(map[string]int), indexes: make(map[string]int),
keychain: keychain, keychain: keychain,
} }
@ -60,7 +60,7 @@ func NewACLListStorageBuilderFromFile(file string) (*ACLListStorageBuilder, erro
return tb, nil return tb, nil
} }
func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte) *aclrecordproto.RawACLRecordWithId { func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte) *aclrecordproto2.RawACLRecordWithId {
protoMarshalled, err := rec.Marshal() protoMarshalled, err := rec.Marshal()
if err != nil { if err != nil {
panic("should be able to marshal final acl message!") panic("should be able to marshal final acl message!")
@ -71,7 +71,7 @@ func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte)
panic("should be able to sign final acl message!") panic("should be able to sign final acl message!")
} }
rawRec := &aclrecordproto.RawACLRecord{ rawRec := &aclrecordproto2.RawACLRecord{
Payload: protoMarshalled, Payload: protoMarshalled,
Signature: signature, Signature: signature,
} }
@ -83,7 +83,7 @@ func (t *ACLListStorageBuilder) createRaw(rec proto.Marshaler, identity []byte)
id, _ := cid.NewCIDFromBytes(rawMarshalled) id, _ := cid.NewCIDFromBytes(rawMarshalled)
return &aclrecordproto.RawACLRecordWithId{ return &aclrecordproto2.RawACLRecordWithId{
Payload: rawMarshalled, Payload: rawMarshalled,
Id: id, Id: id,
} }
@ -101,11 +101,11 @@ func (t *ACLListStorageBuilder) SetHead(headId string) error {
panic("SetHead is not implemented") panic("SetHead is not implemented")
} }
func (t *ACLListStorageBuilder) Root() (*aclrecordproto.RawACLRecordWithId, error) { func (t *ACLListStorageBuilder) Root() (*aclrecordproto2.RawACLRecordWithId, error) {
return t.rawRoot, nil return t.rawRoot, nil
} }
func (t *ACLListStorageBuilder) GetRawRecord(ctx context.Context, id string) (*aclrecordproto.RawACLRecordWithId, error) { func (t *ACLListStorageBuilder) GetRawRecord(ctx context.Context, id string) (*aclrecordproto2.RawACLRecordWithId, error) {
recIdx, ok := t.indexes[id] recIdx, ok := t.indexes[id]
if !ok { if !ok {
if id == t.rawRoot.Id { if id == t.rawRoot.Id {
@ -116,7 +116,7 @@ func (t *ACLListStorageBuilder) GetRawRecord(ctx context.Context, id string) (*a
return t.rawRecords[recIdx], nil return t.rawRecords[recIdx], nil
} }
func (t *ACLListStorageBuilder) AddRawRecord(ctx context.Context, rec *aclrecordproto.RawACLRecordWithId) error { func (t *ACLListStorageBuilder) AddRawRecord(ctx context.Context, rec *aclrecordproto2.RawACLRecordWithId) error {
panic("implement me") panic("implement me")
} }
@ -124,7 +124,7 @@ func (t *ACLListStorageBuilder) ID() (string, error) {
return t.id, nil return t.id, nil
} }
func (t *ACLListStorageBuilder) GetRawRecords() []*aclrecordproto.RawACLRecordWithId { func (t *ACLListStorageBuilder) GetRawRecords() []*aclrecordproto2.RawACLRecordWithId {
return t.rawRecords return t.rawRecords
} }
@ -149,19 +149,19 @@ func (t *ACLListStorageBuilder) Parse(tree *YMLList) {
} }
} }
func (t *ACLListStorageBuilder) parseRecord(rec *Record, prevId string) *aclrecordproto.ACLRecord { func (t *ACLListStorageBuilder) parseRecord(rec *Record, prevId string) *aclrecordproto2.ACLRecord {
k := t.keychain.GetKey(rec.ReadKey).(*SymKey) k := t.keychain.GetKey(rec.ReadKey).(*SymKey)
var aclChangeContents []*aclrecordproto.ACLContentValue var aclChangeContents []*aclrecordproto2.ACLContentValue
for _, ch := range rec.AclChanges { for _, ch := range rec.AclChanges {
aclChangeContent := t.parseACLChange(ch) aclChangeContent := t.parseACLChange(ch)
aclChangeContents = append(aclChangeContents, aclChangeContent) aclChangeContents = append(aclChangeContents, aclChangeContent)
} }
data := &aclrecordproto.ACLData{ data := &aclrecordproto2.ACLData{
AclContent: aclChangeContents, AclContent: aclChangeContents,
} }
bytes, _ := data.Marshal() bytes, _ := data.Marshal()
return &aclrecordproto.ACLRecord{ return &aclrecordproto2.ACLRecord{
PrevId: prevId, PrevId: prevId,
Identity: []byte(t.keychain.GetIdentity(rec.Identity)), Identity: []byte(t.keychain.GetIdentity(rec.Identity)),
Data: bytes, Data: bytes,
@ -170,7 +170,7 @@ func (t *ACLListStorageBuilder) parseRecord(rec *Record, prevId string) *aclreco
} }
} }
func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecordproto.ACLContentValue) { func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecordproto2.ACLContentValue) {
switch { switch {
case ch.UserAdd != nil: case ch.UserAdd != nil:
add := ch.UserAdd add := ch.UserAdd
@ -178,9 +178,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
encKey := t.keychain.GetKey(add.EncryptionKey).(encryptionkey.PrivKey) encKey := t.keychain.GetKey(add.EncryptionKey).(encryptionkey.PrivKey)
rawKey, _ := encKey.GetPublic().Raw() rawKey, _ := encKey.GetPublic().Raw()
convCh = &aclrecordproto.ACLContentValue{ convCh = &aclrecordproto2.ACLContentValue{
Value: &aclrecordproto.ACLContentValue_UserAdd{ Value: &aclrecordproto2.ACLContentValue_UserAdd{
UserAdd: &aclrecordproto.ACLUserAdd{ UserAdd: &aclrecordproto2.ACLUserAdd{
Identity: []byte(t.keychain.GetIdentity(add.Identity)), Identity: []byte(t.keychain.GetIdentity(add.Identity)),
EncryptionKey: rawKey, EncryptionKey: rawKey,
EncryptedReadKeys: t.encryptReadKeys(add.EncryptedReadKeys, encKey), EncryptedReadKeys: t.encryptReadKeys(add.EncryptedReadKeys, encKey),
@ -202,9 +202,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
panic(err) panic(err)
} }
convCh = &aclrecordproto.ACLContentValue{ convCh = &aclrecordproto2.ACLContentValue{
Value: &aclrecordproto.ACLContentValue_UserJoin{ Value: &aclrecordproto2.ACLContentValue_UserJoin{
UserJoin: &aclrecordproto.ACLUserJoin{ UserJoin: &aclrecordproto2.ACLUserJoin{
Identity: []byte(t.keychain.GetIdentity(join.Identity)), Identity: []byte(t.keychain.GetIdentity(join.Identity)),
EncryptionKey: rawKey, EncryptionKey: rawKey,
AcceptSignature: signature, AcceptSignature: signature,
@ -220,9 +220,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
GetKey(invite.EncryptionKey).(encryptionkey.PrivKey) GetKey(invite.EncryptionKey).(encryptionkey.PrivKey)
rawEncKey, _ := encKey.GetPublic().Raw() rawEncKey, _ := encKey.GetPublic().Raw()
convCh = &aclrecordproto.ACLContentValue{ convCh = &aclrecordproto2.ACLContentValue{
Value: &aclrecordproto.ACLContentValue_UserInvite{ Value: &aclrecordproto2.ACLContentValue_UserInvite{
UserInvite: &aclrecordproto.ACLUserInvite{ UserInvite: &aclrecordproto2.ACLUserInvite{
AcceptPublicKey: rawAcceptKey, AcceptPublicKey: rawAcceptKey,
EncryptPublicKey: rawEncKey, EncryptPublicKey: rawEncKey,
EncryptedReadKeys: t.encryptReadKeys(invite.EncryptedReadKeys, encKey), EncryptedReadKeys: t.encryptReadKeys(invite.EncryptedReadKeys, encKey),
@ -234,9 +234,9 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
case ch.UserPermissionChange != nil: case ch.UserPermissionChange != nil:
permissionChange := ch.UserPermissionChange permissionChange := ch.UserPermissionChange
convCh = &aclrecordproto.ACLContentValue{ convCh = &aclrecordproto2.ACLContentValue{
Value: &aclrecordproto.ACLContentValue_UserPermissionChange{ Value: &aclrecordproto2.ACLContentValue_UserPermissionChange{
UserPermissionChange: &aclrecordproto.ACLUserPermissionChange{ UserPermissionChange: &aclrecordproto2.ACLUserPermissionChange{
Identity: []byte(t.keychain.GetIdentity(permissionChange.Identity)), Identity: []byte(t.keychain.GetIdentity(permissionChange.Identity)),
Permissions: t.convertPermission(permissionChange.Permission), Permissions: t.convertPermission(permissionChange.Permission),
}, },
@ -247,7 +247,7 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
newReadKey := t.keychain.GetKey(remove.NewReadKey).(*SymKey) newReadKey := t.keychain.GetKey(remove.NewReadKey).(*SymKey)
var replaces []*aclrecordproto.ACLReadKeyReplace var replaces []*aclrecordproto2.ACLReadKeyReplace
for _, id := range remove.IdentitiesLeft { for _, id := range remove.IdentitiesLeft {
encKey := t.keychain.EncryptionKeysByYAMLIdentity[id] encKey := t.keychain.EncryptionKeysByYAMLIdentity[id]
rawEncKey, _ := encKey.GetPublic().Raw() rawEncKey, _ := encKey.GetPublic().Raw()
@ -255,16 +255,16 @@ func (t *ACLListStorageBuilder) parseACLChange(ch *ACLChange) (convCh *aclrecord
if err != nil { if err != nil {
panic(err) panic(err)
} }
replaces = append(replaces, &aclrecordproto.ACLReadKeyReplace{ replaces = append(replaces, &aclrecordproto2.ACLReadKeyReplace{
Identity: []byte(t.keychain.GetIdentity(id)), Identity: []byte(t.keychain.GetIdentity(id)),
EncryptionKey: rawEncKey, EncryptionKey: rawEncKey,
EncryptedReadKey: encReadKey, EncryptedReadKey: encReadKey,
}) })
} }
convCh = &aclrecordproto.ACLContentValue{ convCh = &aclrecordproto2.ACLContentValue{
Value: &aclrecordproto.ACLContentValue_UserRemove{ Value: &aclrecordproto2.ACLContentValue_UserRemove{
UserRemove: &aclrecordproto.ACLUserRemove{ UserRemove: &aclrecordproto2.ACLUserRemove{
Identity: []byte(t.keychain.GetIdentity(remove.RemovedIdentity)), Identity: []byte(t.keychain.GetIdentity(remove.RemovedIdentity)),
ReadKeyReplaces: replaces, ReadKeyReplaces: replaces,
}, },
@ -291,20 +291,20 @@ func (t *ACLListStorageBuilder) encryptReadKeys(keys []string, encKey encryption
return return
} }
func (t *ACLListStorageBuilder) convertPermission(perm string) aclrecordproto.ACLUserPermissions { func (t *ACLListStorageBuilder) convertPermission(perm string) aclrecordproto2.ACLUserPermissions {
switch perm { switch perm {
case "admin": case "admin":
return aclrecordproto.ACLUserPermissions_Admin return aclrecordproto2.ACLUserPermissions_Admin
case "writer": case "writer":
return aclrecordproto.ACLUserPermissions_Writer return aclrecordproto2.ACLUserPermissions_Writer
case "reader": case "reader":
return aclrecordproto.ACLUserPermissions_Reader return aclrecordproto2.ACLUserPermissions_Reader
default: default:
panic(fmt.Sprintf("incorrect permission: %s", perm)) panic(fmt.Sprintf("incorrect permission: %s", perm))
} }
} }
func (t *ACLListStorageBuilder) traverseFromHead(f func(rec *aclrecordproto.ACLRecord, id string) error) (err error) { func (t *ACLListStorageBuilder) traverseFromHead(f func(rec *aclrecordproto2.ACLRecord, id string) error) (err error) {
for i := len(t.records) - 1; i >= 0; i-- { for i := len(t.records) - 1; i >= 0; i-- {
err = f(t.records[i], t.rawRecords[i].Id) err = f(t.records[i], t.rawRecords[i].Id)
if err != nil { if err != nil {
@ -317,10 +317,10 @@ func (t *ACLListStorageBuilder) traverseFromHead(f func(rec *aclrecordproto.ACLR
func (t *ACLListStorageBuilder) parseRoot(root *Root) { func (t *ACLListStorageBuilder) parseRoot(root *Root) {
rawSignKey, _ := t.keychain.SigningKeysByYAMLIdentity[root.Identity].GetPublic().Raw() rawSignKey, _ := t.keychain.SigningKeysByYAMLIdentity[root.Identity].GetPublic().Raw()
rawEncKey, _ := t.keychain.EncryptionKeysByYAMLIdentity[root.Identity].GetPublic().Raw() rawEncKey, _ := t.keychain.EncryptionKeysByYAMLIdentity[root.Identity].GetPublic().Raw()
readKey, _ := aclrecordproto.ACLReadKeyDerive(rawSignKey, rawEncKey) readKey, _ := aclrecordproto2.ACLReadKeyDerive(rawSignKey, rawEncKey)
hasher := fnv.New64() hasher := fnv.New64()
hasher.Write(readKey.Bytes()) hasher.Write(readKey.Bytes())
t.root = &aclrecordproto.ACLRoot{ t.root = &aclrecordproto2.ACLRoot{
Identity: rawSignKey, Identity: rawSignKey,
EncryptionKey: rawEncKey, EncryptionKey: rawEncKey,
SpaceId: root.SpaceId, SpaceId: root.SpaceId,

View File

@ -9,8 +9,7 @@ package acllistbuilder
import ( import (
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"strings" "strings"
"unicode" "unicode"

View File

@ -2,7 +2,7 @@ package tree
import ( import (
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
) )
var ( var (

View File

@ -2,11 +2,11 @@ package tree
import ( import (
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/cid" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/cid"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"time" "time"
) )

View File

@ -2,15 +2,15 @@ package tree
import ( import (
"fmt" "fmt"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" list2 "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 list.ACLList) error ValidateFullTree(tree *Tree, aclList list2.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 list.ACLList, newChanges []*Change) error ValidateNewChanges(tree *Tree, aclList list2.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 list.ACLList) (err error) { func (v *objectTreeValidator) ValidateFullTree(tree *Tree, aclList list2.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 list.ACLList)
return err return err
} }
func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list.ACLList, newChanges []*Change) (err error) { func (v *objectTreeValidator) ValidateNewChanges(tree *Tree, aclList list2.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 list.ACLLis
return return
} }
func (v *objectTreeValidator) validateChange(tree *Tree, aclList list.ACLList, c *Change) (err error) { func (v *objectTreeValidator) validateChange(tree *Tree, aclList list2.ACLList, c *Change) (err error) {
var ( var (
perm list.UserPermissionPair perm list2.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 list.ACLList, c
} }
if perm.Permission != aclrecordproto.ACLUserPermissions_Writer && perm.Permission != aclrecordproto.ACLUserPermissions_Admin { if perm.Permission != aclrecordproto.ACLUserPermissions_Writer && perm.Permission != aclrecordproto.ACLUserPermissions_Admin {
err = list.ErrInsufficientPermissions err = list2.ErrInsufficientPermissions
return return
} }

View File

@ -6,11 +6,11 @@ package mock_tree
import ( import (
context "context" context "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
tree2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/tree"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
reflect "reflect" reflect "reflect"
storage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
tree "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
treechangeproto "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
gomock "github.com/golang/mock/gomock" gomock "github.com/golang/mock/gomock"
) )
@ -38,10 +38,10 @@ func (m *MockObjectTree) EXPECT() *MockObjectTreeMockRecorder {
} }
// AddContent mocks base method. // AddContent mocks base method.
func (m *MockObjectTree) AddContent(arg0 context.Context, arg1 tree.SignableChangeContent) (tree.AddResult, error) { func (m *MockObjectTree) AddContent(arg0 context.Context, arg1 tree2.SignableChangeContent) (tree2.AddResult, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AddContent", arg0, arg1) ret := m.ctrl.Call(m, "AddContent", arg0, arg1)
ret0, _ := ret[0].(tree.AddResult) ret0, _ := ret[0].(tree2.AddResult)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@ -53,14 +53,14 @@ func (mr *MockObjectTreeMockRecorder) AddContent(arg0, arg1 interface{}) *gomock
} }
// AddRawChanges mocks base method. // AddRawChanges mocks base method.
func (m *MockObjectTree) AddRawChanges(arg0 context.Context, arg1 ...*treechangeproto.RawTreeChangeWithId) (tree.AddResult, error) { func (m *MockObjectTree) AddRawChanges(arg0 context.Context, arg1 ...*treechangeproto.RawTreeChangeWithId) (tree2.AddResult, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{arg0} varargs := []interface{}{arg0}
for _, a := range arg1 { for _, a := range arg1 {
varargs = append(varargs, a) varargs = append(varargs, a)
} }
ret := m.ctrl.Call(m, "AddRawChanges", varargs...) ret := m.ctrl.Call(m, "AddRawChanges", varargs...)
ret0, _ := ret[0].(tree.AddResult) ret0, _ := ret[0].(tree2.AddResult)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@ -177,7 +177,7 @@ func (mr *MockObjectTreeMockRecorder) ID() *gomock.Call {
} }
// Iterate mocks base method. // Iterate mocks base method.
func (m *MockObjectTree) Iterate(arg0 func([]byte) (interface{}, error), arg1 func(*tree.Change) bool) error { func (m *MockObjectTree) Iterate(arg0 func([]byte) (interface{}, error), arg1 func(*tree2.Change) bool) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Iterate", arg0, arg1) ret := m.ctrl.Call(m, "Iterate", arg0, arg1)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@ -191,7 +191,7 @@ func (mr *MockObjectTreeMockRecorder) Iterate(arg0, arg1 interface{}) *gomock.Ca
} }
// IterateFrom mocks base method. // IterateFrom mocks base method.
func (m *MockObjectTree) IterateFrom(arg0 string, arg1 func([]byte) (interface{}, error), arg2 func(*tree.Change) bool) error { func (m *MockObjectTree) IterateFrom(arg0 string, arg1 func([]byte) (interface{}, error), arg2 func(*tree2.Change) bool) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IterateFrom", arg0, arg1, arg2) ret := m.ctrl.Call(m, "IterateFrom", arg0, arg1, arg2)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@ -241,10 +241,10 @@ func (mr *MockObjectTreeMockRecorder) RUnlock() *gomock.Call {
} }
// Root mocks base method. // Root mocks base method.
func (m *MockObjectTree) Root() *tree.Change { func (m *MockObjectTree) Root() *tree2.Change {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Root") ret := m.ctrl.Call(m, "Root")
ret0, _ := ret[0].(*tree.Change) ret0, _ := ret[0].(*tree2.Change)
return ret0 return ret0
} }

View File

@ -4,11 +4,11 @@ package tree
import ( import (
"context" "context"
"errors" "errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/common" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/common"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" list2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"sync" "sync"
) )
@ -66,7 +66,7 @@ type objectTree struct {
validator ObjectTreeValidator validator ObjectTreeValidator
rawChangeLoader *rawChangeLoader rawChangeLoader *rawChangeLoader
treeBuilder *treeBuilder treeBuilder *treeBuilder
aclList list.ACLList aclList list2.ACLList
id string id string
root *treechangeproto.RawTreeChangeWithId root *treechangeproto.RawTreeChangeWithId
@ -91,13 +91,13 @@ type objectTreeDeps struct {
treeStorage storage.TreeStorage treeStorage storage.TreeStorage
validator ObjectTreeValidator validator ObjectTreeValidator
rawChangeLoader *rawChangeLoader rawChangeLoader *rawChangeLoader
aclList list.ACLList aclList list2.ACLList
} }
func defaultObjectTreeDeps( func defaultObjectTreeDeps(
rootChange *treechangeproto.RawTreeChangeWithId, rootChange *treechangeproto.RawTreeChangeWithId,
treeStorage storage.TreeStorage, treeStorage storage.TreeStorage,
aclList list.ACLList) objectTreeDeps { aclList list2.ACLList) objectTreeDeps {
keychain := common.NewKeychain() keychain := common.NewKeychain()
changeBuilder := newChangeBuilder(keychain, rootChange) changeBuilder := newChangeBuilder(keychain, rootChange)
@ -449,7 +449,7 @@ func (ot *objectTree) IterateFrom(id string, convert ChangeConvertFunc, iterate
} }
readKey, exists := ot.keys[c.ReadKeyHash] readKey, exists := ot.keys[c.ReadKeyHash]
if !exists { if !exists {
err = list.ErrNoReadKey err = list2.ErrNoReadKey
return false return false
} }

View File

@ -2,10 +2,10 @@ package tree
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/testutils/acllistbuilder" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/testutils/acllistbuilder"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing" "testing"
@ -53,9 +53,9 @@ func (c *mockChangeCreator) createRaw(id, aclId, snapshotId string, isSnapshot b
} }
} }
func (c *mockChangeCreator) createNewTreeStorage(treeId, aclHeadId string) storage.TreeStorage { func (c *mockChangeCreator) createNewTreeStorage(treeId, aclHeadId string) storage2.TreeStorage {
root := c.createRoot(treeId, aclHeadId) root := c.createRoot(treeId, aclHeadId)
treeStorage, _ := storage.NewInMemoryTreeStorage(treeId, root, []string{root.Id}, []*treechangeproto.RawTreeChangeWithId{root}) treeStorage, _ := storage2.NewInMemoryTreeStorage(treeId, root, []string{root.Id}, []*treechangeproto.RawTreeChangeWithId{root})
return treeStorage return treeStorage
} }
@ -95,7 +95,7 @@ func (m *mockChangeValidator) ValidateFullTree(tree *Tree, aclList list.ACLList)
type testTreeContext struct { type testTreeContext struct {
aclList list.ACLList aclList list.ACLList
treeStorage storage.TreeStorage treeStorage storage2.TreeStorage
changeBuilder *mockChangeBuilder changeBuilder *mockChangeBuilder
changeCreator *mockChangeCreator changeCreator *mockChangeCreator
objTree ObjectTree objTree ObjectTree

View File

@ -1,12 +1,12 @@
package tree package tree
import ( import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/list"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" storage2 "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/asymmetric/signingkey" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys/symmetric" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/keys/symmetric"
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/slice" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/util/slice"
"go.uber.org/zap" "go.uber.org/zap"
"math/rand" "math/rand"
"time" "time"
@ -19,7 +19,7 @@ type ObjectTreeCreatePayload struct {
Identity []byte Identity []byte
} }
func BuildObjectTree(treeStorage storage.TreeStorage, aclList list.ACLList) (ObjectTree, error) { func BuildObjectTree(treeStorage storage2.TreeStorage, aclList list.ACLList) (ObjectTree, error) {
rootChange, err := treeStorage.Root() rootChange, err := treeStorage.Root()
if err != nil { if err != nil {
return nil, err return nil, err
@ -31,14 +31,14 @@ func BuildObjectTree(treeStorage storage.TreeStorage, aclList list.ACLList) (Obj
func CreateDerivedObjectTree( func CreateDerivedObjectTree(
payload ObjectTreeCreatePayload, payload ObjectTreeCreatePayload,
aclList list.ACLList, aclList list.ACLList,
createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { createStorage storage2.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
return createObjectTree(payload, 0, nil, aclList, createStorage) return createObjectTree(payload, 0, nil, aclList, createStorage)
} }
func CreateObjectTree( func CreateObjectTree(
payload ObjectTreeCreatePayload, payload ObjectTreeCreatePayload,
aclList list.ACLList, aclList list.ACLList,
createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { createStorage storage2.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
bytes := make([]byte, 32) bytes := make([]byte, 32)
_, err = rand.Read(bytes) _, err = rand.Read(bytes)
if err != nil { if err != nil {
@ -52,7 +52,7 @@ func createObjectTree(
timestamp int64, timestamp int64,
seed []byte, seed []byte,
aclList list.ACLList, aclList list.ACLList,
createStorage storage.TreeStorageCreatorFunc) (objTree ObjectTree, err error) { createStorage storage2.TreeStorageCreatorFunc) (objTree ObjectTree, err error) {
aclList.RLock() aclList.RLock()
var ( var (
deps = defaultObjectTreeDeps(nil, nil, aclList) deps = defaultObjectTreeDeps(nil, nil, aclList)
@ -80,7 +80,7 @@ func createObjectTree(
deps.changeBuilder.SetRootRawChange(raw) deps.changeBuilder.SetRootRawChange(raw)
// create storage // create storage
st, err := createStorage(storage.TreeStorageCreatePayload{ st, err := createStorage(storage2.TreeStorageCreatePayload{
TreeId: raw.Id, TreeId: raw.Id,
RootRawChange: raw, RootRawChange: raw,
Changes: []*treechangeproto.RawTreeChangeWithId{raw}, Changes: []*treechangeproto.RawTreeChangeWithId{raw},

View File

@ -2,8 +2,8 @@ package tree
import ( import (
"context" "context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto" "github.com/anytypeio/go-anytype-infrastructure-experiments/common/pkg/acl/treechangeproto"
"time" "time"
) )

Some files were not shown because too many files have changed in this diff Show More