Skip to content

Commit adc171e

Browse files
scripted-diff: Rename connection limit variables
-BEGIN VERIFY SCRIPT- sed -i 's/nMaxConnections/m_max_automatic_connections/g' src/net.h src/net.cpp sed -i 's/\.nMaxConnections/\.m_max_automatic_connections/g' src/init.cpp src/test/denialofservice_tests.cpp sed -i 's/nMaxFeeler/m_max_feeler/g' src/net.h sed -i 's/nMaxAddnode/m_max_addnode/g' src/net.h src/net.cpp sed -i 's/m_max_outbound\([^_]\)/m_max_automatic_outbound\1/g' src/net.h src/net.cpp -END VERIFY SCRIPT- Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
1 parent e9fd9c0 commit adc171e

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17481748

17491749
CConnman::Options connOptions;
17501750
connOptions.nLocalServices = nLocalServices;
1751-
connOptions.nMaxConnections = nMaxConnections;
1751+
connOptions.m_max_automatic_connections = nMaxConnections;
17521752
connOptions.uiInterface = &uiInterface;
17531753
connOptions.m_banman = node.banman.get();
17541754
connOptions.m_msgproc = node.peerman.get();

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
27782778
// different netgroups in ipv4/ipv6 networks + all peers in Tor/I2P/CJDNS networks.
27792779
// Don't record addrman failure attempts when node is offline. This can be identified since all local
27802780
// network connections (if any) belong in the same netgroup, and the size of `outbound_ipv46_peer_netgroups` would only be 1.
2781-
const bool count_failures{((int)outbound_ipv46_peer_netgroups.size() + outbound_privacy_network_peers) >= std::min(nMaxConnections - 1, 2)};
2781+
const bool count_failures{((int)outbound_ipv46_peer_netgroups.size() + outbound_privacy_network_peers) >= std::min(m_max_automatic_connections - 1, 2)};
27822782
// Use BIP324 transport when both us and them have NODE_V2_P2P set.
27832783
const bool use_v2transport(addrConnect.nServices & GetLocalServices() & NODE_P2P_V2);
27842784
OpenNetworkConnection(addrConnect, count_failures, std::move(grant), /*strDest=*/nullptr, conn_type, use_v2transport);
@@ -3248,11 +3248,11 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
32483248

32493249
if (semOutbound == nullptr) {
32503250
// initialize semaphore
3251-
semOutbound = std::make_unique<CSemaphore>(std::min(m_max_outbound, nMaxConnections));
3251+
semOutbound = std::make_unique<CSemaphore>(std::min(m_max_automatic_outbound, m_max_automatic_connections));
32523252
}
32533253
if (semAddnode == nullptr) {
32543254
// initialize semaphore
3255-
semAddnode = std::make_unique<CSemaphore>(nMaxAddnode);
3255+
semAddnode = std::make_unique<CSemaphore>(m_max_addnode);
32563256
}
32573257

32583258
//
@@ -3334,13 +3334,13 @@ void CConnman::Interrupt()
33343334
InterruptSocks5(true);
33353335

33363336
if (semOutbound) {
3337-
for (int i=0; i<m_max_outbound; i++) {
3337+
for (int i=0; i<m_max_automatic_outbound; i++) {
33383338
semOutbound->post();
33393339
}
33403340
}
33413341

33423342
if (semAddnode) {
3343-
for (int i=0; i<nMaxAddnode; i++) {
3343+
for (int i=0; i<m_max_addnode; i++) {
33443344
semAddnode->post();
33453345
}
33463346
}

src/net.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ class CConnman
10571057
struct Options
10581058
{
10591059
ServiceFlags nLocalServices = NODE_NONE;
1060-
int nMaxConnections = 0;
1060+
int m_max_automatic_connections = 0;
10611061
CClientUIInterface* uiInterface = nullptr;
10621062
NetEventsInterface* m_msgproc = nullptr;
10631063
BanMan* m_banman = nullptr;
@@ -1084,11 +1084,11 @@ class CConnman
10841084
AssertLockNotHeld(m_total_bytes_sent_mutex);
10851085

10861086
nLocalServices = connOptions.nLocalServices;
1087-
nMaxConnections = connOptions.nMaxConnections;
1088-
m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, nMaxConnections);
1089-
m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, nMaxConnections - m_max_outbound_full_relay);
1090-
m_max_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + nMaxFeeler;
1091-
m_max_inbound = std::max(0, nMaxConnections - m_max_outbound);
1087+
m_max_automatic_connections = connOptions.m_max_automatic_connections;
1088+
m_max_outbound_full_relay = std::min(MAX_OUTBOUND_FULL_RELAY_CONNECTIONS, m_max_automatic_connections);
1089+
m_max_outbound_block_relay = std::min(MAX_BLOCK_RELAY_ONLY_CONNECTIONS, m_max_automatic_connections - m_max_outbound_full_relay);
1090+
m_max_automatic_outbound = m_max_outbound_full_relay + m_max_outbound_block_relay + m_max_feeler;
1091+
m_max_inbound = std::max(0, m_max_automatic_connections - m_max_automatic_outbound);
10921092
m_use_addrman_outgoing = connOptions.m_use_addrman_outgoing;
10931093
m_client_interface = connOptions.uiInterface;
10941094
m_banman = connOptions.m_banman;
@@ -1474,7 +1474,7 @@ class CConnman
14741474

14751475
std::unique_ptr<CSemaphore> semOutbound;
14761476
std::unique_ptr<CSemaphore> semAddnode;
1477-
int nMaxConnections;
1477+
int m_max_automatic_connections;
14781478

14791479
// How many full-relay (tx, block, addr) outbound peers we want
14801480
int m_max_outbound_full_relay;
@@ -1483,9 +1483,9 @@ class CConnman
14831483
// We do not relay tx or addr messages with these peers
14841484
int m_max_outbound_block_relay;
14851485

1486-
int nMaxAddnode{MAX_ADDNODE_CONNECTIONS};
1487-
int nMaxFeeler{MAX_FEELER_CONNECTIONS};
1488-
int m_max_outbound;
1486+
int m_max_addnode{MAX_ADDNODE_CONNECTIONS};
1487+
int m_max_feeler{MAX_FEELER_CONNECTIONS};
1488+
int m_max_automatic_outbound;
14891489
int m_max_inbound;
14901490
bool m_use_addrman_outgoing;
14911491
CClientUIInterface* m_client_interface;

src/test/denialofservice_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
147147

148148
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
149149
CConnman::Options options;
150-
options.nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
150+
options.m_max_automatic_connections = DEFAULT_MAX_PEER_CONNECTIONS;
151151

152152
const auto time_init{GetTime<std::chrono::seconds>()};
153153
SetMockTime(time_init);
@@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
246246
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
247247
constexpr int64_t MINIMUM_CONNECT_TIME{30};
248248
CConnman::Options options;
249-
options.nMaxConnections = DEFAULT_MAX_PEER_CONNECTIONS;
249+
options.m_max_automatic_connections = DEFAULT_MAX_PEER_CONNECTIONS;
250250

251251
connman->Init(options);
252252
std::vector<CNode*> vNodes;

0 commit comments

Comments
 (0)