@@ -46,6 +46,12 @@ static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"
46
46
47
47
#include < math.h>
48
48
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
+
49
55
// How often to dump addresses to peers.dat
50
56
static constexpr std::chrono::minutes DUMP_PEERS_INTERVAL{15 };
51
57
@@ -2431,6 +2437,15 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
2431
2437
}
2432
2438
}
2433
2439
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
+
2434
2449
uiInterface.InitMessage (_ (" Starting network threads..." ).translated );
2435
2450
2436
2451
fAddressesInitialized = true ;
@@ -2546,6 +2561,15 @@ void CConnman::StopNodes()
2546
2561
if (fAddressesInitialized ) {
2547
2562
DumpAddresses ();
2548
2563
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
+ }
2549
2573
}
2550
2574
2551
2575
// Close sockets
0 commit comments