Skip to content

Commit

Permalink
merge bitcoin#22950: Pimpl AddrMan to abstract implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Jun 10, 2024
1 parent 236cf36 commit b6ec8ab
Show file tree
Hide file tree
Showing 21 changed files with 893 additions and 731 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ BITCOIN_CORE_H = \
addressindex.h \
spentindex.h \
addrman.h \
addrman_impl.h \
attributes.h \
banman.h \
base58.h \
Expand Down
10 changes: 5 additions & 5 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,21 @@ bool CBanDB::Read(banmap_t& banSet)
return true;
}

bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr)
bool DumpPeerAddresses(const ArgsManager& args, const AddrMan& addr)
{
const auto pathAddr = GetDataDir() / "peers.dat";
return SerializeFileDB("peers", pathAddr, addr, CLIENT_VERSION);
}

void ReadFromStream(CAddrMan& addr, CDataStream& ssPeers)
void ReadFromStream(AddrMan& addr, CDataStream& ssPeers)
{
DeserializeDB(ssPeers, addr, false);
}

std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<CAddrMan>& addrman)
std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman)
{
auto check_addrman = std::clamp<int32_t>(args.GetArg("-checkaddrman", DEFAULT_ADDRMAN_CONSISTENCY_CHECKS), 0, 1000000);
addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);

int64_t nStart = GetTimeMillis();
const auto path_addr{GetDataDir() / "peers.dat"};
Expand All @@ -194,7 +194,7 @@ std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const A
LogPrintf("Loaded %i addresses from peers.dat %dms\n", addrman->size(), GetTimeMillis() - nStart);
} catch (const DbNotFoundError&) {
// Addrman can be in an inconsistent state after failure, reset it
addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
addrman = std::make_unique<AddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
LogPrintf("Creating peers.dat because the file was not found (%s)\n", path_addr);
DumpPeerAddresses(args, *addrman);
} catch (const std::exception& e) {
Expand Down
8 changes: 4 additions & 4 deletions src/addrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
#include <vector>

class ArgsManager;
class CAddrMan;
class AddrMan;
class CAddress;
class CDataStream;
struct bilingual_str;

bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr);
bool DumpPeerAddresses(const ArgsManager& args, const AddrMan& addr);
/** Only used by tests. */
void ReadFromStream(CAddrMan& addr, CDataStream& ssPeers);
void ReadFromStream(AddrMan& addr, CDataStream& ssPeers);

/** Access to the banlist database (banlist.json) */
class CBanDB
Expand All @@ -48,7 +48,7 @@ class CBanDB
};

/** Returns an error string on failure */
std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<CAddrMan>& addrman);
std::optional<bilingual_str> LoadAddrman(const std::vector<bool>& asmap, const ArgsManager& args, std::unique_ptr<AddrMan>& addrman);

/**
* Dump the anchor IP address database (anchors.dat)
Expand Down
Loading

0 comments on commit b6ec8ab

Please sign in to comment.