-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
37 lines (30 loc) · 897 Bytes
/
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
package stream_api_dial
import (
"github.com/aperturerobotics/bifrost/peer"
"github.com/aperturerobotics/bifrost/protocol"
"github.com/aperturerobotics/bifrost/util/confparse"
)
// Validate validates the configuration.
// This is a cursory validation to see if the values "look correct."
func (c *Config) Validate() error {
if c.GetPeerId() == "" {
return peer.ErrEmptyPeerID
}
if _, err := c.ParseLocalPeerID(); 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 constraint.
// may be empty.
func (c *Config) ParseLocalPeerID() (peer.ID, error) {
return confparse.ParsePeerID(c.GetLocalPeerId())
}
// ParsePeerID parses the target peer ID constraint.
func (c *Config) ParsePeerID() (peer.ID, error) {
return confparse.ParsePeerID(c.GetPeerId())
}