-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
57 lines (49 loc) · 1.31 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
package gogossip
import (
"errors"
"io/fs"
)
var (
// Assign it to a variable for testing.
errInvalidGossipNumber = errors.New("invalid GossipNumber")
errInvalidFilePath = errors.New("invalid FilterWithStorage")
errInvalidEncryptType = errors.New("invalid EncryptType")
errRequirePassphrase = errors.New("require Passphrase")
)
type Config struct {
// FilterWithStorage is the filter option variable. If the
// value is nil, it means a memory filter. Set the path to
// save the data if to use the storage filter.
FilterWithStorage string
// GossipNumber means the number of peers to make pull
// requests per pullInterval. This number must be greater
// than 2, and if set to greater than the total number of
// existing peers, it means broadcasting.
GossipNumber int
EncType EncryptType
Passphrase string
}
func DefaultConfig() *Config {
return &Config{
GossipNumber: 2,
EncType: NON_SECURE_TYPE,
Passphrase: "",
}
}
func (c *Config) validate() error {
if c.GossipNumber < 2 {
return errInvalidGossipNumber
}
if c.FilterWithStorage != "" {
if !fs.ValidPath(c.FilterWithStorage) {
return errInvalidFilePath
}
}
if c.EncType.String() == "" {
return errInvalidEncryptType
}
if c.EncType != NON_SECURE_TYPE && c.Passphrase == "" {
return errRequirePassphrase
}
return nil
}