diff options
Diffstat (limited to 'src/addrman.h')
-rw-r--r-- | src/addrman.h | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/addrman.h b/src/addrman.h index 2548b891ba..0885231ebc 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -6,23 +6,16 @@ #ifndef BITCOIN_ADDRMAN_H #define BITCOIN_ADDRMAN_H -#include <clientversion.h> -#include <config/bitcoin-config.h> #include <fs.h> -#include <hash.h> +#include <logging.h> #include <netaddress.h> #include <protocol.h> -#include <random.h> -#include <streams.h> #include <sync.h> #include <timedata.h> -#include <tinyformat.h> -#include <util/system.h> -#include <iostream> +#include <cstdint> #include <optional> #include <set> -#include <stdint.h> #include <unordered_map> #include <vector> @@ -149,32 +142,13 @@ static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2}; class CAddrMan { public: - // Compressed IP->ASN mapping, loaded from a file when a node starts. - // Should be always empty if no file was provided. - // This mapping is then used for bucketing nodes in Addrman. - // - // 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 was provided, the existing records - // would be re-bucketed accordingly. - std::vector<bool> m_asmap; - - // Read asmap from provided binary file - static std::vector<bool> DecodeAsmap(fs::path path); - template <typename Stream> void Serialize(Stream& s_) const EXCLUSIVE_LOCKS_REQUIRED(!cs); template <typename Stream> void Unserialize(Stream& s_) EXCLUSIVE_LOCKS_REQUIRED(!cs); - explicit CAddrMan(bool deterministic, int32_t consistency_check_ratio); + explicit CAddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio); ~CAddrMan() { @@ -296,6 +270,8 @@ public: Check(); } + const std::vector<bool>& GetAsmap() const { return m_asmap; } + private: //! A mutex to protect the inner data structures. mutable Mutex cs; @@ -363,6 +339,22 @@ private: /** Perform consistency checks every m_consistency_check_ratio operations (if non-zero). */ const int32_t m_consistency_check_ratio; + // Compressed IP->ASN mapping, loaded from a file when a node starts. + // Should be always empty if no file was provided. + // This mapping is then used for bucketing nodes in Addrman. + // + // 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 was provided, the existing records + // would be re-bucketed accordingly. + const std::vector<bool> m_asmap; + //! Find an entry. CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs); |