1
0
Fork 0
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:
Sergey Cherepanov 2022-08-24 00:40:14 +03:00 committed by Mikhail Iudin
parent 8a058b8b23
commit fe2c8bdade
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
4 changed files with 70 additions and 23 deletions

View file

@ -9,6 +9,7 @@ import (
"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/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/pool"
"github.com/anytypeio/go-anytype-infrastructure-experiments/service/net/rpc/server"
@ -97,7 +98,7 @@ func Bootstrap(a *app.App) {
Register(server.New()).
Register(dialer.New()).
Register(pool.NewPool()).
//Register(&example.Example{})
Register(configuration.New()).
Register(document.New()).
Register(message.New()).
Register(requesthandler.New()).

View file

@ -3,10 +3,36 @@ package configuration
import (
"context"
"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 {
Id() string
AllPeers(ctx context.Context, spaceId string) (peers []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")
}

View file

@ -5,7 +5,9 @@ import (
"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/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"
@ -20,41 +22,51 @@ var log = logger.NewNamed(CName)
type Service interface {
GetLast() Configuration
GetById(id string) Configuration
app.ComponentRunnable
app.Component
}
type service struct {
accountId string
bootstrapConfig []config.Node
pool pool.Pool
last Configuration
}
func (s *service) Init(ctx context.Context, a *app.App) (err error) {
conf := a.MustComponent(config.CName).(*config.Config)
s.bootstrapConfig = conf.Nodes
s.accountId = conf.Account.PeerId
return nil
s.pool = a.MustComponent(pool.CName).(pool.Pool)
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) {
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
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
}

View file

@ -24,6 +24,14 @@ type Node struct {
EncryptionKeyString string
}
func (n *Node) Id() string {
return n.PeerId
}
func (n *Node) Capacity() float64 {
return 1
}
func New() app.Component {
return &service{}
}