bitcoin/src
Wladimir J. van der Laan 01fc5891fb
Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman
3c1bc40205 Add extra logging of asmap use and bucketing (Gleb Naumenko)
e4658aa8ea Return mapped AS in RPC call getpeerinfo (Gleb Naumenko)
ec45646de9 Integrate ASN bucketing in Addrman and add tests (Gleb Naumenko)
8feb4e4b66  Add asmap utility which queries a mapping (Gleb Naumenko)

Pull request description:

  This PR attempts to solve the problem explained in #16599.
  A particular attack which encouraged us to work on this issue is explained here  [[Erebus Attack against Bitcoin Peer-to-Peer Network](https://erebus-attack.comp.nus.edu.sg/)] (by @muoitranduc)

  Instead of relying on /16 prefix to diversify the connections every node creates, we would instead rely on the (ip -> ASN) mapping, if this mapping is provided.

  A .map file can be created by every user independently based on a router dump, or provided along with the Bitcoin release. Currently we use the python scripts written by @sipa to create a .map file, which is no larger than 2MB (awesome!).

  Here I suggest adding a field to peers.dat which would represent a hash of asmap file used while serializing addrman (or 0 for /16 prefix legacy approach).
  In this case, every time the file is updated (or grouping method changed), all buckets will be re-computed.
  I believe that alternative selective re-bucketing for only updated ranges would require substantial changes.

  TODO:
  - ~~more unit tests~~
  - ~~find a way to test the code without including >1 MB mapping file in the repo.~~
  - find a way to check that mapping file is not corrupted (checksum?)
  - comments and separate tests for asmap.cpp
  - make python code for .map generation public
  - figure out asmap distribution (?)

  ~Interesting corner case: I’m using std::hash to compute a fingerprint of asmap, and std::hash returns size_t. I guess  if a user updates the OS to 64-bit, then the hash of asap will change? Does it even matter?~

ACKs for top commit:
  laanwj:
    re-ACK 3c1bc40205
  jamesob:
    ACK 3c1bc40205 ([`jamesob/ackr/16702.3.naumenkogs.p2p_supplying_and_using`](https://github.com/jamesob/bitcoin/tree/ackr/16702.3.naumenkogs.p2p_supplying_and_using))
  jonatack:
    ACK 3c1bc40205

Tree-SHA512: e2dc6171188d5cdc2ab2c022fa49ed73a14a0acb8ae4c5ffa970172a0365942a249ad3d57e5fb134bc156a3492662c983f74bd21e78d316629dcadf71576800c
2020-01-29 13:55:43 +01:00
..
bench Fix benchmarks filters 2020-01-28 17:10:15 +02:00
compat scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
config
consensus scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
crypto Merge #17691: doc: Add missed copyright headers 2020-01-16 15:58:35 -05:00
index scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
interfaces scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
leveldb Pull leveldb subtree 2019-01-26 12:45:48 -05:00
logging scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
node Merge #17156: psbt: check that various indexes and amounts are within bounds 2020-01-29 19:39:50 +08:00
policy scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
primitives scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
qt Merge #17453: gui: Fix intro dialog labels when the prune button is toggled 2020-01-27 18:15:45 +01:00
rpc Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
script Fix doxygen errors 2020-01-16 18:25:11 -08:00
secp256k1 Update the secp256k1 subtree to the latest upstream version 2019-03-31 11:41:05 -07:00
support scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
test Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
univalue Update univalue subtree 2019-10-30 16:24:02 -04:00
util Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
wallet Merge #17156: psbt: check that various indexes and amounts are within bounds 2020-01-29 19:39:50 +08:00
zmq scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
.clang-format util: Add AllowShortCaseLabelsOnASingleLine option 2019-10-14 13:24:54 +03:00
addrdb.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
addrdb.h Convert addrdb/addrman to new serialization 2020-01-02 11:05:36 -08:00
addrman.cpp Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
addrman.h Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
amount.h Update copyright headers to 2018 2018-12-29 10:15:01 +01:00
arith_uint256.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
arith_uint256.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
attributes.h Add NODISCARD to all {Decode,Parse}[...](...) functions returning bool. Sort includes. 2018-11-05 17:03:11 +01:00
banman.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
banman.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
base58.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
base58.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bech32.cpp Add some general std::vector utility functions 2019-10-16 08:56:57 -07:00
bech32.h Assert that the HRP is lowercase in Bech32::Encode 2019-09-05 13:25:11 +12:00
bitcoin-cli-res.rc
bitcoin-cli.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bitcoin-tx-res.rc
bitcoin-tx.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bitcoin-wallet-res.rc [tools] Add wallet inspection and modification tool 2019-01-30 16:26:52 -05:00
bitcoin-wallet.cpp bitcoin-wallet: Use PACKAGE_NAME in usage help 2020-01-14 18:19:00 +00:00
bitcoind-res.rc
bitcoind.cpp Merge #16839: Replace Connman and BanMan globals with NodeContext local 2019-10-30 12:35:41 +01:00
blockencodings.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
blockencodings.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
blockfilter.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
blockfilter.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bloom.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
bloom.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chain.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chain.h Convert chain to new serialization 2020-01-13 08:24:44 -08:00
chainparams.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chainparams.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chainparamsbase.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chainparamsbase.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
chainparamsseeds.h contrib: Remove invalid nodes from seeds list 2019-10-02 08:51:12 +02:00
checkqueue.h refactor: Remove redundant conditional 2020-01-21 14:07:42 +00:00
clientversion.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
clientversion.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
coins.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
coins.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
compat.h windows: Set _WIN32_WINNT to 0x0601 (Windows 7) 2019-01-23 16:28:27 +08:00
compressor.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
compressor.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
core_io.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
core_memusage.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
core_read.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
core_write.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
cuckoocache.h Use correct C++11 header for std::swap() 2019-11-29 21:23:25 +02:00
dbwrapper.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
dbwrapper.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
dummywallet.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
flatfile.cpp Style cleanup. 2019-02-22 17:38:45 -08:00
flatfile.h Style cleanup. 2019-02-22 17:38:45 -08:00
fs.cpp scripted-diff: Add missed copyright headers 2020-01-04 20:18:28 +02:00
fs.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
hash.cpp Extract CSipHasher to it's own file in crypto/ directory. 2018-11-05 09:25:15 -08:00
hash.h Squashed 'src/secp256k1/' changes from 0b70241850..b19c000063 2019-03-31 11:41:05 -07:00
httprpc.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
httprpc.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
httpserver.cpp net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface 2020-01-08 12:35:59 +00:00
httpserver.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
indirectmap.h
init.cpp Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
init.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
key.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
key.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
key_io.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
key_io.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
limitedmap.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
logging.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
logging.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
Makefile.am Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
Makefile.bench.include [test] move wallet helper functions into test library 2019-11-25 16:40:09 +01:00
Makefile.leveldb.include build: Remove WINVER pre define in Makefile.leveldb.inlcude 2019-01-26 09:28:48 +08:00
Makefile.qt.include Merge #17513: refactor, qt: Nuke some circular dependencies 2019-11-21 19:38:39 +01:00
Makefile.qt_locale.include Restore English translation option 2020-01-06 22:58:47 -05:00
Makefile.qttest.include build: Create test utility library from src/test/util/ 2019-11-21 21:13:08 +01:00
Makefile.test.include Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
Makefile.test_util.include [test] move wallet helper functions into test library 2019-11-25 16:40:09 +01:00
memusage.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
merkleblock.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
merkleblock.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
miner.cpp rpc: Remove mempool global from miner 2019-12-23 06:12:10 +07:00
miner.h rpc: Remove mempool global from miner 2019-12-23 06:12:10 +07:00
net.cpp Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
net.h Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
net_permissions.cpp net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface 2020-01-08 12:35:59 +00:00
net_permissions.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
net_processing.cpp Fix doxygen errors 2020-01-16 18:25:11 -08:00
net_processing.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
net_types.h refactor: Remove addrdb.h dependency from node.h 2019-10-29 11:30:12 +02:00
netaddress.cpp Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
netaddress.h Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman 2020-01-29 13:55:43 +01:00
netbase.cpp Merge #17754: net: Don't allow resolving of std::string with embedded NUL characters. Add tests. 2020-01-22 20:20:45 +01:00
netbase.h net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface 2020-01-08 12:35:59 +00:00
netmessagemaker.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
noui.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
noui.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
optional.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
outputtype.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
outputtype.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
pow.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
pow.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
prevector.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
protocol.cpp p2p: Remove BIP61 reject messages 2019-10-02 10:39:14 -04:00
protocol.h Merge #17474: Bugfix: GUI: Recognise NETWORK_LIMITED in formatServicesStr 2019-12-11 17:00:27 -05:00
psbt.cpp Merge #17156: psbt: check that various indexes and amounts are within bounds 2020-01-29 19:39:50 +08:00
psbt.h Fix doxygen errors 2020-01-16 18:25:11 -08:00
pubkey.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
pubkey.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
random.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
random.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
randomenv.cpp Put bounds on the number of CPUID leaves explored 2019-11-20 10:54:08 -08:00
randomenv.h [MOVEONLY] Move perfmon data gathering to new randomenv module 2019-11-12 14:50:44 -08:00
rest.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
reverse_iterator.h scripted-diff: Remove trailing whitespaces 2018-07-24 20:46:23 +01:00
reverselock.h
scheduler.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
scheduler.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
serialize.h Convert VARINT to the formatter/Using approach 2020-01-13 08:24:44 -08:00
shutdown.cpp Break circular dependency: init -> * -> init by extracting shutdown.h 2018-06-25 00:08:49 -04:00
shutdown.h Break circular dependency: init -> * -> init by extracting shutdown.h 2018-06-25 00:08:49 -04:00
span.h Add more methods to Span class 2018-07-27 11:52:18 -07:00
streams.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
sync.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
sync.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
threadinterrupt.cpp Merge #11640: Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection 2018-08-31 16:00:38 +02:00
threadinterrupt.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
threadsafety.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
timedata.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
timedata.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
tinyformat.h util: Update tinyformat to upstream 2019-12-06 10:02:08 +01:00
torcontrol.cpp net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface 2020-01-08 12:35:59 +00:00
torcontrol.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
txdb.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
txdb.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
txmempool.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
txmempool.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
ui_interface.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
ui_interface.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
uint256.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
uint256.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
undo.h Extract CSipHasher to it's own file in crypto/ directory. 2018-11-05 09:25:15 -08:00
validation.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
validation.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
validationinterface.cpp scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
validationinterface.h scripted-diff: Bump copyright of files changed in 2020 2020-01-15 02:18:00 +07:00
version.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
versionbits.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
versionbits.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
versionbitsinfo.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
versionbitsinfo.h MOVEONLY: Move versionbits info out of versionbits.o 2018-09-23 22:55:11 +02:00
walletinitinterface.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
warnings.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
warnings.h scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00