mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-14 01:56:44 +00:00

* [NOD-445] Added option to mining simulator to get address list from AWS * [NOD-445] Add support to get miningsimulator addresslist from AWS * [NOD-445] Added mechanism to update when new servers come online * [NOD-445] Set config in connectionManager * [NOD-445] Invert DisableTLS condition in readCert
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/daglabs/btcd/util"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/jessevdk/go-flags"
|
|
)
|
|
|
|
const (
|
|
defaultLogFilename = "miningsimulator.log"
|
|
defaultErrLogFilename = "miningsimulator_err.log"
|
|
)
|
|
|
|
var (
|
|
// Default configuration options
|
|
defaultHomeDir = util.AppDataDir("miningsimulator", false)
|
|
defaultLogFile = filepath.Join(defaultHomeDir, defaultLogFilename)
|
|
defaultErrLogFile = filepath.Join(defaultHomeDir, defaultErrLogFilename)
|
|
)
|
|
|
|
type config struct {
|
|
AutoScalingGroup string `long:"autoscaling" description:"AWS AutoScalingGroup to use for address list"`
|
|
Region string `long:"region" description:"AWS region to use for address list"`
|
|
AddressListPath string `long:"addresslist" description:"Path to a list of nodes' JSON-RPC endpoints"`
|
|
CertificatePath string `long:"cert" description:"Path to certificate accepted by JSON-RPC endpoint"`
|
|
DisableTLS bool `long:"notls" description:"Disable TLS"`
|
|
Verbose bool `long:"verbose" short:"v" description:"Enable logging of RPC requests"`
|
|
}
|
|
|
|
func parseConfig() (*config, error) {
|
|
cfg := &config{}
|
|
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
|
|
_, err := parser.Parse()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if cfg.CertificatePath == "" && !cfg.DisableTLS {
|
|
return nil, errors.New("--notls has to be disabled if --cert is used")
|
|
}
|
|
|
|
if cfg.CertificatePath != "" && cfg.DisableTLS {
|
|
return nil, errors.New("--cert should be omitted if --notls is used")
|
|
}
|
|
|
|
if (cfg.AutoScalingGroup == "" || cfg.Region == "") && cfg.AddressListPath == "" {
|
|
return nil, errors.New("Either (--autoscaling and --region) or --addresslist must be specified")
|
|
}
|
|
|
|
if (cfg.AutoScalingGroup != "" || cfg.Region != "") && cfg.AddressListPath != "" {
|
|
return nil, errors.New("Both (--autoscaling and --region) and --addresslist can't be specified at the same time")
|
|
}
|
|
|
|
if cfg.AutoScalingGroup != "" && cfg.Region == "" {
|
|
return nil, errors.New("If --autoscaling is specified --region must be specified as well")
|
|
}
|
|
|
|
initLog(defaultLogFile, defaultErrLogFile)
|
|
|
|
return cfg, nil
|
|
}
|