-
Notifications
You must be signed in to change notification settings - Fork 37.7k
net: respect -onlynet= when making outbound connections #22834
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
Conversation
Concept ACK, I think this makes onlynet closer to what users expect, clearing up all kind of exceptions that have to be documented. Thanks! |
With this PR, one could use for example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, initial drive-by review on github, will review/test soon
(Feel free to ignore my comments until you re-push.) Do you plan to add functional tests like in #22651? |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
It would be good. I wonder how to test this deterministically. I guess I would want to have an addrman with just addresses from one network and use onlynet another network and check that a connection is never attempted, or something like that. |
Concept ACK Started testing today and need to test lot of combinations with onlynet. Sharing things that I observed during basic tests:
|
Concept ACK! Glad there's a full fix for this now. |
|
@prayank23, thanks for looking into this! So all is working as expected. A room for improvement (out of the scope of this PR): with |
Concept ACK |
Day 2 of testing
Need to test more things.
Thanks. Will try this tomorrow.
Yes we can try this. |
I wonder about the interactions of the new My understanding is that Would it be possible as an alternative approach to get Reachable in line with |
@prayank23 does the machine have an actual IPv6 connectivity? Do you see successful connections to IPv6 hosts when |
Yes it was ipv6 connectivity issue. There were 2 issues: 1. One of my ISP didn't support ipv6 2. Had to change network adapter from NAT to bridged in VM. Checked connectivity on http://test-ipv6.com/ Updated logs above as ipv6 works fine. Will test onion-ipv4, onion-ipv6, i2p-ipv4, i2p-ipv6, i2p-onion and ipv6-ipv4 today. |
@mzumsande, good insight! I think there are two distinct properties of a network:
For example, a setup like Your comments make me think - should we only add addresses to addrman if they are both 1. and 2. (right now it is just 1.)? E.g. // Do not store addresses outside our network
- if (fReachable)
+ if (fReachable && OutboundConnectionAllowedTo(addr))
vAddrOk.push_back(addr); or also limit relay of 1. but not 2. addresses? What about changing the Lines 574 to 575 in b997dd2
|
I agree with @mzumsande. I find it confusing that we have two functions considering |
It tried few combinations with This PR has limited scope and it does fix the issues with ACK 0ea0de6 Will reACK if suggestions discussed above are implemented and functional tests are added: Also not sure why |
@mzumsande, @naumenkogs, if we need not make a distinction between 1. and 2. (from #22834 (comment)), then an alternative approach is possible, similar to the one described above by @mzumsande (but not quite the same). What do you think about this: vasild@46a9a79? Note that even with that, |
I didn't find a place we would need to make the distinction between the ability (1) and the willingness (2) to make outbound connections to networks. Also the status quo for
Is this a relevant scenario, i.e. what should be the practical consequence of a network being "reachable" in this scenario when we wouldn't do automatic connections to it?
Yes, I agree. As far as I can see, all of the manual connection code is completely independent from
I tend to think that this would make sense. I don't see the point of storing addresses in addrman when we won't connect to them - whether this is because we cannot or because we don't want to doesn't seem crucial to me.
On first sight, I like this approach. I don't quite understand why it is possible to just drop the I have been looking into the other call sites of |
Concept ACK |
The only one I can think of is this - it would be strange to display onion as not reachable in
Yes.
It would be possible to reach the network by opening a manual connection. I am not sure if this is "relevant". Maybe it is exotic use case.
Hmm, maybe that is not a good idea - if
I think the logic is this - if a network is not reachable then we cannot accept connections from it. "Reachable" in the broader English word meaning, not the stricter |
Do not make outbound connections to hosts which belong to a network which is restricted by `-onlynet`. This applies to hosts that are automatically chosen to connect to and to anchors. This does not apply to hosts given to `-connect`, `-addnode`, `addnode` RPC, dns seeds, `-seednodes`. Fixes bitcoin#13378 Fixes bitcoin#22647 Supersedes bitcoin#22651
-BEGIN VERIFY SCRIPT- sed -i 's/\<proxyType\>/Proxy/g' $(git grep -l proxyType) -END VERIFY SCRIPT-
Invalidates ACK from @prayank23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 0eea83a
utACK 0eea83a |
Do not make outbound connections to hosts which belong to a network which is restricted by `-onlynet`. This applies to hosts that are automatically chosen to connect to and to anchors. This does not apply to hosts given to `-connect`, `-addnode`, `addnode` RPC, dns seeds, `-seednodes`. Fixes bitcoin#13378 Fixes bitcoin#22647 Supersedes bitcoin#22651 Github-Pull: bitcoin#22834 Rebased-From: 0ea0de6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 0eea83a code review, rebased to master, debug built, and did some manual testing with various config options on signet
Came across the onlynet issue again recently that this pull fixes.
This pull has been through quite a bit of review and has several ACKs. It may be good to have it in v23.
return InitError( | ||
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for " | ||
"reaching the Tor network is not provided (no -proxy= and no -onion= given) or " | ||
"it is explicitly forbidden (-onion=0)")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually tested hitting this error message. A test may be good in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A candidate for #24205?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A candidate for #24205?
Done, along with test coverage for the other proxy/onion/onlynet init errors.
@@ -441,7 +441,7 @@ void SetupServerArgs(ArgsManager& argsman) | |||
argsman.AddArg("-onion=<ip:port>", "Use separate SOCKS5 proxy to reach peers via Tor onion services, set -noonion to disable (default: -proxy)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
argsman.AddArg("-i2psam=<ip:port>", "I2P SAM proxy to reach I2P peers and accept I2P connections (default: none)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
argsman.AddArg("-i2pacceptincoming", "If set and -i2psam is also set then incoming I2P connections are accepted via the SAM proxy. If this is not set but -i2psam is set then only outgoing connections will be made to the I2P network. Ignored if -i2psam is not set. Listening for incoming I2P connections is done through the SAM proxy, not by binding to a local address and port (default: 1)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
argsman.AddArg("-onlynet=<net>", "Make outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks. Warning: if it is used with non-onion networks and the -onion or -proxy option is set, then outbound onion connections will still be made; use -noonion or -onion=0 to disable outbound onion connections in this case.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); | |||
argsman.AddArg("-onlynet=<net>", "Make automatic outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe s/outgoing connections/automatic outbound connections
and s/incoming connections/inbound and manual connections/
in these three lines:
₿ git grep "Incoming connections\|. Incoming"
doc/i2p.md:68:Make outgoing connections only to I2P addresses. Incoming connections are not
doc/tor.md:56: -onlynet=onion Make outgoing connections only to .onion addresses. Incoming
src/init.cpp:444: argsman.AddArg("-onlynet=<net>", "Make automatic outgoing connections only through network <net> (" + Join(GetNetworkNames(), ", ") + "). Incoming connections are not affected by this option. This option can be specified multiple times to allow multiple networks.", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do if I retouch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, can be as a follow-up. This seems RFM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #24468
…ated tor/i2p documentation a1db99a init, doc: improve -onlynet help and tor/i2p documentation (Jon Atack) Pull request description: including review feedback from bitcoin/bitcoin#22834 (comment) and bitcoin/bitcoin#24205 (comment) concerning `src/init.cpp`, `doc/tor.md` and `doc/i2p.md` - s/outgoing/automatic outbound/ - s/Incoming/Inbound and manual/ (are not affected by this option.) - s/only through network/only to network/ - s/this option. This option/this option. It/ - s/network types/networks/ and pick up a few nits in `doc/p2p-bad-ports.md` from bitcoin/bitcoin#23542 (review). ACKs for top commit: laanwj: ACK a1db99a w0xlt: ACK a1db99a theStack: ACK a1db99a Tree-SHA512: dd727904b9b3dadb16053e2b0350e6c0814ef68fb0cca7d34880b883123cfe3aa03b15813b40a863f6367d596d17ee4517eab55281cfe35cd00767b8a39593ca
…/i2p documentation a1db99a init, doc: improve -onlynet help and tor/i2p documentation (Jon Atack) Pull request description: including review feedback from bitcoin#22834 (comment) and bitcoin#24205 (comment) concerning `src/init.cpp`, `doc/tor.md` and `doc/i2p.md` - s/outgoing/automatic outbound/ - s/Incoming/Inbound and manual/ (are not affected by this option.) - s/only through network/only to network/ - s/this option. This option/this option. It/ - s/network types/networks/ and pick up a few nits in `doc/p2p-bad-ports.md` from bitcoin#23542 (review). ACKs for top commit: laanwj: ACK a1db99a w0xlt: ACK a1db99a theStack: ACK a1db99a Tree-SHA512: dd727904b9b3dadb16053e2b0350e6c0814ef68fb0cca7d34880b883123cfe3aa03b15813b40a863f6367d596d17ee4517eab55281cfe35cd00767b8a39593ca
…and safety 58a1479 test: passing -onlynet=onion with -onion=0/-noonion raises expected init error (Jon Atack) 7000f66 test: passing -onlynet=onion without -proxy/-onion raises expected init error (Jon Atack) 8332e6e test: passing invalid -onion raises expected init error (Jon Atack) d5edb08 test: passing invalid -proxy raises expected init error (Jon Atack) bd57dcb test: hoist proxy out of 2 network loops in feature_proxy.py (Jon Atack) afdf2de test: add CJDNS to LimitedAndReachable_Network unit tests (Jon Atack) 2b7a818 net, init: assert each network reachability is true by default (Jon Atack) Pull request description: Adds missing network reachability test coverage and an assertion during init, noticed while reviewing #22834: - assert during init that each network reachability is true by default - add CJDNS to the `LimitedAndReachable_Network` unit tests - hoist proxy out of two network loops in feature_proxy.py - test that passing invalid `-proxy` raises expected init error - test that passing invalid `-onion` raises expected init error - test that passing `-onlynet=onion` without `-proxy` and `-onion` raises expected init error - test that passing `-onlynet=onion` with `-onion=0` and with `-noonion` raises expected init error ACKs for top commit: vasild: ACK 58a1479 brunoerg: ACK 58a1479 dongcarl: Code Review ACK 58a1479 Tree-SHA512: bdee6dd0c12bb63591ce7c9321fe77b509ab1265123054e774adc38a187746dddafe1627cbe89e990bcc78b45e194bfef8dc782710d5b217e2e2106ab0158827
…verage and safety 58a1479 test: passing -onlynet=onion with -onion=0/-noonion raises expected init error (Jon Atack) 7000f66 test: passing -onlynet=onion without -proxy/-onion raises expected init error (Jon Atack) 8332e6e test: passing invalid -onion raises expected init error (Jon Atack) d5edb08 test: passing invalid -proxy raises expected init error (Jon Atack) bd57dcb test: hoist proxy out of 2 network loops in feature_proxy.py (Jon Atack) afdf2de test: add CJDNS to LimitedAndReachable_Network unit tests (Jon Atack) 2b7a818 net, init: assert each network reachability is true by default (Jon Atack) Pull request description: Adds missing network reachability test coverage and an assertion during init, noticed while reviewing bitcoin#22834: - assert during init that each network reachability is true by default - add CJDNS to the `LimitedAndReachable_Network` unit tests - hoist proxy out of two network loops in feature_proxy.py - test that passing invalid `-proxy` raises expected init error - test that passing invalid `-onion` raises expected init error - test that passing `-onlynet=onion` without `-proxy` and `-onion` raises expected init error - test that passing `-onlynet=onion` with `-onion=0` and with `-noonion` raises expected init error ACKs for top commit: vasild: ACK 58a1479 brunoerg: ACK 58a1479 dongcarl: Code Review ACK 58a1479 Tree-SHA512: bdee6dd0c12bb63591ce7c9321fe77b509ab1265123054e774adc38a187746dddafe1627cbe89e990bcc78b45e194bfef8dc782710d5b217e2e2106ab0158827
Do not make outbound connections to hosts which belong to a network
which is restricted by
-onlynet
.This applies to hosts that are automatically chosen to connect to and to
anchors.
This does not apply to hosts given to
-connect
,-addnode
,addnode
RPC, dns seeds,-seednode
.Fixes #13378
Fixes #22647
Supersedes #22651