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/haveno_service.dart';
|
||||||
import 'package:haveno_flutter_app/services/http_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/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/get_version_provider.dart';
|
||||||
import 'package:haveno_flutter_app/providers/account_provider.dart';
|
import 'package:haveno_flutter_app/providers/account_provider.dart';
|
||||||
import 'dart:async';
|
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 {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
@ -31,10 +32,19 @@ void main() async {
|
||||||
_setupLogging();
|
_setupLogging();
|
||||||
|
|
||||||
// Initialize services
|
// Initialize services
|
||||||
//final torService = TorService();
|
Tor tor = Tor(); // Constructing the Tor instance
|
||||||
//await torService.initializeTor();
|
TorService torService = TorService(tor);
|
||||||
|
|
||||||
|
// Strart service and listen
|
||||||
|
torService.startService();
|
||||||
|
//torService.listenToTorServiceEvents();
|
||||||
|
torService.checkControlPort();
|
||||||
|
torService.checkSocks5Port();
|
||||||
|
|
||||||
|
|
||||||
final httpService = HttpService();
|
final httpService = HttpService();
|
||||||
|
final myIP = await httpService.request('GET', 'https://api.ipify.org?format=json');
|
||||||
|
debugPrint(myIP.toString());
|
||||||
final moneroService = MoneroService();
|
final moneroService = MoneroService();
|
||||||
|
|
||||||
final havenoService = HavenoService('127.0.0.1', 3201, 'apitest');
|
final havenoService = HavenoService('127.0.0.1', 3201, 'apitest');
|
||||||
|
|
|
@ -1,53 +1,92 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:tor/tor.dart';
|
import 'package:tor/tor.dart';
|
||||||
|
|
||||||
class TorService {
|
class TorService {
|
||||||
final Tor _tor = Tor();
|
StreamSubscription<dynamic>? _torStatusSubscription;
|
||||||
StreamSubscription<String>? _torStatusSubscription;
|
final StreamController<String> _statusController = StreamController<String>.broadcast();
|
||||||
final StreamController<String> _statusController =
|
final StreamController<String> _controlPortStatusController = StreamController<String>.broadcast();
|
||||||
StreamController<String>.broadcast();
|
|
||||||
final StreamController<String> _controlPortStatusController =
|
|
||||||
StreamController<String>.broadcast();
|
|
||||||
|
|
||||||
Stream<String> get statusStream => _statusController.stream;
|
Stream<String> get statusStream => _statusController.stream;
|
||||||
Stream<String> get controlPortStatusStream =>
|
Stream<String> get controlPortStatusStream => _controlPortStatusController.stream;
|
||||||
_controlPortStatusController.stream;
|
|
||||||
|
|
||||||
final String _controlAddress = '127.0.0.1';
|
final String _controlAddress = '127.0.0.1';
|
||||||
final int _controlPort = 9051;
|
final int _controlPort = 9051;
|
||||||
|
|
||||||
Future<void> initializeTor() async {
|
final Tor _tor;
|
||||||
_torStatusSubscription = Tor.torEvents.listen((String status) {
|
|
||||||
_statusController.add(status);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
TorService(this._tor);
|
||||||
|
|
||||||
|
Future<void> startService() async {
|
||||||
try {
|
try {
|
||||||
await _tor.startTor();
|
await _tor.startService("ControlPort 9051\nCookieAuthentication 0");
|
||||||
//_statusController.add("Tor started successfully!");
|
debugPrint("Tor service started");
|
||||||
//await _checkControlPort();
|
_statusController.add("Tor service started.");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
debugPrint("Tor service failed to start: $e");
|
||||||
_statusController.add("Failed to start Tor: $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...");
|
_controlPortStatusController.add("Checking control port...");
|
||||||
try {
|
try {
|
||||||
final socket = await Socket.connect(_controlAddress, _controlPort,
|
final socket = await Socket.connect(_controlAddress, _controlPort, timeout: Duration(seconds: 10));
|
||||||
timeout: Duration(seconds: 10));
|
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
|
debugPrint("Tor control port is open");
|
||||||
_controlPortStatusController.add("Control port is open and listening.");
|
_controlPortStatusController.add("Control port is open and listening.");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
debugPrint("Failed to connect to Tor control port");
|
||||||
_controlPortStatusController.add("Control port connection failed: $e");
|
_controlPortStatusController.add("Control port connection failed: $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> dispose() async {
|
Future<void> checkSocks5Port() async {
|
||||||
await _torStatusSubscription?.cancel();
|
_controlPortStatusController.add("Checking control port...");
|
||||||
await _statusController.close();
|
try {
|
||||||
await _controlPortStatusController.close();
|
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"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
tor:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
path: "../Flutter Plugins/tor"
|
||||||
|
relative: true
|
||||||
|
source: path
|
||||||
|
version: "0.0.1"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -29,8 +29,8 @@ dependencies:
|
||||||
font_awesome_flutter: ^10.7.0
|
font_awesome_flutter: ^10.7.0
|
||||||
timeline_tile: ^2.0.0
|
timeline_tile: ^2.0.0
|
||||||
# Add your plugin dependency here
|
# Add your plugin dependency here
|
||||||
##tor:
|
tor:
|
||||||
## path: ../flutter_plugins/tor
|
path: "../Flutter Plugins/tor"
|
||||||
protoc_plugin: ^21.1.2
|
protoc_plugin: ^21.1.2
|
||||||
fixnum: ^1.1.0
|
fixnum: ^1.1.0
|
||||||
intl: ^0.17.0
|
intl: ^0.17.0
|
||||||
|
|
Loading…
Reference in a new issue