stuff
This commit is contained in:
parent
4ce603fbf1
commit
3b4c4ad797
4 changed files with 87 additions and 31 deletions
|
@ -18,11 +18,12 @@ import 'package:provider/provider.dart';
|
|||
import 'package:haveno_flutter_app/services/haveno_service.dart';
|
||||
import 'package:haveno_flutter_app/services/http_service.dart';
|
||||
import 'package:haveno_flutter_app/services/monero_service.dart';
|
||||
//import 'package:haveno_flutter_app/services/tor_service.dart';
|
||||
import 'package:haveno_flutter_app/services/tor_service.dart';
|
||||
import 'package:haveno_flutter_app/providers/get_version_provider.dart';
|
||||
import 'package:haveno_flutter_app/providers/account_provider.dart';
|
||||
import 'dart:async';
|
||||
import 'package:badges/badges.dart' as badges; // Import the badges package
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:tor/tor.dart'; // Import the badges package
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
@ -31,10 +32,19 @@ void main() async {
|
|||
_setupLogging();
|
||||
|
||||
// Initialize services
|
||||
//final torService = TorService();
|
||||
//await torService.initializeTor();
|
||||
Tor tor = Tor(); // Constructing the Tor instance
|
||||
TorService torService = TorService(tor);
|
||||
|
||||
// Strart service and listen
|
||||
torService.startService();
|
||||
//torService.listenToTorServiceEvents();
|
||||
torService.checkControlPort();
|
||||
torService.checkSocks5Port();
|
||||
|
||||
|
||||
final httpService = HttpService();
|
||||
final myIP = await httpService.request('GET', 'https://api.ipify.org?format=json');
|
||||
debugPrint(myIP.toString());
|
||||
final moneroService = MoneroService();
|
||||
|
||||
final havenoService = HavenoService('127.0.0.1', 3201, 'apitest');
|
||||
|
|
|
@ -1,53 +1,92 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:tor/tor.dart';
|
||||
|
||||
class TorService {
|
||||
final Tor _tor = Tor();
|
||||
StreamSubscription<String>? _torStatusSubscription;
|
||||
final StreamController<String> _statusController =
|
||||
StreamController<String>.broadcast();
|
||||
final StreamController<String> _controlPortStatusController =
|
||||
StreamController<String>.broadcast();
|
||||
StreamSubscription<dynamic>? _torStatusSubscription;
|
||||
final StreamController<String> _statusController = StreamController<String>.broadcast();
|
||||
final StreamController<String> _controlPortStatusController = StreamController<String>.broadcast();
|
||||
|
||||
Stream<String> get statusStream => _statusController.stream;
|
||||
Stream<String> get controlPortStatusStream =>
|
||||
_controlPortStatusController.stream;
|
||||
Stream<String> get controlPortStatusStream => _controlPortStatusController.stream;
|
||||
|
||||
final String _controlAddress = '127.0.0.1';
|
||||
final int _controlPort = 9051;
|
||||
|
||||
Future<void> initializeTor() async {
|
||||
_torStatusSubscription = Tor.torEvents.listen((String status) {
|
||||
_statusController.add(status);
|
||||
});
|
||||
final Tor _tor;
|
||||
|
||||
TorService(this._tor);
|
||||
|
||||
Future<void> startService() async {
|
||||
try {
|
||||
await _tor.startTor();
|
||||
//_statusController.add("Tor started successfully!");
|
||||
//await _checkControlPort();
|
||||
await _tor.startService("ControlPort 9051\nCookieAuthentication 0");
|
||||
debugPrint("Tor service started");
|
||||
_statusController.add("Tor service started.");
|
||||
} catch (e) {
|
||||
debugPrint("Tor service failed to start: $e");
|
||||
_statusController.add("Failed to start Tor: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkControlPort() async {
|
||||
Future<void> stopService() async {
|
||||
try {
|
||||
await _tor.stopService();
|
||||
_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 {
|
||||
final hiddenServiceInfo = await _tor.initializeHiddenService(
|
||||
listenPort: 3201,
|
||||
exposePort: 12134,
|
||||
privateKey: privateKey,
|
||||
);
|
||||
_statusController.add("Hidden service initialized: $hiddenServiceInfo");
|
||||
} catch (e) {
|
||||
_statusController.add("Failed to initialize hidden service: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> checkControlPort() async {
|
||||
_controlPortStatusController.add("Checking control port...");
|
||||
try {
|
||||
final socket = await Socket.connect(_controlAddress, _controlPort,
|
||||
timeout: Duration(seconds: 10));
|
||||
final socket = await Socket.connect(_controlAddress, _controlPort, 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");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _torStatusSubscription?.cancel();
|
||||
await _statusController.close();
|
||||
await _controlPortStatusController.close();
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void listenToTorServiceEvents() {
|
||||
_torStatusSubscription = _tor.torServiceEvents.listen((event) {
|
||||
_statusController.add("Tor event: $event");
|
||||
debugPrint(event);
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_torStatusSubscription?.cancel();
|
||||
_statusController.close();
|
||||
_controlPortStatusController.close();
|
||||
}
|
||||
}
|
|
@ -549,6 +549,13 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
tor:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../Flutter Plugins/tor"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -29,8 +29,8 @@ dependencies:
|
|||
font_awesome_flutter: ^10.7.0
|
||||
timeline_tile: ^2.0.0
|
||||
# Add your plugin dependency here
|
||||
##tor:
|
||||
## path: ../flutter_plugins/tor
|
||||
tor:
|
||||
path: "../Flutter Plugins/tor"
|
||||
protoc_plugin: ^21.1.2
|
||||
fixnum: ^1.1.0
|
||||
intl: ^0.17.0
|
||||
|
|
Loading…
Reference in a new issue