Skip to content

Commit 2ee4a7a

Browse files
committed
net: remove CNode::m_inbound_onion defaults for explicitness
and to allow the compiler to warn if uninitialized in the ctor or omitted in the caller.
1 parent 24bda56 commit 2ee4a7a

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
476476
NodeId id = GetNewNodeId();
477477
uint64_t nonce = GetDeterministicRandomizer(RANDOMIZER_ID_LOCALHOSTNONCE).Write(id).Finalize();
478478
CAddress addr_bind = GetBindAddress(sock->Get());
479-
CNode* pnode = new CNode(id, nLocalServices, sock->Release(), addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", conn_type);
479+
CNode* pnode = new CNode(id, nLocalServices, sock->Release(), addrConnect, CalculateKeyedNetGroup(addrConnect), nonce, addr_bind, pszDest ? pszDest : "", conn_type, /* inbound_onion */ false);
480480
pnode->AddRef();
481481

482482
// We're making a new connection, harvest entropy from the time (and our peer count)

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class CNode
430430
// Bind address of our side of the connection
431431
const CAddress addrBind;
432432
//! Whether this peer is an inbound onion, i.e. connected via our Tor onion service.
433-
const bool m_inbound_onion{false};
433+
const bool m_inbound_onion;
434434
std::atomic<int> nVersion{0};
435435
RecursiveMutex cs_SubVer;
436436
/**
@@ -603,7 +603,7 @@ class CNode
603603
// Whether a ping is requested.
604604
std::atomic<bool> fPingQueued{false};
605605

606-
CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion = false);
606+
CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion);
607607
~CNode();
608608
CNode(const CNode&) = delete;
609609
CNode& operator=(const CNode&) = delete;

src/test/denialofservice_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
8585

8686
// Mock an outbound peer
8787
CAddress addr1(ip(0xa0b0c001), NODE_NONE);
88-
CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr1, 0, 0, CAddress(), "", ConnectionType::OUTBOUND_FULL_RELAY);
88+
CNode dummyNode1(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr1, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "", ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false);
8989
dummyNode1.SetCommonVersion(PROTOCOL_VERSION);
9090

9191
peerLogic->InitializeNode(&dummyNode1);
@@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
136136
static void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerManager &peerLogic, CConnmanTest* connman)
137137
{
138138
CAddress addr(ip(g_insecure_rand_ctx.randbits(32)), NODE_NONE);
139-
vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr, 0, 0, CAddress(), "", ConnectionType::OUTBOUND_FULL_RELAY));
139+
vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK | NODE_WITNESS), INVALID_SOCKET, addr, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "", ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false));
140140
CNode &node = *vNodes.back();
141141
node.SetCommonVersion(PROTOCOL_VERSION);
142142

@@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
229229

230230
banman->ClearBanned();
231231
CAddress addr1(ip(0xa0b0c001), NODE_NONE);
232-
CNode dummyNode1(id++, NODE_NETWORK, INVALID_SOCKET, addr1, 0, 0, CAddress(), "", ConnectionType::INBOUND);
232+
CNode dummyNode1(id++, NODE_NETWORK, INVALID_SOCKET, addr1, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress(), /* pszDest */ "", ConnectionType::INBOUND, /* inbound_onion */ false);
233233
dummyNode1.SetCommonVersion(PROTOCOL_VERSION);
234234
peerLogic->InitializeNode(&dummyNode1);
235235
dummyNode1.fSuccessfullyConnected = true;
@@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
242242
BOOST_CHECK(!banman->IsDiscouraged(ip(0xa0b0c001|0x0000ff00))); // Different IP, not discouraged
243243

244244
CAddress addr2(ip(0xa0b0c002), NODE_NONE);
245-
CNode dummyNode2(id++, NODE_NETWORK, INVALID_SOCKET, addr2, 1, 1, CAddress(), "", ConnectionType::INBOUND);
245+
CNode dummyNode2(id++, NODE_NETWORK, INVALID_SOCKET, addr2, /* nKeyedNetGroupIn */ 1, /* nLocalHostNonceIn */ 1, CAddress(), /* pszDest */ "", ConnectionType::INBOUND, /* inbound_onion */ false);
246246
dummyNode2.SetCommonVersion(PROTOCOL_VERSION);
247247
peerLogic->InitializeNode(&dummyNode2);
248248
dummyNode2.fSuccessfullyConnected = true;
@@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
279279
SetMockTime(nStartTime); // Overrides future calls to GetTime()
280280

281281
CAddress addr(ip(0xa0b0c001), NODE_NONE);
282-
CNode dummyNode(id++, NODE_NETWORK, INVALID_SOCKET, addr, 4, 4, CAddress(), "", ConnectionType::INBOUND);
282+
CNode dummyNode(id++, NODE_NETWORK, INVALID_SOCKET, addr, /* nKeyedNetGroupIn */ 4, /* nLocalHostNonceIn */ 4, CAddress(), /* pszDest */ "", ConnectionType::INBOUND, /* inbound_onion */ false);
283283
dummyNode.SetCommonVersion(PROTOCOL_VERSION);
284284
peerLogic->InitializeNode(&dummyNode);
285285
dummyNode.fSuccessfullyConnected = true;

src/test/net_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test)
192192
id++, NODE_NETWORK, hSocket, addr,
193193
/* nKeyedNetGroupIn = */ 0,
194194
/* nLocalHostNonceIn = */ 0,
195-
CAddress(), pszDest, ConnectionType::OUTBOUND_FULL_RELAY);
195+
CAddress(), pszDest, ConnectionType::OUTBOUND_FULL_RELAY,
196+
/* inbound_onion = */ false);
196197
BOOST_CHECK(pnode1->IsFullOutboundConn() == true);
197198
BOOST_CHECK(pnode1->IsManualConn() == false);
198199
BOOST_CHECK(pnode1->IsBlockOnlyConn() == false);
@@ -679,7 +680,7 @@ BOOST_AUTO_TEST_CASE(ipv4_peer_with_ipv6_addrMe_test)
679680
in_addr ipv4AddrPeer;
680681
ipv4AddrPeer.s_addr = 0xa0b0c001;
681682
CAddress addr = CAddress(CService(ipv4AddrPeer, 7777), NODE_NETWORK);
682-
std::unique_ptr<CNode> pnode = MakeUnique<CNode>(0, NODE_NETWORK, INVALID_SOCKET, addr, 0, 0, CAddress{}, std::string{}, ConnectionType::OUTBOUND_FULL_RELAY);
683+
std::unique_ptr<CNode> pnode = MakeUnique<CNode>(0, NODE_NETWORK, INVALID_SOCKET, addr, /* nKeyedNetGroupIn */ 0, /* nLocalHostNonceIn */ 0, CAddress{}, /* pszDest */ std::string{}, ConnectionType::OUTBOUND_FULL_RELAY, /* inbound_onion */ false);
683684
pnode->fSuccessfullyConnected.store(true);
684685

685686
// the peer claims to be reaching us via IPv6

0 commit comments

Comments
 (0)