Skip to content

feat(tor): activate tor killswitch independent of tor connection or pref #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/electrumx_rpc/electrumx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,27 @@ class ElectrumXClient {
Future<void> 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.
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.
Expand Down
24 changes: 14 additions & 10 deletions lib/utilities/connection_check/electrum_connection_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@ Future<bool> 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.
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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class Prefs extends ChangeNotifier {

// tor

bool _torKillswitch = true;
bool _torKillswitch = false;

bool get torKillSwitch => _torKillswitch;

Expand Down
Loading