Skip to content

Commit 6593293

Browse files
committed
Merge bitcoin/bitcoin#32110: contrib: document asmap-tool commands more thoroughly
6afffba contrib: (asmap) add docs about encode and decode commands (jurraca) 67d5cc2 contrib: (asmap) add documentation on diff and diff-addrs commands (jurraca) e047b1d contrib: (asmap) add diff-addrs example to README (jurraca) Pull request description: This README was a little sparse in my opinion, and was missing a mention of the `diff-addrs` command. The README updates add background and examples for each command, split in two sections (encode/decode and diff/diff-addrs). This is intended to help people know how and when to run the commands available in the `asmap-tool.py` script. However, I could use some confirmation on the behavior of the `--fill` flag. It's true that files generated with this flag set cannot be used to diff files after the fact, but i don't quite follow what the fill flag does to make that true. sipa could you maybe provide some insight? ACKs for top commit: fjahr: re-ACK 6afffba brunoerg: reACK 6afffba laanwj: re-ACK 6afffba Tree-SHA512: 073e8d7255f7270aa2f5a070332872f5fa6fbe6532eee1f7e3e4158ac0125a49c155f4933bf00655ff3a89f666f3f3bea521e70c516ab09a448845016d2b880a
2 parents c8ade10 + 6afffba commit 6593293

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

contrib/asmap/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,75 @@ Example usage:
99
python3 asmap-tool.py encode /path/to/input.file /path/to/output.file
1010
python3 asmap-tool.py decode /path/to/input.file /path/to/output.file
1111
python3 asmap-tool.py diff /path/to/first.file /path/to/second.file
12+
python3 asmap-tool.py diff-addrs /path/to/first.file /path/to/second.file addrs.file
13+
```
14+
These commands may take a few minutes to run with `python3`,
15+
depending on the amount of data involved and your machine specs.
16+
Consider using `pypy3` for a faster run time.
17+
18+
### Encoding and Decoding
19+
20+
ASmap files are somewhat large in text form, and need to be encoded
21+
to binary before being used with Bitcoin Core.
22+
23+
The `encode` command takes an ASmap and an output file.
24+
25+
The `--fill`/`-f` flag further reduces the size of the output file
26+
by assuming an AS assignment for an unmapped network if an adjacent network is assigned.
27+
This procedure is lossy, in the sense that it loses information
28+
about which ranges were unassigned.
29+
However, if the input ASmap is incomplete,
30+
this procedure will also reassign ranges that should have an AS assignment,
31+
resulting in an ASmap that may diverge from reality significantly.
32+
Finally, another consequence is that the resulting encoded file
33+
will no longer be meaningful for diffs.
34+
Therefore only use `--fill` if
35+
you want to optimise space, you have a reasonably complete ASmap,
36+
and do not intend to diff the file at a later time.
37+
38+
The `decode` command takes an encoded ASmap and an output file.
39+
As with `encode`, the `--fill`/`-f` flag reduces the output file size
40+
by reassigning subnets. Conversely, the `--non-overlapping`/`-n` flag
41+
increases output size by outputting strictly non-overlapping network ranges.
42+
43+
### Comparing ASmaps
44+
45+
AS control of IP networks changes frequently, therefore it can be useful to get
46+
the changes between to ASmaps via the `diff` and `diff_addrs` commands.
47+
48+
`diff` takes two ASmap files, and returns a file detailing the changes
49+
in the state of a network's AS assignment between the first and the second file.
50+
This command may take a few minutes to run, depending on your machine.
51+
52+
The example below shows the three possible output states:
53+
- reassigned to a new AS (`AS26496 # was AS20738`),
54+
- present in the first but not the second (`# 220.157.65.0/24 was AS9723`),
55+
- or present in the second but not the first (`# was unassigned`).
56+
57+
```
58+
217.199.160.0/19 AS26496 # was AS20738
59+
# 220.157.65.0/24 was AS9723
60+
216.151.172.0/23 AS400080 # was unassigned
61+
2001:470:49::/48 AS20205 # was AS6939
62+
# 2001:678:bd0::/48 was AS207631
63+
2001:67c:308::/48 AS26496 # was unassigned
64+
```
65+
`diff` accepts a `--ignore-unassigned`/`-i` flag
66+
which ignores networks present in the second but not the first.
67+
68+
`diff_addrs` is intended to provide changes between two ASmaps and
69+
a node's known peers.
70+
The command takes two ASmap files, and a file of IP addresses as output by
71+
the `bitcoin-cli getnodeaddresses` command.
72+
It returns the changes between the two ASmaps for the peer IPs provided in
73+
the `getnodeaddresses` output.
74+
The resulting file is in the same format as the `diff` command shown above.
75+
76+
You can output address data to a file:
77+
```
78+
bitcoin-cli getnodeaddresses 0 > addrs.json
79+
```
80+
and pass in the address file as the third argument:
81+
```
82+
python3 asmap-tool.py diff_addrs path/to/first.file path/to/second.file addrs.json
1283
```

0 commit comments

Comments
 (0)