mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #16702: p2p: supplying and using asmap to improve IP bucketing in addrman
3c1bc40205Add extra logging of asmap use and bucketing (Gleb Naumenko)e4658aa8eaReturn mapped AS in RPC call getpeerinfo (Gleb Naumenko)ec45646de9Integrate ASN bucketing in Addrman and add tests (Gleb Naumenko)8feb4e4b66Add 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-ACK3c1bc40205jamesob: ACK3c1bc40205([`jamesob/ackr/16702.3.naumenkogs.p2p_supplying_and_using`](https://github.com/jamesob/bitcoin/tree/ackr/16702.3.naumenkogs.p2p_supplying_and_using)) jonatack: ACK3c1bc40205Tree-SHA512: e2dc6171188d5cdc2ab2c022fa49ed73a14a0acb8ae4c5ffa970172a0365942a249ad3d57e5fb134bc156a3492662c983f74bd21e78d316629dcadf71576800c
This commit is contained in:
@@ -83,6 +83,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||
" \"addr\":\"host:port\", (string) The IP address and port of the peer\n"
|
||||
" \"addrbind\":\"ip:port\", (string) Bind address of the connection to the peer\n"
|
||||
" \"addrlocal\":\"ip:port\", (string) Local address as reported by the peer\n"
|
||||
" \"mapped_as\":\"mapped_as\", (string) The AS in the BGP route to the peer used for diversifying peer selection\n"
|
||||
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
|
||||
" \"servicesnames\":[ (array) the services offered, in human-readable form\n"
|
||||
" \"SERVICE_NAME\", (string) the service name if it is recognised\n"
|
||||
@@ -152,6 +153,9 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||
obj.pushKV("addrlocal", stats.addrLocal);
|
||||
if (stats.addrBind.IsValid())
|
||||
obj.pushKV("addrbind", stats.addrBind.ToString());
|
||||
if (stats.m_mapped_as != 0) {
|
||||
obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
|
||||
}
|
||||
obj.pushKV("services", strprintf("%016x", stats.nServices));
|
||||
obj.pushKV("servicesnames", GetServicesNames(stats.nServices));
|
||||
obj.pushKV("relaytxes", stats.fRelayTxes);
|
||||
|
||||
Reference in New Issue
Block a user