diff options
author | John Newbery <john@johnnewbery.com> | 2021-08-31 18:40:18 +0100 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2022-04-20 14:29:29 +0100 |
commit | 19431560e3e1124979c60f39eca9429c4a0df29f (patch) | |
tree | 200eb5df7f34cd71a6b6c66cf37cbc44ee8c7ed8 /src/netgroup.h | |
parent | 17c24d458042229e00dd4e0b75a32e593be29564 (diff) | |
download | bitcoin-19431560e3e1124979c60f39eca9429c4a0df29f.tar.xz |
[net] Move asmap into NetGroupManager
Diffstat (limited to 'src/netgroup.h')
-rw-r--r-- | src/netgroup.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/netgroup.h b/src/netgroup.h index 1fd3470e0f..fcf46bb2bb 100644 --- a/src/netgroup.h +++ b/src/netgroup.h @@ -5,9 +5,41 @@ #ifndef BITCOIN_NETGROUP_H #define BITCOIN_NETGROUP_H +#include <vector> + /** * Netgroup manager */ -class NetGroupManager {}; +class NetGroupManager { +public: + explicit NetGroupManager(std::vector<bool> asmap) + : m_asmap{std::move(asmap)} + {} + + /* Get a reference to (const) asmap. May be held as long as NetGroupManager + * exists, since the data is const. */ + const std::vector<bool>& GetAsmap() const { return m_asmap; } + +private: + /** Compressed IP->ASN mapping, loaded from a file when a node starts. + * + * This mapping is then used for bucketing nodes in Addrman and for + * ensuring we connect to a diverse set of peers in Connman. The map is + * empty if no file was provided. + * + * If asmap is provided, nodes will be bucketed by AS they belong to, in + * order to make impossible for a node to connect to several nodes hosted + * in a single AS. This is done in response to Erebus attack, but also to + * generally diversify the connections every node creates, especially + * useful when a large fraction of nodes operate under a couple of cloud + * providers. + * + * If a new asmap is provided, the existing addrman records are + * re-bucketed. + * + * This is initialized in the constructor, const, and therefore is + * thread-safe. */ + const std::vector<bool> m_asmap; +}; #endif // BITCOIN_NETGROUP_H |