From 0f639dc2c213b3b8f00c3ba2cdbcab730976145a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 5 Mar 2021 09:16:00 +0200 Subject: [PATCH] clear transport on a failed test connection, try ssl or vice-versa on electrum connection failure --- .../ServerPreferencesController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java index 78579f9d..3922fa3c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java @@ -149,6 +149,8 @@ public class ServerPreferencesController extends PreferencesDetailController { private ElectrumServer.ConnectionService connectionService; + private Boolean useSslOriginal; + @Override public void initializeView(Config config) { EventManager.get().register(this); @@ -439,6 +441,8 @@ public class ServerPreferencesController extends PreferencesDetailController { connectionService.setRestartOnFailure(false); EventManager.get().register(connectionService); + useSslOriginal = null; + connectionService.setOnSucceeded(successEvent -> { EventManager.get().unregister(connectionService); ConnectionEvent connectionEvent = (ConnectionEvent)connectionService.getValue(); @@ -450,6 +454,29 @@ public class ServerPreferencesController extends PreferencesDetailController { connectionService.setOnFailed(workerStateEvent -> { EventManager.get().unregister(connectionService); showConnectionFailure(workerStateEvent.getSource().getException()); + connectionService.cancel(); + + if(Config.get().getServerType() == ServerType.ELECTRUM_SERVER) { + if(useSslOriginal == null) { + Integer portAsInteger = getPort(electrumPort.getText()); + if(!electrumUseSsl.isSelected() && portAsInteger != null && portAsInteger == TcpOverTlsTransport.DEFAULT_PORT) { + useSslOriginal = false; + electrumUseSsl.setSelected(true); + } else if(electrumUseSsl.isSelected() && portAsInteger != null && portAsInteger == TcpTransport.DEFAULT_PORT) { + useSslOriginal = true; + electrumUseSsl.setSelected(false); + } + + if(useSslOriginal != null) { + EventManager.get().register(connectionService); + connectionService.reset(); + connectionService.start(); + } + } else { + electrumUseSsl.setSelected(useSslOriginal); + useSslOriginal = null; + } + } }); connectionService.start(); }