Skip to content

Commit

Permalink
Merge pull request #2346 from devinbileck/tor-on-regtest
Browse files Browse the repository at this point in the history
Allow tor to be used with regtest
  • Loading branch information
ManfredKarrer authored Feb 4, 2019
2 parents 3824f6c + d233aef commit 68a6de2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions core/src/main/java/bisq/core/btc/setup/WalletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/bisq/core/btc/setup/WalletsSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
&& (useTorFlagFromOptions == null || useTorFlagFromOptions.isEmpty()))
return false;
else
return prefPayload.isUseTorForBitcoinJ();
Expand Down

0 comments on commit 68a6de2

Please sign in to comment.