net: prevent ASMap group collisions and honor map filenames #37004

pull l0rinc wants to merge 9 commits into bitcoin:master from l0rinc:l0rinc/asmap-improvements changing 10 files +122 −61
  1. l0rinc commented at 8:38 PM on November 27, 2026: contributor

    Problem: A mapped autonomous system and an unmapped IPv6 /32 can share an address group, so the node treats unrelated peers as part of the same network when selecting connections. A node started with -asmap=2026-09-asmap.dat can also silently select the embedded map.

    Fix: Give mapped autonomous systems their own group tag. Nodes using ASMap rebucket stored peers once on upgrade or downgrade across this change.

    • Load digit-leading filenames from disk. -asmap, -asmap= and -asmap=1 still select the embedded map. -asmap=2 now names a file.
    • Report failed path lookups as missing files, and directories or read failures as invalid maps.
    • Require a new destination for exportasmap. A repeated export is cheap to regenerate, but exporting over a custom map silently changes what the node loads on restart. Callers reusing a path must first move or remove the file. Original overwrite rationale
    • Fix the decode --nonoverlapping documentation and help text, and describe how diff_addrs groups peers by their old and new AS assignments.

    I batched these fixes because I don't have the bandwidth to maintain several ASMap PRs. Feel free to carve out and merge individual commits. The ASMap optimizations can be merged independently.

  2. doc: correct asmap-tool decode and diff_addrs docs
    Use the accepted `--nonoverlapping` spelling and fix its help text.
    Describe how `diff_addrs` counts peer reassignments by their old and new AS numbers.
    e6966a8149
  3. test: characterize digit-leading ASMap filenames
    Exercise the existing relative-path and embedded-map cases alongside a dated filename that currently selects the embedded map.
    Without an embedded map, that filename makes startup fail even when the file exists.
    The exact value `1` requests the embedded map, while `./1` loads the file named `1`.
    9a6a2b8d3c
  4. init: load ASMap files with digit-leading names
    Reading `-asmap` as a boolean made a filename such as `2026-09-asmap.dat` select the embedded map.
    Keep the bare option, an explicitly empty value and the exact value `1` as requests for the embedded map. Other values, including `2`, now name files.
    81a507ab75
  5. test: characterize exportasmap overwrites
    Shorten the first export so a second export to the same path reveals whether the RPC replaced the file.
    928877f7fb
  6. rpc: refuse to overwrite files in exportasmap
    With `-asmap=asmap.dat`, running `exportasmap asmap.dat` replaces the configured map on disk with the embedded one.
    The running node keeps using the custom map until its next restart.
    
    The RPC originally allowed overwrites because another export from the same binary is cheap and produces the same bytes.
    Require a new destination to protect files the binary cannot regenerate. Callers that refresh an export at a fixed path must first move or remove the previous file.
    119cf8b050
  7. test: characterize invalid ASMap paths at startup
    Check that an overlong filename prevents startup without relying on platform-specific error text.
    Leave the directory case disabled because the result of trying to read a directory depends on the platform.
    e87fa7a992
  8. init: report unreadable ASMap files at startup
    Reject paths other than regular files before opening them.
    Report a failed path lookup with the existing missing-file error, and a directory or read failure with the existing parse error.
    9b4465d570
  9. test: characterize ASMap groups and bucket restoration
    Mapped AS numbers currently share the IPv6 group tag.
    Load the same saved peer with the version an ASMap node currently stores and with the raw ASMap hash, which are the same for now.
    Its saved position was computed without ASMap, so rebucketing it with ASMap would move it to a different bucket.
    482899178d
  10. net: give ASMap address groups a distinct tag
    An AS number and the /32 prefix of an IPv6 address outside the map can encode the same group.
    Reserve a tag outside the network classes for AS numbers.
    
    Change the bucketing version in `peers.dat` so upgrades and downgrades recalculate bucket placement for nodes using ASMap.
    Nodes without ASMap keep the null bucketing version and reuse their saved buckets.
    The `asmap_version` reported by `getnetworkinfo` still identifies the map itself.
    626ff9baa9
  11. DrahtBot added the label P2P on Nov 27, 2026
  12. DrahtBot commented at 8:38 PM on November 27, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


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-11-29 04:51 UTC

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