Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tor icon #86

Closed
wants to merge 9 commits into from
Closed

Add Tor icon #86

wants to merge 9 commits into from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Sep 10, 2020

New behavior:

  • the Tor icon is showed in the status bar iif all peer connections are made via Tor (credits to Sjors)
  • a click on the Tor icon opens the "Network" tab of the "Options" dialog

Designer: Bosch-0
Icon PNG file is optimized with optimize-pngs.py

Fix bitcoin/bitcoin#7734
Fix #58

Screenshots:
Screenshot from 2020-09-09 17-04-56
Screenshot from 2020-09-09 17-03-54

Screenshot from 2020-10-17 10-03-35

Based on bitcoin/bitcoin#20172 (the first five commits).

@hebasto
Copy link
Member Author

hebasto commented Sep 10, 2020

Moved from bitcoin/bitcoin#19926 as requested by @fanquake.

@@ -87,6 +87,12 @@ class NodeImpl : public Node
}
}
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }

bool hasTorOnlyConnections() override
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to expose this bool over rpc as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@hebasto
Copy link
Member Author

hebasto commented Sep 10, 2020

Updated 4930c92 -> 082a680 (pr86.01 -> pr86.02, diff):

would it make sense to expose this bool over rpc as well?

@jonasschnelli
Copy link
Contributor

Concept ACK.

If one adds a non-TOR node via addnode, will the icon change (I haven't looked through the code yet)?

@hebasto
Copy link
Member Author

hebasto commented Sep 10, 2020

@jonasschnelli

If one adds a non-TOR node via addnode, will the icon change (I haven't looked through the code yet)?

No. updateTorIcon() is called only once in BitcoinGUI::setClientModel(). Going to address this issue.

UPDATE: changed in #86 (comment)

@jonasschnelli
Copy link
Contributor

No. updateTorIcon() is called only once in BitcoinGUI::setClientModel(). Going to address this issue.

Thanks!

I think for TOR only,... it's very important that users can't end up with the icon "confirming" tor-only when the actually have non-tor connections.

@hebasto
Copy link
Member Author

hebasto commented Sep 11, 2020

Updated 082a680 -> e61b120 (pr86.02 -> pr86.03, diff):

I think for TOR only,... it's very important that users can't end up with the icon "confirming" tor-only when the actually have non-tor connections.

@hebasto
Copy link
Member Author

hebasto commented Sep 11, 2020

@fanquake @MarcoFalke Is this PR in its current state (with net part refactoring) placed in this repo correctly?

@Fichte42
Copy link

Concept ACK.

Not tested, code looks pretty straight forward. I would maybe rename tor_connected to tor_only_connections or something like that to reflect that all connections are via tor.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Concept ACK and code review ACK of the net code changes. I've left a bunch of style comments, which you can feel free to ignore, but might be good to address if you have to touch the branch again.

I'm not familiar with the qt code, but I've skimmed the changes and they seem fine.

src/net.cpp Outdated Show resolved Hide resolved
src/net.cpp Outdated Show resolved Hide resolved
src/net.h Outdated Show resolved Hide resolved
src/net.h Outdated Show resolved Hide resolved
src/rpc/mining.cpp Outdated Show resolved Hide resolved
@hebasto
Copy link
Member Author

hebasto commented Sep 11, 2020

Updated 01fb75e -> 6549abc (pr86.04 -> pr86.05, diff):

@Fichte42

I would maybe rename tor_connected to tor_only_connections or something like that to reflect that all connections are via tor.

The icon name is used only once, and there is the only Tor icon in the repo. I'd keep the more general name for now.

@Rspigler
Copy link
Contributor

these conditions could be achieved with -onlynet=onion, -listen=0, and -listenonion=1 options)

onlynet=onion makes it so that Core only connects out to Hidden Services. What about also detecting situations like:

proxy=127.0.0.1:9050 bind=127.0.0.1

This disables listening, so could be with OR without:

listen=1 AND
the ephemeral hidden services supported since Tor version 0.2.7.1 and Core 0.12.0

@hebasto
Copy link
Member Author

hebasto commented Sep 12, 2020

@Rspigler

these conditions could be achieved with -onlynet=onion, -listen=0, and -listenonion=1 options)

