Move 'socks5DiscoverMode' option handling to Config

This commit is contained in:
Chris Beams 2019-12-17 14:09:15 +01:00
parent 90031543b9
commit b7889dd994
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
5 changed files with 16 additions and 10 deletions

View File

@ -60,6 +60,7 @@ public class Config {
public static final String TOR_STREAM_ISOLATION = "torStreamIsolation";
public static final String IGNORE_LOCAL_BTC_NODE = "ignoreLocalBtcNode";
public static final String BTC_NODES = "btcNodes";
public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode";
private static final Logger log = LoggerFactory.getLogger(Config.class);
@ -116,6 +117,7 @@ public class Config {
private final String btcNodes;
private final boolean useTorForBtc;
private final boolean useTorForBtcOptionSetExplicitly;
private final String socks5DiscoverMode;
// properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -404,6 +406,13 @@ public class Config {
.ofType(Boolean.class)
.defaultsTo(false);
ArgumentAcceptingOptionSpec<String> socks5DiscoverModeOpt =
parser.accepts(SOCKS5_DISCOVER_MODE, "Specify discovery mode for Bitcoin nodes. " +
"One or more of: [ADDR, DNS, ONION, ALL] (comma separated, they get OR'd together).")
.withRequiredArg()
.describedAs("mode[,...]")
.defaultsTo("ALL");
try {
OptionSet cliOpts = parser.parse(args);
@ -487,6 +496,7 @@ public class Config {
this.btcNodes = options.valueOf(btcNodesOpt);
this.useTorForBtc = options.valueOf(useTorForBtcOpt);
this.useTorForBtcOptionSetExplicitly = options.has(useTorForBtcOpt);
this.socks5DiscoverMode = options.valueOf(socks5DiscoverModeOpt);
} catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0),
@ -734,4 +744,8 @@ public class Config {
public boolean isUseTorForBtcOptionSetExplicitly() {
return useTorForBtcOptionSetExplicitly;
}
public String getSocks5DiscoverMode() {
return socks5DiscoverMode;
}
}

View File

@ -286,12 +286,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(boolean.class);
//BtcOptionKeys
parser.accepts(BtcOptionKeys.SOCKS5_DISCOVER_MODE,
format("Specify discovery mode for Bitcoin nodes. One or more of: [ADDR, DNS, ONION, ALL]" +
" (comma separated, they get OR'd together). (default: %s)", "ALL"))
.withRequiredArg()
.describedAs("mode[,...]");
parser.accepts(BtcOptionKeys.USE_ALL_PROVIDED_NODES,
"Set to true if connection of bitcoin nodes should include clear net nodes")
.withRequiredArg();

View File

@ -85,8 +85,7 @@ public class BitcoinModule extends AppModule {
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.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode());
String socks5DiscoverMode = environment.getProperty(BtcOptionKeys.SOCKS5_DISCOVER_MODE, String.class, "ALL");
bind(String.class).annotatedWith(Names.named(BtcOptionKeys.SOCKS5_DISCOVER_MODE)).toInstance(socks5DiscoverMode);
bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode());
bind(new TypeLiteral<List<String>>(){}).annotatedWith(named(PROVIDERS)).toInstance(config.getProviders());
bind(AddressEntryList.class).in(Singleton.class);

View File

@ -18,7 +18,6 @@
package bisq.core.btc;
public class BtcOptionKeys {
public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode";
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

@ -154,7 +154,7 @@ public class WalletsSetup {
@Named(Config.WALLET_DIR) File appDir,
@Named(BtcOptionKeys.USE_ALL_PROVIDED_NODES) String useAllProvidedNodes,
@Named(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) String numConnectionForBtc,
@Named(BtcOptionKeys.SOCKS5_DISCOVER_MODE) String socks5DiscoverModeString) {
@Named(Config.SOCKS5_DISCOVER_MODE) String socks5DiscoverModeString) {
this.regTestHost = regTestHost;
this.addressEntryList = addressEntryList;
this.preferences = preferences;