haveno-app/lib/services/tor_service.dart

94 lines
3 KiB
Dart
Raw Normal View History

2024-09-20 17:22:38 +00:00
/* import 'dart:async';
2024-07-14 15:34:24 +00:00
import 'dart:io';
2024-07-16 23:21:28 +00:00
import 'package:flutter/foundation.dart';
2024-07-14 15:34:24 +00:00
import 'package:tor/tor.dart';
class TorService {
2024-07-16 23:21:28 +00:00
StreamSubscription<dynamic>? _torStatusSubscription;
final StreamController<String> _statusController = StreamController<String>.broadcast();
final StreamController<String> _controlPortStatusController = StreamController<String>.broadcast();
2024-07-14 15:34:24 +00:00
Stream<String> get statusStream => _statusController.stream;
2024-07-16 23:21:28 +00:00
Stream<String> get controlPortStatusStream => _controlPortStatusController.stream;
2024-07-14 15:34:24 +00:00
final String _controlAddress = '127.0.0.1';
final int _controlPort = 9051;
2024-07-16 23:21:28 +00:00
final Tor _tor;
TorService(this._tor);
2024-07-14 15:34:24 +00:00
2024-07-16 23:21:28 +00:00
Future<void> startService() async {
2024-07-14 15:34:24 +00:00
try {
2024-09-19 14:51:39 +00:00
//await _tor.startService("ControlPort 9051\nCookieAuthentication 0");
2024-07-16 23:21:28 +00:00
debugPrint("Tor service started");
_statusController.add("Tor service started.");
2024-07-14 15:34:24 +00:00
} catch (e) {
2024-07-16 23:21:28 +00:00
debugPrint("Tor service failed to start: $e");
2024-07-14 15:34:24 +00:00
_statusController.add("Failed to start Tor: $e");
}
}
2024-07-16 23:21:28 +00:00
Future<void> stopService() async {
try {
2024-09-19 14:51:39 +00:00
//await _tor.stopService();
2024-07-16 23:21:28 +00:00
_statusController.add("Tor service stopped.");
} catch (e) {
_statusController.add("Failed to stop Tor: $e");
}
}
Future<void> initializeDaemonHiddenService({required String hostname, required String privateKey}) async {
try {
2024-09-19 14:51:39 +00:00
//final hiddenServiceInfo = await _tor.initializeHiddenService(
// listenPort: 3201,
// exposePort: 12134,
// privateKey: privateKey,
//);
//_statusController.add("Hidden service initialized: $hiddenServiceInfo");
2024-07-16 23:21:28 +00:00
} catch (e) {
_statusController.add("Failed to initialize hidden service: $e");
}
}
Future<void> checkControlPort() async {
2024-07-14 15:34:24 +00:00
_controlPortStatusController.add("Checking control port...");
try {
2024-07-16 23:21:28 +00:00
final socket = await Socket.connect(_controlAddress, _controlPort, timeout: Duration(seconds: 10));
2024-07-14 15:34:24 +00:00
socket.destroy();
2024-07-16 23:21:28 +00:00
debugPrint("Tor control port is open");
2024-07-14 15:34:24 +00:00
_controlPortStatusController.add("Control port is open and listening.");
} catch (e) {
2024-07-16 23:21:28 +00:00
debugPrint("Failed to connect to Tor control port");
2024-07-14 15:34:24 +00:00
_controlPortStatusController.add("Control port connection failed: $e");
}
}
2024-07-16 23:21:28 +00:00
Future<void> checkSocks5Port() async {
_controlPortStatusController.add("Checking control port...");
try {
final socket = await Socket.connect('127.0.0.1', 9050, timeout: Duration(seconds: 10));
socket.destroy();
debugPrint("Tor control port is open");
_controlPortStatusController.add("Control port is open and listening.");
} catch (e) {
debugPrint("Failed to connect to Tor control port");
_controlPortStatusController.add("Control port connection failed: $e");
}
}
2024-07-17 21:30:17 +00:00
2024-07-16 23:21:28 +00:00
void listenToTorServiceEvents() {
2024-09-19 14:51:39 +00:00
//_torStatusSubscription = _tor.torServiceEvents.listen((event) {
// _statusController.add("Tor event: $event");
// debugPrint(event);
//});
2024-07-16 23:21:28 +00:00
}
void dispose() {
_torStatusSubscription?.cancel();
_statusController.close();
_controlPortStatusController.close();
2024-07-14 15:34:24 +00:00
}
2024-09-20 17:22:38 +00:00
} */