feat: proxy (Tor/SOCKS5) support: add optional configurable dart:io HttpClient.#1386
feat: proxy (Tor/SOCKS5) support: add optional configurable dart:io HttpClient.#1386sneurlax wants to merge 4 commits intobrij-digital:masterfrom
Conversation
| this._url, { | ||
| required Duration timeout, | ||
| required Map<String, String> customHeaders, | ||
| HttpClient? httpClient, // Optional client for proxy support. |
There was a problem hiding this comment.
I forgot about one more thing, let's use Client from http package, so that it automatically handles web/native use cases.
There was a problem hiding this comment.
The package:http Client only supports HTTP proxies, not SOCKS proxies. However, today I dealt with a similar problem with the Solana library, which uses an http.Client widely: you can make an http.Client with dart:io's HttpClient which does support SOCKS proxies, but you can't make a SOCKS-supporting io.HttpClient from an http.Client.
There was a problem hiding this comment.
I can do like this: https://github.com/cypherstack/stellar_flutter_sdk/blob/eca1d730e952cf6a6d64502f977cfc03876b75d4/lib/src/stellar_sdk.dart#L43-L50
but I can't do the reverse. http.Client is a subset of dart:io.HttpClient aiui
There was a problem hiding this comment.
Hm, then that's actually a problem because the library should support web as well. Let me think about how to better handle that.
There was a problem hiding this comment.
What about a conditional import type of thing? I don't have much (any) experience using Dart/Flutter for web but I have seen some conditional import statements regarding some web stuff. Might be a possibility?
There was a problem hiding this comment.
Yeah, it could be an option to hide it behind conditional imports, but it will most probably require additional work on creating interfaces and wrapping it all together. Unfortunately, I don't have time to look into it right now, so if anyone has possibility to investigate it, that would be great.
There was a problem hiding this comment.
We may be able to get around to it at some point. If we do, we'll update this PR and comment here
|
Hey @ookami-kb, any thoughts on how to handle this? We are doing maintenance by rebasing these features onto a recent master and I wondered if y'all'd like this PR updated as well or if it's unsuitable due to those platform-/compatibility-related restrictions? |
Pass proxyInfo as a Map<String, dynamic> {String host, int port}.
…t null." This reverts commit 2d7189d.
Closes #1382.
Adds an optional
HttpClient httpClientproperty (from `dart:io) to a Solana RpcClient (and JsonRpcClient). If it's null (as old clients will pass it by default), it changes no behavior. If it's not null, it uses the provided HttpClient to proxy requests.You can see an example of usage in Stack Wallet at https://github.com/cypherstack/stack_wallet/blob/2feb7d0be3fb85c6db270f2a12f0ef8e5ef0334d/lib/wallets/wallet/impl/solana_wallet.dart#L419
See #1378 and #1383 for previous description and discussion.
Thank you @ookami-kb for your guidance through this process! I'm happy that Stack Wallet doesn't have to be the only Solana wallet which can proxy request through a SOCKS5 proxy like Tor. See https://github.com/Foundation-Devices/tor for an easy-to-use embeddable Tor proxy which uses the Tor project's
arti(A Rust Tor Implementation).Changes
RpcClientandJsonRpcClientclasses and the_postRequestmethod in order to optionally support proxied HttpClients.Related issues
Checklist