add config property autoSwitchProxy to disable automatic proxy switching on failure, and improve tor connection failure message

This commit is contained in:
Craig Raw 2023-02-06 11:38:19 +02:00
parent 153815d9e3
commit d84f3bf887
4 changed files with 15 additions and 2 deletions

View file

@ -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); Config.get().setUseProxy(false);
Platform.runLater(() -> restartService(torService)); Platform.runLater(() -> restartService(torService));
return; return;

View file

@ -70,6 +70,7 @@ public class Config {
private File electrumServerCert; private File electrumServerCert;
private boolean useProxy; private boolean useProxy;
private String proxyServer; private String proxyServer;
private boolean autoSwitchProxy = true;
private int maxServerTimeout = DEFAULT_MAX_TIMEOUT; private int maxServerTimeout = DEFAULT_MAX_TIMEOUT;
private int maxPageSize = DEFAULT_PAGE_SIZE; private int maxPageSize = DEFAULT_PAGE_SIZE;
private boolean usePayNym; private boolean usePayNym;
@ -605,6 +606,15 @@ public class Config {
flush(); flush();
} }
public boolean isAutoSwitchProxy() {
return autoSwitchProxy;
}
public void setAutoSwitchProxy(boolean autoSwitchProxy) {
this.autoSwitchProxy = autoSwitchProxy;
flush();
}
public int getMaxServerTimeout() { public int getMaxServerTimeout() {
return maxServerTimeout; return maxServerTimeout;
} }

View file

@ -24,6 +24,6 @@ public class TorTcpTransport extends TcpTransport {
throw new IllegalStateException("Can't create Tor socket, Tor is not running"); 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");
} }
} }

View file

@ -329,6 +329,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
setElectrumServerInConfig(config); setElectrumServerInConfig(config);
electrumCertificate.setDisable(!newValue); electrumCertificate.setDisable(!newValue);
electrumCertificateSelect.setDisable(!newValue); electrumCertificateSelect.setDisable(!newValue);
electrumPort.setPromptText(newValue ? "e.g. 50002" : "e.g. 50001");
}); });
electrumCertificate.textProperty().addListener((observable, oldValue, newValue) -> { 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 + "?"; 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"))) { } 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"; 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); testResults.setText("Could not connect:\n\n" + reason);