onlynet=onion makes it so that Core only connects out to Hidden Services. What about also detecting situations like:

proxy=127.0.0.1:9050 bind=127.0.0.1

This disables listening, so could be with OR without:

listen=1 AND
the ephemeral hidden services supported since Tor version 0.2.7.1 and Core 0.12.0

Currently, only the CNetAddr::IsTor() function is used for checking. Command line options in the OP are listed for testing purposes.

@Bosch-0
Copy link

Bosch-0 commented Sep 14, 2020

ACK, looks good on windows 10. Though I did have to add the below to my .config file - it would be ideal if the user did not have to do this.

onlynet=onion listen=0 listenonion=1

image

A quick note, this was the first PR I have reviewed and as non super technical designer, I did not find the process too difficult - I will be making a concerted effort with the Bitcoin Design community to get more reviewers looking at these kind of PRs.

@jnewbery
Copy link
Contributor

Code review ACK 6549abc (node changes only. Did not fully review qt changes)

@jonatack
Copy link
Member

ACK, looks good on windows 10. Though I did have to add the below to my .config file - it would be ideal if the user did not have to do this.

onlynet=onion listen=0 listenonion=1

@Bosch-0 if you have tor configured and running, running the default configuration of Bitcoin Core should automatically start an onion service. See "3. Automatically listen on Tor" in doc/tor.md.

@hebasto
Copy link
Member Author

hebasto commented Sep 14, 2020

@jonatack

@Bosch-0 if you have tor configured and running, running the default configuration of Bitcoin Core should automatically start an onion service. See "3. Automatically listen on Tor" in doc/tor.md.

Correct. But the default setup does not prevent non-onion connections. Therefore, the Tor icon will not be shown to a user.

@jonatack
Copy link
Member

jonatack commented Sep 14, 2020

The additional configuration is if you only want onion connections. onlynet=onion isn't necessarily recommended, IIUC. Though I can understand why we'd want to indicate when we're running on onion-only.

@hebasto
Copy link
Member Author

hebasto commented Sep 14, 2020

The additional configuration is if you only want onion connections. onlynet=onion isn't necessarily recommended, IIUC.

Correct. onlynet=onion is for outgoing connection. That (the making outgoing connections Tor-only) is optional, ofc.

@Bosch-0
Copy link

Bosch-0 commented Sep 14, 2020

The additional configuration is if you only want onion connections. onlynet=onion isn't necessarily recommended, IIUC

Why is this not recommended?

@jonatack
Copy link
Member

jonatack commented Sep 14, 2020

The additional configuration is if you only want onion connections. onlynet=onion isn't necessarily recommended, IIUC

Why is this not recommended?

  1. https://en.bitcoin.it/wiki/Setting_up_a_Tor_hidden_service:
  • "If you additionally want Bitcoin Core to only connect out to Tor hidden services, also add this line (not particularly recommended):"

    onlynet=onion
    
  • "Doing so will make your specific bitcoind node arguably more secure because it will never have an unencrypted connection to another node, but if everyone used onlynet=onion nobody on the onion bitcoin chain would be able to communicate with the clearnet chain. It is essential that some nodes access both clearnet and Tor. If you need to submit bitcoin transactions to the network with the highest level of obscurity, use onlynet=onion. If you only wish to give access to your node to other Tor users, do not use it."

  1. Also, if you're interested, google "Bitcoin over Tor isn’t a good idea" (from 2015). Possible countermeasures include BIP324 (in the future) or using addnode to ensure connection to trusted "good" onion peers.

  2. Finally, Tor v2 seems increasingly compromised and begins its deprecation period tomorrow (September 15, 2020), which is why implementation of BIP155 is important to move to Tor v3, I2P, CJDNS, etc.

