From 01a57c18f7db597145146bb4b159c9da89ed38d9 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 18 Dec 2023 13:58:02 -0500 Subject: [PATCH] support setting custom node in UI with localhost running --- .../java/haveno/core/api/XmrConnectionService.java | 14 +++++++------- .../main/java/haveno/core/api/XmrLocalNode.java | 3 ++- .../main/java/haveno/core/user/Preferences.java | 5 +++++ .../main/java/haveno/core/xmr/nodes/XmrNodes.java | 4 ++++ .../main/settings/network/NetworkSettingsView.java | 9 +-------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/haveno/core/api/XmrConnectionService.java b/core/src/main/java/haveno/core/api/XmrConnectionService.java index 4fb705c6b3..6b3a6bc7fd 100644 --- a/core/src/main/java/haveno/core/api/XmrConnectionService.java +++ b/core/src/main/java/haveno/core/api/XmrConnectionService.java @@ -399,11 +399,11 @@ public final class XmrConnectionService { public void onConnectionChanged(MoneroRpcConnection connection) { log.info("Local monerod connection changed: " + connection); if (isShutDownStarted || !connectionManager.getAutoSwitch() || !accountService.isAccountOpen()) return; - if (xmrLocalNode.isConnected()) { - setConnection(connection.getUri()); // switch to local node if connected + if (xmrLocalNode.isConnected() && !xmrLocalNode.shouldBeIgnored()) { + setConnection(connection.getUri()); // switch to local node if connected and not ignored checkConnection(); } else if (getConnection() != null && getConnection().getUri().equals(connection.getUri())) { - setConnection(getBestAvailableConnection()); // switch to best available if disconnected from local node + setConnection(getBestAvailableConnection()); // switch to best available connection } } }); @@ -446,7 +446,7 @@ public final class XmrConnectionService { } // restore last connection - if (connectionList.getCurrentConnectionUri().isPresent()) { + if (connectionList.getCurrentConnectionUri().isPresent() && connectionManager.hasConnection(connectionList.getCurrentConnectionUri().get())) { connectionManager.setConnection(connectionList.getCurrentConnectionUri().get()); } @@ -460,7 +460,7 @@ public final class XmrConnectionService { if (coreContext.isApiUser()) connectionManager.setAutoSwitch(connectionList.getAutoSwitch()); else connectionManager.setAutoSwitch(true); - // start local node if used last and offline + // start local node if applicable maybeStartLocalNode(); // update connection @@ -477,7 +477,7 @@ public final class XmrConnectionService { if (useTorProxy(connection)) connection.setProxyUri(getProxyUri()); connectionManager.setConnection(connection); - // start local node if used last and offline + // start local node if applicable maybeStartLocalNode(); // update connection @@ -507,7 +507,7 @@ public final class XmrConnectionService { if (HavenoUtils.havenoSetup == null) return; // start local node if offline and used as last connection - if (connectionManager.getConnection() != null && xmrLocalNode.equalsUri(connectionManager.getConnection().getUri()) && !xmrLocalNode.isDetected()) { + if (connectionManager.getConnection() != null && xmrLocalNode.equalsUri(connectionManager.getConnection().getUri()) && !xmrLocalNode.isDetected() && !xmrLocalNode.shouldBeIgnored()) { try { log.info("Starting local node"); xmrLocalNode.startMoneroNode(); diff --git a/core/src/main/java/haveno/core/api/XmrLocalNode.java b/core/src/main/java/haveno/core/api/XmrLocalNode.java index 9d8786ea24..c927ae3f50 100644 --- a/core/src/main/java/haveno/core/api/XmrLocalNode.java +++ b/core/src/main/java/haveno/core/api/XmrLocalNode.java @@ -22,6 +22,7 @@ import haveno.common.util.Utilities; import haveno.core.trade.HavenoUtils; import haveno.core.user.Preferences; import haveno.core.xmr.XmrNodeSettings; +import haveno.core.xmr.nodes.XmrNodes; import lombok.extern.slf4j.Slf4j; import monero.common.MoneroConnectionManager; import monero.common.MoneroUtils; @@ -102,7 +103,7 @@ public class XmrLocalNode { * Returns whether Haveno should ignore a local Monero node even if it is usable. */ public boolean shouldBeIgnored() { - return config.ignoreLocalXmrNode; + return config.ignoreLocalXmrNode || preferences.getMoneroNodesOption() == XmrNodes.MoneroNodesOption.CUSTOM; } public void addListener(XmrLocalNodeListener listener) { diff --git a/core/src/main/java/haveno/core/user/Preferences.java b/core/src/main/java/haveno/core/user/Preferences.java index 7915146c78..fe34802eb0 100644 --- a/core/src/main/java/haveno/core/user/Preferences.java +++ b/core/src/main/java/haveno/core/user/Preferences.java @@ -33,6 +33,7 @@ import haveno.core.payment.PaymentAccount; import haveno.core.payment.PaymentAccountUtil; import haveno.core.xmr.XmrNodeSettings; import haveno.core.xmr.nodes.XmrNodes; +import haveno.core.xmr.nodes.XmrNodes.MoneroNodesOption; import haveno.core.xmr.wallet.Restrictions; import haveno.network.p2p.network.BridgeAddressProvider; import javafx.beans.property.BooleanProperty; @@ -316,6 +317,10 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid // API /////////////////////////////////////////////////////////////////////////////////////////// + public MoneroNodesOption getMoneroNodesOption() { + return XmrNodes.MoneroNodesOption.values()[getMoneroNodesOptionOrdinal()]; + } + public void dontShowAgain(String key, boolean dontShowAgain) { prefPayload.getDontShowAgainMap().put(key, dontShowAgain); requestPersistence(); diff --git a/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java b/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java index ae32fda9a5..5cc3e9a555 100644 --- a/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java +++ b/core/src/main/java/haveno/core/xmr/nodes/XmrNodes.java @@ -86,6 +86,10 @@ public class XmrNodes { return getXmrNodes(MoneroNodesOption.PUBLIC); } + public List getCustomXmrNodes() { + return getXmrNodes(MoneroNodesOption.CUSTOM); + } + private List getXmrNodes(MoneroNodesOption type) { List nodes = new ArrayList<>(); for (XmrNode node : getAllXmrNodes()) if (node.getType() == type) nodes.add(node); diff --git a/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java b/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java index de322b441b..5ed9e468bd 100644 --- a/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java +++ b/desktop/src/main/java/haveno/desktop/main/settings/network/NetworkSettingsView.java @@ -434,14 +434,7 @@ public class NetworkSettingsView extends ActivatableView { } private void onMoneroPeersToggleSelected(boolean calledFromUser) { - boolean localMoneroNodeShouldBeUsed = xmrLocalNode.shouldBeUsed(); - useTorForXmrLabel.setDisable(localMoneroNodeShouldBeUsed); - moneroNodesLabel.setDisable(localMoneroNodeShouldBeUsed); - xmrNodesLabel.setDisable(localMoneroNodeShouldBeUsed); - xmrNodesInputTextField.setDisable(localMoneroNodeShouldBeUsed); - useProvidedNodesRadio.setDisable(localMoneroNodeShouldBeUsed); - useCustomNodesRadio.setDisable(localMoneroNodeShouldBeUsed); - usePublicNodesRadio.setDisable(localMoneroNodeShouldBeUsed || isPreventPublicXmrNetwork()); + usePublicNodesRadio.setDisable(isPreventPublicXmrNetwork()); XmrNodes.MoneroNodesOption currentMoneroNodesOption = XmrNodes.MoneroNodesOption.values()[preferences.getMoneroNodesOptionOrdinal()];