mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
CW-519 Enable built-in Tor (#1950)
* tor wip * Enable tor on iOS * Prevent app lag when node is exceptionally slow (usually over tor) * fix: logic in daemonBlockchainHeight refresh fix: storing tor state * Pin ledger_flutter_plus dependency to fix builds * bump arti version * wip * add single httpclient * route everything I was able to catch trough the built-in tor node * Enable proxy for http.Client [run tests] * add tor proxy support to cw_evm, cw_tron and cw_polygon [run tests] * remove log pollution, cleanup [skip slack] * fix tests not working in latest main [skip slack] [run tests] * remove cw_wownero import * fix build issues * migrate all remaining calls to use ProxyWrapper add a CI action to enforce using ProxyWrapper instead of http/http.dart to prevent leaks * fix tor background sync (will work on test builds after #2142 is merged and this PR is rebased on top) * wip [skip ci] * relicense to GPLv3 add socks5 license, build fixes * use ProxyWrapper instead of http in robinhood * Revert "relicense to GPLv3" * feat(cw_bitcoin): support socks proxy and CakeTor * fix(tor): migrate OCP and EVM over to ProxyWrapper() * chore: cleanup fix: show tor loading screen when app is starting * fix: tor switch properly dismisses fullscreen loading dialog fix: connectToNode after tor startup on app start * fix(tor): status check for xmr/wow/zano * fix(tor): onramper request fix * fix(api): ServicesResponse is now being cached and doesn't fetch data everytime DashboardViewModel is being rebuilt fix(tor): do not fallback to clearnet when tor failed. fix(tor): do not leak connections during app startup chore: refactor bootstrap() function to be separated into bootstrapOffline and bootstrapOnline fix(cw_bitcoin): migrate payjoin to use ProxyWrapper * [skip ci] remove print * address comments from review * fix: derusting tor implementation Instead of rust-based Arti I've moved back to the OG C++ tor implementation. This fixed all issues we had with Tor. - onion services now work - all requests are going through without random errors - we don't have to navigate a maze of multiple forks of multiple packages - fully working `torrc` config file (probably will be needed for Tari). - logging for Tor client - and so on. feat: network logging tab feat: use built-in proxy on Tails - this should resolve all issues for Tails users (needs testing though) * fix conflicts with main bump https to fix build issue relax store() call * fix(cw_wownero): tor connection fix(tor): connection issues * fix(cw_evm): add missing chainId fix(cw_core): solana rpc fix * feat: mark tor as experimental fix: drop anonpay onion authority fix: drop fiatapi onion authority fix: drop trocador onion authority fix: disable networkimage when tor is enabled fix: handle cakepay errors gracefully * fix re-formatting [skip ci] * changes from review * Delete android/.kotlin/sessions/kotlin-compiler-2468481326039681181.salive * fix missing imports * Update pubspec_base.yaml --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io';
|
||||
|
||||
class FeatureFlag {
|
||||
static const bool isCakePayEnabled = false;
|
||||
static const bool isExolixEnabled = true;
|
||||
static const bool isInAppTorEnabled = false;
|
||||
static const bool isBackgroundSyncEnabled = true;
|
||||
static final bool isInAppTorEnabled = (Platform.isAndroid);
|
||||
static const int verificationWordsCount = kDebugMode ? 0 : 2;
|
||||
static const bool hasDevOptions = bool.fromEnvironment('hasDevOptions', defaultValue: kDebugMode);
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
|
||||
class ImageUtil {
|
||||
static Widget getImageFromPath({required String imagePath, double? height, double? width}) {
|
||||
final bool isNetworkImage = imagePath.startsWith('http') || imagePath.startsWith('https');
|
||||
bool isNetworkImage = imagePath.startsWith('http') || imagePath.startsWith('https');
|
||||
if (CakeTor.instance.enabled && isNetworkImage) {
|
||||
imagePath = "assets/images/tor_logo.svg";
|
||||
isNetworkImage = false;
|
||||
}
|
||||
final bool isSvg = imagePath.endsWith('.svg');
|
||||
final double _height = height ?? 35;
|
||||
final double _width = width ?? 35;
|
||||
|
||||
if (isNetworkImage) {
|
||||
return isSvg
|
||||
? SvgPicture.network(
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cw_core/utils/proxy_wrapper.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
bool didTorStart = false;
|
||||
Future<void> ensureTorStopped({required BuildContext? context}) async {
|
||||
if (!didTorStart) {
|
||||
printV("Tor hasn't been initialized yet, so it can't be stopped.");
|
||||
return;
|
||||
}
|
||||
BuildContext? dialogContext;
|
||||
if (context != null) dialogContext = await showFullscreenDialog(context);
|
||||
didTorStart = false;
|
||||
printV("Stopping tor");
|
||||
await CakeTor.instance.stop();
|
||||
printV("Tor stopped");
|
||||
if (context != null) dismissFullscreenDialog(dialogContext!);
|
||||
}
|
||||
|
||||
Future<void> ensureTorStarted({required BuildContext? context}) async {
|
||||
if (didTorStart) {
|
||||
printV("Tor has already started");
|
||||
return;
|
||||
}
|
||||
BuildContext? dialogContext;
|
||||
if (context != null) dialogContext = await showFullscreenDialog(context);
|
||||
didTorStart = true;
|
||||
printV("Starting tor");
|
||||
// var rootToken = RootIsolateToken.instance!;
|
||||
// await Isolate.run(() async {
|
||||
// BackgroundIsolateBinaryMessenger.ensureInitialized(rootToken);
|
||||
// await CakeTor.instance.start();
|
||||
// });
|
||||
// second start is fast but populates the values on current thread
|
||||
await CakeTor.instance.start();
|
||||
printV("Tor started");
|
||||
while (!CakeTor.instance.started) {
|
||||
printV("Waiting for tor to start (part 1)");
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
while (CakeTor.instance.port == -1) {
|
||||
printV("Waiting for tor to start (listening on port)");
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
printV("Tor started on port ${CakeTor.instance.port}");
|
||||
if (context != null) dismissFullscreenDialog(dialogContext!);
|
||||
}
|
||||
|
||||
Future<BuildContext> showFullscreenDialog(BuildContext context) async {
|
||||
BuildContext? dialogContext;
|
||||
unawaited(
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
dialogContext = context;
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
return dialogContext!;
|
||||
}
|
||||
|
||||
Future<void> dismissFullscreenDialog(BuildContext context) async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
Reference in New Issue
Block a user