Edit: don't let this hijack the PR! Concept ACK.

@Rspigler
Copy link
Contributor

Though I can understand why we'd want to indicate when we're running on onion-only.

I think for the very reason that it risks partitioning the network, and less educated users may think that there is a greater benefit than there really is, we shouldn't have an icon to indicate an onion only mode (this PR doesn't do that).

That (the making outgoing connections) is optional, ofc.

Outgoing connections is default, incoming connections are optional. For outgoing connections, you can set a proxy command in the conf file to put all connections behind tor, or set onlynet=onion to connect out only to HS (not recommended).

For incoming connections, since Tor version 0.2.7.1 and Core 0.12.0, Core can create and destroy ephemeral hidden services programmatically.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

tACK 6549abc with notes for followup

We can decide in another PR whether to encourage Tor more, as well as make it less painful to correctly configure.

Tested on macOS 10.15.6 with the Tor proxy configured in the GUI (using port 9150 which the Tor browser offers), -onlynet=onion and -listen=0.

Note that the Tor icon won't appear until at least one peer is connected. This is the same behavior as connections_tor_only in getnetworkinfo (uses the same code).

I didn't try launching a hidden service; someone running Linux should.

In light of the 727af0f refactor, I also tested that setnetworkactive still works with bitcoin-cli and from the GUI console.

In the event this PR doesn't make it, there's some useful refactoring commits that should be salvaged.

@@ -854,19 +852,6 @@ void RPCConsole::updateNetworkState()
ui->numberOfConnections->setText(connections);
}

