add tor functionality to xmr/wow test connection

This commit is contained in:
julian 2024-06-12 15:12:53 -06:00
parent 22dd11f04a
commit f2a6660552
3 changed files with 59 additions and 17 deletions

View file

@ -12,6 +12,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:socks5_proxy/socks.dart';
import '../widgets/desktop/primary_button.dart';
import '../widgets/desktop/secondary_button.dart';
@ -30,12 +31,26 @@ class MoneroNodeConnectionResponse {
Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
Uri uri,
bool allowBadX509Certificate,
) async {
final client = HttpClient();
bool allowBadX509Certificate, {
required ({
InternetAddress host,
int port,
})? proxyInfo,
}) async {
final httpClient = HttpClient();
MoneroNodeConnectionResponse? badCertResponse;
try {
client.badCertificateCallback = (cert, url, port) {
if (proxyInfo != null) {
SocksTCPClient.assignToHttpClient(httpClient, [
ProxySettings(
proxyInfo.host,
proxyInfo.port,
),
]);
}
httpClient.badCertificateCallback = (cert, url, port) {
if (allowBadX509Certificate) {
return true;
}
@ -49,7 +64,7 @@ Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
return false;
};
final request = await client.postUrl(uri);
final request = await httpClient.postUrl(uri);
final body = utf8.encode(
jsonEncode({
@ -85,7 +100,7 @@ Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
return MoneroNodeConnectionResponse(null, null, null, false);
}
} finally {
client.close(force: true);
httpClient.close(force: true);
}
}

View file

@ -1,27 +1,35 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:solana/solana.dart';
import '../networking/http.dart';
import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
import '../providers/global/prefs_provider.dart';
import '../services/tor_service.dart';
import '../wallets/api/tezos/tezos_rpc_api.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart';
import '../wallets/crypto_currency/intermediate/nano_currency.dart';
import 'connection_check/electrum_connection_check.dart';
import 'logger.dart';
import 'test_epic_box_connection.dart';
import 'test_eth_node_connection.dart';
import 'test_monero_node_connection.dart';
import 'test_stellar_node_connection.dart';
import '../wallets/api/tezos/tezos_rpc_api.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart';
import '../wallets/crypto_currency/intermediate/nano_currency.dart';
Future<bool> _xmrHelper(
NodeFormData nodeFormData,
BuildContext context,
void Function(NodeFormData)? onSuccess,
({
InternetAddress host,
int port,
})? proxyInfo,
) async {
final data = nodeFormData;
final url = data.host!;
@ -36,6 +44,7 @@ Future<bool> _xmrHelper(
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
false,
proxyInfo: proxyInfo,
);
if (response.cert != null) {
@ -48,8 +57,11 @@ Future<bool> _xmrHelper(
);
if (shouldAllowBadCert) {
final response =
await testMoneroNodeConnection(Uri.parse(uriString), true);
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
true,
proxyInfo: proxyInfo,
);
onSuccess?.call(data..host = url);
return response.success;
}
@ -90,6 +102,10 @@ Future<bool> testNodeConnection({
case CryptonoteCurrency():
try {
final proxyInfo = ref.read(prefsChangeNotifierProvider).useTor
? ref.read(pTorService).getProxyInfo()
: null;
final url = formData.host!;
final uri = Uri.tryParse(url);
if (uri != null) {
@ -101,9 +117,10 @@ Future<bool> testNodeConnection({
..useSSL = true,
context,
onSuccess,
proxyInfo,
);
if (testPassed == false) {
if (testPassed == false && context.mounted) {
// try http
testPassed = await _xmrHelper(
formData
@ -111,6 +128,7 @@ Future<bool> testNodeConnection({
..useSSL = false,
context,
onSuccess,
proxyInfo,
);
}
} else {
@ -120,6 +138,7 @@ Future<bool> testNodeConnection({
..useSSL = true,
context,
onSuccess,
proxyInfo,
);
}
}

View file

@ -117,9 +117,12 @@ class NodeOptionsSheet extends ConsumerWidget {
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
false,
proxyInfo: ref.read(prefsChangeNotifierProvider).useTor
? ref.read(pTorService).getProxyInfo()
: null,
);
if (response.cert != null) {
if (response.cert != null && context.mounted) {
// if (mounted) {
final shouldAllowBadCert = await showBadX509CertificateDialog(
response.cert!,
@ -129,8 +132,13 @@ class NodeOptionsSheet extends ConsumerWidget {
);
if (shouldAllowBadCert) {
final response =
await testMoneroNodeConnection(Uri.parse(uriString), true);
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
true,
proxyInfo: ref.read(prefsChangeNotifierProvider).useTor
? ref.read(pTorService).getProxyInfo()
: null,
);
testPassed = response.success;
}
// }