mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
p2p: Integrate DumpAnchors() and ReadAnchors() into CConnman
This commit is contained in:
24
src/net.cpp
24
src/net.cpp
@@ -46,6 +46,12 @@ static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/** Maximum number of block-relay-only anchor connections */
|
||||
static constexpr size_t MAX_BLOCK_RELAY_ONLY_ANCHORS = 2;
|
||||
static_assert (MAX_BLOCK_RELAY_ONLY_ANCHORS <= static_cast<size_t>(MAX_BLOCK_RELAY_ONLY_CONNECTIONS), "MAX_BLOCK_RELAY_ONLY_ANCHORS must not exceed MAX_BLOCK_RELAY_ONLY_CONNECTIONS.");
|
||||
/** Anchor IP address database file name */
|
||||
const char* const ANCHORS_DATABASE_FILENAME = "anchors.dat";
|
||||
|
||||
// How often to dump addresses to peers.dat
|
||||
static constexpr std::chrono::minutes DUMP_PEERS_INTERVAL{15};
|
||||
|
||||
@@ -2431,6 +2437,15 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_use_addrman_outgoing) {
|
||||
// Load addresses from anchors.dat
|
||||
m_anchors = ReadAnchors(GetDataDir() / ANCHORS_DATABASE_FILENAME);
|
||||
if (m_anchors.size() > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
|
||||
m_anchors.resize(MAX_BLOCK_RELAY_ONLY_ANCHORS);
|
||||
}
|
||||
LogPrintf("%i block-relay-only anchors will be tried for connections.\n", m_anchors.size());
|
||||
}
|
||||
|
||||
uiInterface.InitMessage(_("Starting network threads...").translated);
|
||||
|
||||
fAddressesInitialized = true;
|
||||
@@ -2546,6 +2561,15 @@ void CConnman::StopNodes()
|
||||
if (fAddressesInitialized) {
|
||||
DumpAddresses();
|
||||
fAddressesInitialized = false;
|
||||
|
||||
if (m_use_addrman_outgoing) {
|
||||
// Anchor connections are only dumped during clean shutdown.
|
||||
std::vector<CAddress> anchors_to_dump = GetCurrentBlockRelayOnlyConns();
|
||||
if (anchors_to_dump.size() > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
|
||||
anchors_to_dump.resize(MAX_BLOCK_RELAY_ONLY_ANCHORS);
|
||||
}
|
||||
DumpAnchors(GetDataDir() / ANCHORS_DATABASE_FILENAME, anchors_to_dump);
|
||||
}
|
||||
}
|
||||
|
||||
// Close sockets
|
||||
|
||||
Reference in New Issue
Block a user