mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-22 20:19:21 +00:00
reclassify public nodes and use if no provided nodes available (#1315)
This commit is contained in:
parent
ddb48d1846
commit
58787a1d31
6 changed files with 42 additions and 17 deletions
|
@ -718,10 +718,15 @@ public final class XmrConnectionService {
|
||||||
// skip handling if shutting down
|
// skip handling if shutting down
|
||||||
if (isShutDownStarted) return;
|
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 (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());
|
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());
|
preferences.setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.PROVIDED.ordinal());
|
||||||
|
}
|
||||||
initializeConnections();
|
initializeConnections();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import haveno.core.payment.PaymentAccountUtil;
|
||||||
import haveno.core.xmr.XmrNodeSettings;
|
import haveno.core.xmr.XmrNodeSettings;
|
||||||
import haveno.core.xmr.nodes.XmrNodes;
|
import haveno.core.xmr.nodes.XmrNodes;
|
||||||
import haveno.core.xmr.nodes.XmrNodes.MoneroNodesOption;
|
import haveno.core.xmr.nodes.XmrNodes.MoneroNodesOption;
|
||||||
|
import haveno.core.xmr.nodes.XmrNodesSetupPreferences;
|
||||||
import haveno.core.xmr.wallet.Restrictions;
|
import haveno.core.xmr.wallet.Restrictions;
|
||||||
import haveno.network.p2p.network.BridgeAddressProvider;
|
import haveno.network.p2p.network.BridgeAddressProvider;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -130,6 +131,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
private final PersistenceManager<PreferencesPayload> persistenceManager;
|
private final PersistenceManager<PreferencesPayload> persistenceManager;
|
||||||
private final Config config;
|
private final Config config;
|
||||||
private final String xmrNodesFromOptions;
|
private final String xmrNodesFromOptions;
|
||||||
|
private final XmrNodes xmrNodes;
|
||||||
@Getter
|
@Getter
|
||||||
private final BooleanProperty useStandbyModeProperty = new SimpleBooleanProperty(prefPayload.isUseStandbyMode());
|
private final BooleanProperty useStandbyModeProperty = new SimpleBooleanProperty(prefPayload.isUseStandbyMode());
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -142,11 +144,13 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
@Inject
|
@Inject
|
||||||
public Preferences(PersistenceManager<PreferencesPayload> persistenceManager,
|
public Preferences(PersistenceManager<PreferencesPayload> persistenceManager,
|
||||||
Config config,
|
Config config,
|
||||||
@Named(Config.XMR_NODES) String xmrNodesFromOptions) {
|
@Named(Config.XMR_NODES) String xmrNodesFromOptions,
|
||||||
|
XmrNodes xmrNodes) {
|
||||||
|
|
||||||
this.persistenceManager = persistenceManager;
|
this.persistenceManager = persistenceManager;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.xmrNodesFromOptions = xmrNodesFromOptions;
|
this.xmrNodesFromOptions = xmrNodesFromOptions;
|
||||||
|
this.xmrNodes = xmrNodes;
|
||||||
|
|
||||||
useAnimationsProperty.addListener((ov) -> {
|
useAnimationsProperty.addListener((ov) -> {
|
||||||
prefPayload.setUseAnimations(useAnimationsProperty.get());
|
prefPayload.setUseAnimations(useAnimationsProperty.get());
|
||||||
|
@ -284,6 +288,12 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
if (config.useTorForXmrOptionSetExplicitly)
|
if (config.useTorForXmrOptionSetExplicitly)
|
||||||
setUseTorForXmr(config.useTorForXmr);
|
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 (xmrNodesFromOptions != null && !xmrNodesFromOptions.isEmpty()) {
|
||||||
if (getMoneroNodes() != null && !getMoneroNodes().equals(xmrNodesFromOptions)) {
|
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. " +
|
log.warn("The Monero node(s) from the program argument and the one(s) persisted in the UI are different. " +
|
||||||
|
|
|
@ -83,16 +83,15 @@ public class XmrNodes {
|
||||||
);
|
);
|
||||||
case XMR_MAINNET:
|
case XMR_MAINNET:
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "127.0.0.1", 18081, 1, "@local"),
|
new XmrNode(MoneroNodesOption.PUBLIC, 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.PUBLIC, 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.PUBLIC, null, null, "node.community.rino.io", 18081, 2, "@RINOwallet"),
|
||||||
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "nodes.hashvault.pro", 18080, 2, "@HashVault"),
|
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "nodes.hashvault.pro", 18080, 2, "@HashVault"),
|
||||||
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "p2pmd.xmrvsbeast.com", 18080, 2, "@xmrvsbeast"),
|
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "p2pmd.xmrvsbeast.com", 18080, 2, "@xmrvsbeast"),
|
||||||
new XmrNode(MoneroNodesOption.PROVIDED, null, null, "node.monerodevs.org", 18089, 2, "@monerodevs.org"),
|
new XmrNode(MoneroNodesOption.PUBLIC, 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, "nodex.monerujo.io", 18081, 2, "@monerujo.io"),
|
||||||
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "rucknium.me", 18081, 2, "@Rucknium"),
|
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, "node.sethforprivacy.com", 18089, 2, "@sethforprivacy")
|
||||||
new XmrNode(MoneroNodesOption.PUBLIC, null, null, "node3.monerodevs.org", 18089, 2, "@monerodevs.org")
|
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected base currency network: " + Config.baseCurrencyNetwork());
|
throw new IllegalStateException("Unexpected base currency network: " + Config.baseCurrencyNetwork());
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class PreferencesTest {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
XmrLocalNode xmrLocalNode = new XmrLocalNode(config, preferences);
|
XmrLocalNode xmrLocalNode = new XmrLocalNode(config, preferences);
|
||||||
preferences = new Preferences(
|
preferences = new Preferences(
|
||||||
persistenceManager, config, null);
|
persistenceManager, config, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -282,6 +282,12 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
|
||||||
};
|
};
|
||||||
filterPropertyListener = (observable, oldValue, newValue) -> applyPreventPublicXmrNetwork();
|
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
|
//TODO sorting needs other NetworkStatisticListItem as columns type
|
||||||
/* creationDateColumn.setComparator((o1, o2) ->
|
/* creationDateColumn.setComparator((o1, o2) ->
|
||||||
o1.statistic.getCreationDate().compareTo(o2.statistic.getCreationDate()));
|
o1.statistic.getCreationDate().compareTo(o2.statistic.getCreationDate()));
|
||||||
|
@ -433,7 +439,7 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMoneroPeersToggleSelected(boolean calledFromUser) {
|
private void onMoneroPeersToggleSelected(boolean calledFromUser) {
|
||||||
usePublicNodesRadio.setDisable(isPreventPublicXmrNetwork());
|
usePublicNodesRadio.setDisable(isPublicNodesDisabled());
|
||||||
|
|
||||||
XmrNodes.MoneroNodesOption currentMoneroNodesOption = XmrNodes.MoneroNodesOption.values()[preferences.getMoneroNodesOptionOrdinal()];
|
XmrNodes.MoneroNodesOption currentMoneroNodesOption = XmrNodes.MoneroNodesOption.values()[preferences.getMoneroNodesOptionOrdinal()];
|
||||||
|
|
||||||
|
@ -493,7 +499,7 @@ public class NetworkSettingsView extends ActivatableView<GridPane, Void> {
|
||||||
|
|
||||||
private void applyPreventPublicXmrNetwork() {
|
private void applyPreventPublicXmrNetwork() {
|
||||||
final boolean preventPublicXmrNetwork = isPreventPublicXmrNetwork();
|
final boolean preventPublicXmrNetwork = isPreventPublicXmrNetwork();
|
||||||
usePublicNodesRadio.setDisable(xmrLocalNode.shouldBeUsed() || preventPublicXmrNetwork);
|
usePublicNodesRadio.setDisable(isPublicNodesDisabled());
|
||||||
if (preventPublicXmrNetwork && selectedMoneroNodesOption == XmrNodes.MoneroNodesOption.PUBLIC) {
|
if (preventPublicXmrNetwork && selectedMoneroNodesOption == XmrNodes.MoneroNodesOption.PUBLIC) {
|
||||||
selectedMoneroNodesOption = XmrNodes.MoneroNodesOption.PROVIDED;
|
selectedMoneroNodesOption = XmrNodes.MoneroNodesOption.PROVIDED;
|
||||||
preferences.setMoneroNodesOptionOrdinal(selectedMoneroNodesOption.ordinal());
|
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() {
|
private void updateP2PTable() {
|
||||||
if (connectionService.isShutDownStarted()) return; // ignore if shutting down
|
if (connectionService.isShutDownStarted()) return; // ignore if shutting down
|
||||||
p2pPeersTableView.getItems().forEach(P2pNetworkListItem::cleanup);
|
p2pPeersTableView.getItems().forEach(P2pNetworkListItem::cleanup);
|
||||||
|
|
|
@ -39,7 +39,8 @@ public class PreferenceMakers {
|
||||||
public static final Instantiator<Preferences> Preferences = lookup -> new Preferences(
|
public static final Instantiator<Preferences> Preferences = lookup -> new Preferences(
|
||||||
lookup.valueOf(storage, new SameValueDonor<PersistenceManager>(null)),
|
lookup.valueOf(storage, new SameValueDonor<PersistenceManager>(null)),
|
||||||
lookup.valueOf(config, new SameValueDonor<Config>(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));
|
public static final Preferences empty = make(a(Preferences));
|
||||||
|
|
Loading…
Reference in a new issue