Change account logic and add space objects
This commit is contained in:
parent
60d8ad9879
commit
a377b56fe4
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||
"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/net/dialer"
|
||||
"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/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/nodespace"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
|
||||
@ -2,73 +2,12 @@ package account
|
||||
|
||||
import (
|
||||
"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/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 {
|
||||
app.Component
|
||||
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)
|
||||
sp := &space{
|
||||
id: id,
|
||||
conf: s.config,
|
||||
syncService: syncService,
|
||||
diffService: diffService,
|
||||
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/syncservice"
|
||||
"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"
|
||||
treestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/tree"
|
||||
@ -29,9 +28,8 @@ type Space interface {
|
||||
}
|
||||
|
||||
type space struct {
|
||||
id string
|
||||
conf config.Space
|
||||
mu sync.RWMutex
|
||||
id string
|
||||
mu sync.RWMutex
|
||||
|
||||
rpc *rpcHandler
|
||||
|
||||
@ -46,9 +44,13 @@ func (s *space) Id() string {
|
||||
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.diffService.Init(s.getObjectIds())
|
||||
initialIds, err := s.storage.StoredIds()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s.diffService.Init(initialIds)
|
||||
s.syncService.Init()
|
||||
// basically this provides access for the external cache to use space's tree building functions
|
||||
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)
|
||||
}
|
||||
|
||||
func (s *space) getObjectIds() []string {
|
||||
// TODO: add space object logic
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *space) Close() error {
|
||||
s.diffService.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"
|
||||
)
|
||||
|
||||
const CName = "commonspace.storage"
|
||||
|
||||
type Storage interface {
|
||||
storage.Provider
|
||||
StoredIds() ([]string, error)
|
||||
}
|
||||
|
||||
const CName = "commonspace.storage"
|
||||
|
||||
@ -2,13 +2,11 @@ package secure
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/util/keys"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/sec"
|
||||
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
|
||||
"go.uber.org/zap"
|
||||
@ -45,28 +43,6 @@ func (s *service) Init(a *app.App) (err error) {
|
||||
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))
|
||||
|
||||
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 (
|
||||
"context"
|
||||
"errors"
|
||||
"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/pkg/ocache"
|
||||
@ -9,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var log = logger.NewNamed("treecache")
|
||||
var ErrCacheObjectWithoutTree = errors.New("cache object contains no tree")
|
||||
|
||||
type treeCache struct {
|
||||
gcttl int
|
||||
@ -44,11 +46,17 @@ func (c *treeCache) GetTree(ctx context.Context, id string) (res cache.TreeResul
|
||||
return cache.TreeResult{}, err
|
||||
}
|
||||
|
||||
treeContainer, ok := cacheRes.(cache.TreeContainer)
|
||||
if !ok {
|
||||
err = ErrCacheObjectWithoutTree
|
||||
return
|
||||
}
|
||||
|
||||
res = cache.TreeResult{
|
||||
Release: func() {
|
||||
c.cache.Release(id)
|
||||
},
|
||||
TreeContainer: cacheRes.(cache.TreeContainer),
|
||||
TreeContainer: treeContainer,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user