mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
p2p: Integrate DumpAnchors() and ReadAnchors() into CConnman
This commit is contained in:
parent
bad16aff49
commit
4170b46544
2 changed files with 30 additions and 0 deletions
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
|
||||
|
|
|
@ -566,6 +566,12 @@ private:
|
|||
/** Pointer to this node's banman. May be nullptr - check existence before dereferencing. */
|
||||
BanMan* m_banman;
|
||||
|
||||
/**
|
||||
* Addresses that were saved during the previous clean shutdown. We'll
|
||||
* attempt to make block-relay-only connections to them.
|
||||
*/
|
||||
std::vector<CAddress> m_anchors;
|
||||
|
||||
/** SipHasher seeds for deterministic randomness */
|
||||
const uint64_t nSeed0, nSeed1;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue