reclassify public nodes and use if no provided nodes available (#1315)

This commit is contained in:
woodser 2024-10-12 06:18:16 -04:00 committed by GitHub
parent ddb48d1846
commit 58787a1d31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 42 additions and 17 deletions

View file

@ -718,10 +718,15 @@ public final class XmrConnectionService {
// skip handling if shutting down
if (isShutDownStarted) return;
// fallback to provided nodes if custom connection fails on startup
// fallback to provided or public nodes if custom connection fails on startup
if (lastInfo == null && "".equals(config.xmrNode) && preferences.getMoneroNodesOption() == XmrNodes.MoneroNodesOption.CUSTOM) {
if (xmrNodes.getProvidedXmrNodes().isEmpty()) {
log.warn("Failed to fetch daemon info from custom node on startup, falling back to public nodes: " + e.getMessage());
preferences.setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.PUBLIC.ordinal());
} else {
log.warn("Failed to fetch daemon info from custom node on startup, falling back to provided nodes: " + e.getMessage());
preferences.setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.PROVIDED.ordinal());
}
initializeConnections();
return;
}

View file

@ -38,6 +38,7 @@ 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.nodes.XmrNodesSetupPreferences;
import haveno.core.xmr.wallet.Restrictions;
import haveno.network.p2p.network.BridgeAddressProvider;
import java.util.ArrayList;
@ -130,6 +131,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
private final PersistenceManager<PreferencesPayload> persistenceManager;
private final Config config;
private final String xmrNodesFromOptions;
private final XmrNodes xmrNodes;
@Getter
private final BooleanProperty useStandbyModeProperty = new SimpleBooleanProperty(prefPayload.isUseStandbyMode());
@Getter
@ -142,11 +144,13 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
@Inject
public Preferences(PersistenceManager<PreferencesPayload> persistenceManager,
Config config,
@Named(Config.XMR_NODES) String xmrNodesFromOptions) {
@Named(Config.XMR_NODES) String xmrNodesFromOptions,
XmrNodes xmrNodes) {
this.persistenceManager = persistenceManager;
this.config = config;
this.xmrNodesFromOptions = xmrNodesFromOptions;
this.xmrNodes = xmrNodes;
useAnimationsProperty.addListener((ov) -> {
prefPayload.setUseAnimations(useAnimationsProperty.get());
@ -284,6 +288,12 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
if (config.useTorForXmrOptionSetExplicitly)
setUseTorForXmr(config.useTorForXmr);
// switch to public nodes if no provided nodes available
if (getMoneroNodesOptionOrdinal() == XmrNodes.MoneroNodesOption.PROVIDED.ordinal() && xmrNodes.selectPreferredNodes(new XmrNodesSetupPreferences(this)).isEmpty()) {
log.warn("No provided nodes available, switching to public nodes");
setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.PUBLIC.ordinal());
}
if (xmrNodesFromOptions != null && !xmrNodesFromOptions.isEmpty()) {
if (getMoneroNodes() != null && !getMoneroNodes().equals(xmrNodesFromOptions)) {
log.warn("The Monero node(s) from the program argument and the one(s) persisted in the UI are different. " +

View file

@ -83,16 +83,15 @@ public class XmrNodes {
);
case XMR_MAINNET:
return Arrays.asList(
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "127.0.0.1", 18081, 1, "@local"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "xmr-node.cakewallet.com", 18081, 2, "@cakewallet"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "node.community.rino.io", 18081, 2, "@RINOwallet"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "nodes.hashvault.pro", 18080, 2, "@HashVault"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "p2pmd.xmrvsbeast.com", 18080, 2, "@xmrvsbeast"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "node.monerodevs.org", 18089, 2, "@monerodevs.org"),
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "nodex.monerujo.io", 18081, 2, "@monerujo.io"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "127.0.0.1", 18081, 1, "@local"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "xmr-node.cakewallet.com", 18081, 2, "@cakewallet"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node.community.rino.io", 18081, 2, "@RINOwallet"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "nodes.hashvault.pro", 18080, 2, "@HashVault"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "p2pmd.xmrvsbeast.com", 18080, 2, "@xmrvsbeast"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node.monerodevs.org", 18089, 2, "@monerodevs.org"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "nodex.monerujo.io", 18081, 2, "@monerujo.io"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "rucknium.me", 18081, 2, "@Rucknium"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node.sethforprivacy.com", 18089, 2, "@sethforprivacy"),
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node3.monerodevs.org", 18089, 2, "@monerodevs.org")
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node.sethforprivacy.com", 18089, 2, "@sethforprivacy")
);
default:
throw new IllegalStateException("Unexpected base currency network: " + Config.baseCurrencyNetwork());

View file

@ -58,7 +58,7 @@ public class PreferencesTest {
Config config = new Config();
XmrLocalNode xmrLocalNode = new XmrLocalNode(config, preferences);
preferences = new Preferences(
persistenceManager, config, null);
persistenceManager, config, null, null);
}
@Test

View file

@ -282,6 +282,12 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
};
filterPropertyListener = (observable, oldValue, newValue) -> applyPreventPublicXmrNetwork();
// disable radio buttons if no nodes available
if (xmrNodes.getProvidedXmrNodes().isEmpty()) {
useProvidedNodesRadio.setDisable(true);
}
usePublicNodesRadio.setDisable(isPublicNodesDisabled());
//TODO sorting needs other NetworkStatisticListItem as columns type
/* creationDateColumn.setComparator((o1, o2) ->
o1.statistic.getCreationDate().compareTo(o2.statistic.getCreationDate()));
@ -433,7 +439,7 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
}
private void onMoneroPeersToggleSelected(boolean calledFromUser) {
usePublicNodesRadio.setDisable(isPreventPublicXmrNetwork());
usePublicNodesRadio.setDisable(isPublicNodesDisabled());
XmrNodes.MoneroNodesOption currentMoneroNodesOption = XmrNodes.MoneroNodesOption.values()[preferences.getMoneroNodesOptionOrdinal()];
@ -493,7 +499,7 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
private void applyPreventPublicXmrNetwork() {
final boolean preventPublicXmrNetwork = isPreventPublicXmrNetwork();
usePublicNodesRadio.setDisable(xmrLocalNode.shouldBeUsed() || preventPublicXmrNetwork);
usePublicNodesRadio.setDisable(isPublicNodesDisabled());
if (preventPublicXmrNetwork && selectedMoneroNodesOption == XmrNodes.MoneroNodesOption.PUBLIC) {
selectedMoneroNodesOption = XmrNodes.MoneroNodesOption.PROVIDED;
preferences.setMoneroNodesOptionOrdinal(selectedMoneroNodesOption.ordinal());
@ -502,6 +508,10 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
}
}
private boolean isPublicNodesDisabled() {
return xmrNodes.getPublicXmrNodes().isEmpty() || isPreventPublicXmrNetwork();
}
private void updateP2PTable() {
if (connectionService.isShutDownStarted()) return; // ignore if shutting down
p2pPeersTableView.getItems().forEach(P2pNetworkListItem::cleanup);

View file

@ -39,7 +39,8 @@ public class PreferenceMakers {
public static final Instantiator<Preferences> Preferences = lookup -> new Preferences(
lookup.valueOf(storage, new SameValueDonor<PersistenceManager>(null)),
lookup.valueOf(config, new SameValueDonor<Config>(null)),
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null))
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null)),
null
);
public static final Preferences empty = make(a(Preferences));