mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-19 00:54:33 +00:00
change node test logic to support onion and proxied nodes properly
This commit is contained in:
parent
b6dd28562b
commit
1153162fa9
1 changed files with 14 additions and 3 deletions
|
@ -65,7 +65,13 @@ Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!uri.host.endsWith('.onion')) {
|
if (proxyInfo == null) {
|
||||||
|
// If the host ends in .onion, we can't access it without Tor.
|
||||||
|
if (uri.host.endsWith('.onion')) {
|
||||||
|
return MoneroNodeConnectionResponse(null, null, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proxyless connections can use an HttpClient; proxied ones cannot.
|
||||||
final request = await httpClient.postUrl(uri);
|
final request = await httpClient.postUrl(uri);
|
||||||
|
|
||||||
final body = utf8.encode(
|
final body = utf8.encode(
|
||||||
|
@ -95,13 +101,13 @@ Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
|
||||||
// or we can check for certain values in the response to decide
|
// or we can check for certain values in the response to decide
|
||||||
return MoneroNodeConnectionResponse(null, null, null, true);
|
return MoneroNodeConnectionResponse(null, null, null, true);
|
||||||
} else {
|
} else {
|
||||||
// If the URL ends in .onion, we can't use an httpClient to connect to it.
|
// Proxied connections cannot use an HttpClient.
|
||||||
//
|
//
|
||||||
// The SOCKSSocket class from the tor_ffi_plugin package can be used to
|
// The SOCKSSocket class from the tor_ffi_plugin package can be used to
|
||||||
// connect to .onion addresses. We'll do the same things as above but
|
// connect to .onion addresses. We'll do the same things as above but
|
||||||
// with SOCKSSocket instead of httpClient.
|
// with SOCKSSocket instead of httpClient.
|
||||||
final socket = await SOCKSSocket.create(
|
final socket = await SOCKSSocket.create(
|
||||||
proxyHost: proxyInfo!.host.address,
|
proxyHost: proxyInfo.host.address,
|
||||||
proxyPort: proxyInfo.port,
|
proxyPort: proxyInfo.port,
|
||||||
sslEnabled: false,
|
sslEnabled: false,
|
||||||
);
|
);
|
||||||
|
@ -119,6 +125,11 @@ Future<MoneroNodeConnectionResponse> testMoneroNodeConnection(
|
||||||
// Write the request body to the socket.
|
// Write the request body to the socket.
|
||||||
socket.write(body);
|
socket.write(body);
|
||||||
|
|
||||||
|
// If this is an onion address and there are no errors yet, assume success.
|
||||||
|
if (uri.host.endsWith('.onion')) {
|
||||||
|
return MoneroNodeConnectionResponse(null, null, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Read the response.
|
// Read the response.
|
||||||
final response = await socket.inputStream.first;
|
final response = await socket.inputStream.first;
|
||||||
final result = utf8.decode(response);
|
final result = utf8.decode(response);
|
||||||
|
|
Loading…
Reference in a new issue