From dbaf184bb82f9b11cbd3b1455022f9d12cbe00e5 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 5 Feb 2024 14:45:33 -0600 Subject: [PATCH] listen to correct socket depending on tor preference --- .../subscribable_electrumx_client.dart | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/electrumx_rpc/subscribable_electrumx_client.dart b/lib/electrumx_rpc/subscribable_electrumx_client.dart index 9d7169129..c90e47479 100644 --- a/lib/electrumx_rpc/subscribable_electrumx_client.dart +++ b/lib/electrumx_rpc/subscribable_electrumx_client.dart @@ -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(