Skip to content

net: Check an assumed onion inbound's source address under -v2onlyclearnet - #454

Open
LionThunderFingers wants to merge 2 commits into
bitcoinknots:29.x-knotsfrom
LionThunderFingers:fix/v2onlyclearnet-assumed-onion-inbound
Open

LionThunderFingers wants to merge 2 commits into
bitcoinknots:29.x-knotsfrom
LionThunderFingers:fix/v2onlyclearnet-assumed-onion-inbound

Conversation

@LionThunderFingers

@LionThunderFingers LionThunderFingers commented Oct 8, 2026 •

Copy link
Copy Markdown

Fixes #427.

What it changes:

  • net.cpp: if a peer only counts as onion because there's no =onion bind, the peer is now flagged with m_inbound_onion_assumed. Peers connecting from the bind address itself don't get the flag.
  • net_processing.cpp: the inbound v1 check also drops the peer if it is m_inbound_onion_assumed and RequiresV2Peer(pfrom.addr.GetNetClass()) is true, i.e. its real address is public IPv4/IPv6. Local and private addresses where Tor connects from still pass.

Tested with public addresses in two network namespaces, regtest, -bind=1.2.3.4:18444 -v2onlyclearnet=1:

peer rc1 rc1 + this
v1 from 5.6.7.8 (public) stays connected dropped
v1 from 172.17.0.2 (private) stays stays
v1 from 1.2.3.4 (the bind address) stays stays
v2 from 5.6.7.8 stays stays

Two cases added to v2onlyclearnet_inbound_v1 (the public-address one fails without the change). Standard test suite passes.

kwsantiago and others added 2 commits October 12, 2026 09:25
…arnet

Without a -bind=...=onion listener, an inbound connection on the first
-bind is treated as onion, and for a bind that is not bind-any every
inbound connection there is. -v2onlyclearnet then exempted all of them
from its inbound v1 check, so a clearnet peer could stay connected over
v1 (knots#427).

Keep that assumption everywhere else, but for the v1 check also judge an
assumed onion inbound by its source address. Tor reaches the node from
this host or a private address, which stays exempt; any other public
source address is a clearnet peer. Inbound connections on an explicit
-bind=...=onion listener are unchanged.

Fixes bitcoinknots#427
@kwsantiago

Copy link
Copy Markdown

Please rebase onto the oldest commit this applies to rather than the 29.x-knots tip, which the spec assembler cannot merge. It needs v2onlyclearnet-29+knots and fix_tor_common_bind-29.2: merging both and picking this on top applies cleanly.

@LionThunderFingers
LionThunderFingers force-pushed the fix/v2onlyclearnet-assumed-onion-inbound branch from 3ef3079 to fc74e6f Compare October 13, 2026 07:18
@LionThunderFingers

Copy link
Copy Markdown
Author

Saw you'd already rebased it in v2onlyclearnet_assumed_onion-29+knots, so I've pushed that here (fc74e6f). Unit tests and the p2p_v2_* functional tests pass on it.

@kwsantiago kwsantiago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested ACK fc74e6f merged into 29.x-knots. With -bind=1.2.3.4 -v2onlyclearnet=1, a v1 inbound from public 5.6.7.8 is now dropped instead of kept as onion; private, bind-address, loopback and v2 peers still connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-v2onlyclearnet: inbound v1 rule skipped when a specific -bind marks peers as onion

2 participants