[addrman] Introduce CAddrMan::Impl to encapsulate addrman implementation.

Introduce the pimpl pattern for CAddrMan to separate the implementation details
from the externally used object representation. This reduces compile-time
dependencies and conceptually clarifies AddrMan's interface from the
implementation specifics.

Since the unit & fuzz tests currently rely on accessing CAddrMan internals, this
commit introduces addrman_impl.h, which is exclusively imported by addrman.cpp
and test files.

Review hint: git diff --color-moved=dimmed-zebra
--color-moved-ws=ignore-all-space
This commit is contained in:
Amiti Uttarwar
2021-09-01 11:21:29 -07:00
parent f2e5f38f09
commit 8af5b54f97
6 changed files with 371 additions and 245 deletions

View File

@@ -4,6 +4,7 @@
#include <addrdb.h>
#include <addrman.h>
#include <addrman_impl.h>
#include <chainparams.h>
#include <clientversion.h>
#include <hash.h>
@@ -90,30 +91,30 @@ public:
CAddrInfo* Find(const CNetAddr& addr, int* pnId = nullptr)
{
LOCK(cs);
return CAddrMan::Find(addr, pnId);
LOCK(m_impl->cs);
return m_impl->Find(addr, pnId);
}
CAddrInfo* Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId = nullptr)
{
LOCK(cs);
return CAddrMan::Create(addr, addrSource, pnId);
LOCK(m_impl->cs);
return m_impl->Create(addr, addrSource, pnId);
}
void Delete(int nId)
{
LOCK(cs);
CAddrMan::Delete(nId);
LOCK(m_impl->cs);
m_impl->Delete(nId);
}
// Used to test deserialization
std::pair<int, int> GetBucketAndEntry(const CAddress& addr)
{
LOCK(cs);
int nId = mapAddr[addr];
LOCK(m_impl->cs);
int nId = m_impl->mapAddr[addr];
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; ++bucket) {
for (int entry = 0; entry < ADDRMAN_BUCKET_SIZE; ++entry) {
if (nId == vvNew[bucket][entry]) {
if (nId == m_impl->vvNew[bucket][entry]) {
return std::pair<int, int>(bucket, entry);
}
}