From 53cf14791f3bc7fe5cc830ea954b2eb8d23f428b Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Wed, 30 Jan 2019 15:14:58 -0800 Subject: [PATCH 1/3] Allow tor to be used on regtest This allows for a tor .onion address to be specified as the bitcoinRegtestHost parameter and, as long as the --useTorForBtc=true parameter is included, it will use tor when on regtest. --- core/src/main/java/bisq/core/btc/setup/WalletsSetup.java | 7 +++++-- core/src/main/java/bisq/core/user/Preferences.java | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java index 936c617625a..c329cc662ab 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletsSetup.java @@ -236,7 +236,6 @@ protected void onSetupCompleted() { if (regTestHost == RegTestHost.LOCALHOST) { walletConfig.setPeerNodesForLocalHost(); } else if (regTestHost == RegTestHost.REMOTE_HOST) { - walletConfig.setMinBroadcastConnections(1); configPeerNodesForRegTestServer(); } else { configPeerNodes(socks5Proxy); @@ -315,7 +314,11 @@ private int evaluateMode(String socks5DiscoverModeString) { private void configPeerNodesForRegTestServer() { try { - walletConfig.setPeerNodes(new PeerAddress(InetAddress.getByName(RegTestHost.HOST), params.getPort())); + if (RegTestHost.HOST.endsWith(".onion")) { + walletConfig.setPeerNodes(new PeerAddress(RegTestHost.HOST, params.getPort())); + } else { + walletConfig.setPeerNodes(new PeerAddress(InetAddress.getByName(RegTestHost.HOST), params.getPort())); + } } catch (UnknownHostException e) { log.error(e.toString()); e.printStackTrace(); diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 04e7d378830..7873faf94f9 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -692,10 +692,12 @@ public boolean showAgain(String key) { } public boolean getUseTorForBitcoinJ() { - // We override the useTorForBitcoinJ and set it to false if we detected a localhost node or if we are not on mainnet. - // At testnet there are very few Bitcoin tor nodes and we don't provide tor nodes. - if (!BisqEnvironment.getBaseCurrencyNetwork().isMainnet() + // We override the useTorForBitcoinJ and set it to false if we detected a localhost node or if we are not on mainnet, + // unless the useTorForBtc parameter is explicitly provided. + // On testnet there are very few Bitcoin tor nodes and we don't provide tor nodes. + if ((!BisqEnvironment.getBaseCurrencyNetwork().isMainnet() || bisqEnvironment.isBitcoinLocalhostNodeRunning()) + && bisqEnvironment.getProperty(BtcOptionKeys.USE_TOR_FOR_BTC).isEmpty()) return false; else return prefPayload.isUseTorForBitcoinJ(); From ba466d40eeeeba64a1299a6b10aba60bee5386ae Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Wed, 30 Jan 2019 15:24:00 -0800 Subject: [PATCH 2/3] Update logging indicating number of btc nodes The logged message that indicates the number of btc nodes to connect to was incorrect when only a single node is used in regtest mode. --- core/src/main/java/bisq/core/btc/setup/WalletConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java index 3e88fd63951..a68ed53414f 100644 --- a/core/src/main/java/bisq/core/btc/setup/WalletConfig.java +++ b/core/src/main/java/bisq/core/btc/setup/WalletConfig.java @@ -446,8 +446,9 @@ protected void startUp() throws Exception { // before we're actually connected the broadcast waits for an appropriate number of connections. if (peerAddresses != null) { for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr); - log.info("We try to connect to {} btc nodes", numConnectionForBtc); - vPeerGroup.setMaxConnections(Math.min(numConnectionForBtc, peerAddresses.length)); + int maxConnections = Math.min(numConnectionForBtc, peerAddresses.length); + log.info("We try to connect to {} btc nodes", maxConnections); + vPeerGroup.setMaxConnections(maxConnections); peerAddresses = null; } else if (!params.equals(RegTestParams.get())) { vPeerGroup.addPeerDiscovery(discovery != null ? discovery : new DnsDiscovery(params)); From d233aef5b13cafe5e6f030080493e050541498e8 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Sun, 3 Feb 2019 23:17:02 -0800 Subject: [PATCH 3/3] Check useTorFlagFromOptions rather than bisqEnvironment.getProperty --- core/src/main/java/bisq/core/user/Preferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 7873faf94f9..b2f442b176a 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -697,7 +697,7 @@ public boolean getUseTorForBitcoinJ() { // On testnet there are very few Bitcoin tor nodes and we don't provide tor nodes. if ((!BisqEnvironment.getBaseCurrencyNetwork().isMainnet() || bisqEnvironment.isBitcoinLocalhostNodeRunning()) - && bisqEnvironment.getProperty(BtcOptionKeys.USE_TOR_FOR_BTC).isEmpty()) + && (useTorFlagFromOptions == null || useTorFlagFromOptions.isEmpty())) return false; else return prefPayload.isUseTorForBitcoinJ();