43
43
44
44
import org .apache .commons .lang3 .exception .ExceptionUtils ;
45
45
46
+ import javafx .beans .property .BooleanProperty ;
46
47
import javafx .beans .property .IntegerProperty ;
47
48
import javafx .beans .property .LongProperty ;
48
49
import javafx .beans .property .ObjectProperty ;
49
50
import javafx .beans .property .ReadOnlyDoubleProperty ;
50
51
import javafx .beans .property .ReadOnlyIntegerProperty ;
51
52
import javafx .beans .property .ReadOnlyLongProperty ;
52
53
import javafx .beans .property .ReadOnlyObjectProperty ;
54
+ import javafx .beans .property .SimpleBooleanProperty ;
53
55
import javafx .beans .property .SimpleIntegerProperty ;
54
56
import javafx .beans .property .SimpleLongProperty ;
55
57
import javafx .beans .property .SimpleObjectProperty ;
@@ -89,6 +91,8 @@ public final class XmrConnectionService {
89
91
private final LongProperty chainHeight = new SimpleLongProperty (0 );
90
92
private final DownloadListener downloadListener = new DownloadListener ();
91
93
@ Getter
94
+ private final BooleanProperty connectionServiceFallbackProperty = new SimpleBooleanProperty ();
95
+ @ Getter
92
96
private final StringProperty connectionServiceErrorMsg = new SimpleStringProperty ();
93
97
private final LongProperty numUpdates = new SimpleLongProperty (0 );
94
98
private Socks5ProxyProvider socks5ProxyProvider ;
@@ -99,6 +103,7 @@ public final class XmrConnectionService {
99
103
private Boolean isConnected = false ;
100
104
@ Getter
101
105
private MoneroDaemonInfo lastInfo ;
106
+ private Long lastFallbackInvocation ;
102
107
private Long lastLogPollErrorTimestamp ;
103
108
private long lastLogDaemonNotSyncedTimestamp ;
104
109
private Long syncStartHeight ;
@@ -115,6 +120,7 @@ public final class XmrConnectionService {
115
120
private int numRequestsLastMinute ;
116
121
private long lastSwitchTimestamp ;
117
122
private Set <MoneroRpcConnection > excludedConnections = new HashSet <>();
123
+ private static final long FALLBACK_INVOCATION_PERIOD_MS = 1000 * 60 * 1 ; // offer to fallback up to once every minute
118
124
119
125
@ Inject
120
126
public XmrConnectionService (P2PService p2PService ,
@@ -424,6 +430,18 @@ public ReadOnlyLongProperty numUpdatesProperty() {
424
430
return numUpdates ;
425
431
}
426
432
433
+ public void fallbackToBestConnection () {
434
+ if (isShutDownStarted ) return ;
435
+ if (xmrNodes .getProvidedXmrNodes ().isEmpty ()) {
436
+ log .warn ("Falling back to public nodes" );
437
+ preferences .setMoneroNodesOptionOrdinal (XmrNodes .MoneroNodesOption .PUBLIC .ordinal ());
438
+ } else {
439
+ log .warn ("Falling back to provided nodes" );
440
+ preferences .setMoneroNodesOptionOrdinal (XmrNodes .MoneroNodesOption .PROVIDED .ordinal ());
441
+ }
442
+ initializeConnections ();
443
+ }
444
+
427
445
// ------------------------------- HELPERS --------------------------------
428
446
429
447
private void doneDownload () {
@@ -716,16 +734,13 @@ private void doPollDaemon() {
716
734
// skip handling if shutting down
717
735
if (isShutDownStarted ) return ;
718
736
719
- // fallback to provided or public nodes if custom connection fails on startup
720
- if (lastInfo == null && "" .equals (config .xmrNode ) && preferences .getMoneroNodesOption () == XmrNodes .MoneroNodesOption .CUSTOM ) {
721
- if (xmrNodes .getProvidedXmrNodes ().isEmpty ()) {
722
- log .warn ("Failed to fetch daemon info from custom node on startup, falling back to public nodes: " + e .getMessage ());
723
- preferences .setMoneroNodesOptionOrdinal (XmrNodes .MoneroNodesOption .PUBLIC .ordinal ());
724
- } else {
725
- log .warn ("Failed to fetch daemon info from custom node on startup, falling back to provided nodes: " + e .getMessage ());
726
- preferences .setMoneroNodesOptionOrdinal (XmrNodes .MoneroNodesOption .PROVIDED .ordinal ());
737
+ // handle error fetching daemon info on startup with fixed connection
738
+ if (lastInfo == null && isFixedConnection ()) {
739
+ if (!connectionServiceFallbackProperty .get () && (lastFallbackInvocation == null || System .currentTimeMillis () - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS )) {
740
+ log .warn ("Failed to fetch daemon info from fixed connection on startup: " + e .getMessage ());
741
+ lastFallbackInvocation = System .currentTimeMillis ();
742
+ connectionServiceFallbackProperty .set (true );
727
743
}
728
- initializeConnections ();
729
744
return ;
730
745
}
731
746
0 commit comments