--xmrNode starts local node if used last and offline

This commit is contained in:
woodser 2023-08-01 08:01:37 -04:00
parent a01a6f7f95
commit 5d52366861

View file

@ -439,16 +439,8 @@ public final class CoreMoneroConnectionsService {
if (coreContext.isApiUser()) connectionManager.setAutoSwitch(connectionList.getAutoSwitch());
else connectionManager.setAutoSwitch(true);
// start local node if used as last connection and currently offline
if (connectionManager.getConnection() != null && nodeService.equalsUri(connectionManager.getConnection().getUri()) && !nodeService.isOnline()) {
try {
log.info("Starting local node");
nodeService.startMoneroNode();
} catch (Exception e) {
log.warn("Unable to start local monero node: " + e.getMessage());
e.printStackTrace();
}
}
// start local node if used last and offline
startLocalNodeIfUsedLast();
// update connection
if (connectionManager.getConnection() == null || connectionManager.getAutoSwitch()) {
@ -463,6 +455,12 @@ public final class CoreMoneroConnectionsService {
MoneroRpcConnection connection = new MoneroRpcConnection(config.xmrNode, config.xmrNodeUsername, config.xmrNodePassword).setPriority(1);
if (useProxy(connection)) connection.setProxyUri(getProxyUri());
connectionManager.setConnection(connection);
// start local node if used last and offline
startLocalNodeIfUsedLast();
// update connection
checkConnection();
}
// register connection listener
@ -474,6 +472,20 @@ public final class CoreMoneroConnectionsService {
}
}
private void startLocalNodeIfUsedLast() {
// start local node if offline and used as last connection
if (connectionManager.getConnection() != null && nodeService.equalsUri(connectionManager.getConnection().getUri()) && !nodeService.isOnline()) {
try {
log.info("Starting local node");
nodeService.startMoneroNode();
} catch (Exception e) {
log.warn("Unable to start local monero node: " + e.getMessage());
e.printStackTrace();
}
}
}
private void onConnectionChanged(MoneroRpcConnection currentConnection) {
log.info("CoreMoneroConnectionsService.onConnectionChanged() uri={}, connected={}", currentConnection == null ? null : currentConnection.getUri(), currentConnection == null ? "false" : currentConnection.isConnected());
if (isShutDownStarted) return;
@ -544,7 +556,7 @@ public final class CoreMoneroConnectionsService {
if (lastErrorTimestamp != null) {
log.info("Successfully fetched daemon info after previous error");
lastErrorTimestamp = null;
HavenoUtils.havenoSetup.getWalletServiceErrorMsg().set(null);
if (HavenoUtils.havenoSetup != null) HavenoUtils.havenoSetup.getWalletServiceErrorMsg().set(null);
}
// update and notify connected state