mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-25 08:39:06 +00:00
tor only changes
This commit is contained in:
parent
0d3791746f
commit
202a56126c
9 changed files with 22 additions and 29 deletions
|
@ -167,6 +167,12 @@ abstract class ElectrumWalletBase
|
||||||
@override
|
@override
|
||||||
Future<void> connectToNode({required Node node}) async {
|
Future<void> connectToNode({required Node node}) async {
|
||||||
try {
|
try {
|
||||||
|
// we can't connect over tor in this wallet type (yet):
|
||||||
|
if (node.connectOverTorOnly) {
|
||||||
|
syncStatus = FailedSyncStatus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
syncStatus = ConnectingSyncStatus();
|
syncStatus = ConnectingSyncStatus();
|
||||||
await electrumClient.connectToUri(node.uri);
|
await electrumClient.connectToUri(node.uri);
|
||||||
electrumClient.onConnectionStatusChange = (bool isConnected) {
|
electrumClient.onConnectionStatusChange = (bool isConnected) {
|
||||||
|
|
|
@ -63,6 +63,8 @@ class Node extends HiveObject with Keyable {
|
||||||
@HiveField(6)
|
@HiveField(6)
|
||||||
String? socksProxyAddress;
|
String? socksProxyAddress;
|
||||||
|
|
||||||
|
bool connectOverTorOnly = false;
|
||||||
|
|
||||||
bool get isSSL => useSSL ?? false;
|
bool get isSSL => useSSL ?? false;
|
||||||
|
|
||||||
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
|
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
|
||||||
|
|
|
@ -201,7 +201,6 @@ class AnonPayApi {
|
||||||
return await proxy.get(
|
return await proxy.get(
|
||||||
onionUri: onionUri,
|
onionUri: onionUri,
|
||||||
clearnetUri: clearnetUri,
|
clearnetUri: clearnetUri,
|
||||||
torOnly: false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
||||||
onionUri: onionUri,
|
onionUri: onionUri,
|
||||||
clearnetUri: clearnetUri,
|
clearnetUri: clearnetUri,
|
||||||
portOverride: mainThreadProxyPort,
|
portOverride: mainThreadProxyPort,
|
||||||
torOnly: false,
|
|
||||||
torConnectionMode: torConnectionMode,
|
torConnectionMode: torConnectionMode,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,6 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
||||||
return await proxy.get(
|
return await proxy.get(
|
||||||
onionUri: onionUri,
|
onionUri: onionUri,
|
||||||
clearnetUri: clearnetUri,
|
clearnetUri: clearnetUri,
|
||||||
torOnly: false,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,6 @@ class ProxyWrapper {
|
||||||
Future<HttpClientResponse> get({
|
Future<HttpClientResponse> get({
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
int? portOverride,
|
int? portOverride,
|
||||||
bool torOnly = false,
|
|
||||||
TorConnectionMode? torConnectionMode,
|
TorConnectionMode? torConnectionMode,
|
||||||
Uri? clearnetUri,
|
Uri? clearnetUri,
|
||||||
Uri? onionUri,
|
Uri? onionUri,
|
||||||
|
@ -90,17 +89,13 @@ class ProxyWrapper {
|
||||||
HttpClient? torClient;
|
HttpClient? torClient;
|
||||||
late bool torEnabled;
|
late bool torEnabled;
|
||||||
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
||||||
if (torConnectionMode == TorConnectionMode.onionOnly ||
|
if (torConnectionMode == TorConnectionMode.torOnly ||
|
||||||
torConnectionMode == TorConnectionMode.enabled) {
|
torConnectionMode == TorConnectionMode.enabled) {
|
||||||
torEnabled = true;
|
torEnabled = true;
|
||||||
} else {
|
} else {
|
||||||
torEnabled = false;
|
torEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (torConnectionMode == TorConnectionMode.onionOnly && onionUri == null) {
|
|
||||||
throw Exception("Cannot connect to clearnet");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if tor is enabled, try to connect to the onion url first:
|
// if tor is enabled, try to connect to the onion url first:
|
||||||
if (torEnabled) {
|
if (torEnabled) {
|
||||||
try {
|
try {
|
||||||
|
@ -117,7 +112,7 @@ class ProxyWrapper {
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) {
|
if (clearnetUri != null) {
|
||||||
try {
|
try {
|
||||||
return await makeGet(
|
return await makeGet(
|
||||||
client: torClient!,
|
client: torClient!,
|
||||||
|
@ -128,7 +123,7 @@ class ProxyWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) {
|
if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) {
|
||||||
try {
|
try {
|
||||||
return HttpOverrides.runZoned(
|
return HttpOverrides.runZoned(
|
||||||
() async {
|
() async {
|
||||||
|
@ -152,7 +147,6 @@ class ProxyWrapper {
|
||||||
Future<HttpClientResponse> post({
|
Future<HttpClientResponse> post({
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
int? portOverride,
|
int? portOverride,
|
||||||
bool torOnly = false,
|
|
||||||
TorConnectionMode? torConnectionMode,
|
TorConnectionMode? torConnectionMode,
|
||||||
Uri? clearnetUri,
|
Uri? clearnetUri,
|
||||||
Uri? onionUri,
|
Uri? onionUri,
|
||||||
|
@ -160,17 +154,13 @@ class ProxyWrapper {
|
||||||
HttpClient? torClient;
|
HttpClient? torClient;
|
||||||
late bool torEnabled;
|
late bool torEnabled;
|
||||||
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
||||||
if (torConnectionMode == TorConnectionMode.onionOnly ||
|
if (torConnectionMode == TorConnectionMode.torOnly ||
|
||||||
torConnectionMode == TorConnectionMode.enabled) {
|
torConnectionMode == TorConnectionMode.enabled) {
|
||||||
torEnabled = true;
|
torEnabled = true;
|
||||||
} else {
|
} else {
|
||||||
torEnabled = false;
|
torEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (torConnectionMode == TorConnectionMode.onionOnly && onionUri == null) {
|
|
||||||
throw Exception("Cannot connect to clearnet");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if tor is enabled, try to connect to the onion url first:
|
// if tor is enabled, try to connect to the onion url first:
|
||||||
|
|
||||||
if (torEnabled) {
|
if (torEnabled) {
|
||||||
|
@ -188,7 +178,7 @@ class ProxyWrapper {
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) {
|
if (clearnetUri != null) {
|
||||||
try {
|
try {
|
||||||
return await makePost(
|
return await makePost(
|
||||||
client: torClient!,
|
client: torClient!,
|
||||||
|
@ -199,7 +189,7 @@ class ProxyWrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) {
|
if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) {
|
||||||
try {
|
try {
|
||||||
return HttpOverrides.runZoned(
|
return HttpOverrides.runZoned(
|
||||||
() async {
|
() async {
|
||||||
|
|
|
@ -719,10 +719,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setProviders() {
|
void _setProviders() {
|
||||||
if (_settingsStore.torConnectionMode == TorConnectionMode.onionOnly)
|
providerList = _allProviders;
|
||||||
providerList = _allProviders.where((provider) => provider.supportsOnionAddress).toList();
|
|
||||||
else
|
|
||||||
providerList = _allProviders;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get depositMaxDigits => depositCurrency.decimals;
|
int get depositMaxDigits => depositCurrency.decimals;
|
||||||
|
|
|
@ -4,11 +4,11 @@ import 'package:cw_core/enumerable_item.dart';
|
||||||
class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
||||||
const TorConnectionMode({required String title, required int raw}) : super(title: title, raw: raw);
|
const TorConnectionMode({required String title, required int raw}) : super(title: title, raw: raw);
|
||||||
|
|
||||||
static const all = [TorConnectionMode.enabled, TorConnectionMode.disabled, TorConnectionMode.onionOnly];
|
static const all = [TorConnectionMode.enabled, TorConnectionMode.disabled, TorConnectionMode.torOnly];
|
||||||
|
|
||||||
static const enabled = TorConnectionMode(raw: 0, title: 'Enabled');
|
static const enabled = TorConnectionMode(raw: 0, title: 'Enabled');
|
||||||
static const disabled = TorConnectionMode(raw: 1, title: 'Disabled');
|
static const disabled = TorConnectionMode(raw: 1, title: 'Disabled');
|
||||||
static const onionOnly = TorConnectionMode(raw: 2, title: 'Onion only');
|
static const torOnly = TorConnectionMode(raw: 2, title: 'Tor only');
|
||||||
|
|
||||||
static TorConnectionMode deserialize({required int raw}) {
|
static TorConnectionMode deserialize({required int raw}) {
|
||||||
switch (raw) {
|
switch (raw) {
|
||||||
|
@ -17,7 +17,7 @@ class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
||||||
case 1:
|
case 1:
|
||||||
return disabled;
|
return disabled;
|
||||||
case 2:
|
case 2:
|
||||||
return onionOnly;
|
return torOnly;
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected token: $raw for TorConnectionMode deserialize');
|
throw Exception('Unexpected token: $raw for TorConnectionMode deserialize');
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
||||||
return S.current.enabled;
|
return S.current.enabled;
|
||||||
case TorConnectionMode.disabled:
|
case TorConnectionMode.disabled:
|
||||||
return S.current.disabled;
|
return S.current.disabled;
|
||||||
case TorConnectionMode.onionOnly:
|
case TorConnectionMode.torOnly:
|
||||||
return S.current.onion_only;
|
return S.current.tor_only;
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ enum TorConnectionStatus { connecting, connected, disconnected }
|
||||||
abstract class TorViewModelBase with Store {
|
abstract class TorViewModelBase with Store {
|
||||||
TorViewModelBase(this._settingsStore) {
|
TorViewModelBase(this._settingsStore) {
|
||||||
reaction((_) => torConnectionMode, (TorConnectionMode mode) async {
|
reaction((_) => torConnectionMode, (TorConnectionMode mode) async {
|
||||||
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.onionOnly) {
|
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.torOnly) {
|
||||||
startTor();
|
startTor();
|
||||||
} else {
|
} else {
|
||||||
stopTor();
|
stopTor();
|
||||||
|
@ -50,6 +50,7 @@ abstract class TorViewModelBase with Store {
|
||||||
} else if (!connect) {
|
} else if (!connect) {
|
||||||
node.socksProxyAddress = null;
|
node.socksProxyAddress = null;
|
||||||
}
|
}
|
||||||
|
node.connectOverTorOnly = _settingsStore.torConnectionMode == TorConnectionMode.torOnly;
|
||||||
await appStore.wallet!.connectToNode(node: node);
|
await appStore.wallet!.connectToNode(node: node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue