-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
60 lines (49 loc) · 1.41 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 stream_api_accept
import (
"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/bifrost/protocol"
"github.com/aperturerobotics/bifrost/util/confparse"
"github.com/aperturerobotics/controllerbus/config"
)
// ConfigID is the string used to identify this config object.
const ConfigID = ControllerID
// Validate validates the configuration.
// This is a cursory validation to see if the values "look correct."
func (c *Config) Validate() error {
if c.GetLocalPeerId() != "" {
if _, err := c.ParseLocalPeerID(); err != nil {
return err
}
}
if pids := c.GetRemotePeerIds(); len(pids) != 0 {
for _, pid := range pids {
if _, err := confparse.ParsePeerID(pid); err != nil {
return err
}
}
}
pid := protocol.ID(c.GetProtocolId())
if err := pid.Validate(); err != nil {
return err
}
return nil
}
// ParseLocalPeerID parses the local peer ID.
// may return nil.
func (c *Config) ParseLocalPeerID() (peer.ID, error) {
return confparse.ParsePeerID(c.GetLocalPeerId())
}
// GetConfigID returns the unique string for this configuration type.
// This string is stored with the encoded config.
func (c *Config) GetConfigID() string {
return ConfigID
}
// EqualsConfig checks if the config is equal to another.
func (c *Config) EqualsConfig(other config.Config) bool {
ot, ok := other.(*Config)
if !ok {
return false
}
return ot.EqualVT(c)
}
var _ config.Config = ((*Config)(nil))