Add method for localhost bitcoin node configPeerNodesForLocalHostBitcoinNode

This commit is contained in:
Manfred Karrer 2018-01-19 20:46:05 -05:00
parent 839ade1f4d
commit 0e77361d96
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
2 changed files with 21 additions and 8 deletions

View file

@ -45,8 +45,10 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.UnknownHostException;
import java.nio.channels.FileLock;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -462,6 +464,17 @@ public class WalletConfig extends AbstractIdleService {
}
}
void setPeerNodesForLocalHost() {
try {
setPeerNodes(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
} catch (UnknownHostException e) {
log.error(e.toString());
e.printStackTrace();
// Borked machine with no loopback adapter configured properly.
throw new RuntimeException(e);
}
}
private Wallet createOrLoadWallet(File walletFile, boolean shouldReplayWallet,
BisqKeyChainGroup keyChainGroup, boolean isBsqWallet, DeterministicSeed restoreFromSeed)
throws Exception {

View file

@ -201,6 +201,8 @@ public class WalletsSetup {
if (params == RegTestParams.get()) {
configPeerNodesForRegTest();
} else if (bisqEnvironment.isBitcoinLocalhostNodeRunning()) {
configPeerNodesForLocalHostBitcoinNode();
} else {
configPeerNodes(socks5Proxy);
}
@ -287,17 +289,15 @@ public class WalletsSetup {
throw new RuntimeException(e);
}
} else if (regTestHost == RegTestHost.LOCALHOST) {
try {
walletConfig.setPeerNodes(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
} catch (UnknownHostException e) {
log.error(e.toString());
e.printStackTrace();
// Borked machine with no loopback adapter configured properly.
throw new RuntimeException(e);
}
walletConfig.setPeerNodesForLocalHost();
}
}
private void configPeerNodesForLocalHostBitcoinNode() {
walletConfig.setMinBroadcastConnections(1);
walletConfig.setPeerNodesForLocalHost();
}
private void configPeerNodes(Socks5Proxy socks5Proxy) {
List<BitcoinNodes.BtcNode> btcNodeList = new ArrayList<>();
walletConfig.setMinBroadcastConnections((int) Math.floor(DEFAULT_CONNECTIONS * 0.8));