From 759de8e0473d189708be63a8dc0aebf739f54613 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 18 Feb 2021 09:27:01 +0200 Subject: [PATCH] add public server retry period with backoff --- src/main/java/com/sparrowwallet/sparrow/AppController.java | 2 +- src/main/java/com/sparrowwallet/sparrow/AppServices.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index dcdb44a1..ae4b39fb 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1315,7 +1315,7 @@ public class AppController implements Initializable { @Subscribe public void connectionFailed(ConnectionFailedEvent event) { String reason = event.getException().getCause() != null ? event.getException().getCause().getMessage() : event.getException().getMessage(); - String status = "Connection error: " + reason; + String status = "Connection failed: " + reason; statusUpdated(new StatusEvent(status)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 48bf23bc..08fedb34 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -50,6 +50,7 @@ public class AppServices { private static final Logger log = LoggerFactory.getLogger(AppServices.class); private static final int SERVER_PING_PERIOD_SECS = 60; + private static final int PUBLIC_SERVER_RETRY_PERIOD_SECS = 3; private static final int ENUMERATE_HW_PERIOD_SECS = 30; private static final int RATES_PERIOD_SECS = 5 * 60; private static final int VERSION_CHECK_PERIOD_HOURS = 24; @@ -187,6 +188,7 @@ public class AppServices { } }); connectionService.setOnSucceeded(successEvent -> { + connectionService.setPeriod(Duration.seconds(SERVER_PING_PERIOD_SECS)); connectionService.setRestartOnFailure(true); onlineProperty.removeListener(onlineServicesListener); @@ -212,7 +214,7 @@ public class AppServices { if(Config.get().getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER) { List otherServers = Arrays.stream(PublicElectrumServer.values()).map(PublicElectrumServer::getUrl).filter(url -> !url.equals(Config.get().getPublicElectrumServer())).collect(Collectors.toList()); Config.get().setPublicElectrumServer(otherServers.get(new Random().nextInt(otherServers.size()))); - restartService(connectionService); + connectionService.setPeriod(Duration.seconds(PUBLIC_SERVER_RETRY_PERIOD_SECS)); } log.debug("Connection failed", failEvent.getSource().getException());