/
config.go
77 lines (68 loc) · 2.2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package signaling_rpc_client
import (
"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/bifrost/protocol"
"github.com/aperturerobotics/bifrost/signaling"
"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.GetSignalingId() == "" {
return signaling.ErrEmptySignalingID
}
if _, err := c.ParsePeerID(); err != nil {
return err
}
if err := c.GetClient().Validate(); err != nil {
return err
}
if _, err := c.ParseProtocolID(); err != nil {
return err
}
if err := c.GetBackoff().Validate(true); err != nil {
return err
}
return nil
}
// ParsePeerID parses the session peer ID.
func (c *Config) ParsePeerID() (peer.ID, error) {
return confparse.ParsePeerID(c.GetPeerId())
}
// ParseProtocolID parses the signaling protocol id if it is not empty.
func (c *Config) ParseProtocolID() (protocol.ID, error) {
return confparse.ParseProtocolID(c.GetProtocolId(), true)
}
// 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 other config is equal.
func (c *Config) EqualsConfig(other config.Config) bool {
return config.EqualsConfig[*Config](c, other)
}
// GetDebugVals returns the directive arguments as key/value pairs.
// This should be something like param1="test", param2="test".
// This is not necessarily unique, and is primarily intended for display.
func (c *Config) GetDebugVals() config.DebugValues {
vals := make(config.DebugValues)
if pid, _ := c.ParsePeerID(); pid != "" {
vals["peer-id"] = []string{pid.String()}
}
if tp := c.GetSignalingId(); tp != "" {
vals["signaling-id"] = []string{tp}
}
if tp := c.GetServiceId(); tp != "" {
vals["service-id"] = []string{tp}
}
if tp := c.GetProtocolId(); tp != "" {
vals["protocol-id"] = []string{tp}
}
return vals
}
// _ is a type assertion
var _ config.Debuggable = ((*Config)(nil))