From d84f3bf88739b1c3d114edc32e7cf5754754cc6b Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 6 Feb 2023 11:38:19 +0200 Subject: [PATCH] add config property autoSwitchProxy to disable automatic proxy switching on failure, and improve tor connection failure message --- .../java/com/sparrowwallet/sparrow/AppServices.java | 2 +- src/main/java/com/sparrowwallet/sparrow/io/Config.java | 10 ++++++++++ .../com/sparrowwallet/sparrow/net/TorTcpTransport.java | 2 +- .../preferences/ServerPreferencesController.java | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index b15f9f4b..3e9c2340 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -326,7 +326,7 @@ public class AppServices { } } - if(failEvent.getSource().getException() instanceof ProxyServerException && Config.get().isUseProxy() && Config.get().requiresTor()) { + if(failEvent.getSource().getException() instanceof ProxyServerException && Config.get().isUseProxy() && Config.get().isAutoSwitchProxy() && Config.get().requiresTor()) { Config.get().setUseProxy(false); Platform.runLater(() -> restartService(torService)); return; diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index 0a78b4d9..53ce5236 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -70,6 +70,7 @@ public class Config { private File electrumServerCert; private boolean useProxy; private String proxyServer; + private boolean autoSwitchProxy = true; private int maxServerTimeout = DEFAULT_MAX_TIMEOUT; private int maxPageSize = DEFAULT_PAGE_SIZE; private boolean usePayNym; @@ -605,6 +606,15 @@ public class Config { flush(); } + public boolean isAutoSwitchProxy() { + return autoSwitchProxy; + } + + public void setAutoSwitchProxy(boolean autoSwitchProxy) { + this.autoSwitchProxy = autoSwitchProxy; + flush(); + } + public int getMaxServerTimeout() { return maxServerTimeout; } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/TorTcpTransport.java b/src/main/java/com/sparrowwallet/sparrow/net/TorTcpTransport.java index 8fe61adc..627d7603 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/TorTcpTransport.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/TorTcpTransport.java @@ -24,6 +24,6 @@ public class TorTcpTransport extends TcpTransport { throw new IllegalStateException("Can't create Tor socket, Tor is not running"); } - socket = new TorSocket(server.getHost(), server.getPort(), "sparrow"); + socket = new TorSocket(server.getHost(), server.getPortOrDefault(Protocol.TCP.getDefaultPort()), "sparrow"); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java index 3fe7ea56..6a7786cf 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java @@ -329,6 +329,7 @@ public class ServerPreferencesController extends PreferencesDetailController { setElectrumServerInConfig(config); electrumCertificate.setDisable(!newValue); electrumCertificateSelect.setDisable(!newValue); + electrumPort.setPromptText(newValue ? "e.g. 50002" : "e.g. 50001"); }); electrumCertificate.textProperty().addListener((observable, oldValue, newValue) -> { @@ -660,6 +661,8 @@ public class ServerPreferencesController extends PreferencesDetailController { reason += "\nIs a Tor proxy already running on port " + TorService.PROXY_PORT + "?"; } else if(reason != null && (reason.contains("Check if Bitcoin Core is running") || reason.contains("Could not connect to Bitcoin Core RPC"))) { reason += "\n\nSee https://sparrowwallet.com/docs/connect-node.html"; + } else if(reason != null && (reason.startsWith("Cannot connect to hidden service"))) { + reason += " on the server. Check that the onion address and port are correct, and that both Tor and the Electrum server are running on the node. Usually SSL is not enabled, and the port is 50001."; } testResults.setText("Could not connect:\n\n" + reason);