mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +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
|
||||
Future<void> connectToNode({required Node node}) async {
|
||||
try {
|
||||
// we can't connect over tor in this wallet type (yet):
|
||||
if (node.connectOverTorOnly) {
|
||||
syncStatus = FailedSyncStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
syncStatus = ConnectingSyncStatus();
|
||||
await electrumClient.connectToUri(node.uri);
|
||||
electrumClient.onConnectionStatusChange = (bool isConnected) {
|
||||
|
|
|
@ -63,6 +63,8 @@ class Node extends HiveObject with Keyable {
|
|||
@HiveField(6)
|
||||
String? socksProxyAddress;
|
||||
|
||||
bool connectOverTorOnly = false;
|
||||
|
||||
bool get isSSL => useSSL ?? false;
|
||||
|
||||
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
|
||||
|
|
|
@ -201,7 +201,6 @@ class AnonPayApi {
|
|||
return await proxy.get(
|
||||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
torOnly: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
|
|||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
portOverride: mainThreadProxyPort,
|
||||
torOnly: false,
|
||||
torConnectionMode: torConnectionMode,
|
||||
);
|
||||
|
||||
|
|
|
@ -311,7 +311,6 @@ class TrocadorExchangeProvider extends ExchangeProvider {
|
|||
return await proxy.get(
|
||||
onionUri: onionUri,
|
||||
clearnetUri: clearnetUri,
|
||||
torOnly: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,6 @@ class ProxyWrapper {
|
|||
Future<HttpClientResponse> get({
|
||||
Map<String, String>? headers,
|
||||
int? portOverride,
|
||||
bool torOnly = false,
|
||||
TorConnectionMode? torConnectionMode,
|
||||
Uri? clearnetUri,
|
||||
Uri? onionUri,
|
||||
|
@ -90,17 +89,13 @@ class ProxyWrapper {
|
|||
HttpClient? torClient;
|
||||
late bool torEnabled;
|
||||
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
||||
if (torConnectionMode == TorConnectionMode.onionOnly ||
|
||||
if (torConnectionMode == TorConnectionMode.torOnly ||
|
||||
torConnectionMode == TorConnectionMode.enabled) {
|
||||
torEnabled = true;
|
||||
} else {
|
||||
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 (torEnabled) {
|
||||
try {
|
||||
|
@ -117,7 +112,7 @@ class ProxyWrapper {
|
|||
} catch (_) {}
|
||||
}
|
||||
|
||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) {
|
||||
if (clearnetUri != null) {
|
||||
try {
|
||||
return await makeGet(
|
||||
client: torClient!,
|
||||
|
@ -128,7 +123,7 @@ class ProxyWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) {
|
||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) {
|
||||
try {
|
||||
return HttpOverrides.runZoned(
|
||||
() async {
|
||||
|
@ -152,7 +147,6 @@ class ProxyWrapper {
|
|||
Future<HttpClientResponse> post({
|
||||
Map<String, String>? headers,
|
||||
int? portOverride,
|
||||
bool torOnly = false,
|
||||
TorConnectionMode? torConnectionMode,
|
||||
Uri? clearnetUri,
|
||||
Uri? onionUri,
|
||||
|
@ -160,17 +154,13 @@ class ProxyWrapper {
|
|||
HttpClient? torClient;
|
||||
late bool torEnabled;
|
||||
torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled;
|
||||
if (torConnectionMode == TorConnectionMode.onionOnly ||
|
||||
if (torConnectionMode == TorConnectionMode.torOnly ||
|
||||
torConnectionMode == TorConnectionMode.enabled) {
|
||||
torEnabled = true;
|
||||
} else {
|
||||
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 (torEnabled) {
|
||||
|
@ -188,7 +178,7 @@ class ProxyWrapper {
|
|||
} catch (_) {}
|
||||
}
|
||||
|
||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) {
|
||||
if (clearnetUri != null) {
|
||||
try {
|
||||
return await makePost(
|
||||
client: torClient!,
|
||||
|
@ -199,7 +189,7 @@ class ProxyWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) {
|
||||
if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) {
|
||||
try {
|
||||
return HttpOverrides.runZoned(
|
||||
() async {
|
||||
|
|
|
@ -719,10 +719,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
}
|
||||
|
||||
void _setProviders() {
|
||||
if (_settingsStore.torConnectionMode == TorConnectionMode.onionOnly)
|
||||
providerList = _allProviders.where((provider) => provider.supportsOnionAddress).toList();
|
||||
else
|
||||
providerList = _allProviders;
|
||||
providerList = _allProviders;
|
||||
}
|
||||
|
||||
int get depositMaxDigits => depositCurrency.decimals;
|
||||
|
|
|
@ -4,11 +4,11 @@ import 'package:cw_core/enumerable_item.dart';
|
|||
class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
||||
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 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}) {
|
||||
switch (raw) {
|
||||
|
@ -17,7 +17,7 @@ class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
|||
case 1:
|
||||
return disabled;
|
||||
case 2:
|
||||
return onionOnly;
|
||||
return torOnly;
|
||||
default:
|
||||
throw Exception('Unexpected token: $raw for TorConnectionMode deserialize');
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ class TorConnectionMode extends EnumerableItem<int> with Serializable<int> {
|
|||
return S.current.enabled;
|
||||
case TorConnectionMode.disabled:
|
||||
return S.current.disabled;
|
||||
case TorConnectionMode.onionOnly:
|
||||
return S.current.onion_only;
|
||||
case TorConnectionMode.torOnly:
|
||||
return S.current.tor_only;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ enum TorConnectionStatus { connecting, connected, disconnected }
|
|||
abstract class TorViewModelBase with Store {
|
||||
TorViewModelBase(this._settingsStore) {
|
||||
reaction((_) => torConnectionMode, (TorConnectionMode mode) async {
|
||||
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.onionOnly) {
|
||||
if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.torOnly) {
|
||||
startTor();
|
||||
} else {
|
||||
stopTor();
|
||||
|
@ -50,6 +50,7 @@ abstract class TorViewModelBase with Store {
|
|||
} else if (!connect) {
|
||||
node.socksProxyAddress = null;
|
||||
}
|
||||
node.connectOverTorOnly = _settingsStore.torConnectionMode == TorConnectionMode.torOnly;
|
||||
await appStore.wallet!.connectToNode(node: node);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue