|
@ -6,85 +6,12 @@ import ( |
|
|
"flag" |
|
|
"flag" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"log" |
|
|
|
|
|
"os" |
|
|
"os" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
"strings" |
|
|
"strings" |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var rootDir string |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
rootDir = os.Getenv("TMROOT") |
|
|
|
|
|
if rootDir == "" { |
|
|
|
|
|
rootDir = os.Getenv("HOME") + "/.tendermint" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ConfigFile() string { return rootDir + "/config.json" } |
|
|
|
|
|
func GenesisFile() string { return rootDir + "/genesis.json" } |
|
|
|
|
|
func AddrBookFile() string { return rootDir + "/addrbook.json" } |
|
|
|
|
|
func PrivValidatorFile() string { return rootDir + "/priv_validator.json" } |
|
|
|
|
|
func DataDir() string { return rootDir + "/data" } |
|
|
|
|
|
|
|
|
|
|
|
var Config ConfigType |
|
|
|
|
|
|
|
|
|
|
|
func setFlags(printHelp *bool) { |
|
|
|
|
|
flag.BoolVar(printHelp, "help", false, "Print this help message.") |
|
|
|
|
|
flag.StringVar(&Config.LAddr, "laddr", Config.LAddr, "Listen address. (0.0.0.0:0 means any interface, any port)") |
|
|
|
|
|
flag.StringVar(&Config.SeedNode, "seed", Config.SeedNode, "Address of seed node") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ParseFlags() { |
|
|
|
|
|
configFile := ConfigFile() |
|
|
|
|
|
|
|
|
|
|
|
// try to read configuration. if missing, write default
|
|
|
|
|
|
configBytes, err := ioutil.ReadFile(configFile) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
defaultConfig.write(configFile) |
|
|
|
|
|
fmt.Println("Config file written to config.json. Please edit & run again") |
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// try to parse configuration. on error, die
|
|
|
|
|
|
Config = ConfigType{} |
|
|
|
|
|
err = json.Unmarshal(configBytes, &Config) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Panicf("Invalid configuration file %s: %v", configFile, err) |
|
|
|
|
|
} |
|
|
|
|
|
err = Config.validate() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Panicf("Invalid configuration file %s: %v", configFile, err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// try to parse arg flags, which can override file configuration.
|
|
|
|
|
|
var printHelp bool |
|
|
|
|
|
setFlags(&printHelp) |
|
|
|
|
|
flag.Parse() |
|
|
|
|
|
if printHelp { |
|
|
|
|
|
flag.PrintDefaults() |
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------j
|
|
|
|
|
|
// Default configuration
|
|
|
|
|
|
|
|
|
|
|
|
var defaultConfig = ConfigType{ |
|
|
|
|
|
Network: "tendermint_testnet0", |
|
|
|
|
|
LAddr: "0.0.0.0:0", |
|
|
|
|
|
SeedNode: "", |
|
|
|
|
|
Db: DbConfig{ |
|
|
|
|
|
Type: "level", |
|
|
|
|
|
Dir: DataDir(), |
|
|
|
|
|
}, |
|
|
|
|
|
Alert: AlertConfig{}, |
|
|
|
|
|
SMTP: SMTPConfig{}, |
|
|
|
|
|
RPC: RPCConfig{ |
|
|
|
|
|
HTTPPort: 8888, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
. "github.com/tendermint/tendermint/common" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------j
|
|
|
//-----------------------------------------------------------------------------j
|
|
|
// Configuration types
|
|
|
// Configuration types
|
|
@ -93,15 +20,15 @@ type ConfigType struct { |
|
|
Network string |
|
|
Network string |
|
|
LAddr string |
|
|
LAddr string |
|
|
SeedNode string |
|
|
SeedNode string |
|
|
Db DbConfig |
|
|
|
|
|
|
|
|
DB DBConfig |
|
|
Alert AlertConfig |
|
|
Alert AlertConfig |
|
|
SMTP SMTPConfig |
|
|
SMTP SMTPConfig |
|
|
RPC RPCConfig |
|
|
RPC RPCConfig |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type DbConfig struct { |
|
|
|
|
|
Type string |
|
|
|
|
|
Dir string |
|
|
|
|
|
|
|
|
type DBConfig struct { |
|
|
|
|
|
Backend string |
|
|
|
|
|
Dir string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type AlertConfig struct { |
|
|
type AlertConfig struct { |
|
@ -126,8 +53,6 @@ type RPCConfig struct { |
|
|
HTTPPort uint |
|
|
HTTPPort uint |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------j
|
|
|
|
|
|
|
|
|
|
|
|
func (cfg *ConfigType) validate() error { |
|
|
func (cfg *ConfigType) validate() error { |
|
|
if cfg.Network == "" { |
|
|
if cfg.Network == "" { |
|
|
cfg.Network = defaultConfig.Network |
|
|
cfg.Network = defaultConfig.Network |
|
@ -138,8 +63,8 @@ func (cfg *ConfigType) validate() error { |
|
|
if cfg.SeedNode == "" { |
|
|
if cfg.SeedNode == "" { |
|
|
cfg.SeedNode = defaultConfig.SeedNode |
|
|
cfg.SeedNode = defaultConfig.SeedNode |
|
|
} |
|
|
} |
|
|
if cfg.Db.Type == "" { |
|
|
|
|
|
return errors.New("Db.Type must be set") |
|
|
|
|
|
|
|
|
if cfg.DB.Backend == "" { |
|
|
|
|
|
return errors.New("DB.Backend must be set") |
|
|
} |
|
|
} |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
@ -164,3 +89,79 @@ func (cfg *ConfigType) write(configFile string) { |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
var rootDir string |
|
|
|
|
|
var defaultConfig ConfigType |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
|
// Get RootDir
|
|
|
|
|
|
rootDir = os.Getenv("TMROOT") |
|
|
|
|
|
if rootDir == "" { |
|
|
|
|
|
rootDir = os.Getenv("HOME") + "/.tendermint" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Compute defaultConfig
|
|
|
|
|
|
defaultConfig = ConfigType{ |
|
|
|
|
|
Network: "tendermint_testnet0", |
|
|
|
|
|
LAddr: "0.0.0.0:0", |
|
|
|
|
|
SeedNode: "", |
|
|
|
|
|
DB: DBConfig{ |
|
|
|
|
|
Backend: "leveldb", |
|
|
|
|
|
Dir: DataDir(), |
|
|
|
|
|
}, |
|
|
|
|
|
Alert: AlertConfig{}, |
|
|
|
|
|
SMTP: SMTPConfig{}, |
|
|
|
|
|
RPC: RPCConfig{ |
|
|
|
|
|
HTTPPort: 8888, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ConfigFile() string { return rootDir + "/config.json" } |
|
|
|
|
|
func GenesisFile() string { return rootDir + "/genesis.json" } |
|
|
|
|
|
func AddrBookFile() string { return rootDir + "/addrbook.json" } |
|
|
|
|
|
func PrivValidatorFile() string { return rootDir + "/priv_validator.json" } |
|
|
|
|
|
func DataDir() string { return rootDir + "/data" } |
|
|
|
|
|
|
|
|
|
|
|
var Config ConfigType |
|
|
|
|
|
|
|
|
|
|
|
func setFlags(printHelp *bool) { |
|
|
|
|
|
flag.BoolVar(printHelp, "help", false, "Print this help message.") |
|
|
|
|
|
flag.StringVar(&Config.LAddr, "laddr", Config.LAddr, "Listen address. (0.0.0.0:0 means any interface, any port)") |
|
|
|
|
|
flag.StringVar(&Config.SeedNode, "seed", Config.SeedNode, "Address of seed node") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ParseFlags() { |
|
|
|
|
|
configFile := ConfigFile() |
|
|
|
|
|
|
|
|
|
|
|
// try to read configuration. if missing, write default
|
|
|
|
|
|
configBytes, err := ioutil.ReadFile(configFile) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
defaultConfig.write(configFile) |
|
|
|
|
|
fmt.Println("Config file written to config.json. Please edit & run again") |
|
|
|
|
|
os.Exit(1) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// try to parse configuration. on error, die
|
|
|
|
|
|
Config = ConfigType{} |
|
|
|
|
|
err = json.Unmarshal(configBytes, &Config) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
Exitf("Invalid configuration file %s: %v", configFile, err) |
|
|
|
|
|
} |
|
|
|
|
|
err = Config.validate() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
Exitf("Invalid configuration file %s: %v", configFile, err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// try to parse arg flags, which can override file configuration.
|
|
|
|
|
|
var printHelp bool |
|
|
|
|
|
setFlags(&printHelp) |
|
|
|
|
|
flag.Parse() |
|
|
|
|
|
if printHelp { |
|
|
|
|
|
flag.PrintDefaults() |
|
|
|
|
|
os.Exit(0) |
|
|
|
|
|
} |
|
|
|
|
|
} |