check local connection before switching

This commit is contained in:
woodser 2023-12-27 14:08:51 -05:00
parent 6c2f3ea154
commit 2e86d4a62a
2 changed files with 18 additions and 6 deletions

View File

@ -400,12 +400,24 @@ public final class XmrConnectionService {
@Override @Override
public void onConnectionChanged(MoneroRpcConnection connection) { public void onConnectionChanged(MoneroRpcConnection connection) {
log.info("Local monerod connection changed: " + connection); log.info("Local monerod connection changed: " + connection);
if (isShutDownStarted || !connectionManager.getAutoSwitch() || !accountService.isAccountOpen()) return;
if (xmrLocalNode.isConnected() && !xmrLocalNode.shouldBeIgnored()) { // skip if ignored
setConnection(connection.getUri()); // switch to local node if connected and not ignored if (isShutDownStarted || !connectionManager.getAutoSwitch() || !accountService.isAccountOpen() ||
checkConnection(); !connectionManager.hasConnection(connection.getUri()) || xmrLocalNode.shouldBeIgnored()) return;
// check connection
boolean isConnected = false;
if (xmrLocalNode.isConnected()) {
MoneroRpcConnection conn = connectionManager.getConnectionByUri(connection.getUri());
conn.checkConnection(connectionManager.getTimeout());
isConnected = Boolean.TRUE.equals(conn.isConnected());
}
// update connection
if (isConnected) {
setConnection(connection.getUri());
} else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) { } else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) {
setConnection(getBestAvailableConnection()); // switch to best available connection setConnection(getBestAvailableConnection()); // switch to best connection
} }
} }
}); });

View File

@ -951,7 +951,7 @@ public class XmrWalletService {
}); });
} }
log.info("Done setting main wallet daemon connection: " + (connection == null ? null : connection.getUri())); log.info("Done setting main wallet daemon connection: " + (wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getUri()));
} }
} }