WIP: Remove CNode dependency for local address functions and introduce LocalAddressManager

bitcoin/bitcoin: PR #35040

1 minor finding · 3 suggestions

Findings

Link

[minor] · Renamed log line breaks the documented AddLocal search

With -logips enabled, the documented AddLocal search no longer finds newly logged onion or I2P addresses, although getnetworkinfo and -netinfo remain available.

Location: src/local_addresses.cpp:73 (head).

Details and suggested fix

doc/tor.md and doc/i2p.md still tell users to grep the debug log for AddLocal. This line previously emitted AddLocal(%s,%i), but now emits LocalAddressManager: Adding %s (Score: %i), so following those instructions misses the address even when IP logging is enabled. Update both documents to search for the new token in the same change.


Optional improvements

Link

[suggestion] · Inbound-Tor network contract is undocumented and untested at the adapter

No current caller supplies the wrong network, but Get() leaves its privacy-sensitive connected_through contract undocumented, and the tests bypass the adapter that must supply it.

Location: src/local_addresses.h:48 (head).

Details and suggested fix

connected_through must describe the connection network, not simply addr.GetNetClass(). For an inbound Tor peer at 127.0.0.1, the latter returns NET_UNROUTABLE rather than NET_ONION. Passing it would admit a stored IPv4 address and exclude the onion address. The explicit Get(addr_ipv4, NET_ONION) checks and separate ConnectedThroughNetwork() assertion would still pass if only GetLocalAddrForPeer() supplied the wrong argument.

Document this distinction on Get() and add a test invoking GetLocalAddrForPeer() with an INBOUND loopback CNode, inbound_onion=true, listening enabled, and successfully added IPv4 and onion entries in the global manager. Assert that it returns the onion address, not IPv4. Loopback makes IsPeerAddrLocalGood() false, so peer-reported discovery cannot mask the selection. This protects the adapter while keeping the manager independent of CNode.


Link

[suggestion] · File extraction leaves a module cycle until the final commit

Moving the globals prerequisite earlier would expose the intended dependency boundary immediately and avoid the intermediate lint failure inferred from source; the final tree already removes the cycle.

Location: src/local_addresses.cpp:9 at 317f80525fff (commit) (commit).

Details and suggested fix

317f80525fffe1858477f2d6afdce4ba8e6c9b85 introduces local_addresses -> net -> local_addresses. The cycle remains at 24a168a4bad7fe1e39cf0f8c82409a34020c41db and is removed only by the final globals extraction, dd8968cbd9dc19a4ab91b86080bf9271cdd8b2a2. The circular-dependency lint combines corresponding .cpp and .h files into modules and rejects this unallowlisted cycle. This is an intermediate review-flow issue, not a head defect; lint was not run.

Move the fDiscover, fListen, and strSubVersion extraction into netglobals.h/.cpp before 317f80525fffe1858477f2d6afdce4ba8e6c9b85, including its CMake entry and consumer includes. In the file-extraction commit, temporarily move the map and mutex declarations to local_addresses.h and replace the implementation's net.h include with the required netglobals.h, netbase.h, sync.h, and protocol.h dependencies. protocol.h is needed while the API still takes CAddress. Keep their later privatization in d57ace41f0f9b0a17f564287ef0bb60f814c44c7. This preserves the staged removal of direct map users while making the extracted module independently reviewable from its introduction.


Link

[suggestion] · Privacy accessors lose their last callers

The refactor leaves CNode::IsConnectedThroughPrivacyNet() unused, and CNetAddr::IsPrivacyNet() now serves only that dead method.

Location: src/net.cpp:178 (base).

Details and suggested fix

GetLocal() was the last live user of these accessors. Its replacement uses IsPrivacyNetwork() with the supplied connection network, leaving an unused public CNode method and its otherwise-unused address wrapper. Remove both accessors as part of this refactor. This shrinks the CNode surface without changing behavior; privacy-network membership is already shared through IsPrivacyNetwork().


Coverage details