From 93cebf4145126c140cbfb88a869afa3221e9663d Mon Sep 17 00:00:00 2001 From: sqrrm Date: Fri, 12 Jul 2019 00:38:41 +0200 Subject: [PATCH] Add option to ignore local bitcoin node --- .../java/bisq/core/app/BisqEnvironment.java | 17 +++++++++++++---- .../main/java/bisq/core/app/BisqExecutable.java | 4 ++++ core/src/main/java/bisq/core/app/BisqSetup.java | 4 +++- .../main/java/bisq/core/btc/BitcoinModule.java | 1 + .../main/java/bisq/core/btc/BtcOptionKeys.java | 1 + 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqEnvironment.java b/core/src/main/java/bisq/core/app/BisqEnvironment.java index 4c7afa5d49d..59319dd525b 100644 --- a/core/src/main/java/bisq/core/app/BisqEnvironment.java +++ b/core/src/main/java/bisq/core/app/BisqEnvironment.java @@ -191,12 +191,13 @@ public static boolean isDaoActivated(Environment environment) { @Getter protected List bannedSeedNodes, bannedBtcNodes, bannedPriceRelayNodes; - protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, rpcPassword, - rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode, + protected final String btcNodes, seedNodes, ignoreDevMsg, useDevPrivilegeKeys, useDevMode, useTorForBtc, rpcUser, + rpcPassword, rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress, torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile, - socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, - referralId, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep; + socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, + genesisTotalSupply, referralId, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, + sendMsgThrottleSleep, ignoreLocalBtcNode; protected final boolean externalTorUseSafeCookieAuthentication, torStreamIsolation; @@ -346,6 +347,9 @@ public BisqEnvironment(PropertySource commandLineProperties) { numConnectionForBtc = commandLineProperties.containsProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) ? (String) commandLineProperties.getProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) : "9"; + ignoreLocalBtcNode = commandLineProperties.containsProperty(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE) ? + (String) commandLineProperties.getProperty(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE) : + "false"; MutablePropertySources propertySources = this.getPropertySources(); propertySources.addFirst(commandLineProperties); @@ -429,6 +433,10 @@ protected void setProperty(String key, String value) { } } + public boolean getIgnoreLocalBtcNode() { + return ignoreLocalBtcNode.equalsIgnoreCase("true"); + } + public String getAppDataDir() { return appDataDir; } @@ -511,6 +519,7 @@ private PropertySource defaultProperties() { setProperty(BtcOptionKeys.USER_AGENT, userAgent); setProperty(BtcOptionKeys.USE_ALL_PROVIDED_NODES, useAllProvidedNodes); setProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, numConnectionForBtc); + setProperty(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE, ignoreLocalBtcNode); setProperty(UserAgent.NAME_KEY, appName); setProperty(UserAgent.VERSION_KEY, Version.VERSION); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index b2a8ee122e7..28805139198 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -501,6 +501,10 @@ protected void customizeOptionParsing(OptionParser parser) { .withRequiredArg() .describedAs("host"); + parser.accepts(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE, + "If set to true a Bitcoin core node running locally will be ignored") + .withRequiredArg(); + parser.accepts(BtcOptionKeys.BTC_NODES, "Custom nodes used for BitcoinJ as comma separated IP addresses.") .withRequiredArg() diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 26cc912e6c7..cbeeca5f08a 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -418,7 +418,9 @@ private void maybeShowTac() { private void checkIfLocalHostNodeIsRunning() { // For DAO testnet we ignore local btc node - if (BisqEnvironment.getBaseCurrencyNetwork().isDaoRegTest() || BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet()) { + if (BisqEnvironment.getBaseCurrencyNetwork().isDaoRegTest() || + BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet() || + bisqEnvironment.getIgnoreLocalBtcNode()) { step3(); } else { Thread checkIfLocalHostNodeIsRunningThread = new Thread(() -> { diff --git a/core/src/main/java/bisq/core/btc/BitcoinModule.java b/core/src/main/java/bisq/core/btc/BitcoinModule.java index 67a8265cc42..8361e0a4304 100644 --- a/core/src/main/java/bisq/core/btc/BitcoinModule.java +++ b/core/src/main/java/bisq/core/btc/BitcoinModule.java @@ -86,6 +86,7 @@ protected void configure() { 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(BtcOptionKeys.USE_TOR_FOR_BTC)).to(environment.getRequiredProperty(BtcOptionKeys.USE_TOR_FOR_BTC)); + bindConstant().annotatedWith(named(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE)).to(environment.getRequiredProperty(BtcOptionKeys.IGNORE_LOCAL_BTC_NODE)); 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(named(AppOptionKeys.PROVIDERS)).to(environment.getRequiredProperty(AppOptionKeys.PROVIDERS)); diff --git a/core/src/main/java/bisq/core/btc/BtcOptionKeys.java b/core/src/main/java/bisq/core/btc/BtcOptionKeys.java index 79d6f27f54a..14d19c5f6fa 100644 --- a/core/src/main/java/bisq/core/btc/BtcOptionKeys.java +++ b/core/src/main/java/bisq/core/btc/BtcOptionKeys.java @@ -27,4 +27,5 @@ public class BtcOptionKeys { 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"; public static final String REG_TEST_HOST = "bitcoinRegtestHost"; + public static final String IGNORE_LOCAL_BTC_NODE = "ignoreLocalBtcNode"; }