net: advertise CJDNS addresses when -externalip disables discovery #34812

pull w0xlt wants to merge 3 commits into bitcoin:master from w0xlt:fix-33471-cjdns-externalip changing 4 files +136 −5
  1. w0xlt commented at 1:51 am on March 12, 2026: contributor

    Fixes #33471

    When -externalip is set, -discover is implicitly disabled. This prevents CJDNS bound addresses from being added to localaddresses, so the node never advertises itself on the CJDNS network - even though outbound CJDNS connections work fine.

    CJDNS addresses live on a separate overlay network and don’t conflict with manually specified external IPs, so there is no reason to suppress them. This PR adds CJDNS exceptions to the three code paths in net.cpp that gate on fDiscover:

    • AddLocal() — accept CJDNS regardless of fDiscover
    • Discover() — don’t skip CJDNS-prefixed interfaces when !fDiscover
    • Bind() — call AddLocal() for CJDNS bound addresses when !fDiscover

    Note to reviewers: the functional test (feature_cjdns_externalip.py) requires Docker to create an fc00::/8 bridge interface and is skipped when Docker is unavailable. It is included so reviewers can easily verify the fix end-to-end, but can be easily dropped (it’s in a separate commit) if the dependency is unwanted. Note that this test cannot be run in CI containers.

  2. net: allow CJDNS addresses when -externalip disables discovery
    When -externalip is set, -discover is implicitly disabled. This
    prevented CJDNS addresses from being registered in mapLocalHost
    (shown in the localaddresses RPC field), even though CJDNS operates
    on a separate overlay network unrelated to the node's public
    IPv4/IPv6 address.
    
    Note: registering in mapLocalHost is a prerequisite for address
    advertisement, but GetLocal() already ensures CJDNS addresses are
    only advertised to CJDNS peers (privacy network isolation).
    
    Fix three code paths that blocked CJDNS when fDiscover was false:
    
    - Discover(): skip the early return for CJDNS-prefix addresses
    - AddLocal(): allow CJDNS addresses regardless of discovery score
    - Bind(): register bound CJDNS addresses even without discovery
    a525b06892
  3. DrahtBot commented at 1:52 am on March 12, 2026: contributor

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

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34458 (net: Don’t log own ips during discover by sedited)
    • #34028 (p2p: Prevent integer overflow in LocalServiceInfo::nScore by codeabysss)

    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.

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • Lookup(“fc00:1122:3344:5566:7788:9900:aabb:ccdd”, 8333, false) in src/test/net_tests.cpp
    • UtilBuildAddress(0x003, 0x001, 0x001, 0x001) in src/test/net_tests.cpp

    2026-03-12 08:22:37

  4. DrahtBot added the label CI failed on Mar 12, 2026
  5. w0xlt marked this as a draft on Mar 12, 2026
  6. w0xlt force-pushed on Mar 12, 2026
  7. test: add functional test for CJDNS address with -externalip
    Verify that a CJDNS address bound via -bind is registered in
    localaddresses even when -externalip is set (which disables
    -discover). The test creates a Docker network with an fc00::/8
    subnet to provide a bindable CJDNS-prefix address.
    7f898e23fc
  8. test: unit test AddLocal() accepts CJDNS when fDiscover is false
    Verify that AddLocal() registers a CJDNS address with LOCAL_IF score
    even when fDiscover is false, while still rejecting a regular IPv4
    address under the same conditions.
    
    This runs in CI without special network setup (unlike the functional
    test which requires a bindable fc00::/8 address on a local interface).
    0513c9f14f
  9. w0xlt force-pushed on Mar 12, 2026
  10. w0xlt marked this as ready for review on Mar 12, 2026
  11. DrahtBot removed the label CI failed on Mar 12, 2026
  12. DrahtBot added the label P2P on Mar 12, 2026
  13. w0xlt commented at 5:36 pm on March 12, 2026: contributor

    To reproduce the error and verify the fix manually, run ./build/bin/bitcoind -cjdnsreachable -externalip=<ip> -daemon and then ./build/bin/bitcoin-cli getnetworkinfo | jq '.localaddresses'.

    On master, the fc00:: address is missing. In this branch, both fc00:: and <ip> appear.

  14. luke-jr commented at 4:39 pm on March 18, 2026: member
    Why wouldn’t this also apply to Tor?
  15. w0xlt commented at 0:32 am on March 19, 2026: contributor
    Tor onion services are handled differently. The automatically created onion service is added in TorController::add_onion_cb() via AddLocal(service,LOCAL_MANUAL), so it does not hit the fDiscover check in AddLocal(), because that check only rejects addresses with nScore < LOCAL_MANUAL.
  16. DrahtBot added the label Needs rebase on Mar 26, 2026
  17. DrahtBot commented at 7:41 pm on March 26, 2026: contributor
    🐙 This pull request conflicts with the target branch and needs rebase.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-03-30 12:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me