diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java index c722801b..62b671f9 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java @@ -135,7 +135,13 @@ public class UtxosController extends WalletFormController implements Initializab Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWalletForm().getWallet()); if(whirlpool != null) { stopMix.visibleProperty().bind(whirlpool.mixingProperty()); + if(whirlpool.startingProperty().getValue()) { + mixingStartingListener.changed(whirlpool.startingProperty(), null, whirlpool.startingProperty().getValue()); + } whirlpool.startingProperty().addListener(new WeakChangeListener<>(mixingStartingListener)); + if(whirlpool.stoppingProperty().getValue()) { + mixingStoppingListener.changed(whirlpool.stoppingProperty(), null, whirlpool.stoppingProperty().getValue()); + } whirlpool.stoppingProperty().addListener(new WeakChangeListener<>(mixingStoppingListener)); whirlpool.mixingProperty().addListener(new WeakChangeListener<>(mixingListener)); updateMixToButton(); diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java index 7015221b..08dcc46f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/Whirlpool.java @@ -373,6 +373,10 @@ public class Whirlpool { config.setServerApi(serverApi); } + public void refreshTorCircuits() { + torClientService.changeIdentity(); + } + public String getScode() { return config.getScode(); } @@ -578,14 +582,17 @@ public class Whirlpool { updateProgress(-1, 1); updateMessage("Starting Whirlpool..."); - whirlpool.startingProperty.set(true); - WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet(); - if(AppServices.onlineProperty().get()) { - whirlpoolWallet.start(); - } - whirlpool.startingProperty.set(false); + try { + whirlpool.startingProperty.set(true); + WhirlpoolWallet whirlpoolWallet = whirlpool.getWhirlpoolWallet(); + if(AppServices.onlineProperty().get()) { + whirlpoolWallet.start(); + } - return whirlpoolWallet; + return whirlpoolWallet; + } finally { + whirlpool.startingProperty.set(false); + } } }; } @@ -604,10 +611,14 @@ public class Whirlpool { protected Boolean call() throws Exception { updateProgress(-1, 1); updateMessage("Disconnecting from Whirlpool..."); - whirlpool.stoppingProperty.set(true); - whirlpool.shutdown(); - whirlpool.stoppingProperty.set(false); - return true; + + try { + whirlpool.stoppingProperty.set(true); + whirlpool.shutdown(); + return true; + } finally { + whirlpool.stoppingProperty.set(false); + } } }; } diff --git a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java index b1e4c337..8f8533c0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/whirlpool/WhirlpoolServices.java @@ -19,10 +19,12 @@ import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.SocketTimeoutException; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; public class WhirlpoolServices { @@ -94,6 +96,16 @@ public class WhirlpoolServices { }); startupService.setOnFailed(workerStateEvent -> { log.error("Failed to start whirlpool", workerStateEvent.getSource().getException()); + Throwable exception = workerStateEvent.getSource().getException(); + while(exception.getCause() != null) { + exception = exception.getCause(); + } + if(exception instanceof TimeoutException || exception instanceof SocketTimeoutException) { + EventManager.get().post(new StatusEvent("Error connecting to Whirlpool server, will retry soon...")); + if(torProxy != null) { + whirlpool.refreshTorCircuits(); + } + } }); startupService.start(); }