diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-09-12 18:05:54 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2020-10-09 14:29:05 +0300 |
commit | 4170b46544231e7cf1d64ac3baa314083be37502 (patch) | |
tree | 5d4324f5db9a1984224b581cdfa2bf908d9776c6 /src/net.cpp | |
parent | bad16aff490dcf87722fbfe202a869fb24c734e1 (diff) | |
download | bitcoin-4170b46544231e7cf1d64ac3baa314083be37502.tar.xz |
p2p: Integrate DumpAnchors() and ReadAnchors() into CConnman
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index 53cf4ca017..0fb4bf9bde 100644 --- a/src/net.cpp +++ b/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 |