-
Notifications
You must be signed in to change notification settings - Fork 44
/
config.go
60 lines (48 loc) · 1.16 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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"
NodeTypeNamingNode NodeType = "namingNode"
NodeTypePaymentProcessingNode NodeType = "paymentProcessingNode"
)
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"`
}