From 8ea849d782d81249248b68de1fcd2fb9eeec41a2 Mon Sep 17 00:00:00 2001 From: Sergiu Costea Date: Wed, 16 Jan 2019 14:23:25 +0100 Subject: [PATCH] Reduce code duplication in service configs (#2351) Fixes #2311. This reduces some type duplication in config tests, and makes configs more self-contained. --- .../{csconfig/conf.go => config/config.go} | 26 +++++-- .../conf_test.go => config/config_test.go} | 28 ++----- .../internal/{csconfig => config}/sample.go | 2 +- .../internal/{csconfig => config}/state.go | 2 +- .../{csconfig => config}/state_test.go | 2 +- .../{csconfig => config}/testdata/as.yml | 0 .../testdata/csconfig.toml | 0 .../testdata/keys/as-decrypt.key | 0 .../testdata/keys/as-sig.seed | 0 .../testdata/keys/core-sig.seed | 0 .../testdata/keys/master0.key | 0 .../testdata/keys/master1.key | 0 .../testdata/keys/offline-root.seed | 0 .../testdata/keys/online-root.seed | 0 go/cert_srv/internal/reiss/handler.go | 4 +- go/cert_srv/internal/reiss/requester.go | 4 +- go/cert_srv/internal/reiss/self.go | 4 +- go/cert_srv/main.go | 59 ++++++-------- go/cert_srv/setup.go | 76 +++++++++---------- .../psconfig.go => config/config.go} | 21 ++++- .../internal/{psconfig => config}/sample.go | 2 +- .../{psconfig => config}/sample_test.go | 16 +--- go/path_srv/internal/handlers/common.go | 6 +- go/path_srv/main.go | 50 +++++------- .../sdconfig.go => config/config.go} | 22 +++++- .../internal/{sdconfig => config}/sample.go | 2 +- .../{sdconfig => config}/sample_test.go | 16 +--- go/sciond/internal/fetcher/fetcher.go | 9 +-- go/sciond/main.go | 63 +++++++-------- 29 files changed, 196 insertions(+), 218 deletions(-) rename go/cert_srv/internal/{csconfig/conf.go => config/config.go} (82%) rename go/cert_srv/internal/{csconfig/conf_test.go => config/config_test.go} (91%) rename go/cert_srv/internal/{csconfig => config}/sample.go (99%) rename go/cert_srv/internal/{csconfig => config}/state.go (99%) rename go/cert_srv/internal/{csconfig => config}/state_test.go (99%) rename go/cert_srv/internal/{csconfig => config}/testdata/as.yml (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/csconfig.toml (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/as-decrypt.key (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/as-sig.seed (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/core-sig.seed (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/master0.key (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/master1.key (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/offline-root.seed (100%) rename go/cert_srv/internal/{csconfig => config}/testdata/keys/online-root.seed (100%) rename go/path_srv/internal/{psconfig/psconfig.go => config/config.go} (76%) rename go/path_srv/internal/{psconfig => config}/sample.go (99%) rename go/path_srv/internal/{psconfig => config}/sample_test.go (87%) rename go/sciond/internal/{sdconfig/sdconfig.go => config/config.go} (86%) rename go/sciond/internal/{sdconfig => config}/sample.go (99%) rename go/sciond/internal/{sdconfig => config}/sample_test.go (89%) diff --git a/go/cert_srv/internal/csconfig/conf.go b/go/cert_srv/internal/config/config.go similarity index 82% rename from go/cert_srv/internal/csconfig/conf.go rename to go/cert_srv/internal/config/config.go index 215e17f95e..9bc980ebdb 100644 --- a/go/cert_srv/internal/csconfig/conf.go +++ b/go/cert_srv/internal/config/config.go @@ -12,14 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package csconfig +package config import ( "path/filepath" "time" "github.com/scionproto/scion/go/lib/as_conf" + "github.com/scionproto/scion/go/lib/env" "github.com/scionproto/scion/go/lib/scrypto/cert" + "github.com/scionproto/scion/go/lib/truststorage" "github.com/scionproto/scion/go/lib/util" ) @@ -36,7 +38,21 @@ const ( ErrorCustomers = "Unable to load Customers" ) -type Conf struct { +type Config struct { + General env.General + Sciond env.SciondClient `toml:"sd_client"` + Logging env.Logging + Metrics env.Metrics + TrustDB truststorage.TrustDBConf + Infra env.Infra + CS CSConfig +} + +func (c *Config) Init(confDir string) error { + return c.CS.Init(confDir) +} + +type CSConfig struct { // LeafReissueLeadTime indicates how long in advance of leaf cert expiration // the reissuance process starts. LeafReissueLeadTime util.DurWrap @@ -52,7 +68,7 @@ type Conf struct { } // Init sets the uninitialized fields. -func (c *Conf) Init(confDir string) error { +func (c *CSConfig) Init(confDir string) error { c.initDefaults() if c.LeafReissueLeadTime.Duration == 0 { if err := c.loadLeafReissTime(confDir); err != nil { @@ -62,7 +78,7 @@ func (c *Conf) Init(confDir string) error { return nil } -func (c *Conf) initDefaults() { +func (c *CSConfig) initDefaults() { if c.IssuerReissueLeadTime.Duration == 0 { c.IssuerReissueLeadTime.Duration = IssuerReissTime } @@ -76,7 +92,7 @@ func (c *Conf) initDefaults() { // loadLeafReissTime loads the as conf and sets the LeafReissTime to the PathSegmentTTL // to provide optimal coverage. -func (c *Conf) loadLeafReissTime(confDir string) error { +func (c *CSConfig) loadLeafReissTime(confDir string) error { if err := as_conf.Load(filepath.Join(confDir, as_conf.CfgName)); err != nil { return err } diff --git a/go/cert_srv/internal/csconfig/conf_test.go b/go/cert_srv/internal/config/config_test.go similarity index 91% rename from go/cert_srv/internal/csconfig/conf_test.go rename to go/cert_srv/internal/config/config_test.go index af45ab7b50..3affcf1862 100644 --- a/go/cert_srv/internal/csconfig/conf_test.go +++ b/go/cert_srv/internal/config/config_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package csconfig +package config import ( "strings" @@ -21,23 +21,11 @@ import ( "github.com/BurntSushi/toml" . "github.com/smartystreets/goconvey/convey" - - "github.com/scionproto/scion/go/lib/env" - "github.com/scionproto/scion/go/lib/truststorage" ) -type TestConfig struct { - General env.General - Logging env.Logging - Metrics env.Metrics - Infra env.Infra - TrustDB truststorage.TrustDBConf - CS Conf -} - func TestSampleCorrect(t *testing.T) { Convey("Load", t, func() { - var cfg TestConfig + var cfg Config // Make sure AutomaticRenweal is set during decoding. cfg.CS.AutomaticRenewal = true _, err := toml.Decode(Sample, &cfg) @@ -68,7 +56,7 @@ func TestSampleCorrect(t *testing.T) { func TestLoadConf(t *testing.T) { Convey("Load Conf", t, func() { - var cfg TestConfig + var cfg Config _, err := toml.DecodeFile("testdata/csconfig.toml", &cfg) SoMsg("err", err, ShouldBeNil) SoMsg("leafTime", cfg.CS.LeafReissueLeadTime.Duration, ShouldEqual, 7*time.Hour) @@ -79,7 +67,7 @@ func TestLoadConf(t *testing.T) { }) Convey("Load Default", t, func() { - var cfg TestConfig + var cfg Config _, err := toml.DecodeReader(strings.NewReader("[cs]"), &cfg) SoMsg("err", err, ShouldBeNil) SoMsg("leafTime", cfg.CS.LeafReissueLeadTime.Duration, ShouldBeZeroValue) @@ -92,12 +80,12 @@ func TestLoadConf(t *testing.T) { func TestConfig_Init(t *testing.T) { Convey("Load Conf", t, func() { - var cfg TestConfig + var cfg Config _, err := toml.DecodeFile("testdata/csconfig.toml", &cfg) SoMsg("err", err, ShouldBeNil) Convey("Init does not override values", func() { - err := cfg.CS.Init("testdata") + err := cfg.Init("testdata") SoMsg("err", err, ShouldBeNil) SoMsg("leafTime", cfg.CS.LeafReissueLeadTime.Duration, ShouldEqual, 7*time.Hour) SoMsg("issuerTime", cfg.CS.IssuerReissueLeadTime.Duration, ShouldEqual, 48*time.Hour) @@ -108,12 +96,12 @@ func TestConfig_Init(t *testing.T) { }) Convey("Load Default", t, func() { - var cfg TestConfig + var cfg Config _, err := toml.DecodeReader(strings.NewReader("[cs]"), &cfg) SoMsg("err", err, ShouldBeNil) Convey("Init loads default values", func() { - err := cfg.CS.Init("testdata") + err := cfg.Init("testdata") SoMsg("err", err, ShouldBeNil) SoMsg("leafTime", cfg.CS.LeafReissueLeadTime.Duration, ShouldEqual, 6*time.Hour) SoMsg("issuerTime", cfg.CS.IssuerReissueLeadTime.Duration, ShouldEqual, IssuerReissTime) diff --git a/go/cert_srv/internal/csconfig/sample.go b/go/cert_srv/internal/config/sample.go similarity index 99% rename from go/cert_srv/internal/csconfig/sample.go rename to go/cert_srv/internal/config/sample.go index 2dff9634b8..24cae2d7f9 100644 --- a/go/cert_srv/internal/csconfig/sample.go +++ b/go/cert_srv/internal/config/sample.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package csconfig +package config const Sample = `[general] # The ID of the service. This is used to choose the relevant portion of the diff --git a/go/cert_srv/internal/csconfig/state.go b/go/cert_srv/internal/config/state.go similarity index 99% rename from go/cert_srv/internal/csconfig/state.go rename to go/cert_srv/internal/config/state.go index e1ec6a6762..3025da3bcb 100644 --- a/go/cert_srv/internal/csconfig/state.go +++ b/go/cert_srv/internal/config/state.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package csconfig +package config import ( "path/filepath" diff --git a/go/cert_srv/internal/csconfig/state_test.go b/go/cert_srv/internal/config/state_test.go similarity index 99% rename from go/cert_srv/internal/csconfig/state_test.go rename to go/cert_srv/internal/config/state_test.go index bd041b4fad..0410cc6ad8 100644 --- a/go/cert_srv/internal/csconfig/state_test.go +++ b/go/cert_srv/internal/config/state_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package csconfig +package config import ( "testing" diff --git a/go/cert_srv/internal/csconfig/testdata/as.yml b/go/cert_srv/internal/config/testdata/as.yml similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/as.yml rename to go/cert_srv/internal/config/testdata/as.yml diff --git a/go/cert_srv/internal/csconfig/testdata/csconfig.toml b/go/cert_srv/internal/config/testdata/csconfig.toml similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/csconfig.toml rename to go/cert_srv/internal/config/testdata/csconfig.toml diff --git a/go/cert_srv/internal/csconfig/testdata/keys/as-decrypt.key b/go/cert_srv/internal/config/testdata/keys/as-decrypt.key similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/as-decrypt.key rename to go/cert_srv/internal/config/testdata/keys/as-decrypt.key diff --git a/go/cert_srv/internal/csconfig/testdata/keys/as-sig.seed b/go/cert_srv/internal/config/testdata/keys/as-sig.seed similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/as-sig.seed rename to go/cert_srv/internal/config/testdata/keys/as-sig.seed diff --git a/go/cert_srv/internal/csconfig/testdata/keys/core-sig.seed b/go/cert_srv/internal/config/testdata/keys/core-sig.seed similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/core-sig.seed rename to go/cert_srv/internal/config/testdata/keys/core-sig.seed diff --git a/go/cert_srv/internal/csconfig/testdata/keys/master0.key b/go/cert_srv/internal/config/testdata/keys/master0.key similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/master0.key rename to go/cert_srv/internal/config/testdata/keys/master0.key diff --git a/go/cert_srv/internal/csconfig/testdata/keys/master1.key b/go/cert_srv/internal/config/testdata/keys/master1.key similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/master1.key rename to go/cert_srv/internal/config/testdata/keys/master1.key diff --git a/go/cert_srv/internal/csconfig/testdata/keys/offline-root.seed b/go/cert_srv/internal/config/testdata/keys/offline-root.seed similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/offline-root.seed rename to go/cert_srv/internal/config/testdata/keys/offline-root.seed diff --git a/go/cert_srv/internal/csconfig/testdata/keys/online-root.seed b/go/cert_srv/internal/config/testdata/keys/online-root.seed similarity index 100% rename from go/cert_srv/internal/csconfig/testdata/keys/online-root.seed rename to go/cert_srv/internal/config/testdata/keys/online-root.seed diff --git a/go/cert_srv/internal/reiss/handler.go b/go/cert_srv/internal/reiss/handler.go index 6e68df576c..bf74421bd5 100644 --- a/go/cert_srv/internal/reiss/handler.go +++ b/go/cert_srv/internal/reiss/handler.go @@ -20,7 +20,7 @@ import ( "net" "time" - "github.com/scionproto/scion/go/cert_srv/internal/csconfig" + "github.com/scionproto/scion/go/cert_srv/internal/config" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" @@ -47,7 +47,7 @@ const ( // key in the customer mapping. Certificate chains are issued automatically by // the issuer ASes. type Handler struct { - State *csconfig.State + State *config.State IA addr.IA } diff --git a/go/cert_srv/internal/reiss/requester.go b/go/cert_srv/internal/reiss/requester.go index c68404ad91..f9bf6a014b 100644 --- a/go/cert_srv/internal/reiss/requester.go +++ b/go/cert_srv/internal/reiss/requester.go @@ -21,7 +21,7 @@ import ( "golang.org/x/crypto/ed25519" - "github.com/scionproto/scion/go/cert_srv/internal/csconfig" + "github.com/scionproto/scion/go/cert_srv/internal/config" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" @@ -43,7 +43,7 @@ var _ periodic.Task = (*Requester)(nil) // expiration of the currently active certificate chain. type Requester struct { Msgr *messenger.Messenger - State *csconfig.State + State *config.State IA addr.IA LeafTime time.Duration } diff --git a/go/cert_srv/internal/reiss/self.go b/go/cert_srv/internal/reiss/self.go index 8953002ff6..261c427fdd 100644 --- a/go/cert_srv/internal/reiss/self.go +++ b/go/cert_srv/internal/reiss/self.go @@ -18,7 +18,7 @@ import ( "context" "time" - "github.com/scionproto/scion/go/cert_srv/internal/csconfig" + "github.com/scionproto/scion/go/cert_srv/internal/config" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl" @@ -40,7 +40,7 @@ var _ periodic.Task = (*Self)(nil) type Self struct { // Msgr is used to propagate key updates to the messenger, and not for network traffic Msgr *messenger.Messenger - State *csconfig.State + State *config.State IA addr.IA IssTime time.Duration LeafTime time.Duration diff --git a/go/cert_srv/main.go b/go/cert_srv/main.go index 321f3c199a..c55b9f7c1e 100644 --- a/go/cert_srv/main.go +++ b/go/cert_srv/main.go @@ -23,7 +23,7 @@ import ( "github.com/BurntSushi/toml" - "github.com/scionproto/scion/go/cert_srv/internal/csconfig" + "github.com/scionproto/scion/go/cert_srv/internal/config" "github.com/scionproto/scion/go/cert_srv/internal/reiss" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/env" @@ -33,22 +33,11 @@ import ( "github.com/scionproto/scion/go/lib/infra/modules/itopo" "github.com/scionproto/scion/go/lib/log" "github.com/scionproto/scion/go/lib/periodic" - "github.com/scionproto/scion/go/lib/truststorage" ) -type Config struct { - General env.General - Sciond env.SciondClient `toml:"sd_client"` - Logging env.Logging - Metrics env.Metrics - TrustDB truststorage.TrustDBConf - Infra env.Infra - CS csconfig.Conf - state *csconfig.State -} - var ( - config Config + cfg config.Config + state *config.State environment *env.Env reissRunner *periodic.Runner msgr *messenger.Messenger @@ -67,7 +56,7 @@ func realMain() int { fatal.Init() env.AddFlags() flag.Parse() - if v, ok := env.CheckFlags(csconfig.Sample); !ok { + if v, ok := env.CheckFlags(config.Sample); !ok { return v } if err := setupBasic(); err != nil { @@ -75,7 +64,7 @@ func realMain() int { return 1 } defer log.Flush() - defer env.LogAppStopped(common.CS, config.General.ID) + defer env.LogAppStopped(common.CS, cfg.General.ID) defer log.LogPanicAndExit() // Setup the state and the messenger if err := setup(); err != nil { @@ -90,14 +79,14 @@ func realMain() int { msgr.ListenAndServe() }() // Set environment to listen for signals. - environment = infraenv.InitInfraEnvironmentFunc(config.General.TopologyPath, func() { + environment = infraenv.InitInfraEnvironmentFunc(cfg.General.TopologyPath, func() { if err := reload(); err != nil { log.Error("Unable to reload", "err", err) } }) // Cleanup when the CS exits. defer stop() - config.Metrics.StartPrometheus() + cfg.Metrics.StartPrometheus() select { case <-environment.AppShutdownSignal: // Whenever we receive a SIGINT or SIGTERM we exit without an error. @@ -111,16 +100,16 @@ func realMain() int { func reload() error { // FIXME(roosd): KeyConf reloading is not yet supported. // https://github.com/scionproto/scion/issues/2077 - config.General.Topology = itopo.GetCurrentTopology() - var newConf Config + cfg.General.Topology = itopo.GetCurrentTopology() + var newConf config.Config // Load new config to get the CS parameters. if _, err := toml.DecodeFile(env.ConfigFile(), &newConf); err != nil { return err } - if err := newConf.CS.Init(config.General.ConfigDir); err != nil { + if err := newConf.CS.Init(cfg.General.ConfigDir); err != nil { return common.NewBasicError("Unable to initialize CS config", err) } - config.CS = newConf.CS + cfg.CS = newConf.CS // Restart the periodic reissue task to respect the fresh parameters. stopReissRunner() startReissRunner() @@ -130,22 +119,22 @@ func reload() error { // startReissRunner starts a periodic reissuance task. Core starts self-issuer. // Non-core starts a requester. func startReissRunner() { - if !config.CS.AutomaticRenewal { + if !cfg.CS.AutomaticRenewal { log.Info("Reissue disabled, not starting reiss task.") return } - if config.General.Topology.Core { + if cfg.General.Topology.Core { log.Info("Starting periodic reiss.Self task") reissRunner = periodic.StartPeriodicTask( &reiss.Self{ Msgr: msgr, - State: config.state, - IA: config.General.Topology.ISD_AS, - IssTime: config.CS.IssuerReissueLeadTime.Duration, - LeafTime: config.CS.LeafReissueLeadTime.Duration, + State: state, + IA: cfg.General.Topology.ISD_AS, + IssTime: cfg.CS.IssuerReissueLeadTime.Duration, + LeafTime: cfg.CS.LeafReissueLeadTime.Duration, }, - periodic.NewTicker(config.CS.ReissueRate.Duration), - config.CS.ReissueTimeout.Duration, + periodic.NewTicker(cfg.CS.ReissueRate.Duration), + cfg.CS.ReissueTimeout.Duration, ) return } @@ -153,12 +142,12 @@ func startReissRunner() { reissRunner = periodic.StartPeriodicTask( &reiss.Requester{ Msgr: msgr, - State: config.state, - IA: config.General.Topology.ISD_AS, - LeafTime: config.CS.LeafReissueLeadTime.Duration, + State: state, + IA: cfg.General.Topology.ISD_AS, + LeafTime: cfg.CS.LeafReissueLeadTime.Duration, }, - periodic.NewTicker(config.CS.ReissueRate.Duration), - config.CS.ReissueTimeout.Duration, + periodic.NewTicker(cfg.CS.ReissueRate.Duration), + cfg.CS.ReissueTimeout.Duration, ) } diff --git a/go/cert_srv/setup.go b/go/cert_srv/setup.go index fe54a16678..63c4e8efef 100644 --- a/go/cert_srv/setup.go +++ b/go/cert_srv/setup.go @@ -19,7 +19,7 @@ import ( "github.com/BurntSushi/toml" - "github.com/scionproto/scion/go/cert_srv/internal/csconfig" + "github.com/scionproto/scion/go/cert_srv/internal/config" "github.com/scionproto/scion/go/cert_srv/internal/reiss" "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" @@ -46,38 +46,38 @@ const ( // setupBasic loads the config from file and initializes logging. func setupBasic() error { // Load and initialize config. - if _, err := toml.DecodeFile(env.ConfigFile(), &config); err != nil { + if _, err := toml.DecodeFile(env.ConfigFile(), &cfg); err != nil { return err } - if err := env.InitLogging(&config.Logging); err != nil { + if err := env.InitLogging(&cfg.Logging); err != nil { return err } - return env.LogAppStarted(common.CS, config.General.ID) + return env.LogAppStarted(common.CS, cfg.General.ID) } // setup initializes the config and sets the messenger. func setup() error { - if err := env.InitGeneral(&config.General); err != nil { + if err := env.InitGeneral(&cfg.General); err != nil { return common.NewBasicError("Unable to initialize General config", err) } - itopo.SetCurrentTopology(config.General.Topology) - env.InitSciondClient(&config.Sciond) - if err := config.CS.Init(config.General.ConfigDir); err != nil { + itopo.SetCurrentTopology(cfg.General.Topology) + env.InitSciondClient(&cfg.Sciond) + if err := cfg.Init(cfg.General.ConfigDir); err != nil { return common.NewBasicError("Unable to initialize CS config", err) } // Load CS state. - if err := initState(&config); err != nil { + if err := initState(&cfg); err != nil { return common.NewBasicError("Unable to initialize CS state", err) } - if err := setMessenger(&config); err != nil { + if err := setMessenger(&cfg); err != nil { return common.NewBasicError("Unable to set messenger", err) } return nil } // initState sets the state. -func initState(config *Config) error { - trustDB, err := config.TrustDB.New() +func initState(cfg *config.Config) error { + trustDB, err := cfg.TrustDB.New() if err != nil { return common.NewBasicError("Unable to initialize trustDB", err) } @@ -85,26 +85,26 @@ func initState(config *Config) error { MustHaveLocalChain: true, ServiceType: proto.ServiceType_cs, } - trustStore, err := trust.NewStore(trustDB, config.General.Topology.ISD_AS, + trustStore, err := trust.NewStore(trustDB, cfg.General.Topology.ISD_AS, trustConf, log.Root()) if err != nil { return common.NewBasicError("Unable to initialize trust store", err) } - config.state, err = csconfig.LoadState(config.General.ConfigDir, config.General.Topology.Core, + state, err = config.LoadState(cfg.General.ConfigDir, cfg.General.Topology.Core, trustDB, trustStore) if err != nil { return common.NewBasicError("Unable to load CS state", err) } - err = config.state.Store.LoadAuthoritativeTRC(filepath.Join(config.General.ConfigDir, "certs")) + err = state.Store.LoadAuthoritativeTRC(filepath.Join(cfg.General.ConfigDir, "certs")) if err != nil { return common.NewBasicError("Unable to load local TRC", err) } - err = config.state.Store.LoadAuthoritativeChain( - filepath.Join(config.General.ConfigDir, "certs")) + err = state.Store.LoadAuthoritativeChain( + filepath.Join(cfg.General.ConfigDir, "certs")) if err != nil { return common.NewBasicError("Unable to load local Chain", err) } - if err = setDefaultSignerVerifier(config.state, config.General.Topology.ISD_AS); err != nil { + if err = setDefaultSignerVerifier(state, cfg.General.Topology.ISD_AS); err != nil { return common.NewBasicError("Unable to set default signer and verifier", err) } return nil @@ -112,7 +112,7 @@ func initState(config *Config) error { // setDefaultSignerVerifier sets the signer and verifier. The newest certificate chain version // in the store is used. -func setDefaultSignerVerifier(c *csconfig.State, pubIA addr.IA) error { +func setDefaultSignerVerifier(c *config.State, pubIA addr.IA) error { sign, err := trust.CreateSign(pubIA, c.Store) if err != nil { return err @@ -123,27 +123,27 @@ func setDefaultSignerVerifier(c *csconfig.State, pubIA addr.IA) error { } // setMessenger sets the messenger and the internal messenger of the store in -// config.CS. This function may only be called once per config. -func setMessenger(config *Config) error { - topoAddress := config.General.Topology.CS.GetById(config.General.ID) +// cfg.CS. This function may only be called once per config. +func setMessenger(cfg *config.Config) error { + topoAddress := cfg.General.Topology.CS.GetById(cfg.General.ID) if topoAddress == nil { return common.NewBasicError("Unable to find topo address", nil) } msgrI, err := infraenv.InitMessengerWithSciond( - config.General.Topology.ISD_AS, - env.GetPublicSnetAddress(config.General.Topology.ISD_AS, topoAddress), - env.GetBindSnetAddress(config.General.Topology.ISD_AS, topoAddress), + cfg.General.Topology.ISD_AS, + env.GetPublicSnetAddress(cfg.General.Topology.ISD_AS, topoAddress), + env.GetBindSnetAddress(cfg.General.Topology.ISD_AS, topoAddress), addr.SvcCS, - config.General.ReconnectToDispatcher, - config.state.Store, - config.Sciond, + cfg.General.ReconnectToDispatcher, + state.Store, + cfg.Sciond, ) if err != nil { return common.NewBasicError("Unable to initialize SCION Messenger", err) } // FIXME(roosd): Hack to make Store.ChooseServer not panic. // Remove when https://github.com/scionproto/scion/issues/2029 is resolved. - if err := snet.Init(config.General.Topology.ISD_AS, config.Sciond.Path, ""); err != nil { + if err := snet.Init(cfg.General.Topology.ISD_AS, cfg.Sciond.Path, ""); err != nil { return common.NewBasicError("Unable to initialize snet", err) } // FIXME(roosd): We need the actual type to set the signer and verifier. @@ -153,17 +153,17 @@ func setMessenger(config *Config) error { return common.NewBasicError("Unsupported messenger type", nil, "msgrI", common.TypeOf(msgrI)) } - msgr.AddHandler(infra.ChainRequest, config.state.Store.NewChainReqHandler(true)) - msgr.AddHandler(infra.TRCRequest, config.state.Store.NewTRCReqHandler(true)) - msgr.AddHandler(infra.Chain, config.state.Store.NewChainPushHandler()) - msgr.AddHandler(infra.TRC, config.state.Store.NewTRCPushHandler()) - msgr.UpdateSigner(config.state.GetSigner(), []infra.MessageType{infra.ChainIssueRequest}) - msgr.UpdateVerifier(config.state.GetVerifier()) + msgr.AddHandler(infra.ChainRequest, state.Store.NewChainReqHandler(true)) + msgr.AddHandler(infra.TRCRequest, state.Store.NewTRCReqHandler(true)) + msgr.AddHandler(infra.Chain, state.Store.NewChainPushHandler()) + msgr.AddHandler(infra.TRC, state.Store.NewTRCPushHandler()) + msgr.UpdateSigner(state.GetSigner(), []infra.MessageType{infra.ChainIssueRequest}) + msgr.UpdateVerifier(state.GetVerifier()) // Only core CS handles certificate reissuance requests. - if config.General.Topology.Core { + if cfg.General.Topology.Core { msgr.AddHandler(infra.ChainIssueRequest, &reiss.Handler{ - State: config.state, - IA: config.General.Topology.ISD_AS, + State: state, + IA: cfg.General.Topology.ISD_AS, }) } return nil diff --git a/go/path_srv/internal/psconfig/psconfig.go b/go/path_srv/internal/config/config.go similarity index 76% rename from go/path_srv/internal/psconfig/psconfig.go rename to go/path_srv/internal/config/config.go index 3669e2b633..7b3aa944cf 100644 --- a/go/path_srv/internal/psconfig/psconfig.go +++ b/go/path_srv/internal/config/config.go @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package psconfig contains the configuration of the path server. -package psconfig +// Package config contains the configuration of the path server. +package config import ( "time" + "github.com/scionproto/scion/go/lib/env" "github.com/scionproto/scion/go/lib/pathstorage" + "github.com/scionproto/scion/go/lib/truststorage" "github.com/scionproto/scion/go/lib/util" ) @@ -27,6 +29,19 @@ var ( ) type Config struct { + General env.General + Logging env.Logging + Metrics env.Metrics + TrustDB truststorage.TrustDBConf + Infra env.Infra + PS PSConfig +} + +func (c *Config) InitDefaults() { + c.PS.initDefaults() +} + +type PSConfig struct { // SegSync enables the "old" replication of down segments between cores, // using SegSync messages. SegSync bool @@ -37,7 +52,7 @@ type Config struct { QueryInterval util.DurWrap } -func (c *Config) InitDefaults() { +func (c *PSConfig) initDefaults() { if c.QueryInterval.Duration == 0 { c.QueryInterval.Duration = DefaultQueryInterval } diff --git a/go/path_srv/internal/psconfig/sample.go b/go/path_srv/internal/config/sample.go similarity index 99% rename from go/path_srv/internal/psconfig/sample.go rename to go/path_srv/internal/config/sample.go index fafeda6d12..1e6e05a372 100644 --- a/go/path_srv/internal/psconfig/sample.go +++ b/go/path_srv/internal/config/sample.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package psconfig +package config const Sample = `[general] # The ID of the service. This is used to choose the relevant portion of the diff --git a/go/path_srv/internal/psconfig/sample_test.go b/go/path_srv/internal/config/sample_test.go similarity index 87% rename from go/path_srv/internal/psconfig/sample_test.go rename to go/path_srv/internal/config/sample_test.go index 082c19d3bc..cecb9c92df 100644 --- a/go/path_srv/internal/psconfig/sample_test.go +++ b/go/path_srv/internal/config/sample_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package psconfig +package config import ( "testing" @@ -20,23 +20,11 @@ import ( "github.com/BurntSushi/toml" . "github.com/smartystreets/goconvey/convey" - - "github.com/scionproto/scion/go/lib/env" - "github.com/scionproto/scion/go/lib/truststorage" ) -type TestConfig struct { - General env.General - Logging env.Logging - Metrics env.Metrics - Infra env.Infra - TrustDB truststorage.TrustDBConf - PS Config -} - func TestSampleCorrect(t *testing.T) { Convey("Load", t, func() { - var cfg TestConfig + var cfg Config // Make sure SegSync is set. cfg.PS.SegSync = true _, err := toml.Decode(Sample, &cfg) diff --git a/go/path_srv/internal/handlers/common.go b/go/path_srv/internal/handlers/common.go index b4af337f9e..396567ca67 100644 --- a/go/path_srv/internal/handlers/common.go +++ b/go/path_srv/internal/handlers/common.go @@ -32,7 +32,7 @@ import ( "github.com/scionproto/scion/go/lib/pathdb/query" "github.com/scionproto/scion/go/lib/revcache" "github.com/scionproto/scion/go/lib/topology" - "github.com/scionproto/scion/go/path_srv/internal/psconfig" + "github.com/scionproto/scion/go/path_srv/internal/config" "github.com/scionproto/scion/go/path_srv/internal/segutil" ) @@ -45,7 +45,7 @@ type HandlerArgs struct { PathDB pathdb.PathDB RevCache revcache.RevCache TrustStore infra.TrustStore - Config psconfig.Config + Config config.PSConfig IA addr.IA } @@ -56,7 +56,7 @@ type baseHandler struct { trustStore infra.TrustStore topology *topology.Topo retryInt time.Duration - config psconfig.Config + config config.PSConfig } func newBaseHandler(request *infra.Request, args HandlerArgs) *baseHandler { diff --git a/go/path_srv/main.go b/go/path_srv/main.go index 7672f8dce7..f1bf247117 100644 --- a/go/path_srv/main.go +++ b/go/path_srv/main.go @@ -39,25 +39,15 @@ import ( "github.com/scionproto/scion/go/lib/pathstorage" "github.com/scionproto/scion/go/lib/periodic" "github.com/scionproto/scion/go/lib/revcache" - "github.com/scionproto/scion/go/lib/truststorage" + "github.com/scionproto/scion/go/path_srv/internal/config" "github.com/scionproto/scion/go/path_srv/internal/cryptosyncer" "github.com/scionproto/scion/go/path_srv/internal/handlers" - "github.com/scionproto/scion/go/path_srv/internal/psconfig" "github.com/scionproto/scion/go/path_srv/internal/segsyncer" "github.com/scionproto/scion/go/proto" ) -type Config struct { - General env.General - Logging env.Logging - Metrics env.Metrics - TrustDB truststorage.TrustDBConf - Infra env.Infra - PS psconfig.Config -} - var ( - config Config + cfg config.Config environment *env.Env tasks *periodicTasks @@ -76,7 +66,7 @@ func realMain() int { fatal.Init() env.AddFlags() flag.Parse() - if v, ok := env.CheckFlags(psconfig.Sample); !ok { + if v, ok := env.CheckFlags(config.Sample); !ok { return v } if err := setupBasic(); err != nil { @@ -84,18 +74,18 @@ func realMain() int { return 1 } defer log.Flush() - defer env.LogAppStopped(common.PS, config.General.ID) + defer env.LogAppStopped(common.PS, cfg.General.ID) defer log.LogPanicAndExit() if err := setup(); err != nil { log.Crit("Setup failed", "err", err) return 1 } - pathDB, revCache, err := pathstorage.NewPathStorage(config.PS.PathDB, config.PS.RevCache) + pathDB, revCache, err := pathstorage.NewPathStorage(cfg.PS.PathDB, cfg.PS.RevCache) if err != nil { log.Crit("Unable to initialize path storage", "err", err) return 1 } - trustDB, err := config.TrustDB.New() + trustDB, err := cfg.TrustDB.New() if err != nil { log.Crit("Unable to initialize trustDB", "err", err) return 1 @@ -109,12 +99,12 @@ func realMain() int { log.Crit("Unable to initialize trust store", "err", err) return 1 } - err = trustStore.LoadAuthoritativeTRC(filepath.Join(config.General.ConfigDir, "certs")) + err = trustStore.LoadAuthoritativeTRC(filepath.Join(cfg.General.ConfigDir, "certs")) if err != nil { log.Crit("TRC error", "err", err) return 1 } - topoAddress := topo.PS.GetById(config.General.ID) + topoAddress := topo.PS.GetById(cfg.General.ID) if topoAddress == nil { log.Crit("Unable to find topo address") return 1 @@ -124,7 +114,7 @@ func realMain() int { env.GetPublicSnetAddress(topo.ISD_AS, topoAddress), env.GetBindSnetAddress(topo.ISD_AS, topoAddress), addr.SvcPS, - config.General.ReconnectToDispatcher, + cfg.General.ReconnectToDispatcher, trustStore, ) if err != nil { @@ -139,7 +129,7 @@ func realMain() int { PathDB: pathDB, RevCache: revCache, TrustStore: trustStore, - Config: config.PS, + Config: cfg.PS, IA: topo.ISD_AS, } core := topo.Core @@ -153,12 +143,12 @@ func realMain() int { msger.AddHandler(infra.SegRequest, segReqHandler) msger.AddHandler(infra.SegReg, handlers.NewSegRegHandler(args)) msger.AddHandler(infra.IfStateInfos, handlers.NewIfStatInfoHandler(args)) - if config.PS.SegSync && core { + if cfg.PS.SegSync && core { // Old down segment sync mechanism msger.AddHandler(infra.SegSync, handlers.NewSyncHandler(args)) } msger.AddHandler(infra.SegRev, handlers.NewRevocHandler(args)) - config.Metrics.StartPrometheus() + cfg.Metrics.StartPrometheus() // Start handling requests/messages go func() { defer log.LogPanicAndExit() @@ -201,7 +191,7 @@ func (t *periodicTasks) Start() { return } var err error - if config.PS.SegSync && config.General.Topology.Core { + if cfg.PS.SegSync && cfg.General.Topology.Core { t.segSyncers, err = segsyncer.StartAll(t.args, t.msger) if err != nil { fatal.Fatal(common.NewBasicError("Unable to start seg syncer", err)) @@ -237,21 +227,21 @@ func (t *periodicTasks) Kill() { } func setupBasic() error { - if _, err := toml.DecodeFile(env.ConfigFile(), &config); err != nil { + if _, err := toml.DecodeFile(env.ConfigFile(), &cfg); err != nil { return err } - if err := env.InitLogging(&config.Logging); err != nil { + if err := env.InitLogging(&cfg.Logging); err != nil { return err } - return env.LogAppStarted(common.PS, config.General.ID) + return env.LogAppStarted(common.PS, cfg.General.ID) } func setup() error { - if err := env.InitGeneral(&config.General); err != nil { + if err := env.InitGeneral(&cfg.General); err != nil { return err } - itopo.SetCurrentTopology(config.General.Topology) - environment = infraenv.InitInfraEnvironment(config.General.TopologyPath) - config.PS.InitDefaults() + itopo.SetCurrentTopology(cfg.General.Topology) + environment = infraenv.InitInfraEnvironment(cfg.General.TopologyPath) + cfg.InitDefaults() return nil } diff --git a/go/sciond/internal/sdconfig/sdconfig.go b/go/sciond/internal/config/config.go similarity index 86% rename from go/sciond/internal/sdconfig/sdconfig.go rename to go/sciond/internal/config/config.go index 38bb78bc93..cdb4703477 100644 --- a/go/sciond/internal/sdconfig/sdconfig.go +++ b/go/sciond/internal/config/config.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package sdconfig contains the configuration of sciond. -package sdconfig +// Package config contains the configuration of sciond. +package config import ( "os" @@ -21,9 +21,11 @@ import ( "time" "github.com/scionproto/scion/go/lib/common" + "github.com/scionproto/scion/go/lib/env" "github.com/scionproto/scion/go/lib/pathstorage" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/snet" + "github.com/scionproto/scion/go/lib/truststorage" "github.com/scionproto/scion/go/lib/util" ) @@ -32,6 +34,18 @@ var ( ) type Config struct { + General env.General + Logging env.Logging + Metrics env.Metrics + TrustDB truststorage.TrustDBConf + SD SDConfig +} + +func (c *Config) InitDefaults() { + c.SD.initDefaults() +} + +type SDConfig struct { // Address to listen on via the reliable socket protocol. If empty, // a reliable socket server on the default socket is started. Reliable string @@ -55,7 +69,7 @@ type Config struct { QueryInterval util.DurWrap } -func (c *Config) InitDefaults() { +func (c *SDConfig) initDefaults() { if c.Reliable == "" { c.Reliable = sciond.DefaultSCIONDPath } @@ -69,7 +83,7 @@ func (c *Config) InitDefaults() { c.RevCache.InitDefaults() } -func (c *Config) CreateSocketDirs() error { +func (c *SDConfig) CreateSocketDirs() error { reliableDir := filepath.Dir(c.Reliable) if _, err := os.Stat(reliableDir); os.IsNotExist(err) { if err = os.MkdirAll(reliableDir, 0755); err != nil { diff --git a/go/sciond/internal/sdconfig/sample.go b/go/sciond/internal/config/sample.go similarity index 99% rename from go/sciond/internal/sdconfig/sample.go rename to go/sciond/internal/config/sample.go index bd0ad76c03..b30feb5eb7 100644 --- a/go/sciond/internal/sdconfig/sample.go +++ b/go/sciond/internal/config/sample.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sdconfig +package config const Sample = `[general] # The ID of the service. diff --git a/go/sciond/internal/sdconfig/sample_test.go b/go/sciond/internal/config/sample_test.go similarity index 89% rename from go/sciond/internal/sdconfig/sample_test.go rename to go/sciond/internal/config/sample_test.go index b642e3b1f1..ec305d4819 100644 --- a/go/sciond/internal/sdconfig/sample_test.go +++ b/go/sciond/internal/config/sample_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package sdconfig +package config import ( "testing" @@ -20,23 +20,11 @@ import ( "github.com/BurntSushi/toml" . "github.com/smartystreets/goconvey/convey" - - "github.com/scionproto/scion/go/lib/env" - "github.com/scionproto/scion/go/lib/truststorage" ) -type TestConfig struct { - General env.General - Logging env.Logging - Metrics env.Metrics - Infra env.Infra - TrustDB truststorage.TrustDBConf - SD Config -} - func TestSampleCorrect(t *testing.T) { Convey("Load", t, func() { - var cfg TestConfig + var cfg Config // Make sure DeleteSocket is set. cfg.SD.DeleteSocket = true _, err := toml.Decode(Sample, &cfg) diff --git a/go/sciond/internal/fetcher/fetcher.go b/go/sciond/internal/fetcher/fetcher.go index 280c61e125..7f1eb9a7e0 100644 --- a/go/sciond/internal/fetcher/fetcher.go +++ b/go/sciond/internal/fetcher/fetcher.go @@ -42,7 +42,7 @@ import ( "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/lib/util" "github.com/scionproto/scion/go/proto" - "github.com/scionproto/scion/go/sciond/internal/sdconfig" + "github.com/scionproto/scion/go/sciond/internal/config" ) const ( @@ -54,12 +54,11 @@ type Fetcher struct { pathDB pathdb.PathDB trustStore infra.TrustStore revocationCache revcache.RevCache - config sdconfig.Config + config config.SDConfig } -func NewFetcher(messenger infra.Messenger, pathDB pathdb.PathDB, - trustStore infra.TrustStore, revCache revcache.RevCache, cfg sdconfig.Config, - logger log.Logger) *Fetcher { +func NewFetcher(messenger infra.Messenger, pathDB pathdb.PathDB, trustStore infra.TrustStore, + revCache revcache.RevCache, cfg config.SDConfig, logger log.Logger) *Fetcher { return &Fetcher{ messenger: messenger, diff --git a/go/sciond/main.go b/go/sciond/main.go index f82b931c59..4a745e03ea 100644 --- a/go/sciond/main.go +++ b/go/sciond/main.go @@ -37,10 +37,9 @@ import ( "github.com/scionproto/scion/go/lib/pathstorage" "github.com/scionproto/scion/go/lib/periodic" "github.com/scionproto/scion/go/lib/revcache" - "github.com/scionproto/scion/go/lib/truststorage" "github.com/scionproto/scion/go/proto" + "github.com/scionproto/scion/go/sciond/internal/config" "github.com/scionproto/scion/go/sciond/internal/fetcher" - "github.com/scionproto/scion/go/sciond/internal/sdconfig" "github.com/scionproto/scion/go/sciond/internal/servers" ) @@ -48,16 +47,8 @@ const ( ShutdownWaitTimeout = 5 * time.Second ) -type Config struct { - General env.General - Logging env.Logging - Metrics env.Metrics - TrustDB truststorage.TrustDBConf - SD sdconfig.Config -} - var ( - config Config + cfg config.Config environment *env.Env ) @@ -73,7 +64,7 @@ func realMain() int { fatal.Init() env.AddFlags() flag.Parse() - if v, ok := env.CheckFlags(sdconfig.Sample); !ok { + if v, ok := env.CheckFlags(config.Sample); !ok { return v } if err := setupBasic(); err != nil { @@ -81,38 +72,38 @@ func realMain() int { return 1 } defer log.Flush() - defer env.LogAppStopped("SD", config.General.ID) + defer env.LogAppStopped("SD", cfg.General.ID) defer log.LogPanicAndExit() if err := setup(); err != nil { log.Crit("Setup failed", "err", err) return 1 } - pathDB, revCache, err := pathstorage.NewPathStorage(config.SD.PathDB, config.SD.RevCache) + pathDB, revCache, err := pathstorage.NewPathStorage(cfg.SD.PathDB, cfg.SD.RevCache) if err != nil { log.Crit("Unable to initialize path storage", "err", err) return 1 } - trustDB, err := config.TrustDB.New() + trustDB, err := cfg.TrustDB.New() if err != nil { log.Crit("Unable to initialize trustDB", "err", err) return 1 } - trustStore, err := trust.NewStore(trustDB, config.General.Topology.ISD_AS, nil, log.Root()) + trustStore, err := trust.NewStore(trustDB, cfg.General.Topology.ISD_AS, nil, log.Root()) if err != nil { log.Crit("Unable to initialize trust store", "err", err) return 1 } - err = trustStore.LoadAuthoritativeTRC(filepath.Join(config.General.ConfigDir, "certs")) + err = trustStore.LoadAuthoritativeTRC(filepath.Join(cfg.General.ConfigDir, "certs")) if err != nil { log.Crit("TRC error", "err", err) return 1 } msger, err := infraenv.InitMessenger( - config.General.Topology.ISD_AS, - config.SD.Public, - config.SD.Bind, + cfg.General.Topology.ISD_AS, + cfg.SD.Public, + cfg.SD.Bind, addr.SvcNone, - config.General.ReconnectToDispatcher, + cfg.General.ReconnectToDispatcher, trustStore, ) if err != nil { @@ -127,7 +118,7 @@ func realMain() int { pathDB, trustStore, revCache, - config.SD, + cfg.SD, log.Root(), ), }, @@ -148,13 +139,13 @@ func realMain() int { periodic.NewTicker(10*time.Second), 10*time.Second) defer rcCleaner.Stop() // Start servers - rsockServer, shutdownF := NewServer("rsock", config.SD.Reliable, handlers, log.Root()) + rsockServer, shutdownF := NewServer("rsock", cfg.SD.Reliable, handlers, log.Root()) defer shutdownF() - StartServer("ReliableSockServer", config.SD.Reliable, rsockServer) - unixpacketServer, shutdownF := NewServer("unixpacket", config.SD.Unix, handlers, log.Root()) + StartServer("ReliableSockServer", cfg.SD.Reliable, rsockServer) + unixpacketServer, shutdownF := NewServer("unixpacket", cfg.SD.Unix, handlers, log.Root()) defer shutdownF() - StartServer("UnixServer", config.SD.Unix, unixpacketServer) - config.Metrics.StartPrometheus() + StartServer("UnixServer", cfg.SD.Unix, unixpacketServer) + cfg.Metrics.StartPrometheus() select { case <-environment.AppShutdownSignal: // Whenever we receive a SIGINT or SIGTERM we exit without an error. @@ -166,23 +157,23 @@ func realMain() int { } func setupBasic() error { - if _, err := toml.DecodeFile(env.ConfigFile(), &config); err != nil { + if _, err := toml.DecodeFile(env.ConfigFile(), &cfg); err != nil { return err } - if err := env.InitLogging(&config.Logging); err != nil { + if err := env.InitLogging(&cfg.Logging); err != nil { return err } - return env.LogAppStarted("SD", config.General.ID) + return env.LogAppStarted("SD", cfg.General.ID) } func setup() error { - if err := env.InitGeneral(&config.General); err != nil { + if err := env.InitGeneral(&cfg.General); err != nil { return err } - itopo.SetCurrentTopology(config.General.Topology) - environment = infraenv.InitInfraEnvironment(config.General.TopologyPath) - config.SD.InitDefaults() - return config.SD.CreateSocketDirs() + itopo.SetCurrentTopology(cfg.General.Topology) + environment = infraenv.InitInfraEnvironment(cfg.General.TopologyPath) + cfg.InitDefaults() + return cfg.SD.CreateSocketDirs() } func NewServer(network string, rsockPath string, handlers servers.HandlerMap, @@ -200,7 +191,7 @@ func NewServer(network string, rsockPath string, handlers servers.HandlerMap, func StartServer(name, sockPath string, server *servers.Server) { go func() { defer log.LogPanicAndExit() - if config.SD.DeleteSocket { + if cfg.SD.DeleteSocket { if err := os.Remove(sockPath); err != nil && !os.IsNotExist(err) { fatal.Fatal(common.NewBasicError(name+" SocketRemoval error", err)) }