1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/nodeconf/config.go
2023-04-24 15:04:11 +02:00

58 lines
1 KiB
Go

package nodeconf
import (
"errors"
"time"
)
type ConfigGetter interface {
GetNodeConf() Configuration
}
type ConfigUpdateGetter interface {
GetNodeConfUpdateInterval() int
}
var (
ErrConfigurationNotFound = errors.New("node nodeConf not found")
)
type NodeType string
const (
NodeTypeTree NodeType = "tree"
NodeTypeConsensus NodeType = "consensus"
NodeTypeFile NodeType = "file"
NodeTypeCoordinator NodeType = "coordinator"
)
type Node struct {
PeerId string `yaml:"peerId" bson:"peerId"`
Addresses []string `yaml:"addresses" bson:"addresses"`
Types []NodeType `yaml:"types,omitempty" bson:"types"`
}
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
}
}
return false
}
type Configuration struct {
Id string `yaml:"id"`
NetworkId string `yaml:"networkId"`
Nodes []Node `yaml:"nodes"`
CreationTime time.Time `yaml:"creationTime"`
}