listen to correct socket depending on tor preference

This commit is contained in:
sneurlax 2024-02-05 14:45:33 -06:00
parent 7646f97cc1
commit dbaf184bb8

View file

@ -206,12 +206,35 @@ class SubscribableElectrumXClient {
_updateConnectionStatus(true);
_socket!.listen(
_dataHandler,
onError: _errorHandler,
onDone: _doneHandler,
cancelOnError: true,
);
if (_prefs.useTor) {
if (_socksSocket == null) {
final String msg = "SubscribableElectrumXClient.connect(): "
"cannot listen to $host:$port via SOCKSSocket because it is not connected.";
Logging.instance.log(msg, level: LogLevel.Fatal);
throw Exception(msg);
}
_socksSocket!.listen(
_dataHandler,
onError: _errorHandler,
onDone: _doneHandler,
cancelOnError: true,
);
} else {
if (_socket == null) {
final String msg = "SubscribableElectrumXClient.connect(): "
"cannot listen to $host:$port via socket because it is not connected.";
Logging.instance.log(msg, level: LogLevel.Fatal);
throw Exception(msg);
}
_socket!.listen(
_dataHandler,
onError: _errorHandler,
onDone: _doneHandler,
cancelOnError: true,
);
}
_aliveTimer?.cancel();
_aliveTimer = Timer.periodic(