-
Notifications
You must be signed in to change notification settings - Fork 211
/
config.go
58 lines (50 loc) · 1.68 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
package config
import (
"time"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/timesync/peersync"
)
// ConfigValues specifies default values for node config params.
var (
TimeConfigValues = DefaultConfig()
)
// TimeConfig specifies the timesync params for ntp.
type TimeConfig struct {
MaxAllowedDrift time.Duration `mapstructure:"max-allowed-time-drift"`
NtpQueries int `mapstructure:"ntp-queries"`
DefaultTimeoutLatency time.Duration `mapstructure:"default-timeout-latency"`
RefreshNtpInterval time.Duration `mapstructure:"refresh-ntp-interval"`
NTPServers []string `mapstructure:"ntp-servers"`
Peersync peersync.Config `mapstructure:"peersync"`
}
//todo: this is a duplicate function found also in p2p config
func duration(duration string) (dur time.Duration) {
dur, err := time.ParseDuration(duration)
if err != nil {
log.Error("Could not parse duration string returning 0, error:", err)
}
return dur
}
// DefaultConfig defines the default tymesync configuration
func DefaultConfig() TimeConfig {
// TimeConfigValues defines default values for all time and ntp related params.
var TimeConfigValues = TimeConfig{
MaxAllowedDrift: duration("10s"),
NtpQueries: 5,
DefaultTimeoutLatency: duration("10s"),
RefreshNtpInterval: duration("30m"),
NTPServers: []string{
"time-a-wwv.nist.gov",
"time-b-wwv.nist.gov",
"time-c-wwv.nist.gov",
"time.google.com",
"time1.google.com",
"time3.google.com",
"time4.google.com",
"time.asia.apple.com",
"time.americas.apple.com",
},
Peersync: peersync.DefaultConfig(),
}
return TimeConfigValues
}