2017-12-11 21:56:06 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"strconv"
|
2017-12-13 09:23:11 +00:00
|
|
|
"strings"
|
2018-06-20 12:06:27 +00:00
|
|
|
"time"
|
2017-12-11 21:56:06 +00:00
|
|
|
"unicode"
|
|
|
|
|
|
|
|
cli "gopkg.in/urfave/cli.v1"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/naoina/toml"
|
|
|
|
|
|
|
|
bzzapi "github.com/ethereum/go-ethereum/swarm/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//flag definition for the dumpconfig command
|
|
|
|
DumpConfigCommand = cli.Command{
|
|
|
|
Action: utils.MigrateFlags(dumpConfig),
|
|
|
|
Name: "dumpconfig",
|
|
|
|
Usage: "Show configuration values",
|
|
|
|
ArgsUsage: "",
|
|
|
|
Flags: app.Flags,
|
|
|
|
Category: "MISCELLANEOUS COMMANDS",
|
|
|
|
Description: `The dumpconfig command shows configuration values.`,
|
|
|
|
}
|
|
|
|
|
|
|
|
//flag definition for the config file command
|
|
|
|
SwarmTomlConfigPathFlag = cli.StringFlag{
|
|
|
|
Name: "config",
|
|
|
|
Usage: "TOML configuration file",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
//constants for environment variables
|
|
|
|
const (
|
2019-02-24 11:39:23 +00:00
|
|
|
SwarmEnvChequebookAddr = "SWARM_CHEQUEBOOK_ADDR"
|
|
|
|
SwarmEnvAccount = "SWARM_ACCOUNT"
|
|
|
|
SwarmEnvListenAddr = "SWARM_LISTEN_ADDR"
|
|
|
|
SwarmEnvPort = "SWARM_PORT"
|
|
|
|
SwarmEnvNetworkID = "SWARM_NETWORK_ID"
|
|
|
|
SwarmEnvSwapEnable = "SWARM_SWAP_ENABLE"
|
|
|
|
SwarmEnvSwapAPI = "SWARM_SWAP_API"
|
|
|
|
SwarmEnvSyncDisable = "SWARM_SYNC_DISABLE"
|
|
|
|
SwarmEnvSyncUpdateDelay = "SWARM_ENV_SYNC_UPDATE_DELAY"
|
|
|
|
SwarmEnvMaxStreamPeerServers = "SWARM_ENV_MAX_STREAM_PEER_SERVERS"
|
|
|
|
SwarmEnvLightNodeEnable = "SWARM_LIGHT_NODE_ENABLE"
|
|
|
|
SwarmEnvDeliverySkipCheck = "SWARM_DELIVERY_SKIP_CHECK"
|
|
|
|
SwarmEnvENSAPI = "SWARM_ENS_API"
|
|
|
|
SwarmEnvENSAddr = "SWARM_ENS_ADDR"
|
|
|
|
SwarmEnvCORS = "SWARM_CORS"
|
|
|
|
SwarmEnvBootnodes = "SWARM_BOOTNODES"
|
|
|
|
SwarmEnvPSSEnable = "SWARM_PSS_ENABLE"
|
|
|
|
SwarmEnvStorePath = "SWARM_STORE_PATH"
|
|
|
|
SwarmEnvStoreCapacity = "SWARM_STORE_CAPACITY"
|
|
|
|
SwarmEnvStoreCacheCapacity = "SWARM_STORE_CACHE_CAPACITY"
|
|
|
|
SwarmEnvBootnodeMode = "SWARM_BOOTNODE_MODE"
|
|
|
|
SwarmAccessPassword = "SWARM_ACCESS_PASSWORD"
|
|
|
|
SwarmAutoDefaultPath = "SWARM_AUTO_DEFAULTPATH"
|
|
|
|
SwarmGlobalstoreAPI = "SWARM_GLOBALSTORE_API"
|
|
|
|
GethEnvDataDir = "GETH_DATADIR"
|
2017-12-11 21:56:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// These settings ensure that TOML keys use the same names as Go struct fields.
|
|
|
|
var tomlSettings = toml.Config{
|
|
|
|
NormFieldName: func(rt reflect.Type, key string) string {
|
|
|
|
return key
|
|
|
|
},
|
|
|
|
FieldToKey: func(rt reflect.Type, field string) string {
|
|
|
|
return field
|
|
|
|
},
|
|
|
|
MissingField: func(rt reflect.Type, field string) error {
|
|
|
|
link := ""
|
|
|
|
if unicode.IsUpper(rune(rt.Name()[0])) && rt.PkgPath() != "main" {
|
|
|
|
link = fmt.Sprintf(", check github.com/ethereum/go-ethereum/swarm/api/config.go for available fields")
|
|
|
|
}
|
|
|
|
return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
//before booting the swarm node, build the configuration
|
|
|
|
func buildConfig(ctx *cli.Context) (config *bzzapi.Config, err error) {
|
|
|
|
//start by creating a default config
|
2018-06-20 12:06:27 +00:00
|
|
|
config = bzzapi.NewConfig()
|
2017-12-11 21:56:06 +00:00
|
|
|
//first load settings from config file (if provided)
|
|
|
|
config, err = configFileOverride(config, ctx)
|
2017-12-19 22:05:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-12-11 21:56:06 +00:00
|
|
|
//override settings provided by environment variables
|
|
|
|
config = envVarsOverride(config)
|
|
|
|
//override settings provided by command line
|
|
|
|
config = cmdLineOverride(config, ctx)
|
2017-12-19 10:47:26 +00:00
|
|
|
//validate configuration parameters
|
|
|
|
err = validateConfig(config)
|
2017-12-11 21:56:06 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//finally, after the configuration build phase is finished, initialize
|
2019-03-22 04:55:47 +00:00
|
|
|
func initSwarmNode(config *bzzapi.Config, stack *node.Node, ctx *cli.Context, nodeconfig *node.Config) error {
|
2017-12-11 21:56:06 +00:00
|
|
|
//at this point, all vars should be set in the Config
|
|
|
|
//get the account for the provided swarm account
|
|
|
|
prvkey := getAccount(config.BzzAccount, ctx, stack)
|
|
|
|
//set the resolved config path (geth --datadir)
|
2018-09-25 12:54:47 +00:00
|
|
|
config.Path = expandPath(stack.InstanceDir())
|
2017-12-11 21:56:06 +00:00
|
|
|
//finally, initialize the configuration
|
2019-03-22 04:55:47 +00:00
|
|
|
err := config.Init(prvkey, nodeconfig.NodeKey())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-11 21:56:06 +00:00
|
|
|
//configuration phase completed here
|
|
|
|
log.Debug("Starting Swarm with the following parameters:")
|
|
|
|
//after having created the config, print it to screen
|
|
|
|
log.Debug(printConfig(config))
|
2019-03-22 04:55:47 +00:00
|
|
|
return nil
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 09:37:00 +00:00
|
|
|
//configFileOverride overrides the current config with the config file, if a config file has been provided
|
2017-12-11 21:56:06 +00:00
|
|
|
func configFileOverride(config *bzzapi.Config, ctx *cli.Context) (*bzzapi.Config, error) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
//only do something if the -config flag has been set
|
|
|
|
if ctx.GlobalIsSet(SwarmTomlConfigPathFlag.Name) {
|
|
|
|
var filepath string
|
|
|
|
if filepath = ctx.GlobalString(SwarmTomlConfigPathFlag.Name); filepath == "" {
|
|
|
|
utils.Fatalf("Config file flag provided with invalid file path")
|
|
|
|
}
|
2018-08-09 09:37:00 +00:00
|
|
|
var f *os.File
|
|
|
|
f, err = os.Open(filepath)
|
2017-12-11 21:56:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
//decode the TOML file into a Config struct
|
|
|
|
//note that we are decoding into the existing defaultConfig;
|
|
|
|
//if an entry is not present in the file, the default entry is kept
|
|
|
|
err = tomlSettings.NewDecoder(f).Decode(&config)
|
|
|
|
// Add file name to errors that have a line number.
|
|
|
|
if _, ok := err.(*toml.LineError); ok {
|
|
|
|
err = errors.New(filepath + ", " + err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return config, err
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:02:18 +00:00
|
|
|
// cmdLineOverride overrides the current config with whatever is provided through the command line
|
|
|
|
// most values are not allowed a zero value (empty string), if not otherwise noted
|
2017-12-11 21:56:06 +00:00
|
|
|
func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Config {
|
|
|
|
if keyid := ctx.GlobalString(SwarmAccountFlag.Name); keyid != "" {
|
|
|
|
currentConfig.BzzAccount = keyid
|
|
|
|
}
|
|
|
|
|
|
|
|
if chbookaddr := ctx.GlobalString(ChequebookAddrFlag.Name); chbookaddr != "" {
|
|
|
|
currentConfig.Contract = common.HexToAddress(chbookaddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
id, err := strconv.ParseUint(networkid, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
utils.Fatalf("invalid cli flag %s: %v", SwarmNetworkIdFlag.Name, err)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
2018-09-28 13:56:42 +00:00
|
|
|
if id != 0 {
|
|
|
|
currentConfig.NetworkID = id
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.GlobalIsSet(utils.DataDirFlag.Name) {
|
|
|
|
if datadir := ctx.GlobalString(utils.DataDirFlag.Name); datadir != "" {
|
2018-09-25 12:54:47 +00:00
|
|
|
currentConfig.Path = expandPath(datadir)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bzzport := ctx.GlobalString(SwarmPortFlag.Name)
|
|
|
|
if len(bzzport) > 0 {
|
|
|
|
currentConfig.Port = bzzport
|
|
|
|
}
|
|
|
|
|
|
|
|
if bzzaddr := ctx.GlobalString(SwarmListenAddrFlag.Name); bzzaddr != "" {
|
|
|
|
currentConfig.ListenAddr = bzzaddr
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.GlobalIsSet(SwarmSwapEnabledFlag.Name) {
|
|
|
|
currentConfig.SwapEnabled = true
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmSyncDisabledFlag.Name) {
|
|
|
|
currentConfig.SyncEnabled = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if d := ctx.GlobalDuration(SwarmSyncUpdateDelay.Name); d > 0 {
|
|
|
|
currentConfig.SyncUpdateDelay = d
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 15:40:22 +00:00
|
|
|
// any value including 0 is acceptable
|
|
|
|
currentConfig.MaxStreamPeerServers = ctx.GlobalInt(SwarmMaxStreamPeerServersFlag.Name)
|
|
|
|
|
2018-08-07 13:34:11 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmLightNodeEnabled.Name) {
|
|
|
|
currentConfig.LightNodeEnabled = true
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmDeliverySkipCheckFlag.Name) {
|
|
|
|
currentConfig.DeliverySkipCheck = true
|
|
|
|
}
|
|
|
|
|
|
|
|
currentConfig.SwapAPI = ctx.GlobalString(SwarmSwapAPIFlag.Name)
|
|
|
|
if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf(SwarmErrSwapSetNoAPI)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.GlobalIsSet(EnsAPIFlag.Name) {
|
2017-12-13 09:23:11 +00:00
|
|
|
ensAPIs := ctx.GlobalStringSlice(EnsAPIFlag.Name)
|
2017-12-18 15:22:39 +00:00
|
|
|
// preserve backward compatibility to disable ENS with --ens-api=""
|
2017-12-13 09:23:11 +00:00
|
|
|
if len(ensAPIs) == 1 && ensAPIs[0] == "" {
|
2017-12-18 15:22:39 +00:00
|
|
|
ensAPIs = nil
|
2017-12-13 09:23:11 +00:00
|
|
|
}
|
2018-09-25 12:54:47 +00:00
|
|
|
for i := range ensAPIs {
|
|
|
|
ensAPIs[i] = expandPath(ensAPIs[i])
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:22:39 +00:00
|
|
|
currentConfig.EnsAPIs = ensAPIs
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if cors := ctx.GlobalString(CorsStringFlag.Name); cors != "" {
|
|
|
|
currentConfig.Cors = cors
|
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if storePath := ctx.GlobalString(SwarmStorePath.Name); storePath != "" {
|
|
|
|
currentConfig.LocalStoreParams.ChunkDbPath = storePath
|
|
|
|
}
|
|
|
|
|
|
|
|
if storeCapacity := ctx.GlobalUint64(SwarmStoreCapacity.Name); storeCapacity != 0 {
|
|
|
|
currentConfig.LocalStoreParams.DbCapacity = storeCapacity
|
|
|
|
}
|
|
|
|
|
2019-03-07 11:44:00 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmStoreCacheCapacity.Name) {
|
|
|
|
currentConfig.LocalStoreParams.CacheCapacity = ctx.GlobalUint(SwarmStoreCacheCapacity.Name)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 11:02:18 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmBootnodeModeFlag.Name) {
|
|
|
|
currentConfig.BootnodeMode = ctx.GlobalBool(SwarmBootnodeModeFlag.Name)
|
|
|
|
}
|
|
|
|
|
2019-02-07 14:46:58 +00:00
|
|
|
if ctx.GlobalIsSet(SwarmGlobalStoreAPIFlag.Name) {
|
|
|
|
currentConfig.GlobalStoreAPI = ctx.GlobalString(SwarmGlobalStoreAPIFlag.Name)
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:56:06 +00:00
|
|
|
return currentConfig
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:02:18 +00:00
|
|
|
// envVarsOverride overrides the current config with whatver is provided in environment variables
|
|
|
|
// most values are not allowed a zero value (empty string), if not otherwise noted
|
2017-12-11 21:56:06 +00:00
|
|
|
func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
|
2019-02-24 11:39:23 +00:00
|
|
|
if keyid := os.Getenv(SwarmEnvAccount); keyid != "" {
|
2017-12-11 21:56:06 +00:00
|
|
|
currentConfig.BzzAccount = keyid
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if chbookaddr := os.Getenv(SwarmEnvChequebookAddr); chbookaddr != "" {
|
2017-12-11 21:56:06 +00:00
|
|
|
currentConfig.Contract = common.HexToAddress(chbookaddr)
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if networkid := os.Getenv(SwarmEnvNetworkID); networkid != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
id, err := strconv.ParseUint(networkid, 10, 64)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvNetworkID, err)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
2018-09-28 13:56:42 +00:00
|
|
|
if id != 0 {
|
|
|
|
currentConfig.NetworkID = id
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if datadir := os.Getenv(GethEnvDataDir); datadir != "" {
|
2018-09-25 12:54:47 +00:00
|
|
|
currentConfig.Path = expandPath(datadir)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
bzzport := os.Getenv(SwarmEnvPort)
|
2017-12-11 21:56:06 +00:00
|
|
|
if len(bzzport) > 0 {
|
|
|
|
currentConfig.Port = bzzport
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if bzzaddr := os.Getenv(SwarmEnvListenAddr); bzzaddr != "" {
|
2017-12-11 21:56:06 +00:00
|
|
|
currentConfig.ListenAddr = bzzaddr
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if swapenable := os.Getenv(SwarmEnvSwapEnable); swapenable != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
swap, err := strconv.ParseBool(swapenable)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvSwapEnable, err)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
2018-09-27 10:36:35 +00:00
|
|
|
currentConfig.SwapEnabled = swap
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if syncdisable := os.Getenv(SwarmEnvSyncDisable); syncdisable != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
sync, err := strconv.ParseBool(syncdisable)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvSyncDisable, err)
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
2018-09-27 10:36:35 +00:00
|
|
|
currentConfig.SyncEnabled = !sync
|
2018-06-20 12:06:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if v := os.Getenv(SwarmEnvDeliverySkipCheck); v != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
skipCheck, err := strconv.ParseBool(v)
|
|
|
|
if err != nil {
|
2018-06-20 12:06:27 +00:00
|
|
|
currentConfig.DeliverySkipCheck = skipCheck
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if v := os.Getenv(SwarmEnvSyncUpdateDelay); v != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
d, err := time.ParseDuration(v)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvSyncUpdateDelay, err)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
2018-09-27 10:36:35 +00:00
|
|
|
currentConfig.SyncUpdateDelay = d
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if max := os.Getenv(SwarmEnvMaxStreamPeerServers); max != "" {
|
2018-09-27 08:08:57 +00:00
|
|
|
m, err := strconv.Atoi(max)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvMaxStreamPeerServers, err)
|
2018-09-24 15:40:22 +00:00
|
|
|
}
|
2018-09-27 08:08:57 +00:00
|
|
|
currentConfig.MaxStreamPeerServers = m
|
2018-09-24 15:40:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if lne := os.Getenv(SwarmEnvLightNodeEnable); lne != "" {
|
2018-09-27 10:36:35 +00:00
|
|
|
lightnode, err := strconv.ParseBool(lne)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvLightNodeEnable, err)
|
2018-08-07 13:34:11 +00:00
|
|
|
}
|
2018-09-27 10:36:35 +00:00
|
|
|
currentConfig.LightNodeEnabled = lightnode
|
2018-08-07 13:34:11 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if swapapi := os.Getenv(SwarmEnvSwapAPI); swapapi != "" {
|
2018-06-20 12:06:27 +00:00
|
|
|
currentConfig.SwapAPI = swapapi
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:06:27 +00:00
|
|
|
if currentConfig.SwapEnabled && currentConfig.SwapAPI == "" {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf(SwarmErrSwapSetNoAPI)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if ensapi := os.Getenv(SwarmEnvENSAPI); ensapi != "" {
|
2017-12-18 15:22:39 +00:00
|
|
|
currentConfig.EnsAPIs = strings.Split(ensapi, ",")
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if ensaddr := os.Getenv(SwarmEnvENSAddr); ensaddr != "" {
|
2017-12-11 21:56:06 +00:00
|
|
|
currentConfig.EnsRoot = common.HexToAddress(ensaddr)
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if cors := os.Getenv(SwarmEnvCORS); cors != "" {
|
2017-12-11 21:56:06 +00:00
|
|
|
currentConfig.Cors = cors
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if bm := os.Getenv(SwarmEnvBootnodeMode); bm != "" {
|
2019-01-24 11:02:18 +00:00
|
|
|
bootnodeMode, err := strconv.ParseBool(bm)
|
|
|
|
if err != nil {
|
2019-02-24 11:39:23 +00:00
|
|
|
utils.Fatalf("invalid environment variable %s: %v", SwarmEnvBootnodeMode, err)
|
2019-01-24 11:02:18 +00:00
|
|
|
}
|
|
|
|
currentConfig.BootnodeMode = bootnodeMode
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:39:23 +00:00
|
|
|
if api := os.Getenv(SwarmGlobalstoreAPI); api != "" {
|
2019-02-07 14:46:58 +00:00
|
|
|
currentConfig.GlobalStoreAPI = api
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:56:06 +00:00
|
|
|
return currentConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// dumpConfig is the dumpconfig command.
|
|
|
|
// writes a default config to STDOUT
|
|
|
|
func dumpConfig(ctx *cli.Context) error {
|
|
|
|
cfg, err := buildConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
utils.Fatalf(fmt.Sprintf("Uh oh - dumpconfig triggered an error %v", err))
|
|
|
|
}
|
|
|
|
comment := ""
|
|
|
|
out, err := tomlSettings.Marshal(&cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
io.WriteString(os.Stdout, comment)
|
|
|
|
os.Stdout.Write(out)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-12-19 10:47:26 +00:00
|
|
|
//validate configuration parameters
|
|
|
|
func validateConfig(cfg *bzzapi.Config) (err error) {
|
|
|
|
for _, ensAPI := range cfg.EnsAPIs {
|
|
|
|
if ensAPI != "" {
|
|
|
|
if err := validateEnsAPIs(ensAPI); err != nil {
|
|
|
|
return fmt.Errorf("invalid format [tld:][contract-addr@]url for ENS API endpoint configuration %q: %v", ensAPI, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
//validate EnsAPIs configuration parameter
|
|
|
|
func validateEnsAPIs(s string) (err error) {
|
|
|
|
// missing contract address
|
|
|
|
if strings.HasPrefix(s, "@") {
|
|
|
|
return errors.New("missing contract address")
|
|
|
|
}
|
|
|
|
// missing url
|
|
|
|
if strings.HasSuffix(s, "@") {
|
|
|
|
return errors.New("missing url")
|
|
|
|
}
|
|
|
|
// missing tld
|
|
|
|
if strings.HasPrefix(s, ":") {
|
|
|
|
return errors.New("missing tld")
|
|
|
|
}
|
|
|
|
// missing url
|
|
|
|
if strings.HasSuffix(s, ":") {
|
|
|
|
return errors.New("missing url")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:56:06 +00:00
|
|
|
//print a Config as string
|
|
|
|
func printConfig(config *bzzapi.Config) string {
|
|
|
|
out, err := tomlSettings.Marshal(&config)
|
|
|
|
if err != nil {
|
2018-01-03 12:14:47 +00:00
|
|
|
return fmt.Sprintf("Something is not right with the configuration: %v", err)
|
2017-12-11 21:56:06 +00:00
|
|
|
}
|
|
|
|
return string(out)
|
|
|
|
}
|