diff --git a/lib/networking/tor_service.dart b/lib/networking/tor_service.dart new file mode 100644 index 000000000..b4725414e --- /dev/null +++ b/lib/networking/tor_service.dart @@ -0,0 +1,20 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/utilities/stack_file_system.dart'; +import 'package:tor/tor.dart'; + +final pTorService = Provider((_) => TorService()); + +class TorService { + final _tor = Tor(); + + int get port => _tor.port; + + Future start() async { + final dir = await StackFileSystem.applicationTorDirectory(); + return await _tor.start(torDir: dir); + } + + Future stop() async { + return await _tor.disable(); + } +} diff --git a/lib/utilities/stack_file_system.dart b/lib/utilities/stack_file_system.dart index f36fadf01..4fb3e4617 100644 --- a/lib/utilities/stack_file_system.dart +++ b/lib/utilities/stack_file_system.dart @@ -60,6 +60,19 @@ abstract class StackFileSystem { } } + static Future applicationTorDirectory() async { + final root = await applicationRootDirectory(); + if (Util.isDesktop) { + final dir = Directory("${root.path}/tor"); + if (!dir.existsSync()) { + await dir.create(); + } + return dir; + } else { + return root; + } + } + static Future applicationHiveDirectory() async { final root = await applicationRootDirectory(); if (Util.isDesktop) {