mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-23 12:39:23 +00:00
check local connection before switching
This commit is contained in:
parent
6c2f3ea154
commit
2e86d4a62a
2 changed files with 18 additions and 6 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue