From c392915c4a6f117eda9f500976758edc75fdd874 Mon Sep 17 00:00:00 2001 From: danda Date: Tue, 19 Jul 2016 17:59:32 -0700 Subject: [PATCH] ensure useTor==false case works, and also that wallet init is deferred only for useTor==true case --- .../bitsquare/btc/WalletAppKitBitSquare.java | 10 ++++++-- .../java/io/bitsquare/btc/WalletService.java | 9 ++++--- .../io/bitsquare/gui/main/MainViewModel.java | 25 ++++++++++++++----- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/io/bitsquare/btc/WalletAppKitBitSquare.java b/core/src/main/java/io/bitsquare/btc/WalletAppKitBitSquare.java index 7aa39dedf8..c203d13e55 100644 --- a/core/src/main/java/io/bitsquare/btc/WalletAppKitBitSquare.java +++ b/core/src/main/java/io/bitsquare/btc/WalletAppKitBitSquare.java @@ -43,7 +43,14 @@ public class WalletAppKitBitSquare extends WalletAppKit { } protected PeerGroup createPeerGroup() throws TimeoutException { - int CONNECT_TIMEOUT_MSEC = 60 * 1000; + + // no proxy case. + if(proxy == null) { + return super.createPeerGroup(); + } + + // proxy case. + int CONNECT_TIMEOUT_MSEC = 60 * 1000; // same value used in bitcoinj. ProxySocketFactory proxySocketFactory = new ProxySocketFactory(proxy); BlockingClientManager mgr = new BlockingClientManager(proxySocketFactory); PeerGroup result = new PeerGroup(params, vChain, mgr); @@ -51,7 +58,6 @@ public class WalletAppKitBitSquare extends WalletAppKit { mgr.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC); result.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC); - // result.addPeerDiscovery(new OnionSeedPeers(params)); return result; } } diff --git a/core/src/main/java/io/bitsquare/btc/WalletService.java b/core/src/main/java/io/bitsquare/btc/WalletService.java index 861c607722..28ade06144 100644 --- a/core/src/main/java/io/bitsquare/btc/WalletService.java +++ b/core/src/main/java/io/bitsquare/btc/WalletService.java @@ -272,10 +272,11 @@ public class WalletService { //TODO Check how to pass seed nodes to the wallet kit. Probably via walletAppKit.setPeerNodes } - if (useTor && params.getId().equals(NetworkParameters.ID_MAINNET)) - walletAppKit.useTor(); - - + // We do not call walletAppKit.useTor() anymore because that would turn + // on orchid Tor, which we do not want. Instead, we create a Tor proxy + // later. + // if (useTor && params.getId().equals(NetworkParameters.ID_MAINNET)) + // walletAppKit.useTor(); // Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen // or progress widget to keep the user engaged whilst we initialise, but we don't. diff --git a/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java b/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java index ec04986f5b..7d6a7f1dfa 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java +++ b/gui/src/main/java/io/bitsquare/gui/main/MainViewModel.java @@ -352,7 +352,9 @@ public class MainViewModel implements ViewModel { public void onTorNodeReady() { bootstrapState.set("Tor node created"); p2PNetworkIconId.set("image-connection-tor"); - initWalletService(); + if( preferences.getUseTorForBitcoinJ() ) { + initWalletService(); + } } @Override @@ -428,6 +430,13 @@ public class MainViewModel implements ViewModel { private BooleanProperty initBitcoinWallet() { final BooleanProperty walletInitialized = new SimpleBooleanProperty(); + + // We only init wallet service here if not using Tor for bitcoinj. + // When using Tor, wallet init must be deferred until Tor is ready. + if( !preferences.getUseTorForBitcoinJ() ) { + initWalletService(); + } + return walletInitialized; } @@ -472,11 +481,15 @@ public class MainViewModel implements ViewModel { btcInfo.set(newValue); }); - // Use p2p service - Socks5Proxy socks5Proxy = p2PService.getNetworkNode().getSocksProxy(); - Proxy proxy = proxy = new Proxy ( Proxy.Type.SOCKS, - new InetSocketAddress(socks5Proxy.getInetAddress().getHostName(), - socks5Proxy.getPort() ) ); + Proxy proxy = null; + + if( preferences.getUseTorForBitcoinJ() ) { + // Use p2p service + Socks5Proxy socks5Proxy = p2PService.getNetworkNode().getSocksProxy(); + proxy = new Proxy ( Proxy.Type.SOCKS, + new InetSocketAddress(socks5Proxy.getInetAddress().getHostName(), + socks5Proxy.getPort() ) ); + } /** * Uncomment this to wire up user specified proxy via program args or config file.