From ce9dce27a3d2b594da7c84d43ea35be0c8c0ce0d Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 28 Feb 2022 13:51:23 -0500 Subject: [PATCH] Added global constants files for use in this and other projects --- controller/config.go | 8 +++--- controller/constants.go | 10 +++++++ controller/network/constants.go | 13 +++++++++ controller/network/options.go | 14 +++++----- router/forwarder/constants.go | 25 ++++++++++++++++++ router/forwarder/options.go | 47 +++++++++++++++++---------------- xweb/config.go | 23 +++++----------- xweb/constants.go | 31 ++++++++++++++++++++++ 8 files changed, 121 insertions(+), 50 deletions(-) create mode 100644 controller/constants.go create mode 100644 controller/network/constants.go create mode 100644 router/forwarder/constants.go create mode 100644 xweb/constants.go diff --git a/controller/config.go b/controller/config.go index 01a64db1f..10c68d8fd 100644 --- a/controller/config.go +++ b/controller/config.go @@ -174,7 +174,7 @@ func LoadConfig(path string) (*Config, error) { if value, found := submap["intervalMs"]; found { controllerConfig.Profile.Memory.Interval = time.Duration(value.(int)) * time.Millisecond } else { - controllerConfig.Profile.Memory.Interval = 15 * time.Second + controllerConfig.Profile.Memory.Interval = DefaultProfileMemoryInterval } } } @@ -288,9 +288,9 @@ func LoadConfig(path string) (*Config, error) { } } - controllerConfig.HealthChecks.BoltCheck.Interval = 30 * time.Second - controllerConfig.HealthChecks.BoltCheck.Timeout = 20 * time.Second - controllerConfig.HealthChecks.BoltCheck.InitialDelay = 30 * time.Second + controllerConfig.HealthChecks.BoltCheck.Interval = DefaultHealthChecksBoltCheckInterval + controllerConfig.HealthChecks.BoltCheck.Timeout = DefaultHealthChecksBoltCheckTimeout + controllerConfig.HealthChecks.BoltCheck.InitialDelay = DefaultHealthChecksBoltCheckInitialDelay if value, found := cfgmap["healthChecks"]; found { if healthChecksMap, ok := value.(map[interface{}]interface{}); ok { diff --git a/controller/constants.go b/controller/constants.go new file mode 100644 index 000000000..e3a231fa6 --- /dev/null +++ b/controller/constants.go @@ -0,0 +1,10 @@ +package controller + +import "time" + +const ( + DefaultProfileMemoryInterval = 15 * time.Second + DefaultHealthChecksBoltCheckInterval = 30 * time.Second + DefaultHealthChecksBoltCheckTimeout = 20 * time.Second + DefaultHealthChecksBoltCheckInitialDelay = 30 * time.Second +) diff --git a/controller/network/constants.go b/controller/network/constants.go new file mode 100644 index 000000000..78813c6bd --- /dev/null +++ b/controller/network/constants.go @@ -0,0 +1,13 @@ +package network + +import "time" + +const ( + DefaultNetworkOptionsCycleSeconds = 60 + DefaultNetworkOptionsRouteTimeout = 10 * time.Second + DefaultNetworkOptionsCreateCircuitRetries = 3 + DefaultNetworkOptionsCtrlChanLatencyInterval = 10 * time.Second + DefaultNetworkOptionsPendingLinkTimeout = 10 * time.Second + DefaultNetworkOptionsSmartRerouteFraction = 0.02 + DefaultNetworkOptionsSmartRerouteCap = 4 +) diff --git a/controller/network/options.go b/controller/network/options.go index e2df90131..d8ee3fd4e 100644 --- a/controller/network/options.go +++ b/controller/network/options.go @@ -36,14 +36,14 @@ type Options struct { func DefaultOptions() *Options { options := &Options{ - CycleSeconds: 60, - RouteTimeout: 10 * time.Second, - CreateCircuitRetries: 3, - CtrlChanLatencyInterval: 10 * time.Second, - PendingLinkTimeout: 10 * time.Second, + CycleSeconds: DefaultNetworkOptionsCycleSeconds, + RouteTimeout: DefaultNetworkOptionsRouteTimeout, + CreateCircuitRetries: DefaultNetworkOptionsCreateCircuitRetries, + CtrlChanLatencyInterval: DefaultNetworkOptionsCtrlChanLatencyInterval, + PendingLinkTimeout: DefaultNetworkOptionsPendingLinkTimeout, } - options.Smart.RerouteFraction = 0.02 - options.Smart.RerouteCap = 4 + options.Smart.RerouteFraction = DefaultNetworkOptionsSmartRerouteFraction + options.Smart.RerouteCap = DefaultNetworkOptionsSmartRerouteCap return options } diff --git a/router/forwarder/constants.go b/router/forwarder/constants.go new file mode 100644 index 000000000..60d9fc8bd --- /dev/null +++ b/router/forwarder/constants.go @@ -0,0 +1,25 @@ +package forwarder + +import "time" + +const ( + DefaultLatencyProbeInterval = 10 * time.Second + DefaultLatencyProbeTimeout = 10 * time.Second + DefaultXgressCloseCheckInterval = 5 * time.Second + DefaultXgressDialDwellTime = 0 + DefaultFaultTxInterval = 15 * time.Second + DefaultIdleTxInterval = 60 * time.Second + DefaultIdleCircuitTimeout = 60 * time.Second + DefaultXgressDialWorkerQueueLength = 1000 + MinXgressDialWorkerQueueLength = 1 + MaxXgressDialWorkerQueueLength = 10000 + DefaultXgressDialWorkerCount = 10 + MinXgressDialWorkerCount = 1 + MaxXgressDialWorkerCount = 10000 + DefaultLinkDialQueueLength = 1000 + MinLinkDialWorkerQueueLength = 1 + MaxLinkDialWorkerQueueLength = 10000 + DefaultLinkDialWorkerCount = 10 + MinLinkDialWorkerCount = 1 + MaxLinkDialWorkerCount = 10000 +) diff --git a/router/forwarder/options.go b/router/forwarder/options.go index 3c0a072b4..016157cc3 100644 --- a/router/forwarder/options.go +++ b/router/forwarder/options.go @@ -18,6 +18,7 @@ package forwarder import ( "errors" + "fmt" "time" ) @@ -40,20 +41,20 @@ type WorkerPoolOptions struct { func DefaultOptions() *Options { return &Options{ - LatencyProbeInterval: 10 * time.Second, - LatencyProbeTimeout: 10 * time.Second, - XgressCloseCheckInterval: 5 * time.Second, - XgressDialDwellTime: 0, - FaultTxInterval: 15 * time.Second, - IdleTxInterval: 60 * time.Second, - IdleCircuitTimeout: 60 * time.Second, + LatencyProbeInterval: DefaultLatencyProbeInterval, + LatencyProbeTimeout: DefaultLatencyProbeTimeout, + XgressCloseCheckInterval: DefaultXgressCloseCheckInterval, + XgressDialDwellTime: DefaultXgressDialDwellTime, + FaultTxInterval: DefaultFaultTxInterval, + IdleTxInterval: DefaultIdleTxInterval, + IdleCircuitTimeout: DefaultIdleCircuitTimeout, XgressDial: WorkerPoolOptions{ - QueueLength: 1000, - WorkerCount: 10, + QueueLength: DefaultXgressDialWorkerQueueLength, + WorkerCount: DefaultXgressDialWorkerCount, }, LinkDial: WorkerPoolOptions{ - QueueLength: 1000, - WorkerCount: 10, + QueueLength: DefaultLinkDialQueueLength, + WorkerCount: DefaultLinkDialWorkerCount, }, } } @@ -119,45 +120,45 @@ func LoadOptions(src map[interface{}]interface{}) (*Options, error) { if value, found := src["xgressDialQueueLength"]; found { if length, ok := value.(int); ok { - if length <= 0 || length > 10000 { - return nil, errors.New("invalid value for 'xgressDialQueueLength', expected integer between 1 and 1000") + if length < MinXgressDialWorkerQueueLength || length > MaxXgressDialWorkerQueueLength { + return nil, errors.New(fmt.Sprintf("invalid value for 'xgressDialQueueLength', expected integer between %v and %v", MinXgressDialWorkerQueueLength, MaxXgressDialWorkerQueueLength)) } options.XgressDial.QueueLength = uint16(length) } else { - return nil, errors.New("invalid value for 'xgressDialQueueLength', expected integer between 1 and 1000") + return nil, errors.New(fmt.Sprintf("invalid value for 'xgressDialQueueLength', expected integer between %v and %v", MinXgressDialWorkerQueueLength, MaxXgressDialWorkerQueueLength)) } } if value, found := src["xgressDialWorkerCount"]; found { if workers, ok := value.(int); ok { - if workers <= 0 || workers > 10000 { - return nil, errors.New("invalid value for 'xgressDialWorkerCount', expected integer between 1 and 1000") + if workers < MinXgressDialWorkerCount || workers > MaxXgressDialWorkerCount { + return nil, errors.New(fmt.Sprintf("invalid value for 'xgressDialWorkerCount', expected integer between %v and %v", MinXgressDialWorkerCount, MaxXgressDialWorkerCount)) } options.XgressDial.WorkerCount = uint16(workers) } else { - return nil, errors.New("invalid value for 'xgressDialWorkerCount', expected integer between 1 and 1000") + return nil, errors.New(fmt.Sprintf("invalid value for 'xgressDialWorkerCount', expected integer between %v and %v", MinXgressDialWorkerCount, MaxXgressDialWorkerCount)) } } if value, found := src["linkDialQueueLength"]; found { if length, ok := value.(int); ok { - if length <= 0 || length > 10000 { - return nil, errors.New("invalid value for 'linkDialQueueLength', expected integer between 1 and 1000") + if length < MinLinkDialWorkerQueueLength || length > MaxLinkDialWorkerQueueLength { + return nil, errors.New(fmt.Sprintf("invalid value for 'linkDialQueueLength', expected integer between %v and %v", MinLinkDialWorkerQueueLength, MaxLinkDialWorkerQueueLength)) } options.LinkDial.QueueLength = uint16(length) } else { - return nil, errors.New("invalid value for 'linkDialQueueLength', expected integer between 1 and 1000") + return nil, errors.New(fmt.Sprintf("invalid value for 'linkDialQueueLength', expected integer between %v and %v", MinLinkDialWorkerQueueLength, MaxLinkDialWorkerQueueLength)) } } if value, found := src["linkDialWorkerCount"]; found { if workers, ok := value.(int); ok { - if workers <= 0 || workers > 10000 { - return nil, errors.New("invalid value for 'linkDialWorkerCount', expected integer between 10 and 1000") + if workers <= MinLinkDialWorkerCount || workers > MaxLinkDialWorkerCount { + return nil, errors.New(fmt.Sprintf("invalid value for 'linkDialWorkerCount', expected integer between %v and %v", MinLinkDialWorkerCount, MaxLinkDialWorkerCount)) } options.LinkDial.WorkerCount = uint16(workers) } else { - return nil, errors.New("invalid value for 'linkDialWorkerCount', expected integer between 10 and 1000") + return nil, errors.New(fmt.Sprintf("invalid value for 'linkDialWorkerCount', expected integer between %v and %v", MinLinkDialWorkerCount, MaxLinkDialWorkerCount)) } } diff --git a/xweb/config.go b/xweb/config.go index 0b23bf246..9b44f90b6 100644 --- a/xweb/config.go +++ b/xweb/config.go @@ -17,7 +17,6 @@ package xweb import ( - "crypto/tls" "errors" "fmt" "github.com/openziti/foundation/identity/identity" @@ -180,9 +179,9 @@ type TimeoutOptions struct { // Default defaults all HTTP timeout options func (timeoutOptions *TimeoutOptions) Default() { - timeoutOptions.WriteTimeout = time.Second * 10 - timeoutOptions.ReadTimeout = time.Second * 5 - timeoutOptions.IdleTimeout = time.Second * 5 + timeoutOptions.WriteTimeout = DefaultHttpWriteTimeout + timeoutOptions.ReadTimeout = DefaultHttpReadTimeout + timeoutOptions.IdleTimeout = DefaultHttpIdleTimeout } // Parse parses a config map @@ -252,18 +251,10 @@ type TlsVersionOptions struct { maxTLSVersionStr string } -// tlsVersionMap is a map of configuration strings to TLS version identifiers -var tlsVersionMap = map[string]int{ - "TLS1.0": tls.VersionTLS10, - "TLS1.1": tls.VersionTLS11, - "TLS1.2": tls.VersionTLS12, - "TLS1.3": tls.VersionTLS13, -} - // Default defaults TLS versions func (tlsVersionOptions *TlsVersionOptions) Default() { - tlsVersionOptions.MinTLSVersion = tls.VersionTLS12 - tlsVersionOptions.MaxTLSVersion = tls.VersionTLS13 + tlsVersionOptions.MinTLSVersion = MinTLSVersion + tlsVersionOptions.MaxTLSVersion = MaxTLSVersion } // Parse parses a config map @@ -271,7 +262,7 @@ func (tlsVersionOptions *TlsVersionOptions) Parse(config map[interface{}]interfa if interfaceVal, ok := config["minTLSVersion"]; ok { var ok bool if tlsVersionOptions.minTLSVersionStr, ok = interfaceVal.(string); ok { - if minTLSVersion, ok := tlsVersionMap[tlsVersionOptions.minTLSVersionStr]; ok { + if minTLSVersion, ok := TlsVersionMap[tlsVersionOptions.minTLSVersionStr]; ok { tlsVersionOptions.MinTLSVersion = minTLSVersion } else { return fmt.Errorf("could not use value for minTLSVersion, invalid value [%s]", tlsVersionOptions.minTLSVersionStr) @@ -284,7 +275,7 @@ func (tlsVersionOptions *TlsVersionOptions) Parse(config map[interface{}]interfa if interfaceVal, ok := config["maxTLSVersion"]; ok { var ok bool if tlsVersionOptions.maxTLSVersionStr, ok = interfaceVal.(string); ok { - if maxTLSVersion, ok := tlsVersionMap[tlsVersionOptions.maxTLSVersionStr]; ok { + if maxTLSVersion, ok := TlsVersionMap[tlsVersionOptions.maxTLSVersionStr]; ok { tlsVersionOptions.MaxTLSVersion = maxTLSVersion } else { return fmt.Errorf("could not use value for maxTLSVersion, invalid value [%s]", tlsVersionOptions.maxTLSVersionStr) diff --git a/xweb/constants.go b/xweb/constants.go new file mode 100644 index 000000000..6dd21f3af --- /dev/null +++ b/xweb/constants.go @@ -0,0 +1,31 @@ +package xweb + +import ( + "crypto/tls" + "time" +) + +const ( + MinTLSVersion = tls.VersionTLS12 + MaxTLSVersion = tls.VersionTLS13 + + DefaultHttpWriteTimeout = time.Second * 10 + DefaultHttpReadTimeout = time.Second * 5 + DefaultHttpIdleTimeout = time.Second * 5 +) + +// TlsVersionMap is a map of configuration strings to TLS version identifiers +var TlsVersionMap = map[string]int{ + "TLS1.0": tls.VersionTLS10, + "TLS1.1": tls.VersionTLS11, + "TLS1.2": tls.VersionTLS12, + "TLS1.3": tls.VersionTLS13, +} + +// ReverseTlsVersionMap is a map of TLS version identifiers to configuration strings +var ReverseTlsVersionMap = map[int]string{ + tls.VersionTLS10: "TLS1.0", + tls.VersionTLS11: "TLS1.1", + tls.VersionTLS12: "TLS1.2", + tls.VersionTLS13: "TLS1.3", +}