@@ -494,24 +494,46 @@ abstract class LibSalviumWallet<T extends CryptonoteCurrency>
494494 return ;
495495 }
496496
497- final node = getCurrentNode ();
497+ await _updateNodeMutex.protect (() async {
498+ if (wallet == null ) {
499+ return ;
500+ }
498501
499- if (_torNodeMismatchGuard (node)) {
500- throw Exception ("TOR – clearnet mismatch" );
501- }
502+ final node = getCurrentNode ();
502503
503- final host = node.host.endsWith (".onion" )
504- ? node.host
505- : Uri .parse (node.host).host;
506- final ({InternetAddress host, int port})? proxy =
507- AppConfig .hasFeature (AppFeature .tor) && prefs.useTor && ! node.forceNoTor
508- ? TorService .sharedInstance.getProxyInfo ()
509- : null ;
504+ if (_torNodeMismatchGuard (node)) {
505+ throw Exception ("TOR – clearnet mismatch" );
506+ }
510507
511- _setSyncStatus (ConnectingSyncStatus ());
512- try {
513- if (_requireMutex) {
514- await _torConnectingLock.protect (() async {
508+ final host = node.host.endsWith (".onion" )
509+ ? node.host
510+ : Uri .parse (node.host).host;
511+ final ({InternetAddress host, int port})? proxy =
512+ AppConfig .hasFeature (AppFeature .tor) &&
513+ prefs.useTor &&
514+ ! node.forceNoTor
515+ ? TorService .sharedInstance.getProxyInfo ()
516+ : null ;
517+
518+ _setSyncStatus (ConnectingSyncStatus ());
519+ try {
520+ if (_requireMutex) {
521+ await _torConnectingLock.protect (() async {
522+ await csSalvium.connect (
523+ wallet! ,
524+ daemonAddress: "$host :${node .port }" ,
525+ daemonUsername: node.loginName,
526+ daemonPassword: await node.getPassword (secureStorageInterface),
527+ trusted: node.trusted ?? false ,
528+ useSSL: node.useSSL,
529+ socksProxyAddress: node.forceNoTor
530+ ? null
531+ : proxy == null
532+ ? null
533+ : "${proxy .host .address }:${proxy .port }" ,
534+ );
535+ });
536+ } else {
515537 await csSalvium.connect (
516538 wallet! ,
517539 daemonAddress: "$host :${node .port }" ,
@@ -525,37 +547,21 @@ abstract class LibSalviumWallet<T extends CryptonoteCurrency>
525547 ? null
526548 : "${proxy .host .address }:${proxy .port }" ,
527549 );
528- });
529- } else {
530- await csSalvium.connect (
531- wallet! ,
532- daemonAddress: "$host :${node .port }" ,
533- daemonUsername: node.loginName,
534- daemonPassword: await node.getPassword (secureStorageInterface),
535- trusted: node.trusted ?? false ,
536- useSSL: node.useSSL,
537- socksProxyAddress: node.forceNoTor
538- ? null
539- : proxy == null
540- ? null
541- : "${proxy .host .address }:${proxy .port }" ,
550+ }
551+ csSalvium.startSyncing (wallet! );
552+ csSalvium.startListeners (wallet! );
553+ csSalvium.startAutoSaving (wallet! );
554+
555+ // _setSyncStatus(ConnectedSyncStatus());
556+ } catch (e, s) {
557+ // _setSyncStatus(FailedSyncStatus());
558+ Logging .instance.e (
559+ "Exception caught in $runtimeType .updateNode(): " ,
560+ error: e,
561+ stackTrace: s,
542562 );
543563 }
544- csSalvium.startSyncing (wallet! );
545- csSalvium.startListeners (wallet! );
546- csSalvium.startAutoSaving (wallet! );
547-
548- // _setSyncStatus(ConnectedSyncStatus());
549- } catch (e, s) {
550- // _setSyncStatus(FailedSyncStatus());
551- Logging .instance.e (
552- "Exception caught in $runtimeType .updateNode(): " ,
553- error: e,
554- stackTrace: s,
555- );
556- }
557-
558- return ;
564+ });
559565 }
560566
561567 @override
@@ -1617,6 +1623,8 @@ abstract class LibSalviumWallet<T extends CryptonoteCurrency>
16171623
16181624 final Mutex _torConnectingLock = Mutex ();
16191625 bool _requireMutex = false ;
1626+
1627+ final Mutex _updateNodeMutex = Mutex ();
16201628}
16211629
16221630String _libSalviumWalletPasswordKey (String walletName) =>
0 commit comments