use tor for nodes

This commit is contained in:
sneurlax 2023-09-06 17:48:50 -05:00
parent 7a01682bff
commit f7ddaa1f73
2 changed files with 30 additions and 7 deletions

View file

@ -38,8 +38,8 @@ class JsonRPC {
final _JsonRPCRequestQueue _requestQueue = _JsonRPCRequestQueue();
Socket? _socket;
SOCKSSocket? _socksSocket;
StreamSubscription<Uint8List>? _subscription;
StreamSubscription<Uint8List>? get subscription => _subscription;
StreamSubscription<List<int>>? _subscription;
StreamSubscription<List<int>>? get subscription => _subscription;
void _dataHandler(List<int> data) {
_requestQueue.nextIncompleteReq.then((req) {
@ -86,7 +86,7 @@ class JsonRPC {
_socket!.write('${req.jsonRequest}\r\n');
}
if (_socksSocket != null) {
_socksSocket!.write('${req.jsonRequest}\r\n\n');
_socksSocket!.write('${req.jsonRequest}\r\n');
// _socksSocket!.socket.writeln('${req.jsonRequest}\r\n');
}
@ -248,7 +248,7 @@ class JsonRPC {
"JsonRPC.connect(): failed to connect to tor proxy, $e");
}
_subscription = _socksSocket!.socket.listen(
_subscription = _socksSocket!.listen(
_dataHandler,
onError: _errorHandler,
onDone: _doneHandler,

View file

@ -73,10 +73,12 @@ class SOCKSSocket {
StreamController.broadcast();
/// Getter for the StreamController that listens to the _socksSocket and
/// broadcasts.
/// broadcasts, or the _secureSocksSocket and broadcasts if SSL is enabled.
StreamController<List<int>> get responseController =>
sslEnabled ? _secureResponseController : _responseController;
StreamSubscription? _subscription;
/// A StreamController that listens to the _secureSocksSocket and broadcasts.
final StreamController<List<int>> _secureResponseController =
StreamController.broadcast();
@ -134,7 +136,7 @@ class SOCKSSocket {
);
// Listen to the socket.
_socksSocket.listen(
_subscription = _socksSocket.listen(
(data) {
// Add the data to the response controller.
_responseController.add(data);
@ -217,7 +219,7 @@ class SOCKSSocket {
);
// Listen to the secure socket.
_secureSocksSocket.listen(
_subscription = _secureSocksSocket.listen(
(data) {
// Add the data to the response controller.
_secureResponseController.add(data);
@ -311,4 +313,25 @@ class SOCKSSocket {
await _responseController.close();
return await _socksSocket.close();
}
StreamSubscription<List<int>> listen(
void Function(List<int> data)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return sslEnabled
? _secureResponseController.stream.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
)
: _responseController.stream.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
}