void RPCConsole::setNumConnections()
{
if (!clientModel)
Copy link
Member

Choose a reason for hiding this comment

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

Was this check already superfluous?

src/net.cpp Outdated
@@ -2598,13 +2598,16 @@ ConnCounts CConnman::ConnectionCounts()
{
int num_in{0};
int num_out{0};
bool tor_only{false};
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this should be an Optional, but I don't care deeply.

src/rpc/net.cpp Outdated
@@ -544,6 +544,7 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
obj.pushKV("connections", conn_counts.all);
obj.pushKV("connections_in", conn_counts.in);
obj.pushKV("connections_out", conn_counts.out);
obj.pushKV("connections_tor_only", conn_counts.tor_only);
Copy link
Member

Choose a reason for hiding this comment

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

connections_tor_only should be documented in the RPCResult above

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the RPC and net changes are not gui related, so should go into the main repo

Copy link
Member Author

Choose a reason for hiding this comment

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

src/net.cpp Outdated
for (const auto& pnode : vNodes) {
pnode->IsInboundConn() ? ++num_in : ++num_out;
if (!pnode->addr.IsTor()) tor_only = false;
Copy link
Member

Choose a reason for hiding this comment

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

I didn't test if IsTor() behaves correctly when you have an inbound connection via a hidden service.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't test if IsTor() behaves correctly when you have an inbound connection via a hidden service.

No, it doesn't. Going to rework his code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

@Sjors Sjors Sep 17, 2020

Choose a reason for hiding this comment

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

If it's too tedious, I'm fine with the current change and just leaving correct handling of hidden service as a (well documented) TODO. At least this PR shows the Tor icon in a subset of acceptable circumstances.

Copy link
Member Author

Choose a reason for hiding this comment

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

The solution suggested by @laanwj submitted in bitcoin/bitcoin#19991.

updateNetworkState();
if (conn_counts.onion_only) {
m_tor_icon->setPixmap(platformStyle->SingleColorIcon(":/icons/tor_connected").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
m_tor_icon->setToolTip(tr("All connections are <b>via Tor</b> only"));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "All current connections are via Tor only"?

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

I don't think the logic makes sense as-is.

I see two possibilities for a Tor icon:

  1. Tor is working and usable (reachability).
  2. All connections, even hypothetically, will be only via Tor (network privacy).

Right now, it's "all connections at the moment happen to be via Tor", which seems relatively useless - it doesn't guarantee network privacy, nor reachability. What good is it?

IMO the icon should probably be tri-state: "off", or either scenario listed above.

@jonatack
Copy link
Member

jonatack commented Oct 24, 2020

Agree with @luke-jr here. I'd suggest the first one, "Tor is working and usable on this node", and not focus on the onion-only aspect for the reasons described above in #86 (comment).

We may also want to distinguish between outbound (onlynet=onion) and inbound onion connections.

The tooltip needs to be precise and clear about what the icon states signify.

@Rspigler
Copy link
Contributor

I was hesitant to make an argument because I don't review code, but as my comment (#86 (comment)) indicates above, I agree with @luke-jr and @jonatack as well. I would need someone else to analyze the partitioning risks of many nodes possibly going onion only, I don't know enough to do so myself. But I prefer the 'tri-state' option to Jonatack's dual-state because it would be nice for user's to know if they (1) have configured their HS properly and/or (2) have Tor only settings achieved.

@vasild
Copy link
Contributor

vasild commented Oct 26, 2020

  1. All connections, even hypothetically, will be only via Tor (network privacy).

Currently we can't "guarantee" this because we always have a listening port for clearnet. bitcoin/bitcoin#20234 would make it possible. With that PR, if -bind=127.0.0.1:8334=onion is specified we would not bind on any other port and we can assume the node is running in Tor-only mode (for incoming connections, I guess -onlynet=onion would control the outgoing ones).

Also, something to consider - once we have I2P connectivity, if "all connections, even hypothetically will be only via Tor or I2P", should we then display both Tor or I2P icons or none of them (wrt the 3rd state "network privacy")?

@Sjors
Copy link
Member

Sjors commented Oct 26, 2020

The combination ""All connections, at the moment happen to be via Tor" && "All connections, even hypothetically, will be only via Tor" makes sense as the boolean.

A tristate works for me too, if there's actually a way to verify reachability.

@Rspigler
Copy link
Contributor

Currently we can't "guarantee" this because we always have a listening port for clearnet.

What about a HS with onlynet=onion listen=0 listenonion=1 ?

once we have I2P connectivity, if "all connections, even hypothetically will be only via Tor or I2P", should we then display both Tor or I2P icons or none of them (wrt the 3rd state "network privacy")?

Probably should be both, but maybe re-word the tooltip text from "All connections will be only via Tor" to something like "Clearnet connections are disabled for all connections. Tor is enabled) so there's no error in logic when one or both is enabled.

@vasild
Copy link
Contributor

vasild commented Oct 27, 2020

Currently we can't "guarantee" this because we always have a listening port for clearnet.

What about a HS with onlynet=onion listen=0 listenonion=1 ?

listen=0 will cause us not to listen on any port, so we would not accept any incoming connections, regardless of whether clearnet or Tor. listenonion=1 will be automatically changed to listenonion=0 due to listen=0.

But yes, just onlynet=onion listen=0 can be considered as Tor-only mode.

@Sjors
Copy link
Member

Sjors commented Oct 27, 2020

We could expand the behavior of onlynet=onion to prevent listening on the non-onion port.

Currently:

  -onlynet=<net>
       Make outgoing connections only through network <net> (ipv4, ipv6 or
       onion). Incoming connections are not affected by this option.
       This option can be specified multiple times to allow multiple
       networks.

@Rspigler
Copy link
Contributor

Rspigler commented Oct 28, 2020

listenonion=1 will be automatically changed to listenonion=0 due to listen=0.

I don't think this is true, because when I set onlynet=onion listen=0 and listenonion=1 my HS is enabled. But when I have onlynet=onion listen=0 and listenonion=0 in my config, my HS is disabled. So I would assume it would allow incoming onion connections

We could expand the behavior of onlynet=onion to prevent listening on the non-onion port.

I believe this was discussed here: bitcoin/bitcoin#13436

@vasild
Copy link
Contributor

vasild commented Oct 28, 2020

Alright, I was halfway wrong.

listenonion=1 will be automatically changed to listenonion=0 due to listen=0

^ this is not true, as you have observed. However the following is true:

listen=0 will cause us not to listen on any port, so we would not accept any incoming connections, regardless of whether clearnet or Tor.

$ bitcoind
...
2020-10-28T08:41:57Z Config file arg: listen="0"
2020-10-28T08:41:57Z Config file arg: listenonion="1"
2020-10-28T08:41:57Z Config file arg: rpcport="8332"
...
2020-10-28T08:42:19Z tor: Got service ID foo, advertising service foo.onion:8333
2020-10-28T08:42:19Z AddLocal(foo.onion:8333,4)

$ netstat
tcp4       0      0 127.0.0.1.8332         *.*                    LISTEN     
(bitcoind is only listening on the RPC port)

I guess this can be considered as a bug because it will (I guess) advertise foo.onion:8333 where nobody is listening.

@Sjors
Copy link
Member

Sjors commented Oct 30, 2020

I believe this was discussed here: bitcoin/bitcoin#13436

That discussion was before we had a separate Tor port (binding to 127.0.0.1).

@Rspigler
Copy link
Contributor

That discussion was before we had a separate Tor port (binding to 127.0.0.1).

Ah, ok. IMO, that seems like it would be the easiest for the end user and also for this PR. Not sure how changing it would interact with other current network setting configurations we have.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 1, 2020

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@Rspigler
Copy link
Contributor

I think @luke-jr's Tri-state should be combined w/ @jonatack's inbound/outbound distinction. Discussed more here: #110 (comment)

Is @vasild's bitcoin/bitcoin#20234 still a blocker for this? How does that work with/without expanding the behavior of onlynet=onion @Sjors ?

@Rspigler
Copy link
Contributor

Edit: I feel less strongly about the concept of a Tor icon in general. Definitely supportive of switches in the GUI to help end users set up permanent configurations of connection types (#110 (comment)). But, if the user has done that, they should know what their connections are like.

The icon possibility set is just too much. Tor incoming, both proxy and tor outgoing...etc. We would either need far too many icons, or the icons would only apply in rare scenarios (Would you give someone a Tor icon if they only have Tor outgoing and Incoming disabled? What about Tor outgoing and Proxy incoming? Or Tor outgoing and Tor incoming?)...

This would get more complicated when I2P support is added. Maybe just have an icon for "My connections are only using privacy networks" as suggested by @kristapsk (bitcoin/bitcoin#20172 (comment))

Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

Concept ACK, Tested bd8df33 on macOS 11.1 with Qt 5.15.2

Tor Only: Tor Icon Shows
Screen Shot 2021-01-18 at 7 20 48 PM

Tor and IPv4 Connection: Tor Icon Does not Show (intended)
Screen Shot 2021-01-18 at 7 20 57 PM

Thoughts on the discussion had so far:
This is part of a bigger discussion, but it would be a good feature to represent the connection type in the form of an Icon, for all connection types. The Tor icon is one step towards this. While outside the scope of this PR, I would propose an Icon for each network type to show.

Specifically concerning the Tor Icon:
I think that the Tor Icon should show ONLY when ALL of our connections are Tor (Like this PR implements). Perhaps we show a (to be designed) Fusion icon when you have a combination of Tor and another network type like IPv4.

@rebroad
Copy link
Contributor

rebroad commented Apr 19, 2021

@hebasto What's a use case for this?

@hebasto
Copy link
Member Author

hebasto commented May 2, 2021

@rebroad

@hebasto What's a use case for this?

The initial idea was to give to a user some representation about her node privacy level.

@hebasto
Copy link
Member Author

hebasto commented May 2, 2021

Closing. Leaving it up for grabs.

@hebasto hebasto closed this May 2, 2021
@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tor status indicator icon in bottom right Feat Request (Qt/GUI): Tor status indicator icon in bottom right