Skip to content

Commit 223988c

Browse files
committed
show error popup when unrestricted monerod has 0 peers
1 parent 036a50a commit 223988c

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

core/src/main/java/haveno/core/api/XmrConnectionService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public enum XmrConnectionFallbackType {
9393
private final MoneroConnectionManager connectionManager;
9494
private final EncryptedConnectionList connectionList;
9595
private final ObjectProperty<List<MoneroRpcConnection>> connections = new SimpleObjectProperty<>();
96-
private final IntegerProperty numConnections = new SimpleIntegerProperty(0);
96+
private final IntegerProperty numConnections = new SimpleIntegerProperty(-1);
9797
private final ObjectProperty<MoneroRpcConnection> connectionProperty = new SimpleObjectProperty<>();
9898
private final LongProperty chainHeight = new SimpleLongProperty(0);
9999
private final DownloadListener downloadListener = new DownloadListener();
@@ -845,6 +845,9 @@ private void doPollMonerod() {
845845
return;
846846
}
847847

848+
// get the number of connections, which is only available if not restricted
849+
int numOutgoingConnections = Boolean.TRUE.equals(lastInfo.isRestricted()) ? -1 : lastInfo.getNumOutgoingConnections();
850+
848851
// update properties on user thread
849852
UserThread.execute(() -> {
850853

@@ -870,12 +873,19 @@ else if (lastInfo.isBusySyncing()) {
870873
}
871874
}
872875
connections.set(availableConnections);
873-
numConnections.set(availableConnections.size());
876+
numConnections.set(numOutgoingConnections);
874877

875878
// notify update
876879
numUpdates.set(numUpdates.get() + 1);
877880
});
878881

882+
// invoke error handling if no connections
883+
if (numOutgoingConnections == 0) {
884+
String errorMsg = "The Monero node has no connected peers. It may be experiencing a network connectivity issue.";
885+
log.warn(errorMsg);
886+
throw new RuntimeException(errorMsg);
887+
}
888+
879889
// handle error recovery
880890
if (lastLogPollErrorTimestamp != null) {
881891
log.info("Successfully fetched monerod info after previous error");

core/src/main/java/haveno/core/app/P2PNetworkSetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ BooleanProperty init(Runnable onReadyHandler, @Nullable Consumer<Boolean> displa
9494
if (warning != null && p2pPeers == 0) {
9595
result = warning;
9696
} else {
97-
String p2pInfo = ((int) numXmrPeers > 0 ? Res.get("mainView.footer.xmrPeers", numXmrPeers) + " / " : "") + Res.get("mainView.footer.p2pPeers", numP2pPeers);
97+
String p2pInfo = ((int) numXmrPeers >= 0 ? Res.get("mainView.footer.xmrPeers", numXmrPeers) + " / " : "") + Res.get("mainView.footer.p2pPeers", numP2pPeers);
9898
if (dataReceived && hiddenService) {
9999
result = p2pInfo;
100100
} else if (p2pPeers == 0)

desktop/src/main/java/haveno/desktop/main/MainView.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
126126
private Label splashP2PNetworkLabel;
127127
private ProgressBar xmrSyncIndicator;
128128
private Label xmrSplashInfo;
129-
private Popup p2PNetworkWarnMsgPopup, xmrNetworkWarnMsgPopup;
130129
private final TorNetworkSettingsWindow torNetworkSettingsWindow;
131130
private final Preferences preferences;
132131
private static final int networkIconSize = 20;
@@ -713,15 +712,10 @@ private AnchorPane createFooter() {
713712
if (newValue != null) {
714713
xmrInfoLabel.setId("splash-error-state-msg");
715714
xmrInfoLabel.getStyleClass().add("error-text");
716-
if (xmrNetworkWarnMsgPopup == null) {
717-
xmrNetworkWarnMsgPopup = new Popup().warning(newValue);
718-
xmrNetworkWarnMsgPopup.show();
719-
}
715+
new Popup().warning(newValue).show();
720716
} else {
721717
xmrInfoLabel.setId("footer-pane");
722718
xmrInfoLabel.getStyleClass().remove("error-text");
723-
if (xmrNetworkWarnMsgPopup != null)
724-
xmrNetworkWarnMsgPopup.hide();
725719
}
726720
});
727721

@@ -804,10 +798,7 @@ private AnchorPane createFooter() {
804798
p2PNetworkLabel.idProperty().bind(model.getP2pNetworkLabelId());
805799
model.getP2pNetworkWarnMsg().addListener((ov, oldValue, newValue) -> {
806800
if (newValue != null) {
807-
p2PNetworkWarnMsgPopup = new Popup().warning(newValue);
808-
p2PNetworkWarnMsgPopup.show();
809-
} else if (p2PNetworkWarnMsgPopup != null) {
810-
p2PNetworkWarnMsgPopup.hide();
801+
new Popup().warning(newValue).show();
811802
}
812803
});
813804
p2PNetworkIcon.setOnMouseClicked(e -> {

0 commit comments

Comments
 (0)