implement tor killswitch

comment update
This commit is contained in:
sneurlax 2023-09-08 10:50:50 -05:00
parent cf27dd9252
commit d317bc5e8b

View file

@ -158,11 +158,24 @@ class ElectrumX {
} }
void _checkRpcClient() { void _checkRpcClient() {
// If we're supposed to use Tor...
if (_prefs.useTor) { if (_prefs.useTor) {
// But Tor isn't enabled...
if (!_torService.enabled) { if (!_torService.enabled) {
throw Exception("Tor is not enabled"); // And the killswitch isn't set...
if (!_prefs.torKillswitch) {
// Then we'll just proceed and connect to ElectrumX through clearnet at the bottom of this function.
Logging.instance.log(
"Tor preference set but Tor is not enabled, killswitch not set, connecting to ElectrumX through clearnet",
level: LogLevel.Warning,
);
} 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 ElectrumX");
} }
} else {
// Get the proxy info from the TorService.
final proxyInfo = _torService.proxyInfo; final proxyInfo = _torService.proxyInfo;
if (currentFailoverIndex == -1) { if (currentFailoverIndex == -1) {
@ -189,7 +202,11 @@ class ElectrumX {
reason: "Tor proxyInfo does not match current info", reason: "Tor proxyInfo does not match current info",
); );
} }
} else {
return;
}
}
if (currentFailoverIndex == -1) { if (currentFailoverIndex == -1) {
_rpcClient ??= JsonRPC( _rpcClient ??= JsonRPC(
host: host, host: host,
@ -208,7 +225,6 @@ class ElectrumX {
); );
} }
} }
}
/// Send raw rpc command /// Send raw rpc command
Future<dynamic> request({ Future<dynamic> request({