Prevent connection to localhost bitcoin node if dao testnet is used

This commit is contained in:
Manfred Karrer 2019-02-21 12:00:35 -05:00
parent 64fd8d9bc8
commit 518fe724d9
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
2 changed files with 33 additions and 24 deletions

View File

@ -417,30 +417,35 @@ public class BisqSetup {
}
private void checkIfLocalHostNodeIsRunning() {
Thread checkIfLocalHostNodeIsRunningThread = new Thread(() -> {
Thread.currentThread().setName("checkIfLocalHostNodeIsRunningThread");
Socket socket = null;
try {
socket = new Socket();
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"),
BisqEnvironment.getBaseCurrencyNetwork().getParameters().getPort()), 5000);
log.info("Localhost Bitcoin node detected.");
UserThread.execute(() -> {
bisqEnvironment.setBitcoinLocalhostNodeRunning(true);
step3();
});
} catch (Throwable e) {
UserThread.execute(BisqSetup.this::step3);
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException ignore) {
// For DAO testnet we ignore local btc node
if (BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet()) {
step3();
} else {
Thread checkIfLocalHostNodeIsRunningThread = new Thread(() -> {
Thread.currentThread().setName("checkIfLocalHostNodeIsRunningThread");
Socket socket = null;
try {
socket = new Socket();
socket.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"),
BisqEnvironment.getBaseCurrencyNetwork().getParameters().getPort()), 5000);
log.info("Localhost Bitcoin node detected.");
UserThread.execute(() -> {
bisqEnvironment.setBitcoinLocalhostNodeRunning(true);
step3();
});
} catch (Throwable e) {
UserThread.execute(BisqSetup.this::step3);
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException ignore) {
}
}
}
}
});
checkIfLocalHostNodeIsRunningThread.start();
});
checkIfLocalHostNodeIsRunningThread.start();
}
}
private void readMapsFromResources() {

View File

@ -22,7 +22,6 @@ import bisq.core.btc.nodes.ProxySocketFactory;
import bisq.core.btc.wallet.BisqRiskAnalysis;
import bisq.common.app.Version;
import bisq.common.util.Utilities;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.CheckpointManager;
@ -220,7 +219,7 @@ public class WalletConfig extends AbstractIdleService {
socks5Proxy.getPort()));
ProxySocketFactory proxySocketFactory = new ProxySocketFactory(proxy);
// we dont use tor mode if we have a local node running
// We don't use tor mode if we have a local node running
BlockingClientManager blockingClientManager = bisqEnvironment.isBitcoinLocalhostNodeRunning() ?
new BlockingClientManager() :
new BlockingClientManager(proxySocketFactory);
@ -230,6 +229,11 @@ public class WalletConfig extends AbstractIdleService {
blockingClientManager.setConnectTimeoutMillis(TIMEOUT);
peerGroup.setConnectTimeoutMillis(TIMEOUT);
// For dao testnet (server side regtest) we prevent to connect to a localhost node to avoid confusion
// if local btc node is not synced with our dao testnet master node.
if (BisqEnvironment.getBaseCurrencyNetwork().isDaoTestNet())
peerGroup.setUseLocalhostPeerWhenPossible(false);
return peerGroup;
}
}