Skip to content

Conversation

qubenix
Copy link
Contributor

@qubenix qubenix commented Nov 15, 2018

I'm not sure if this is done correctly, but it does fix the behavior in my tests. I will not be offended if this gets rejected for a more appropriate method.

@fanquake fanquake added the P2P label Nov 15, 2018
@qubenix
Copy link
Contributor Author

qubenix commented Nov 15, 2018

Pushed a fix to the comment to reflect the new behavior and rebased.

if (gArgs.GetArg("-onion", "") == "") {
// Now that we know Tor is running, setup the proxy for onion addresses
// if -onion and -proxy isn't set to something else.
if (gArgs.GetArg("-onion", "-proxy") == "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default must be set to a value, not the name of the arg it should default to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might have fixed it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoFalke I noticed in another spots this was handled differently. Would it be more preferable like this:

        // Now that we know Tor is running setup the proxy for onion addresses
        // if -onion isn't set to something else.
        std::string onion = gArgs.GetArg("-onion", "");
        std::string proxy = gArgs.GetArg("-proxy", "");
        if (onion.empty() && proxy.empty()) {

- fixes #14722
- only use default tor ip:port (127.0.0.1:9050) if -onion and -proxy not set
- fix comment to reflect new behavior
@qubenix
Copy link
Contributor Author

qubenix commented Nov 15, 2018

Thank you for reviewing.

I think I may have done this the correct way now. If not, I will stop wasting your time and close this so someone more suited can take it up.

bitcoin/src/torcontrol.cpp

Lines 525 to 527 in 38640a0

// Now that we know Tor is running, setup the proxy for onion addresses
// if -onion and -proxy isn't set to something else.
if (gArgs.GetArg("-onion", "") == "" && gArgs.GetArg("-proxy", "") == "") {

if (gArgs.GetArg("-onion", "") == "") {
// Now that we know Tor is running, setup the proxy for onion addresses
// if -onion and -proxy isn't set to something else.
if (gArgs.GetArg("-onion", "") == "" && gArgs.GetArg("-proxy", "") == "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this will work in most cases.

Though ideally we'd query Net's state directly here for "is there a proxy for onion already" instead of indirectly divising it from the arguments. This would really solve the problem of the current code here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this will work in most cases.

Though ideally we'd query Net's state directly here for "is there a proxy for onion already" instead of indirectly divising it from the arguments. This would really solve the problem of the current code here.

Hi, @qubenix

diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index bec64fbf2..b632513c3 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -524,7 +524,8 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply&
 
         // Now that we know Tor is running, setup the proxy for onion addresses
         // if -onion and -proxy isn't set to something else.
-        if (gArgs.GetArg("-onion", "") == "" && gArgs.GetArg("-proxy", "") == "") {
+        proxyType addrOnion;
+        if (gArgs.GetArg("-onion", "") == "" && !GetProxy(NET_ONION, addrOnion)) {
             CService resolved(LookupNumeric("127.0.0.1", 9050));
             proxyType addrOnion = proxyType(resolved, true);
             SetProxy(NET_ONION, addrOnion);

This litle patch should do the trick and fix the problem and that should be in line what @laanwj suggested, please feel free to copy paste. ;-)

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 15, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@luke-jr
Copy link
Member

luke-jr commented Feb 16, 2019

I think when using the Tor controller, we probably want to use the Tor's own listening config (see #15423) over a -proxy setting...

@qubenix
Copy link
Contributor Author

qubenix commented Feb 18, 2019

@luke-jr Could be better to listen to the control port, just don't forget about situations where onion-grater is used and the response from the Tor controller intentionally lies to the application. Onion-grater use is considered a Tor best practice and is being used in Whonix and TAILS.

In Whonix there is a dedicated port for Bitcoin traffic, <gateway-ip>:9111, but if you rely on the control port you get a response like this:

user@host:~$ nc -nv 127.0.0.1 9051
(UNKNOWN) [127.0.0.1] 9051 (?) open
AUTHENTICATE
250 OK
GETINFO net/listeners/socks
250-net/listeners/socks="127.0.0.1:9150"
250 OK

Probably best to rely on the controller and systems using onion-grater can use a profile. Maybe an example one can be included in this repo for such systems.

This PR was only meant to correct the defined behavior of defaulting to -proxy:

-onion=ip:port
Use separate SOCKS5 proxy to reach peers via Tor hidden services, set -noonion to disable (default: -proxy)

@laanwj

Though ideally we'd query Net's state directly here for "is there a proxy for onion already" instead of indirectly divising it from the arguments. This would really solve the problem of the current code here.

Sorry, I'm not sure how to do that. I only wanted to help, but I'm afraid the existence of this PR may be keeping others from doing it the ideal way which you suggested. Just let me know if closing this is more help.

@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 273 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@adamjonas
Copy link
Member

@qubenix bumping here to see if you are planning on continuing to push this forward.

@qubenix
Copy link
Contributor Author

qubenix commented May 18, 2020

@adamjonas I don't what I can/should be doing to push this forward. This PR fixes the bug, but if it's not done in an acceptable way then there's nothing more I can do. I'm not a coder by trade, I just found a bug and offered a solution that I was able to figure out.
That being said, I'm happy to do whatever is expected of me here as long as it's within my ability. I'm just not sure what that is.

@Saibato
Copy link
Contributor

Saibato commented Jun 23, 2020

@adamjonas I don't what I can/should be doing to push this forward. This PR fixes the bug, but if it's not done in an acceptable way then there's nothing more I can do. I'm not a coder by trade, I just found a bug and offered a solution that I was able to figure out.
That being said, I'm happy to do whatever is expected of me here as long as it's within my ability. I'm just not sure what that is.

Hi @qubenix might take a look at #19358? I run in the same problem and found that other settings are also ignored by this footgun proxy fallback, so i took the freedom and pushed this alternative fix.

@fanquake
Copy link
Member

Anyone interested in this PR should instead review #19358.

@fanquake fanquake closed this Sep 29, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-onion does not default to -proxy
8 participants