import 'package:socks5_proxy/socks_client.dart';
import 'package:tor/tor.dart';
Future<void> main() async {
...
final int port = await startTor();
final HttpClient httpClient = createProxyClient(port);
await accessInternetThroughTor(httpClient, destination: Uri.parse('https://icanhazip.com/'));
...
}
Future<int> startTor() async {
await Tor.init();
await Tor.instance.start();
return Tor.instance.port;
}
HttpClient createProxyClient(int port) {
final httpClient = HttpClient();
SocksTCPClient.assignToHttpClient(httpClient, [ProxySettings(InternetAddress.loopbackIPv4, port)]);
return httpClient;
}
Future<void> accessInternetThroughTor(HttpClient httpClient, {required Uri destination}) async {
final HttpClientRequest request = await httpClient.getUrl(destination); // FIXME
final HttpClientResponse response = await request.close();
print('STATUS: ${response.statusCode}\nRESPONSE: ${await utf8.decodeStream(response)}');
}
The line commented with FIXME will throw an ByteReaderException. Whether or not we catch it, the variable request won't be valid, which means we cannot access the destination site (in this example https://icanhazip.com/) through Tor proxy.
Please note that this isn't necessary an issue on package:socks5_proxy. It may be an issue on package:tor, due to the fact that when we use an external Tor proxy instead, all codes work.
Also, it would be great if you could try package:tor yourself. You definitely will know more about this issue than we do.
As mentioned in https://github.com/LacticWhale/socks_dart/issues/8, though
RangeError
now becomesByteReaderException
, we still cannot get the HTTP response from the Tor proxy.Assume we have simple code like this:
The line commented with FIXME will throw an
ByteReaderException
. Whether or not we catch it, the variablerequest
won't be valid, which means we cannot access the destination site (in this examplehttps://icanhazip.com/
) through Tor proxy.Please note that this isn't necessary an issue on
package:socks5_proxy
. It may be an issue onpackage:tor
, due to the fact that when we use an external Tor proxy instead, all codes work.Also, it would be great if you could try
package:tor
yourself. You definitely will know more about this issue than we do.