-
Notifications
You must be signed in to change notification settings - Fork 290
Description
After the merge of apoelstra/rust-jsonrpc#70, which adds SOCKS5 proxy support to the http transport, I am trying to expose this feature through bitcoincore-rpc. While trying to test out the RPC connection I am getting a general SOCKS server failure
error message.
I have added the proxy version of client creation in the integration_test
crate main function
let cl = Client::new(&rpc_url, auth).unwrap(); |
Like this
#[cfg(not(feature = "proxy"))]
let cl = Client::new(&rpc_url, auth).unwrap();
#[cfg(feature = "proxy")]
let cl = Client::new_with_proxy(&rpc_url, auth, "127.0.0.1:9050", None).unwrap();
Tor in my local machine seems to be working
$ systemctl status tor
● tor.service - Anonymizing overlay network for TCP (multi-instance-master)
Loaded: loaded (/lib/systemd/system/tor.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2022-09-17 09:51:47 IST; 4h 15min ago
Main PID: 1018 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 18414)
Memory: 0B
CPU: 0
CGroup: /system.slice/tor.service
Sep 17 09:51:47 electra systemd[1]: Starting Anonymizing overlay network for TCP (multi-instance-master)...
Sep 17 09:51:47 electra systemd[1]: Finished Anonymizing overlay network for TCP (multi-instance-master).
Bitcoin core is listening for RPC at 18443
$ sudo netstat -nptl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:18443 0.0.0.0:* LISTEN 166695/bitcoind
tcp 0 0 0.0.0.0:18444 0.0.0.0:* LISTEN 166695/bitcoind
tcp 0 0 127.0.0.1:28332 0.0.0.0:* LISTEN 166695/bitcoind
tcp 0 0 127.0.0.1:18445 0.0.0.0:* LISTEN 166695/bitcoind
tcp 0 0 127.0.0.1:28333 0.0.0.0:* LISTEN 166695/bitcoind
And the running the main
function as below and getting the error
$ RPC_URL=127.0.0.1:18443 RPC_COOKIE=/home/raj/.bitcoin/regtest/.cookie cargo run --features proxy
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `/home/raj/github-repo/rust-bitcoincore-rpc/target/debug/integration_test`
[DEBUG][bitcoincore_rpc]: JSON-RPC request: getnetworkinfo []
[DEBUG][bitcoincore_rpc]: JSON-RPC failed parsing reply of getnetworkinfo: JsonRpc(Transport(SocketError(Custom { kind: Other, error: "general SOCKS server failure" })))
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: JsonRpc(Transport(SocketError(Custom { kind: Other, error: "general SOCKS server failure" })))', integration_test/src/main.rs:227:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I tried googling on the error and most threads are suggesting that this happens because of ISP blocking.. I tried to check my if my tor connection is working and that seems to be working fine
$ curl -x socks5h://localhost:9050 -s https://check.torproject.org/api/ip
{"IsTor":true,"IP":"185.220.101.180"}
Am I missing something for connecting to RPC via Tor? Any suggestion on this would be very much helpful..
Activity
RCasatta commentedon Sep 17, 2022
Hi @rajarshimaitra ,
I think you are missing a step, to serve bitcoin rpc via tor you need to create an hidden service on your machine that maps port 18443 to another port X, then your test should use proxy
127.0.0.1:9050
and connect to port Xrajarshimaitra commentedon Sep 28, 2022
Thansk @RCasatta .. I tried many things but unfortunately can't seem to get it working.. Below are the details of all the things I have set.
/etc/tor/torrc
The tor config is set as below
bitcoin.conf
After running
bitcoind
it seems to be successfully connecting to tor and creating an onion address.regtest/debug.log
Both Bitcoind and tor are running at their designated ports.
And when I am running the integration test with new proxy config, still getting the following error
rajarshimaitra commentedon Sep 28, 2022
For better understanding of the code changes I am trying with I have opened the draft PR #249
RCasatta commentedon Sep 28, 2022
didn't look at details but this
HiddenServicePort 18443 127.0.0.1:18443
looks wrong because ports should not be the same, ( doesn't tor complain when you restart it?)
rajarshimaitra commentedon Sep 28, 2022
Nope it din't say anything on that.. I tried with different port too like
HiddenServicePort 20090 127.0.0.1:18443
and tried running withRPC_URl=127.0.0.1:20090
and got the same result.. So changed the ports to same and tried and thats what ended up reporting here..I restarted tor after changing the port.. But theres nothing seems to be listening at port
20090
..rajarshimaitra commentedon Nov 19, 2022
Closing this in favor of #249 (comment).
Any review comments over #249 will be very much appreciated.. 🙏