ensure useTor==false case works, and also that wallet init is deferred only for useTor==true case

This commit is contained in:
danda 2016-07-19 17:59:32 -07:00
parent 6198307d76
commit c392915c4a
3 changed files with 32 additions and 12 deletions

View file

@ -43,7 +43,14 @@ public class WalletAppKitBitSquare extends WalletAppKit {
} }
protected PeerGroup createPeerGroup() throws TimeoutException { 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); ProxySocketFactory proxySocketFactory = new ProxySocketFactory(proxy);
BlockingClientManager mgr = new BlockingClientManager(proxySocketFactory); BlockingClientManager mgr = new BlockingClientManager(proxySocketFactory);
PeerGroup result = new PeerGroup(params, vChain, mgr); PeerGroup result = new PeerGroup(params, vChain, mgr);
@ -51,7 +58,6 @@ public class WalletAppKitBitSquare extends WalletAppKit {
mgr.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC); mgr.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC);
result.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC); result.setConnectTimeoutMillis(CONNECT_TIMEOUT_MSEC);
// result.addPeerDiscovery(new OnionSeedPeers(params));
return result; return result;
} }
} }

View file

@ -272,10 +272,11 @@ public class WalletService {
//TODO Check how to pass seed nodes to the wallet kit. Probably via walletAppKit.setPeerNodes //TODO Check how to pass seed nodes to the wallet kit. Probably via walletAppKit.setPeerNodes
} }
if (useTor && params.getId().equals(NetworkParameters.ID_MAINNET)) // We do not call walletAppKit.useTor() anymore because that would turn
walletAppKit.useTor(); // 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 // 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. // or progress widget to keep the user engaged whilst we initialise, but we don't.

View file

@ -352,7 +352,9 @@ public class MainViewModel implements ViewModel {
public void onTorNodeReady() { public void onTorNodeReady() {
bootstrapState.set("Tor node created"); bootstrapState.set("Tor node created");
p2PNetworkIconId.set("image-connection-tor"); p2PNetworkIconId.set("image-connection-tor");
initWalletService(); if( preferences.getUseTorForBitcoinJ() ) {
initWalletService();
}
} }
@Override @Override
@ -428,6 +430,13 @@ public class MainViewModel implements ViewModel {
private BooleanProperty initBitcoinWallet() { private BooleanProperty initBitcoinWallet() {
final BooleanProperty walletInitialized = new SimpleBooleanProperty(); 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; return walletInitialized;
} }
@ -472,11 +481,15 @@ public class MainViewModel implements ViewModel {
btcInfo.set(newValue); btcInfo.set(newValue);
}); });
// Use p2p service Proxy proxy = null;
Socks5Proxy socks5Proxy = p2PService.getNetworkNode().getSocksProxy();
Proxy proxy = proxy = new Proxy ( Proxy.Type.SOCKS, if( preferences.getUseTorForBitcoinJ() ) {
new InetSocketAddress(socks5Proxy.getInetAddress().getHostName(), // Use p2p service
socks5Proxy.getPort() ) ); 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. * Uncomment this to wire up user specified proxy via program args or config file.