CW-224-Allow-Monero-proxy-in-node-settings (#966)

* update setupNodeSync func

* minor fixes

* localization

* add request node with proxy

* formatting
This commit is contained in:
Serhii 2023-08-02 14:48:52 +03:00 committed by GitHub
parent fcf4fbdc14
commit d5c0012964
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 180 additions and 27 deletions

View file

@ -18,6 +18,7 @@ class Node extends HiveObject with Keyable {
this.password,
this.useSSL,
this.trusted = false,
this.socksProxyAddress,
String? uri,
WalletType? type,}) {
if (uri != null) {
@ -33,7 +34,8 @@ class Node extends HiveObject with Keyable {
login = map['login'] as String?,
password = map['password'] as String?,
useSSL = map['useSSL'] as bool?,
trusted = map['trusted'] as bool? ?? false;
trusted = map['trusted'] as bool? ?? false,
socksProxyAddress = map['socksProxyPort'] as String?;
static const typeId = 1;
static const boxName = 'Nodes';
@ -56,8 +58,13 @@ class Node extends HiveObject with Keyable {
@HiveField(5, defaultValue: false)
bool trusted;
@HiveField(6)
String? socksProxyAddress;
bool get isSSL => useSSL ?? false;
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
Uri get uri {
switch (type) {
case WalletType.monero:
@ -81,7 +88,8 @@ class Node extends HiveObject with Keyable {
other.password == password &&
other.typeRaw == typeRaw &&
other.useSSL == useSSL &&
other.trusted == trusted);
other.trusted == trusted &&
other.socksProxyAddress == socksProxyAddress);
@override
int get hashCode =>
@ -90,7 +98,8 @@ class Node extends HiveObject with Keyable {
password.hashCode ^
typeRaw.hashCode ^
useSSL.hashCode ^
trusted.hashCode;
trusted.hashCode ^
socksProxyAddress.hashCode;
@override
dynamic get keyIndex {
@ -108,7 +117,7 @@ class Node extends HiveObject with Keyable {
try {
switch (type) {
case WalletType.monero:
return requestMoneroNode();
return useSocksProxy ? requestNodeWithProxy(socksProxyAddress ?? '') : requestMoneroNode();
case WalletType.bitcoin:
return requestElectrumServer();
case WalletType.litecoin:
@ -159,6 +168,22 @@ class Node extends HiveObject with Keyable {
}
}
Future<bool> requestNodeWithProxy(String proxy) async {
if (proxy.isEmpty || !proxy.contains(':')) {
return false;
}
final proxyAddress = proxy.split(':')[0];
final proxyPort = int.parse(proxy.split(':')[1]);
try {
final socket = await Socket.connect(proxyAddress, proxyPort, timeout: Duration(seconds: 5));
socket.destroy();
return true;
} catch (_) {
return false;
}
}
Future<bool> requestElectrumServer() async {
try {
await SecureSocket.connect(uri.host, uri.port,