mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-10 01:51:11 +09:00
configuration from config
This commit is contained in:
parent
8a058b8b23
commit
fe2c8bdade
4 changed files with 70 additions and 23 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/account"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/account"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/api"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/api"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/configuration"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/dialer"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/dialer"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/pool"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/pool"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/rpc/server"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/rpc/server"
|
||||||
|
@ -97,7 +98,7 @@ func Bootstrap(a *app.App) {
|
||||||
Register(server.New()).
|
Register(server.New()).
|
||||||
Register(dialer.New()).
|
Register(dialer.New()).
|
||||||
Register(pool.NewPool()).
|
Register(pool.NewPool()).
|
||||||
//Register(&example.Example{})
|
Register(configuration.New()).
|
||||||
Register(document.New()).
|
Register(document.New()).
|
||||||
Register(message.New()).
|
Register(message.New()).
|
||||||
Register(requesthandler.New()).
|
Register(requesthandler.New()).
|
||||||
|
|
|
@ -3,10 +3,36 @@ package configuration
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/peer"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/peer"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/pool"
|
||||||
|
"github.com/anytypeio/go-chash"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func New() Service {
|
||||||
|
return new(service)
|
||||||
|
}
|
||||||
|
|
||||||
type Configuration interface {
|
type Configuration interface {
|
||||||
Id() string
|
Id() string
|
||||||
AllPeers(ctx context.Context, spaceId string) (peers []peer.Peer, err error)
|
AllPeers(ctx context.Context, spaceId string) (peers []peer.Peer, err error)
|
||||||
OnePeer(ctx context.Context, spaceId string) (p peer.Peer, err error)
|
OnePeer(ctx context.Context, spaceId string) (p peer.Peer, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type configuration struct {
|
||||||
|
id string
|
||||||
|
pool pool.Pool
|
||||||
|
chash chash.CHash
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configuration) Id() string {
|
||||||
|
return c.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configuration) AllPeers(ctx context.Context, spaceId string) (peers []peer.Peer, err error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configuration) OnePeer(ctx context.Context, spaceId string) (p peer.Peer, err error) {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@ import (
|
||||||
"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/service/net/peer"
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/pool"
|
||||||
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/node"
|
||||||
|
"github.com/anytypeio/go-chash"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CName = "configuration"
|
const CName = "configuration"
|
||||||
|
@ -20,41 +22,51 @@ var log = logger.NewNamed(CName)
|
||||||
type Service interface {
|
type Service interface {
|
||||||
GetLast() Configuration
|
GetLast() Configuration
|
||||||
GetById(id string) Configuration
|
GetById(id string) Configuration
|
||||||
app.ComponentRunnable
|
app.Component
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
accountId string
|
accountId string
|
||||||
bootstrapConfig []config.Node
|
pool pool.Pool
|
||||||
|
|
||||||
|
last Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Init(ctx context.Context, a *app.App) (err error) {
|
func (s *service) Init(ctx context.Context, a *app.App) (err error) {
|
||||||
conf := a.MustComponent(config.CName).(*config.Config)
|
conf := a.MustComponent(config.CName).(*config.Config)
|
||||||
s.bootstrapConfig = conf.Nodes
|
|
||||||
s.accountId = conf.Account.PeerId
|
s.accountId = conf.Account.PeerId
|
||||||
|
s.pool = a.MustComponent(pool.CName).(pool.Pool)
|
||||||
return nil
|
configNodes := a.MustComponent(node.CName).(node.Service).Nodes()
|
||||||
|
config := &configuration{
|
||||||
|
id: "config",
|
||||||
|
pool: s.pool,
|
||||||
|
}
|
||||||
|
if config.chash, err = chash.New(chash.Config{
|
||||||
|
PartitionCount: partitionCount,
|
||||||
|
ReplicationFactor: replicationFactor,
|
||||||
|
}); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
members := make([]chash.Member, 0, len(configNodes))
|
||||||
|
for _, n := range configNodes {
|
||||||
|
members = append(members, n)
|
||||||
|
}
|
||||||
|
if err = config.chash.AddMembers(members...); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.last = config
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) Name() (name string) {
|
func (s *service) Name() (name string) {
|
||||||
return CName
|
return CName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) AllPeers(ctx context.Context, spaceId string) (peers []peer.Peer, err error) {
|
func (s *service) GetLast() Configuration {
|
||||||
|
return s.last
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *service) GetById(id string) Configuration {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *service) OnePeer(ctx context.Context, spaceId string) (p peer.Peer, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Run(ctx context.Context) (err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *service) Close(ctx context.Context) (err error) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,6 +24,14 @@ type Node struct {
|
||||||
EncryptionKeyString string
|
EncryptionKeyString string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) Id() string {
|
||||||
|
return n.PeerId
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) Capacity() float64 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
func New() app.Component {
|
func New() app.Component {
|
||||||
return &service{}
|
return &service{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue