From 8b7d1e688864a32459ff4428b06d1f25ed4a0f79 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 15 Mar 2021 14:07:48 +0200 Subject: [PATCH] try proxy setting if internal tor cant start --- .../ServerPreferencesController.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java index 2a62c437..3dbd7d26 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java @@ -151,6 +151,8 @@ public class ServerPreferencesController extends PreferencesDetailController { private Boolean useSslOriginal; + private Boolean useProxyOriginal; + @Override public void initializeView(Config config) { EventManager.get().register(this); @@ -424,6 +426,18 @@ public class ServerPreferencesController extends PreferencesDetailController { torService.cancel(); testResults.appendText("\nTor failed to start"); showConnectionFailure(workerStateEvent.getSource().getException()); + + Throwable exception = workerStateEvent.getSource().getException(); + if(Config.get().getServerType() == ServerType.ELECTRUM_SERVER && + exception.getCause() != null && exception.getCause() instanceof TorControlError && exception.getCause().getMessage().contains("Failed to bind") && + useProxyOriginal == null && !useProxy.isSelected() && proxyHost.getText().isEmpty() && proxyPort.getText().isEmpty()) { + useProxy.setSelected(true); + proxyHost.setText("localhost"); + proxyPort.setText("9050"); + useProxyOriginal = false; + testResults.appendText("\n\nAssuming Tor proxy is running on port 9050 and trying again..."); + startElectrumConnection(); + } }); torService.start(); @@ -448,6 +462,7 @@ public class ServerPreferencesController extends PreferencesDetailController { getMasterController().reconnectOnClosingProperty().set(true); Config.get().setMode(Mode.ONLINE); connectionService.cancel(); + useProxyOriginal = null; }); connectionService.setOnFailed(workerStateEvent -> { EventManager.get().unregister(connectionService); @@ -475,6 +490,13 @@ public class ServerPreferencesController extends PreferencesDetailController { useSslOriginal = null; } } + + if(useProxyOriginal != null && !useProxyOriginal) { + useProxy.setSelected(false); + proxyHost.setText(""); + proxyPort.setText(""); + useProxyOriginal = null; + } }); connectionService.start(); }