Change account logic and add space objects
This commit is contained in:
parent
67f0b82ae4
commit
c111257f63
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
|
||||||
"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/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"
|
||||||
@ -14,6 +13,7 @@ import (
|
|||||||
"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/config"
|
||||||
|
"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"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|||||||
@ -2,73 +2,12 @@ package account
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/account"
|
||||||
"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"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const CName = "account"
|
const CName = "common.account"
|
||||||
|
|
||||||
type Service interface {
|
type Service interface {
|
||||||
|
app.Component
|
||||||
Account() *account.AccountData
|
Account() *account.AccountData
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
|
||||||
accountData *account.AccountData
|
|
||||||
peerId string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Account() *account.AccountData {
|
|
||||||
return s.accountData
|
|
||||||
}
|
|
||||||
|
|
||||||
type StaticAccount struct {
|
|
||||||
SigningKey string `yaml:"signingKey"`
|
|
||||||
EncryptionKey string `yaml:"encryptionKey"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func New() app.Component {
|
|
||||||
return &service{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Init(a *app.App) (err error) {
|
|
||||||
cfg := a.MustComponent(config.CName).(*config.Config)
|
|
||||||
// TODO: add deviceKey
|
|
||||||
acc := cfg.Account
|
|
||||||
|
|
||||||
decodedEncryptionKey, err := keys.DecodeKeyFromString(
|
|
||||||
acc.EncryptionKey,
|
|
||||||
encryptionkey.NewEncryptionRsaPrivKeyFromBytes,
|
|
||||||
nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
decodedSigningKey, err := keys.DecodeKeyFromString(
|
|
||||||
acc.SigningKey,
|
|
||||||
signingkey.NewSigningEd25519PrivKeyFromBytes,
|
|
||||||
nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
identity, err := decodedSigningKey.GetPublic().Raw()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
s.accountData = &account.AccountData{
|
|
||||||
Identity: identity,
|
|
||||||
SignKey: decodedSigningKey,
|
|
||||||
EncKey: decodedEncryptionKey,
|
|
||||||
}
|
|
||||||
s.peerId = acc.PeerId
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Name() (name string) {
|
|
||||||
return CName
|
|
||||||
}
|
|
||||||
|
|||||||
@ -51,7 +51,6 @@ func (s *service) CreateSpace(ctx context.Context, id string, deps SpaceDeps) (S
|
|||||||
syncService := syncservice.NewSyncService(id, diffService, deps.Cache, lastConfiguration)
|
syncService := syncservice.NewSyncService(id, diffService, deps.Cache, lastConfiguration)
|
||||||
sp := &space{
|
sp := &space{
|
||||||
id: id,
|
id: id,
|
||||||
conf: s.config,
|
|
||||||
syncService: syncService,
|
syncService: syncService,
|
||||||
diffService: diffService,
|
diffService: diffService,
|
||||||
cache: deps.Cache,
|
cache: deps.Cache,
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import (
|
|||||||
"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"
|
||||||
"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/config"
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/list"
|
||||||
treestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
treestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
|
||||||
@ -29,9 +28,8 @@ type Space interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type space struct {
|
type space struct {
|
||||||
id string
|
id string
|
||||||
conf config.Space
|
mu sync.RWMutex
|
||||||
mu sync.RWMutex
|
|
||||||
|
|
||||||
rpc *rpcHandler
|
rpc *rpcHandler
|
||||||
|
|
||||||
@ -46,9 +44,13 @@ func (s *space) Id() string {
|
|||||||
return s.id
|
return s.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *space) Init(ctx context.Context) error {
|
func (s *space) Init(ctx context.Context) (err error) {
|
||||||
s.rpc = &rpcHandler{s: s}
|
s.rpc = &rpcHandler{s: s}
|
||||||
s.diffService.Init(s.getObjectIds())
|
initialIds, err := s.storage.StoredIds()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.diffService.Init(initialIds)
|
||||||
s.syncService.Init()
|
s.syncService.Init()
|
||||||
// basically this provides access for the external cache to use space's tree building functions
|
// basically this provides access for the external cache to use space's tree building functions
|
||||||
s.cache.SetBuildFunc(s.BuildTree)
|
s.cache.SetBuildFunc(s.BuildTree)
|
||||||
@ -119,11 +121,6 @@ func (s *space) BuildTree(ctx context.Context, id string, listener synctree.Upda
|
|||||||
return synctree.BuildSyncTree(ctx, s.syncService, store.(treestorage.TreeStorage), listener, s.aclList)
|
return synctree.BuildSyncTree(ctx, s.syncService, store.(treestorage.TreeStorage), listener, s.aclList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *space) getObjectIds() []string {
|
|
||||||
// TODO: add space object logic
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *space) Close() error {
|
func (s *space) Close() error {
|
||||||
s.diffService.Close()
|
s.diffService.Close()
|
||||||
s.cache.Close()
|
s.cache.Close()
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
package spacetree
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SpaceTree interface {
|
|
||||||
cache.TreeContainer
|
|
||||||
ID() string
|
|
||||||
GetObjectIds() []string
|
|
||||||
Sync()
|
|
||||||
}
|
|
||||||
|
|
||||||
type spaceTree struct{}
|
|
||||||
|
|
||||||
func (s *spaceTree) Tree() tree.ObjectTree {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *spaceTree) ID() string {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *spaceTree) GetObjectIds() []string {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *spaceTree) Sync() {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSpaceTree(id string) (SpaceTree, error) {
|
|
||||||
return &spaceTree{}, nil
|
|
||||||
}
|
|
||||||
@ -4,8 +4,9 @@ import (
|
|||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const CName = "commonspace.storage"
|
||||||
|
|
||||||
type Storage interface {
|
type Storage interface {
|
||||||
storage.Provider
|
storage.Provider
|
||||||
|
StoredIds() ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CName = "commonspace.storage"
|
|
||||||
|
|||||||
@ -2,13 +2,11 @@ package secure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||||
"github.com/libp2p/go-libp2p-core/crypto"
|
"github.com/libp2p/go-libp2p-core/crypto"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
"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"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -45,28 +43,6 @@ func (s *service) Init(a *app.App) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pid, err := peer.Decode(account.PeerId)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var testData = []byte("test data")
|
|
||||||
sign, err := s.key.Sign(testData)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pubKey, err := pid.ExtractPublicKey()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ok, err := pubKey.Verify(testData, sign)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("peerId and privateKey mismatched")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("secure service init", zap.String("peerId", account.PeerId))
|
log.Info("secure service init", zap.String("peerId", account.PeerId))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
63
node/account/service.go
Normal file
63
node/account/service.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||||
|
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/pkg/acl/account"
|
||||||
|
"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"
|
||||||
|
)
|
||||||
|
|
||||||
|
type service struct {
|
||||||
|
accountData *account.AccountData
|
||||||
|
peerId string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Account() *account.AccountData {
|
||||||
|
return s.accountData
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() app.Component {
|
||||||
|
return &service{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Init(a *app.App) (err error) {
|
||||||
|
cfg := a.MustComponent(config.CName).(*config.Config)
|
||||||
|
acc := cfg.Account
|
||||||
|
|
||||||
|
decodedEncryptionKey, err := keys.DecodeKeyFromString(
|
||||||
|
acc.EncryptionKey,
|
||||||
|
encryptionkey.NewEncryptionRsaPrivKeyFromBytes,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
decodedSigningKey, err := keys.DecodeKeyFromString(
|
||||||
|
acc.SigningKey,
|
||||||
|
signingkey.NewSigningEd25519PrivKeyFromBytes,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
identity, err := decodedSigningKey.GetPublic().Raw()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.accountData = &account.AccountData{
|
||||||
|
Identity: identity,
|
||||||
|
SignKey: decodedSigningKey,
|
||||||
|
EncKey: decodedEncryptionKey,
|
||||||
|
}
|
||||||
|
s.peerId = acc.PeerId
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) Name() (name string) {
|
||||||
|
return commonaccount.CName
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ package nodecache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/cache"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ocache"
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var log = logger.NewNamed("treecache")
|
var log = logger.NewNamed("treecache")
|
||||||
|
var ErrCacheObjectWithoutTree = errors.New("cache object contains no tree")
|
||||||
|
|
||||||
type treeCache struct {
|
type treeCache struct {
|
||||||
gcttl int
|
gcttl int
|
||||||
@ -44,11 +46,17 @@ func (c *treeCache) GetTree(ctx context.Context, id string) (res cache.TreeResul
|
|||||||
return cache.TreeResult{}, err
|
return cache.TreeResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
treeContainer, ok := cacheRes.(cache.TreeContainer)
|
||||||
|
if !ok {
|
||||||
|
err = ErrCacheObjectWithoutTree
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
res = cache.TreeResult{
|
res = cache.TreeResult{
|
||||||
Release: func() {
|
Release: func() {
|
||||||
c.cache.Release(id)
|
c.cache.Release(id)
|
||||||
},
|
},
|
||||||
TreeContainer: cacheRes.(cache.TreeContainer),
|
TreeContainer: treeContainer,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user