Skip to content

Commit

Permalink
Remove forgotten configuration types from beacon_srv (#3603)
Browse files Browse the repository at this point in the history
  • Loading branch information
juagargi authored and scrye committed Jan 14, 2020
1 parent 76bb67e commit 1352c6c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 154 deletions.
5 changes: 0 additions & 5 deletions go/beacon_srv/internal/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ go_library(
deps = [
"//go/cs/beaconstorage:go_default_library",
"//go/cs/config:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/config:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/infra/modules/idiscovery:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/truststorage:go_default_library",
"//go/lib/util:go_default_library",
],
)

Expand All @@ -26,11 +23,9 @@ go_test(
deps = [
"//go/cs/beaconstorage/beaconstoragetest:go_default_library",
"//go/cs/config:go_default_library",
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/env/envtest:go_default_library",
"//go/lib/infra/modules/idiscovery/idiscoverytest:go_default_library",
"//go/lib/truststorage/truststoragetest:go_default_library",
"//go/lib/util:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
Expand Down
132 changes: 0 additions & 132 deletions go/beacon_srv/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ import (

"github.com/scionproto/scion/go/cs/beaconstorage"
controlconfig "github.com/scionproto/scion/go/cs/config"
"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/serrors"
"github.com/scionproto/scion/go/lib/truststorage"
"github.com/scionproto/scion/go/lib/util"
)

const (
Expand Down Expand Up @@ -125,132 +122,3 @@ func (cfg *Config) Sample(dst io.Writer, path config.Path, _ config.CtxMap) {
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 serrors.New("KeepaliveInterval not set")
}
if cfg.KeepaliveTimeout.Duration == 0 {
return serrors.New("KeepaliveTimeout not set")
}
if cfg.OriginationInterval.Duration == 0 {
return serrors.New("OriginationInterval not set")
}
if cfg.PropagationInterval.Duration == 0 {
return serrors.New("PropagationInterval not set")
}
if cfg.RegistrationInterval.Duration == 0 {
return serrors.New("RegistrationInterval not set")
}
if cfg.ExpiredCheckInterval.Duration == 0 {
return serrors.New("ExpiredCheckInterval not set")
}
if cfg.RevTTL.Duration == 0 {
return serrors.New("RevTTL is not set")
}
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 serrors.New("RevOverlap not set")
}
if cfg.RevOverlap.Duration > cfg.RevTTL.Duration {
return serrors.New("RevOverlap cannot be greater than RevTTL")
}
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, controlconfig.BSSample)
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, controlconfig.PoliciesSample)
}

// ConfigName is the toml key for the beacon server specific configuration.
func (cfg *Policies) ConfigName() string {
return "policies"
}
17 changes: 0 additions & 17 deletions go/beacon_srv/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ package config
import (
"bytes"
"testing"
"time"

"github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert"

"github.com/scionproto/scion/go/cs/beaconstorage/beaconstoragetest"
controlconfig "github.com/scionproto/scion/go/cs/config"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/env/envtest"
"github.com/scionproto/scion/go/lib/infra/modules/idiscovery/idiscoverytest"
"github.com/scionproto/scion/go/lib/truststorage/truststoragetest"
"github.com/scionproto/scion/go/lib/util"
)

func TestConfigSample(t *testing.T) {
Expand All @@ -43,20 +40,6 @@ func TestConfigSample(t *testing.T) {
CheckTestConfig(t, &cfg, idSample)
}

func TestInvalidTTL(t *testing.T) {
cfg := BSConfig{}
cfg.InitDefaults()
err := cfg.Validate()
assert.NoError(t, err)
cfg.RevOverlap = util.DurWrap{Duration: cfg.RevTTL.Duration + time.Second}
err = cfg.Validate()
assert.Error(t, err)
cfg.InitDefaults()
cfg.RevTTL = util.DurWrap{Duration: path_mgmt.MinRevTTL - time.Second}
err = cfg.Validate()
assert.Error(t, err)
}

func InitTestConfig(cfg *Config) {
envtest.InitTest(&cfg.General, &cfg.Logging, &cfg.Metrics, &cfg.Tracing, nil)
truststoragetest.InitTestConfig(&cfg.TrustDB)
Expand Down

0 comments on commit 1352c6c

Please sign in to comment.