@@ -46,6 +46,12 @@ static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"
4646
4747#include < math.h>
4848
49+ /* * Maximum number of block-relay-only anchor connections */
50+ static constexpr size_t MAX_BLOCK_RELAY_ONLY_ANCHORS = 2 ;
51+ 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." );
52+ /* * Anchor IP address database file name */
53+ const char * const ANCHORS_DATABASE_FILENAME = " anchors.dat" ;
54+
4955// How often to dump addresses to peers.dat
5056static constexpr std::chrono::minutes DUMP_PEERS_INTERVAL{15 };
5157
@@ -2431,6 +2437,15 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
24312437 }
24322438 }
24332439
2440+ if (m_use_addrman_outgoing) {
2441+ // Load addresses from anchors.dat
2442+ m_anchors = ReadAnchors (GetDataDir () / ANCHORS_DATABASE_FILENAME);
2443+ if (m_anchors.size () > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
2444+ m_anchors.resize (MAX_BLOCK_RELAY_ONLY_ANCHORS);
2445+ }
2446+ LogPrintf (" %i block-relay-only anchors will be tried for connections.\n " , m_anchors.size ());
2447+ }
2448+
24342449 uiInterface.InitMessage (_ (" Starting network threads..." ).translated );
24352450
24362451 fAddressesInitialized = true ;
@@ -2546,6 +2561,15 @@ void CConnman::StopNodes()
25462561 if (fAddressesInitialized ) {
25472562 DumpAddresses ();
25482563 fAddressesInitialized = false ;
2564+
2565+ if (m_use_addrman_outgoing) {
2566+ // Anchor connections are only dumped during clean shutdown.
2567+ std::vector<CAddress> anchors_to_dump = GetCurrentBlockRelayOnlyConns ();
2568+ if (anchors_to_dump.size () > MAX_BLOCK_RELAY_ONLY_ANCHORS) {
2569+ anchors_to_dump.resize (MAX_BLOCK_RELAY_ONLY_ANCHORS);
2570+ }
2571+ DumpAnchors (GetDataDir () / ANCHORS_DATABASE_FILENAME, anchors_to_dump);
2572+ }
25492573 }
25502574
25512575 // Close sockets
0 commit comments