From 70981eb759715083bd8c1d7a45a99f1f39b772ec Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 25 Apr 2025 11:36:53 -0500 Subject: [PATCH 1/3] feat(tor): do not enable tor killswitch by default TODO: enable in Privacy Mode? --- lib/utilities/prefs.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 395e5ecd6..f13605a36 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -459,7 +459,7 @@ class Prefs extends ChangeNotifier { // tor - bool _torKillswitch = true; + bool _torKillswitch = false; bool get torKillSwitch => _torKillswitch; From 5349cc26cb0e0727e2a697127def58c21d0cec01 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 25 Apr 2025 12:59:26 -0500 Subject: [PATCH 2/3] feat(tor): activate tor killswitch independent of tor connection or pref --- lib/electrumx_rpc/electrumx_client.dart | 20 ++++++++++++++----- .../electrum_connection_check.dart | 19 ++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 2691adf5a..55f5982a0 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -225,20 +225,30 @@ class ElectrumXClient { Future checkElectrumAdapter() async { ({InternetAddress host, int port})? proxyInfo; - // If we're supposed to use Tor... + if (_prefs.torKillSwitch) { + // If the killswitch is set... + if (_torService.status != TorConnectionStatus.connected) { + // And Tor isn't connected, then we'll throw an exception. + throw Exception( + "Tor killswitch set but Tor is not connected, not connecting to Electrum adapter", + ); + } + } + if (_prefs.useTor) { - // But Tor isn't running... + // If we're supposed to use Tor... if (_torService.status != TorConnectionStatus.connected) { - // And the killswitch isn't set... + // But Tor isn't running... if (!_prefs.torKillSwitch) { - // Then we'll just proceed and connect to ElectrumX through - // clearnet at the bottom of this function. + // And the killswitch isn't set... + // Then we'll just proceed and connect to ElectrumX through clearnet at the bottom of this function. Logging.instance.w( "Tor preference set but Tor is not enabled, killswitch not set," " connecting to Electrum adapter through clearnet", ); } else { // ... But if the killswitch is set, then we throw an exception. + // This should never be reached. throw Exception( "Tor preference and killswitch set but Tor is not enabled, " "not connecting to Electrum adapter", diff --git a/lib/utilities/connection_check/electrum_connection_check.dart b/lib/utilities/connection_check/electrum_connection_check.dart index 325cfa059..a1b823110 100644 --- a/lib/utilities/connection_check/electrum_connection_check.dart +++ b/lib/utilities/connection_check/electrum_connection_check.dart @@ -20,25 +20,36 @@ Future checkElectrumServer({ ({InternetAddress host, int port})? proxyInfo; try { - // If we're supposed to use Tor... + if (_prefs.torKillSwitch) { + // If the killswitch is set... + if (_torService.status != TorConnectionStatus.connected) { + // And Tor isn't connected, then we'll throw an exception. + throw Exception( + "Tor killswitch set but Tor is not connected, not connecting to Electrum adapter", + ); + } + } + if (_prefs.useTor) { - // But Tor isn't running... + // If we're supposed to use Tor... if (_torService.status != TorConnectionStatus.connected) { - // And the killswitch isn't set... + // But Tor isn't connected... if (!_prefs.torKillSwitch) { + // And the killswitch isn't set... // Then we'll just proceed and connect to ElectrumX through clearnet at the bottom of this function. Logging.instance.w( "Tor preference set but Tor is not enabled, killswitch not set, connecting to Electrum adapter through clearnet", ); } else { // ... But if the killswitch is set, then we throw an exception. + // This should never be reached. throw Exception( "Tor preference and killswitch set but Tor is not enabled, not connecting to Electrum adapter", ); // TODO [prio=low]: Try to start Tor. } } else { - // Get the proxy info from the TorService. + // If Tor is connected, get the proxy info from the TorService. proxyInfo = _torService.getProxyInfo(); } } From b6e11b6f3b1f04f550058bf8f38417df075751d8 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 25 Apr 2025 13:02:00 -0500 Subject: [PATCH 3/3] refactor(tor): remove dead code --- lib/electrumx_rpc/electrumx_client.dart | 8 -------- .../connection_check/electrum_connection_check.dart | 7 ------- 2 files changed, 15 deletions(-) diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 55f5982a0..8302cbdd2 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -246,14 +246,6 @@ class ElectrumXClient { "Tor preference set but Tor is not enabled, killswitch not set," " connecting to Electrum adapter through clearnet", ); - } else { - // ... But if the killswitch is set, then we throw an exception. - // This should never be reached. - throw Exception( - "Tor preference and killswitch set but Tor is not enabled, " - "not connecting to Electrum adapter", - ); - // TODO [prio=low]: Try to start Tor. } } else { // Get the proxy info from the TorService. diff --git a/lib/utilities/connection_check/electrum_connection_check.dart b/lib/utilities/connection_check/electrum_connection_check.dart index a1b823110..4943cf169 100644 --- a/lib/utilities/connection_check/electrum_connection_check.dart +++ b/lib/utilities/connection_check/electrum_connection_check.dart @@ -40,13 +40,6 @@ Future checkElectrumServer({ Logging.instance.w( "Tor preference set but Tor is not enabled, killswitch not set, connecting to Electrum adapter through clearnet", ); - } else { - // ... But if the killswitch is set, then we throw an exception. - // This should never be reached. - throw Exception( - "Tor preference and killswitch set but Tor is not enabled, not connecting to Electrum adapter", - ); - // TODO [prio=low]: Try to start Tor. } } else { // If Tor is connected, get the proxy info from the TorService.