mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-22 05:29:33 -04:00
Add timer for lost connection handling
This commit is contained in:
parent
e9c9834733
commit
22a1377c24
1 changed files with 15 additions and 3 deletions
|
@ -63,6 +63,7 @@ class MainViewModel implements ViewModel {
|
||||||
private static final Logger log = LoggerFactory.getLogger(MainViewModel.class);
|
private static final Logger log = LoggerFactory.getLogger(MainViewModel.class);
|
||||||
|
|
||||||
private static final long BLOCKCHAIN_SYNC_TIMEOUT = 30000;
|
private static final long BLOCKCHAIN_SYNC_TIMEOUT = 30000;
|
||||||
|
private static final long LOST_CONNECTION_TIMEOUT = 10000;
|
||||||
|
|
||||||
// BTC network
|
// BTC network
|
||||||
final StringProperty blockchainSyncInfo = new SimpleStringProperty("Initializing");
|
final StringProperty blockchainSyncInfo = new SimpleStringProperty("Initializing");
|
||||||
|
@ -107,6 +108,7 @@ class MainViewModel implements ViewModel {
|
||||||
private final UpdateProcess updateProcess;
|
private final UpdateProcess updateProcess;
|
||||||
private final BSFormatter formatter;
|
private final BSFormatter formatter;
|
||||||
private Timer blockchainSyncTimeoutTimer;
|
private Timer blockchainSyncTimeoutTimer;
|
||||||
|
private Timer lostConnectionTimeoutTimer;
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -163,9 +165,19 @@ class MainViewModel implements ViewModel {
|
||||||
|
|
||||||
clientNode.numPeersProperty().addListener((observable, oldValue, newValue) -> {
|
clientNode.numPeersProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
numDHTPeers.set(String.valueOf(newValue) + " peers");
|
numDHTPeers.set(String.valueOf(newValue) + " peers");
|
||||||
if ((int) newValue < 1) {
|
if ((int) newValue == 0) {
|
||||||
// TODO swallow connection drops for a certain time.
|
if (lostConnectionTimeoutTimer != null)
|
||||||
// bootstrapErrorMsg.set("We lost connection to the last peer.");
|
lostConnectionTimeoutTimer.cancel();
|
||||||
|
lostConnectionTimeoutTimer = Utilities.setTimeout(LOST_CONNECTION_TIMEOUT, () -> {
|
||||||
|
log.trace("Connection lost timeout reached");
|
||||||
|
bootstrapErrorMsg.set("We lost connection to the last peer.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if ((int) oldValue == 0 && (int) newValue > 0) {
|
||||||
|
if (lostConnectionTimeoutTimer != null) {
|
||||||
|
lostConnectionTimeoutTimer.cancel();
|
||||||
|
lostConnectionTimeoutTimer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue