Route HttpClient over Socks5 Proxy, with remote DNS resolution. #545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request partially addresses #522.
I say partially because there is some wiring up left to do so that HttpClient gets access to a Socks5Proxy object when called by a PriceProvider subclass. But the core functionality of making a request over socks5 with remote DNS is working.
I found it necessary to pull in apache components, as commented in the issue. They are only used when a proxy is available to HttpClient. Otherwise, the pre-existing code is used. The caller API (requestWithGet) remains the same.
The HttpClient code (proxy case) looks at the value of proxy.resolveAddrLocally(). So if a user setting is made to control that, then HttpClient will abide by it.
Testing
I tested this code twice by hard-coding addresses of (1) system tor port 9050 and (2) an ssh socks proxy, so that all callers used the proxy even without passing in a Socks5Proxy. I went so far as to firewall block all outgoing tcp/udp ports on the system except those used by tor (9001,9030). With this configuration, I was able to run bitsquare with full functionality when using the ssh tor port, and with everything but poloniex working when run over Tor ( because Poloniex uses cloudflare that blocks tor exit nodes. )
If anyone would like to duplicate the tor-only firewall config, I used the following ufw script on ubuntu:
It can then be turned off with sudo ufw disable. You will likely want to save your old firewall config first, if any.
Note that bitsquare may take a little longer to connect to tor network with these firewall rules because tor normally use ports 80 and 443 as well as 9001 and 9030. I disabled 80 and 443 to be certain the http requests are not leaking.
I would have liked to finalize the integration, but I find myself baffled as to how to get the Socks5Proxy object to HttpClient. I do not yet grok this injection voodoo. So I think it best that @ManfredKarrer wire that up, and I will thereby learn.
Bounty
A bounty offer was made. At such time as the code is deemed acceptable to be merged, payment can be made to 1Byv5zUGHYtodMScTZcdBBc47Ber2GWNf. A reduced payment is acceptable given the unfinished status. I consider this code to be at least 90% complete. Of course I will fix any issues/nits found during review, etc.