diff --git a/coordinator/coordinatorproto/protos/coordinator.proto b/coordinator/coordinatorproto/protos/coordinator.proto index bffe0998..4bfc211b 100644 --- a/coordinator/coordinatorproto/protos/coordinator.proto +++ b/coordinator/coordinatorproto/protos/coordinator.proto @@ -107,15 +107,21 @@ message SpaceStatusChangeResponse { SpaceStatusPayload payload = 1; } -// NetworkConfigurationRequest contains the requested configurationId, it can be empty to request the latest version +// NetworkConfigurationRequest contains currenId of the client configuration, it can be empty message NetworkConfigurationRequest { - string configurationId = 1; + // currenId of the client configuration + // if the currentId is equal to the latest configuration id then the response will not contain a nodes list + string currentId = 1; } // NetworkConfigurationResponse contains list of nodes message NetworkConfigurationResponse { + // id of current configuration string configurationId = 1; + // nodes list - it will be empty if the client's currentId is equal configurationId repeated Node nodes = 2; + // unix timestamp of the creation time of configuration + uint64 creationTimeUnix = 3; } // NodeType determines the type of API that a node supports diff --git a/go.mod b/go.mod index ba9eb925..8a1788c5 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-merkledag v0.10.0 github.com/ipfs/go-unixfs v0.4.5 - github.com/libp2p/go-libp2p v0.24.1 + github.com/libp2p/go-libp2p v0.25.1 github.com/mr-tron/base58 v1.2.0 github.com/multiformats/go-multibase v0.2.0 github.com/multiformats/go-multihash v0.2.1 @@ -37,6 +37,7 @@ require ( golang.org/x/exp v0.0.0-20230206171751-46f607a40771 golang.org/x/net v0.8.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 + gopkg.in/yaml.v2 v2.4.0 storj.io/drpc v0.0.32 ) @@ -59,11 +60,12 @@ require ( github.com/ipfs/go-bitfield v1.1.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect - github.com/ipfs/go-ipfs-files v0.2.0 // indirect + github.com/ipfs/go-ipfs-files v0.3.0 // indirect github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect github.com/ipfs/go-ipfs-util v0.0.2 // indirect github.com/ipfs/go-ipld-cbor v0.0.6 // indirect github.com/ipfs/go-ipld-legacy v0.1.1 // indirect + github.com/ipfs/go-libipfs v0.7.0 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect @@ -72,7 +74,7 @@ require ( github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/cpuid/v2 v2.2.2 // indirect + github.com/klauspost/cpuid/v2 v2.2.3 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-openssl v0.1.0 // indirect github.com/mattn/go-isatty v0.0.17 // indirect @@ -83,7 +85,7 @@ require ( github.com/multiformats/go-base36 v0.2.0 // indirect github.com/multiformats/go-multiaddr v0.8.0 // indirect github.com/multiformats/go-multicodec v0.8.0 // indirect - github.com/multiformats/go-multistream v0.3.3 // indirect + github.com/multiformats/go-multistream v0.4.1 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -94,7 +96,7 @@ require ( github.com/prometheus/procfs v0.9.0 // indirect github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 // indirect + github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect go.opentelemetry.io/otel v1.11.2 // indirect go.opentelemetry.io/otel/trace v1.11.2 // indirect diff --git a/go.sum b/go.sum index 2120dbdc..73d1b08f 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,8 @@ github.com/ipfs/go-ipfs-exchange-interface v0.2.0/go.mod h1:z6+RhJuDQbqKguVyslSO github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA= github.com/ipfs/go-ipfs-files v0.2.0 h1:z6MCYHQSZpDWpUSK59Kf0ajP1fi4gLCf6fIulVsp8A8= github.com/ipfs/go-ipfs-files v0.2.0/go.mod h1:vT7uaQfIsprKktzbTPLnIsd+NGw9ZbYwSq0g3N74u0M= +github.com/ipfs/go-ipfs-files v0.3.0 h1:fallckyc5PYjuMEitPNrjRfpwl7YFt69heCOUhsbGxQ= +github.com/ipfs/go-ipfs-files v0.3.0/go.mod h1:xAUtYMwB+iu/dtf6+muHNSFQCJG2dSiStR2P6sn9tIM= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= @@ -134,6 +136,8 @@ github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSg github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc= github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg= +github.com/ipfs/go-libipfs v0.7.0 h1:Mi54WJTODaOL2/ZSm5loi3SwI3jI2OuFWUrQIkJ5cpM= +github.com/ipfs/go-libipfs v0.7.0/go.mod h1:KsIf/03CqhICzyRGyGo68tooiBE2iFbI/rXW7FhAYr0= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= @@ -171,6 +175,7 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.2.2 h1:xPMwiykqNK9VK0NYC3+jTMYv9I6Vl3YdjZgPZKG3zO0= github.com/klauspost/cpuid/v2 v2.2.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/koron/go-ssdp v0.0.3 h1:JivLMY45N76b4p/vsWGOKewBQu6uf39y8l+AQ7sDKx8= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -185,6 +190,7 @@ github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QT github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= github.com/libp2p/go-libp2p v0.24.1 h1:+lS4fqj7RF9egcPq9Yo3iqdRTcDMApzoBbQMhxtwOVw= github.com/libp2p/go-libp2p v0.24.1/go.mod h1:5LJqbrqFsUzWrq70JHCYqjATlX4ey8Klpct3OEe8hSI= +github.com/libp2p/go-libp2p v0.25.1/go.mod h1:xnK9/1d9+jeQCVvi/f1g12KqtVi/jP/SijtKV1hML3g= github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= @@ -239,6 +245,7 @@ github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= github.com/multiformats/go-multistream v0.3.3 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o= github.com/multiformats/go-multistream v0.3.3/go.mod h1:ODRoqamLUsETKS9BNcII4gcRsJBU5VAwRIv7O39cEXg= +github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= @@ -301,6 +308,7 @@ github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvS github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 h1:obKzQ1ey5AJg5NKjgtTo/CKwLImVP4ETLRcsmzFJ4Qw= github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= @@ -442,6 +450,7 @@ gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3M gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/nodeconf/config.go b/nodeconf/config.go index 4fef1fae..1ef1f5ed 100644 --- a/nodeconf/config.go +++ b/nodeconf/config.go @@ -1,5 +1,18 @@ package nodeconf +import ( + "errors" + "time" +) + +type ConfigGetter interface { + GetNodeConf() Configuration +} + +var ( + ErrConfigurationNotFound = errors.New("node nodeConf not found") +) + type NodeType string const ( @@ -10,18 +23,21 @@ const ( NodeTypeCoordinator NodeType = "coordinator" ) -type ConfigGetter interface { - GetNodes() []NodeConfig - GetNodesConfId() string -} - -type NodeConfig struct { +type Node struct { PeerId string `yaml:"peerId"` Addresses []string `yaml:"address"` Types []NodeType `yaml:"types,omitempty"` } -func (n NodeConfig) HasType(t NodeType) bool { +func (n Node) Id() string { + return n.PeerId +} + +func (n Node) Capacity() float64 { + return 1 +} + +func (n Node) HasType(t NodeType) bool { for _, nt := range n.Types { if nt == t { return true @@ -29,3 +45,10 @@ func (n NodeConfig) HasType(t NodeType) bool { } return false } + +type Configuration struct { + Id string `yaml:"id"` + NetworkId string `yaml:"networkId"` + Nodes []Node `yaml:"nodes"` + CreationTime time.Time `yaml:"creationTime"` +} diff --git a/nodeconf/configuration.go b/nodeconf/nodeconf.go similarity index 72% rename from nodeconf/configuration.go rename to nodeconf/nodeconf.go index 121b79fa..c7be0a90 100644 --- a/nodeconf/configuration.go +++ b/nodeconf/nodeconf.go @@ -1,4 +1,4 @@ -//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service,Configuration +//go:generate mockgen -destination mock_nodeconf/mock_nodeconf.go github.com/anytypeio/any-sync/nodeconf Service package nodeconf import ( @@ -6,9 +6,11 @@ import ( "strings" ) -type Configuration interface { +type NodeConf interface { // Id returns current nodeconf id Id() string + // Configuration returns configuration struct + Configuration() Configuration // NodeIds returns list of peerId for given spaceId NodeIds(spaceId string) []string // IsResponsible checks if current account responsible for given spaceId @@ -29,21 +31,26 @@ type Configuration interface { NodeTypes(nodeId string) []NodeType } -type configuration struct { +type nodeConf struct { id string accountId string filePeers []string consensusPeers []string coordinatorPeers []string chash chash.CHash - allMembers []NodeConfig + allMembers []Node + c Configuration } -func (c *configuration) Id() string { +func (c *nodeConf) Id() string { return c.id } -func (c *configuration) NodeIds(spaceId string) []string { +func (c *nodeConf) Configuration() Configuration { + return c.c +} + +func (c *nodeConf) NodeIds(spaceId string) []string { members := c.chash.GetMembers(ReplKey(spaceId)) res := make([]string, 0, len(members)) for _, m := range members { @@ -54,7 +61,7 @@ func (c *configuration) NodeIds(spaceId string) []string { return res } -func (c *configuration) IsResponsible(spaceId string) bool { +func (c *nodeConf) IsResponsible(spaceId string) bool { for _, m := range c.chash.GetMembers(ReplKey(spaceId)) { if m.Id() == c.accountId { return true @@ -63,19 +70,19 @@ func (c *configuration) IsResponsible(spaceId string) bool { return false } -func (c *configuration) FilePeers() []string { +func (c *nodeConf) FilePeers() []string { return c.filePeers } -func (c *configuration) ConsensusPeers() []string { +func (c *nodeConf) ConsensusPeers() []string { return c.consensusPeers } -func (c *configuration) CoordinatorPeers() []string { +func (c *nodeConf) CoordinatorPeers() []string { return c.coordinatorPeers } -func (c *configuration) Addresses() map[string][]string { +func (c *nodeConf) Addresses() map[string][]string { res := make(map[string][]string) for _, m := range c.allMembers { res[m.PeerId] = m.Addresses @@ -83,15 +90,15 @@ func (c *configuration) Addresses() map[string][]string { return res } -func (c *configuration) CHash() chash.CHash { +func (c *nodeConf) CHash() chash.CHash { return c.chash } -func (c *configuration) Partition(spaceId string) (part int) { +func (c *nodeConf) Partition(spaceId string) (part int) { return c.chash.GetPartition(ReplKey(spaceId)) } -func (c *configuration) NodeTypes(nodeId string) []NodeType { +func (c *nodeConf) NodeTypes(nodeId string) []NodeType { for _, m := range c.allMembers { if m.PeerId == nodeId { return m.Types diff --git a/nodeconf/configuration_test.go b/nodeconf/nodeconf_test.go similarity index 98% rename from nodeconf/configuration_test.go rename to nodeconf/nodeconf_test.go index fee5eefb..3d73af80 100644 --- a/nodeconf/configuration_test.go +++ b/nodeconf/nodeconf_test.go @@ -21,7 +21,7 @@ func TestConfiguration_NodeIds(t *testing.T) { ReplicationFactor: ReplicationFactor, }) require.NoError(t, err) - conf := &configuration{ + conf := &nodeConf{ id: "last", accountId: "1", chash: ch, diff --git a/nodeconf/service.go b/nodeconf/service.go index e7fb5907..eb29d70c 100644 --- a/nodeconf/service.go +++ b/nodeconf/service.go @@ -4,9 +4,7 @@ import ( commonaccount "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app/logger" - "github.com/anytypeio/any-sync/util/crypto" "github.com/anytypeio/go-chash" - "github.com/libp2p/go-libp2p/core/peer" "go.uber.org/zap" "sync" ) @@ -25,121 +23,135 @@ func New() Service { } type Service interface { - GetLast() Configuration - SetLastConfig(id string, nodes []NodeConfig) (err error) + NodeConf app.Component } type service struct { accountId string - last Configuration + last NodeConf mu sync.RWMutex } -type Node struct { - Addresses []string - PeerId string - SigningKey crypto.PubKey -} - -func (n *Node) Id() string { - return n.PeerId -} - -func (n *Node) Capacity() float64 { - return 1 -} - func (s *service) Init(a *app.App) (err error) { nodesConf := a.MustComponent("config").(ConfigGetter) s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId - return s.SetLastConfig(nodesConf.GetNodesConfId(), nodesConf.GetNodes()) + return s.setLastConfiguration(nodesConf.GetNodeConf()) } func (s *service) Name() (name string) { return CName } -func (s *service) GetLast() Configuration { - s.mu.RLock() - defer s.mu.RUnlock() - return s.last -} - -func (s *service) SetLastConfig(id string, nodesConf []NodeConfig) (err error) { +func (s *service) setLastConfiguration(c Configuration) (err error) { s.mu.Lock() defer s.mu.Unlock() - if s.last != nil && s.last.Id() == id { + if s.last != nil && s.last.Id() == c.Id { return } - fileConfig := &configuration{ - id: id, + nc := &nodeConf{ + id: c.Id, + c: c, accountId: s.accountId, } - if fileConfig.chash, err = chash.New(chash.Config{ + if nc.chash, err = chash.New(chash.Config{ PartitionCount: PartitionCount, ReplicationFactor: ReplicationFactor, }); err != nil { return } - members := make([]chash.Member, 0, len(nodesConf)) - for _, n := range nodesConf { + members := make([]chash.Member, 0, len(c.Nodes)) + for _, n := range c.Nodes { if n.HasType(NodeTypeTree) { - var member *Node - member, err = nodeFromConfigNode(n) - if err != nil { - return - } - members = append(members, member) + members = append(members, n) } if n.HasType(NodeTypeConsensus) { - fileConfig.consensusPeers = append(fileConfig.consensusPeers, n.PeerId) + nc.consensusPeers = append(nc.consensusPeers, n.PeerId) } if n.HasType(NodeTypeFile) { - fileConfig.filePeers = append(fileConfig.filePeers, n.PeerId) + nc.filePeers = append(nc.filePeers, n.PeerId) } if n.HasType(NodeTypeCoordinator) { - fileConfig.coordinatorPeers = append(fileConfig.coordinatorPeers, n.PeerId) + nc.coordinatorPeers = append(nc.coordinatorPeers, n.PeerId) } - fileConfig.allMembers = append(fileConfig.allMembers, n) + nc.allMembers = append(nc.allMembers, n) } - if err = fileConfig.chash.AddMembers(members...); err != nil { + if err = nc.chash.AddMembers(members...); err != nil { return } var beforeId = "" if s.last != nil { beforeId = s.last.Id() } - log.Info("configuration changed", zap.String("before", beforeId), zap.String("after", fileConfig.Id())) - s.last = fileConfig + log.Info("nodeConf changed", zap.String("before", beforeId), zap.String("after", nc.Id())) + s.last = nc return } -func nodeFromConfigNode(n NodeConfig) (*Node, error) { - p, err := peer.Decode(n.PeerId) - if err != nil { - return nil, err - } - ic, err := p.ExtractPublicKey() - if err != nil { - return nil, err - } - - icRaw, err := ic.Raw() - if err != nil { - return nil, err - } - - sigPubKey, err := crypto.UnmarshalEd25519PublicKey(icRaw) - if err != nil { - return nil, err - } - - return &Node{ - Addresses: n.Addresses, - PeerId: n.PeerId, - SigningKey: sigPubKey, - }, nil +func (s *service) Id() string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Id() +} + +func (s *service) Configuration() Configuration { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Configuration() +} + +func (s *service) NodeIds(spaceId string) []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeIds(spaceId) +} + +func (s *service) IsResponsible(spaceId string) bool { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.IsResponsible(spaceId) +} + +func (s *service) FilePeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.FilePeers() +} + +func (s *service) ConsensusPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.ConsensusPeers() +} + +func (s *service) CoordinatorPeers() []string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CoordinatorPeers() +} + +func (s *service) Addresses() map[string][]string { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Addresses() +} + +func (s *service) CHash() chash.CHash { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.CHash() +} + +func (s *service) Partition(spaceId string) (part int) { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.Partition(spaceId) +} + +func (s *service) NodeTypes(nodeId string) []NodeType { + s.mu.RLock() + defer s.mu.RUnlock() + return s.last.NodeTypes(nodeId) } diff --git a/nodeconf/source.go b/nodeconf/source.go new file mode 100644 index 00000000..85e60aaa --- /dev/null +++ b/nodeconf/source.go @@ -0,0 +1,9 @@ +package nodeconf + +import "context" + +const CNameSource = "common.nodeconf.source" + +type Source interface { + GetLast(ctx context.Context) (c Configuration, err error) +} diff --git a/nodeconf/store.go b/nodeconf/store.go new file mode 100644 index 00000000..70b1e644 --- /dev/null +++ b/nodeconf/store.go @@ -0,0 +1,10 @@ +package nodeconf + +import "context" + +const CNameStore = "common.nodeconf.store" + +type Store interface { + GetLast(ctx context.Context, netId string) (c Configuration, err error) + SaveLast(ctx context.Context, c Configuration) (err error) +} diff --git a/testutil/accounttest/accountservice.go b/testutil/accounttest/accountservice.go index 7aec1c14..3c9f6e11 100644 --- a/testutil/accounttest/accountservice.go +++ b/testutil/accounttest/accountservice.go @@ -5,6 +5,7 @@ import ( "github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/commonspace/object/accountdata" "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/nodeconfstore" "github.com/anytypeio/any-sync/util/crypto" ) @@ -47,8 +48,8 @@ func (s *AccountTestService) Account() *accountdata.AccountKeys { return s.acc } -func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig { - return nodeconf.NodeConfig{ +func (s *AccountTestService) NodeConf(addrs []string) nodeconfstore.NodeConfig { + return nodeconfstore.NodeConfig{ PeerId: s.acc.PeerId, Addresses: addrs, Types: []nodeconf.NodeType{nodeconf.NodeTypeTree}, diff --git a/testutil/testnodeconf/testnodeconf.go b/testutil/testnodeconf/testnodeconf.go index 19b62fcb..118fcfdd 100644 --- a/testutil/testnodeconf/testnodeconf.go +++ b/testutil/testnodeconf/testnodeconf.go @@ -3,7 +3,7 @@ package testnodeconf import ( "github.com/anytypeio/any-sync/accountservice" "github.com/anytypeio/any-sync/app" - "github.com/anytypeio/any-sync/nodeconf" + "github.com/anytypeio/any-sync/nodeconf/nodeconfstore" "github.com/anytypeio/any-sync/testutil/accounttest" ) @@ -24,7 +24,7 @@ func GenNodeConfig(num int) (conf *Config) { } type Config struct { - nodes []nodeconf.NodeConfig + nodes []nodeconfstore.NodeConfig configs []*accounttest.AccountTestService } @@ -35,7 +35,7 @@ func (c *Config) GetNodesConfId() string { return "test" } -func (c *Config) GetNodes() []nodeconf.NodeConfig { +func (c *Config) GetNodes() []nodeconfstore.NodeConfig { return c.nodes }