aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.h
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-09-06 12:41:31 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-09-06 12:41:36 +0200
commita8fdfea77b0cdfcbc406558435968c1b801a5fdd (patch)
treede829ce0c6de4c158c56d4300509e53578a09838 /src/addrman.h
parent2c6707be8b62ec56a6e2017b43c167b319ef17c3 (diff)
parent724c4975622bc22cedc3f3814dfc8e66cf8371f7 (diff)
downloadbitcoin-a8fdfea77b0cdfcbc406558435968c1b801a5fdd.tar.xz
Merge bitcoin/bitcoin#22791: init: Fix asmap/addrman initialization order bug
724c4975622bc22cedc3f3814dfc8e66cf8371f7 [fuzz] Add ConsumeAsmap() function (John Newbery) 5840476714ffebb2599999c85a23b52ebcff6090 [addrman] Make m_asmap private (John Newbery) f9002cb5dbd573cd9ca200de21319fa296e26055 [net] Rename the copyStats arg from m_asmap to asmap (John Newbery) f572f2b2048994b3b50f4cfd5de19e40b1acfb22 [addrman] Set m_asmap in CAddrMan initializer list (John Newbery) 593247872decd6d483a76e96d79433247226ad14 [net] Remove CConnMan::SetAsmap() (John Newbery) 50fd77045e2f858a53486b5e02e1798c92ab946c [init] Read/decode asmap before constructing addrman (John Newbery) Pull request description: Commit 181a1207 introduced an initialization order bug: CAddrMan's m_asmap must be set before deserializing peers.dat. The first commit restores the correct initialization order. The remaining commits make `CAddrMan::m_asmap` usage safer: - don't reach into `CAddrMan`'s internal data from `CConnMan` - set `m_asmap` in the initializer list and make it const - make `m_asmap` private, and access it (as a reference to const) from a getter. This ensures that peers.dat deserialization must happen after setting m_asmap, since m_asmap is set during CAddrMan construction. ACKs for top commit: mzumsande: Tested ACK 724c4975622bc22cedc3f3814dfc8e66cf8371f7 amitiuttarwar: code review but utACK 724c497562 naumenkogs: utACK 724c4975622bc22cedc3f3814dfc8e66cf8371f7 vasild: ACK 724c4975622bc22cedc3f3814dfc8e66cf8371f7 MarcoFalke: review ACK 724c4975622bc22cedc3f3814dfc8e66cf8371f7 👫 Tree-SHA512: 684a4cf9e3d4496c9997fb2bc4ec874809987055c157ec3fad1d2143b8223df52b5a0af787d028930b27388c8efeba0aeb2446cb35c337a5552ae76112ade726
Diffstat (limited to 'src/addrman.h')
-rw-r--r--src/addrman.h36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/addrman.h b/src/addrman.h
index 2548b891ba..74bfe9748b 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -149,22 +149,6 @@ 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);
@@ -174,7 +158,7 @@ public:
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 +280,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 +349,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);