This adds a new binary, bitcoin-asmap
that can be used to construct, inspect, and query asmap files. It replaces the Python scripts I had at https://github.com/sipa/asmap with something more performant, efficient, and auditable.
There are some rough edges still (in particular documenting the code and a number of edge cases), but I’d like to offer it for comments here. I’m not sure we want this code to be part of the Bitcoin Core codebase, but it certainly has advantages (in terms of code reuse and having consistent encoder/decoder). I think it may also be beneficial that users have a way to audit these files using code that’s subject to our review and testing process.
This PR includes a fuzz test that verifies (for small, reduced inputs) that encoding produces asmap files consistent with their input, that invoking the interpreter on them works as expected, and that decoding and re-encoding does not change their behavior.
Given a text file asmap.txt
with lines like these:
0193.189.95.0/24 AS34906
1193.189.96.0/24 AS20850
2193.189.98.0/23 AS33925
3193.190.0.0/15 AS2611
4193.19.102.0/23 AS20485
5193.19.103.0/24 AS8342
6193.19.106.0/23 AS3257
You can run bitcoin-asmap encode asmap.dat <asmap.txt
to construct an asmap file in a few seconds. bitcoin-asmap decode asmap.dat
will decode it back to the original format (note however that the result may look very different, as unassigned IP ranges get remapped for efficiency). bitcoin-asmap lookup asmap.dat 193.190.253.208
will look up one entry in it.
There is code at https://github.com/rrybarczyk/asmap-rs (by @rrybarczyk and @naumenkogs) to build input for this tool using RIPE’s dumps of Internet routing tables.