Move 'useAllProvidedNodes' option handling to Config

This commit is contained in:
Chris Beams 2019-12-17 14:22:09 +01:00
parent b7889dd994
commit 97cafaf61e
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
6 changed files with 18 additions and 11 deletions

View File

@ -61,6 +61,7 @@ public class Config {
public static final String IGNORE_LOCAL_BTC_NODE = "ignoreLocalBtcNode";
public static final String BTC_NODES = "btcNodes";
public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode";
public static final String USE_ALL_PROVIDED_NODES = "useAllProvidedNodes";
private static final Logger log = LoggerFactory.getLogger(Config.class);
@ -118,6 +119,7 @@ public class Config {
private final boolean useTorForBtc;
private final boolean useTorForBtcOptionSetExplicitly;
private final String socks5DiscoverMode;
private final boolean useAllProvidedNodes;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -413,6 +415,13 @@ public class Config {
.describedAs("mode[,...]")
.defaultsTo("ALL");
ArgumentAcceptingOptionSpec<Boolean> useAllProvidedNodesOpt =
parser.accepts(USE_ALL_PROVIDED_NODES,
"Set to true if connection of bitcoin nodes should include clear net nodes")
.withRequiredArg()
.ofType(boolean.class)
.defaultsTo(false);
try {
OptionSet cliOpts = parser.parse(args);
@ -497,6 +506,7 @@ public class Config {
this.useTorForBtc = options.valueOf(useTorForBtcOpt);
this.useTorForBtcOptionSetExplicitly = options.has(useTorForBtcOpt);
this.socks5DiscoverMode = options.valueOf(socks5DiscoverModeOpt);
this.useAllProvidedNodes = options.valueOf(useAllProvidedNodesOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -748,4 +758,8 @@ public class Config {
public String getSocks5DiscoverMode() {
return socks5DiscoverMode;
}
public boolean isUseAllProvidedNodes() {
return useAllProvidedNodes;
}
}

View File

@ -61,7 +61,7 @@ public class BisqEnvironment extends StandardEnvironment {
protected final String rpcUser, rpcPassword,
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply,
numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply,
daoActivated;
public BisqEnvironment(OptionSet options) {
@ -87,7 +87,6 @@ public class BisqEnvironment extends StandardEnvironment {
//BtcOptionKeys
userAgent = getProperty(commandLineProperties, BtcOptionKeys.USER_AGENT, "Bisq");
useAllProvidedNodes = getProperty(commandLineProperties, BtcOptionKeys.USE_ALL_PROVIDED_NODES, "false");
numConnectionForBtc = getProperty(commandLineProperties, BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, "9");
MutablePropertySources propertySources = getPropertySources();
@ -120,7 +119,6 @@ public class BisqEnvironment extends StandardEnvironment {
setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);
setProperty(BtcOptionKeys.USER_AGENT, userAgent);
setProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES, useAllProvidedNodes);
setProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, numConnectionForBtc);
}
});

View File

@ -286,10 +286,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(boolean.class);
//BtcOptionKeys
parser.accepts(BtcOptionKeys.USE_ALL_PROVIDED_NODES,
"Set to true if connection of bitcoin nodes should include clear net nodes")
.withRequiredArg();
parser.accepts(BtcOptionKeys.USER_AGENT,
"User agent at btc node connections")
.withRequiredArg();

View File

@ -83,7 +83,7 @@ public class BitcoinModule extends AppModule {
bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.getBtcNodes());
bindConstant().annotatedWith(named(BtcOptionKeys.USER_AGENT)).to(environment.getRequiredProperty(BtcOptionKeys.USER_AGENT));
bindConstant().annotatedWith(named(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC)).to(environment.getRequiredProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC));
bindConstant().annotatedWith(named(BtcOptionKeys.USE_ALL_PROVIDED_NODES)).to(environment.getRequiredProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES));
bindConstant().annotatedWith(named(Config.USE_ALL_PROVIDED_NODES)).to(config.isUseAllProvidedNodes());
bindConstant().annotatedWith(named(Config.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode());
bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode());
bind(new TypeLiteral<List<String>>(){}).annotatedWith(named(PROVIDERS)).toInstance(config.getProviders());

View File

@ -19,6 +19,5 @@ package bisq.core.btc;
public class BtcOptionKeys {
public static final String USER_AGENT = "userAgent";
public static final String USE_ALL_PROVIDED_NODES = "useAllProvidedNodes"; // We only use onion nodes if tor is enabled. That flag overrides that default behavior.
public static final String NUM_CONNECTIONS_FOR_BTC = "numConnectionForBtc";
}

View File

@ -152,7 +152,7 @@ public class WalletsSetup {
BtcNodes btcNodes,
@Named(BtcOptionKeys.USER_AGENT) String userAgent,
@Named(Config.WALLET_DIR) File appDir,
@Named(BtcOptionKeys.USE_ALL_PROVIDED_NODES) String useAllProvidedNodes,
@Named(Config.USE_ALL_PROVIDED_NODES) boolean useAllProvidedNodes,
@Named(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) String numConnectionForBtc,
@Named(Config.SOCKS5_DISCOVER_MODE) String socks5DiscoverModeString) {
this.regTestHost = regTestHost;
@ -162,7 +162,7 @@ public class WalletsSetup {
this.config = config;
this.btcNodes = btcNodes;
this.numConnectionForBtc = numConnectionForBtc != null ? Integer.parseInt(numConnectionForBtc) : DEFAULT_CONNECTIONS;
this.useAllProvidedNodes = "true".equals(useAllProvidedNodes);
this.useAllProvidedNodes = useAllProvidedNodes;
this.userAgent = userAgent;
this.socks5DiscoverMode = evaluateMode(socks5DiscoverModeString);