-
Notifications
You must be signed in to change notification settings - Fork 162
/
config.go
250 lines (229 loc) · 8.58 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright 2019 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package config describes the configuration of the beacon server.
package config
import (
"io"
"time"
"github.com/scionproto/scion/go/beacon_srv/internal/beaconstorage"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/config"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/infra/modules/idiscovery"
"github.com/scionproto/scion/go/lib/truststorage"
"github.com/scionproto/scion/go/lib/util"
)
const (
// DefaultKeepaliveInterval is the default interval between sending
// interface keepalives.
DefaultKeepaliveInterval = time.Second
// DefaultKeepaliveTimeout is the timeout indicating how long an interface
// can receive no keepalive default until it is considered expired.
DefaultKeepaliveTimeout = 3 * time.Second
// DefaultOriginationInterval is the default interval between originating
// beacons in a core BS.
DefaultOriginationInterval = 5 * time.Second
// DefaultPropagationInterval is the default interval between propagating beacons.
DefaultPropagationInterval = 5 * time.Second
// DefaultRegistrationInterval is the default interval between registering segments.
DefaultRegistrationInterval = 5 * time.Second
// DefaultExpiredCheckInterval is the default interval between checking for
// expired interfaces.
DefaultExpiredCheckInterval = 200 * time.Millisecond
// DefaultRevTTL is the default revocation TTL.
DefaultRevTTL = 10 * time.Second
// DefaultRevOverlap specifies the default for how long before the expiry of an existing
// revocation the revoker can reissue a new revocation.
DefaultRevOverlap = DefaultRevTTL / 2
)
var _ config.Config = (*Config)(nil)
// Config is the beacon server configuration.
type Config struct {
General env.General
Features env.Features
Logging env.Logging
Metrics env.Metrics
Tracing env.Tracing
QUIC env.QUIC `toml:"quic"`
TrustDB truststorage.TrustDBConf
BeaconDB beaconstorage.BeaconDBConf
Discovery idiscovery.Config
BS BSConfig
EnableQUICTest bool
}
// InitDefaults initializes the default values for all parts of the config.
func (cfg *Config) InitDefaults() {
config.InitAll(
&cfg.General,
&cfg.Features,
&cfg.Logging,
&cfg.Metrics,
&cfg.Tracing,
&cfg.TrustDB,
&cfg.BeaconDB,
&cfg.Discovery,
&cfg.BS,
)
}
// Validate validates all parts of the config.
func (cfg *Config) Validate() error {
return config.ValidateAll(
&cfg.General,
&cfg.Features,
&cfg.Logging,
&cfg.Metrics,
&cfg.TrustDB,
&cfg.BeaconDB,
&cfg.Discovery,
&cfg.BS,
)
}
// Sample generates a sample config file for the beacon server.
func (cfg *Config) Sample(dst io.Writer, path config.Path, _ config.CtxMap) {
config.WriteSample(dst, path, config.CtxMap{config.ID: idSample},
&cfg.General,
&cfg.Features,
&cfg.Logging,
&cfg.Metrics,
&cfg.Tracing,
&cfg.QUIC,
&cfg.TrustDB,
&cfg.BeaconDB,
&cfg.Discovery,
&cfg.BS,
)
}
// ConfigName is the toml key.
func (cfg *Config) ConfigName() string {
return "bs_config"
}
var _ config.Config = (*BSConfig)(nil)
// BSConfig holds the configuration specific to the beacon server.
type BSConfig struct {
// KeepaliveInterval is the interval between sending interface keepalives.
KeepaliveInterval util.DurWrap
// KeepaliveTimeout is the timeout indicating how long an interface can
// receive no keepalive until it is considered expired.
KeepaliveTimeout util.DurWrap
// OriginationInterval is the interval between originating beacons in a core BS.
OriginationInterval util.DurWrap
// PropagationInterval is the interval between propagating beacons.
PropagationInterval util.DurWrap
// RegistrationInterval is the interval between registering segments.
RegistrationInterval util.DurWrap
// ExpiredCheckInterval is the interval between checking whether interfaces
// have expired and should be revoked.
ExpiredCheckInterval util.DurWrap
// RevTTL is the revocation TTL. (default 10s)
RevTTL util.DurWrap
// RevOverlap specifies for how long before the expiry of an existing revocation the revoker
// can reissue a new revocation. (default 5s)
RevOverlap util.DurWrap
// Policies contains the policy files.
Policies Policies
}
// InitDefaults the default values for the durations that are equal to zero.
func (cfg *BSConfig) InitDefaults() {
initDurWrap(&cfg.KeepaliveInterval, DefaultKeepaliveInterval)
initDurWrap(&cfg.KeepaliveTimeout, DefaultKeepaliveTimeout)
initDurWrap(&cfg.OriginationInterval, DefaultOriginationInterval)
initDurWrap(&cfg.PropagationInterval, DefaultPropagationInterval)
initDurWrap(&cfg.RegistrationInterval, DefaultRegistrationInterval)
initDurWrap(&cfg.ExpiredCheckInterval, DefaultExpiredCheckInterval)
initDurWrap(&cfg.RevTTL, DefaultRevTTL)
initDurWrap(&cfg.RevOverlap, DefaultRevOverlap)
}
// Validate validates that all durations are set.
func (cfg *BSConfig) Validate() error {
if cfg.KeepaliveInterval.Duration == 0 {
return common.NewBasicError("KeepaliveInterval not set", nil)
}
if cfg.KeepaliveTimeout.Duration == 0 {
return common.NewBasicError("KeepaliveTimeout not set", nil)
}
if cfg.OriginationInterval.Duration == 0 {
return common.NewBasicError("OriginationInterval not set", nil)
}
if cfg.PropagationInterval.Duration == 0 {
return common.NewBasicError("PropagationInterval not set", nil)
}
if cfg.RegistrationInterval.Duration == 0 {
return common.NewBasicError("RegistrationInterval not set", nil)
}
if cfg.ExpiredCheckInterval.Duration == 0 {
return common.NewBasicError("ExpiredCheckInterval not set", nil)
}
if cfg.RevTTL.Duration == 0 {
return common.NewBasicError("RevTTL is not set", nil)
}
if cfg.RevTTL.Duration < path_mgmt.MinRevTTL {
return common.NewBasicError("RevTTL must be equal or greater than MinRevTTL", nil,
"MinRevTTL", path_mgmt.MinRevTTL)
}
if cfg.RevOverlap.Duration == 0 {
return common.NewBasicError("RevOverlap not set", nil)
}
if cfg.RevOverlap.Duration > cfg.RevTTL.Duration {
return common.NewBasicError("RevOverlap cannot be greater than RevTTL", nil)
}
return nil
}
// Sample generates a sample for the beacon server specific configuration.
func (cfg *BSConfig) Sample(dst io.Writer, path config.Path, ctx config.CtxMap) {
config.WriteString(dst, bsconfigSample)
config.WriteSample(dst, path, ctx, &cfg.Policies)
}
// ConfigName is the toml key for the beacon server specific configuration.
func (cfg *BSConfig) ConfigName() string {
return "bs"
}
func initDurWrap(w *util.DurWrap, def time.Duration) {
if w.Duration == 0 {
w.Duration = def
}
}
var _ config.Config = (*Policies)(nil)
// Policies contains the file paths of the policies.
type Policies struct {
config.NoDefaulter
config.NoValidator
// Propagation contains the file path for the propagation policy. If this
// is the empty string, the default policy is used.
Propagation string
// CoreRegistration contains the file path for the core registration
// policy. If this is the empty string, the default policy is used. In a
// non-core beacon server, this field is ignored.
CoreRegistration string
// UpRegistration contains the file path for the up registration policy. If
// this is the empty string, the default policy is used. In a core beacon
// server, this field is ignored.
UpRegistration string
// DownRegistration contains the file path for the down registration policy.
// If this is the empty string, the default policy is used. In a core beacon
// server, this field is ignored.
DownRegistration string
// HiddenPathRegistration contains the file path for the hidden path registration policy
// and the corresponding hidden path groups.
// If this is the empty string, no hidden path functionality is used.
HiddenPathRegistration string
}
// Sample generates a sample for the beacon server specific configuration.
func (cfg *Policies) Sample(dst io.Writer, _ config.Path, _ config.CtxMap) {
config.WriteString(dst, policiesSample)
}
// ConfigName is the toml key for the beacon server specific configuration.
func (cfg *Policies) ConfigName() string {
return "policies"
}