cmd/swarm, swarm: disable ENS API by default

Specifying ENS API CLI flag, env variable or configuration
field is required for ENS resolving. Backward compatibility is
preserved with --ens-api="" CLI flag value.
This commit is contained in:
Janos Guljas 2017-12-18 16:22:39 +01:00
parent 47a8014559
commit c0a4d9e1e6
3 changed files with 12 additions and 36 deletions

View File

@ -195,17 +195,13 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API) utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
} }
//EnsAPIs can be set to "", so can't check for empty string, as it is allowed!
if ctx.GlobalIsSet(EnsAPIFlag.Name) { if ctx.GlobalIsSet(EnsAPIFlag.Name) {
ensAPIs := ctx.GlobalStringSlice(EnsAPIFlag.Name) ensAPIs := ctx.GlobalStringSlice(EnsAPIFlag.Name)
// Disable ENS resolver if --ens-api="" is specified // preserve backward compatibility to disable ENS with --ens-api=""
if len(ensAPIs) == 1 && ensAPIs[0] == "" { if len(ensAPIs) == 1 && ensAPIs[0] == "" {
currentConfig.EnsDisabled = true ensAPIs = nil
currentConfig.EnsAPIs = nil
} else {
currentConfig.EnsDisabled = false
currentConfig.EnsAPIs = ensAPIs
} }
currentConfig.EnsAPIs = ensAPIs
} }
if ensaddr := ctx.GlobalString(DeprecatedEnsAddrFlag.Name); ensaddr != "" { if ensaddr := ctx.GlobalString(DeprecatedEnsAddrFlag.Name); ensaddr != "" {
@ -275,17 +271,8 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API) utils.Fatalf(SWARM_ERR_SWAP_SET_NO_API)
} }
//EnsAPIs can be set to "", so can't check for empty string, as it is allowed if ensapi := os.Getenv(SWARM_ENV_ENS_API); ensapi != "" {
if ensapi, exists := os.LookupEnv(SWARM_ENV_ENS_API); exists { currentConfig.EnsAPIs = strings.Split(ensapi, ",")
ensAPIs := strings.Split(ensapi, ",")
// Disable ENS resolver if SWARM_ENS_API="" is specified
if len(ensAPIs) == 0 {
currentConfig.EnsDisabled = true
currentConfig.EnsAPIs = nil
} else {
currentConfig.EnsDisabled = false
currentConfig.EnsAPIs = ensAPIs
}
} }
if ensaddr := os.Getenv(SWARM_ENV_ENS_ADDR); ensaddr != "" { if ensaddr := os.Getenv(SWARM_ENV_ENS_ADDR); ensaddr != "" {

View File

@ -48,7 +48,6 @@ type Config struct {
*network.SyncParams *network.SyncParams
Contract common.Address Contract common.Address
EnsRoot common.Address EnsRoot common.Address
EnsDisabled bool
EnsAPIs []string EnsAPIs []string
Path string Path string
ListenAddr string ListenAddr string
@ -78,7 +77,6 @@ func NewDefaultConfig() (self *Config) {
Path: node.DefaultDataDir(), Path: node.DefaultDataDir(),
EnsAPIs: nil, EnsAPIs: nil,
EnsRoot: ens.TestNetAddress, EnsRoot: ens.TestNetAddress,
EnsDisabled: false,
NetworkId: network.NetworkId, NetworkId: network.NetworkId,
SwapEnabled: false, SwapEnabled: false,
SyncEnabled: true, SyncEnabled: true,

View File

@ -138,26 +138,17 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
self.dpa = storage.NewDPA(dpaChunkStore, self.config.ChunkerParams) self.dpa = storage.NewDPA(dpaChunkStore, self.config.ChunkerParams)
log.Debug(fmt.Sprintf("-> Content Store API")) log.Debug(fmt.Sprintf("-> Content Store API"))
if !config.EnsDisabled { if len(config.EnsAPIs) > 0 {
if len(config.EnsAPIs) == 0 { opts := []api.MultiResolverOption{}
// ENS is enabled and has no specific configuration, for _, c := range config.EnsAPIs {
// use defaults tld, endpoint, addr := parseEnsAPIAddress(c)
self.dns, err = newEnsClient(node.DefaultIPCEndpoint("geth"), config.EnsRoot, config) r, err := newEnsClient(endpoint, addr, config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else { opts = append(opts, api.MultiResolverOptionWithResolver(r, tld))
opts := []api.MultiResolverOption{}
for _, c := range config.EnsAPIs {
tld, endpoint, addr := parseEnsAPIAddress(c)
r, err := newEnsClient(endpoint, addr, config)
if err != nil {
return nil, err
}
opts = append(opts, api.MultiResolverOptionWithResolver(r, tld))
}
self.dns = api.NewMultiResolver(opts...)
} }
self.dns = api.NewMultiResolver(opts...)
} }
self.api = api.NewApi(self.dpa, self.dns) self.api = api.NewApi(self.dpa, self.dns)