24
24
import haveno .common .app .DevEnv ;
25
25
import haveno .common .config .BaseCurrencyNetwork ;
26
26
import haveno .common .config .Config ;
27
+ import haveno .core .locale .Res ;
27
28
import haveno .core .trade .HavenoUtils ;
28
29
import haveno .core .user .Preferences ;
29
30
import haveno .core .xmr .model .EncryptedConnectionList ;
43
44
44
45
import org .apache .commons .lang3 .exception .ExceptionUtils ;
45
46
46
- import javafx .beans .property .BooleanProperty ;
47
47
import javafx .beans .property .IntegerProperty ;
48
48
import javafx .beans .property .LongProperty ;
49
49
import javafx .beans .property .ObjectProperty ;
50
50
import javafx .beans .property .ReadOnlyDoubleProperty ;
51
51
import javafx .beans .property .ReadOnlyIntegerProperty ;
52
52
import javafx .beans .property .ReadOnlyLongProperty ;
53
53
import javafx .beans .property .ReadOnlyObjectProperty ;
54
- import javafx .beans .property .SimpleBooleanProperty ;
55
54
import javafx .beans .property .SimpleIntegerProperty ;
56
55
import javafx .beans .property .SimpleLongProperty ;
57
56
import javafx .beans .property .SimpleObjectProperty ;
@@ -91,7 +90,7 @@ public final class XmrConnectionService {
91
90
private final LongProperty chainHeight = new SimpleLongProperty (0 );
92
91
private final DownloadListener downloadListener = new DownloadListener ();
93
92
@ Getter
94
- private final BooleanProperty connectionServiceFallbackHandlerActive = new SimpleBooleanProperty ();
93
+ private final SimpleStringProperty connectionServiceFallbackHandler = new SimpleStringProperty ();
95
94
@ Getter
96
95
private final StringProperty connectionServiceErrorMsg = new SimpleStringProperty ();
97
96
private final LongProperty numUpdates = new SimpleLongProperty (0 );
@@ -261,6 +260,7 @@ public MoneroRpcConnection getBestConnection() {
261
260
262
261
private MoneroRpcConnection getBestConnection (Collection <MoneroRpcConnection > ignoredConnections ) {
263
262
accountService .checkAccountOpen ();
263
+ if (!fallbackApplied && lastUsedLocalSyncingNode () && !xmrLocalNode .isDetected ()) return null ; // user needs to explicitly allow fallback after syncing local node
264
264
Set <MoneroRpcConnection > ignoredConnectionsSet = new HashSet <>(ignoredConnections );
265
265
addLocalNodeIfIgnored (ignoredConnectionsSet );
266
266
MoneroRpcConnection bestConnection = connectionManager .getBestAvailableConnection (ignoredConnectionsSet .toArray (new MoneroRpcConnection [0 ])); // checks connections
@@ -604,9 +604,6 @@ public void onConnectionChanged(MoneroRpcConnection connection) {
604
604
if (coreContext .isApiUser ()) connectionManager .setAutoSwitch (connectionList .getAutoSwitch ());
605
605
else connectionManager .setAutoSwitch (true ); // auto switch is always enabled on desktop ui
606
606
607
- // start local node if applicable
608
- maybeStartLocalNode ();
609
-
610
607
// update connection
611
608
if (connectionManager .getConnection () == null || connectionManager .getAutoSwitch ()) {
612
609
MoneroRpcConnection bestConnection = getBestConnection ();
@@ -619,9 +616,6 @@ public void onConnectionChanged(MoneroRpcConnection connection) {
619
616
MoneroRpcConnection connection = new MoneroRpcConnection (config .xmrNode , config .xmrNodeUsername , config .xmrNodePassword ).setPriority (1 );
620
617
if (isProxyApplied (connection )) connection .setProxyUri (getProxyUri ());
621
618
connectionManager .setConnection (connection );
622
-
623
- // start local node if applicable
624
- maybeStartLocalNode ();
625
619
}
626
620
627
621
// register connection listener
@@ -634,20 +628,8 @@ public void onConnectionChanged(MoneroRpcConnection connection) {
634
628
onConnectionChanged (connectionManager .getConnection ());
635
629
}
636
630
637
- private void maybeStartLocalNode () {
638
-
639
- // skip if seed node
640
- if (HavenoUtils .isSeedNode ()) return ;
641
-
642
- // start local node if offline and used as last connection
643
- if (connectionManager .getConnection () != null && xmrLocalNode .equalsUri (connectionManager .getConnection ().getUri ()) && !xmrLocalNode .isDetected () && !xmrLocalNode .shouldBeIgnored ()) {
644
- try {
645
- log .info ("Starting local node" );
646
- xmrLocalNode .start ();
647
- } catch (Exception e ) {
648
- log .error ("Unable to start local monero node, error={}\n " , e .getMessage (), e );
649
- }
650
- }
631
+ private boolean lastUsedLocalSyncingNode () {
632
+ return connectionManager .getConnection () != null && xmrLocalNode .equalsUri (connectionManager .getConnection ().getUri ()) && !xmrLocalNode .isDetected () && !xmrLocalNode .shouldBeIgnored ();
651
633
}
652
634
653
635
private void onConnectionChanged (MoneroRpcConnection currentConnection ) {
@@ -733,12 +715,17 @@ private void doPollDaemon() {
733
715
if (isShutDownStarted ) return ;
734
716
735
717
// invoke fallback handling on startup error
736
- boolean canFallback = isFixedConnection () || isCustomConnections ();
718
+ boolean canFallback = isFixedConnection () || isCustomConnections () || lastUsedLocalSyncingNode () ;
737
719
if (lastInfo == null && canFallback ) {
738
- if (!connectionServiceFallbackHandlerActive .get () && (lastFallbackInvocation == null || System .currentTimeMillis () - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS )) {
739
- log .warn ("Failed to fetch daemon info from custom connection on startup: " + e .getMessage ());
720
+ if (connectionServiceFallbackHandler .get () == null || connectionServiceFallbackHandler .equals ("" ) && (lastFallbackInvocation == null || System .currentTimeMillis () - lastFallbackInvocation > FALLBACK_INVOCATION_PERIOD_MS )) {
740
721
lastFallbackInvocation = System .currentTimeMillis ();
741
- connectionServiceFallbackHandlerActive .set (true );
722
+ if (lastUsedLocalSyncingNode ()) {
723
+ log .warn ("Failed to fetch daemon info from local connection on startup: " + e .getMessage ());
724
+ connectionServiceFallbackHandler .set (Res .get ("connectionFallback.localNode" ));
725
+ } else {
726
+ log .warn ("Failed to fetch daemon info from custom connection on startup: " + e .getMessage ());
727
+ connectionServiceFallbackHandler .set (Res .get ("connectionFallback.customNode" ));
728
+ }
742
729
}
743
730
return ;
744
731
}
0 commit comments