Skip to content

Commit 0e52a65

Browse files
committed
[net/refactor] Add feeler connections to ConnectionType enum
1 parent 1521c47 commit 0e52a65

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/net.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
17771777
for (const std::string& strAddr : connect)
17781778
{
17791779
CAddress addr(CService(), NODE_NONE);
1780-
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, false, ConnectionType::MANUAL);
1780+
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, ConnectionType::MANUAL);
17811781
for (int i = 0; i < 10 && i < nLoop; i++)
17821782
{
17831783
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
@@ -1943,7 +1943,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
19431943
// well for sanity.)
19441944
bool block_relay_only = nOutboundBlockRelay < m_max_outbound_block_relay && !fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay;
19451945

1946-
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler, ConnectionType::OUTBOUND, block_relay_only);
1946+
ConnectionType conn_type = (fFeeler ? ConnectionType::FEELER : ConnectionType::OUTBOUND);
1947+
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, conn_type, block_relay_only);
19471948
}
19481949
}
19491950
}
@@ -2018,7 +2019,7 @@ void CConnman::ThreadOpenAddedConnections()
20182019
}
20192020
tried = true;
20202021
CAddress addr(CService(), NODE_NONE);
2021-
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), false, false, ConnectionType::MANUAL);
2022+
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), false, ConnectionType::MANUAL);
20222023
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
20232024
return;
20242025
}
@@ -2030,7 +2031,7 @@ void CConnman::ThreadOpenAddedConnections()
20302031
}
20312032

20322033
// if successful, this moves the passed grant to the constructed node
2033-
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, bool fFeeler, ConnectionType conn_type, bool block_relay_only)
2034+
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, ConnectionType conn_type, bool block_relay_only)
20342035
{
20352036
assert(conn_type != ConnectionType::INBOUND);
20362037

@@ -2059,8 +2060,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
20592060
grantOutbound->MoveTo(pnode->grantOutbound);
20602061
if (m_addr_fetch)
20612062
pnode->m_addr_fetch = true;
2062-
if (fFeeler)
2063-
pnode->fFeeler = true;
20642063

20652064
m_msgproc->InitializeNode(pnode);
20662065
{
@@ -2738,6 +2737,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27382737
: nTimeConnected(GetSystemTimeInSeconds()),
27392738
addr(addrIn),
27402739
addrBind(addrBindIn),
2740+
fFeeler(conn_type_in == ConnectionType::FEELER),
27412741
m_manual_connection(conn_type_in == ConnectionType::MANUAL),
27422742
fInbound(conn_type_in == ConnectionType::INBOUND),
27432743
nKeyedNetGroup(nKeyedNetGroupIn),

src/net.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ enum class ConnectionType {
117117
INBOUND,
118118
OUTBOUND,
119119
MANUAL,
120+
FEELER,
120121
};
121122

122123
class NetEventsInterface;
@@ -202,7 +203,7 @@ class CConnman
202203
bool GetNetworkActive() const { return fNetworkActive; };
203204
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
204205
void SetNetworkActive(bool active);
205-
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool m_addr_fetch = false, bool fFeeler = false, ConnectionType conn_type = ConnectionType::OUTBOUND, bool block_relay_only = false);
206+
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool m_addr_fetch = false, ConnectionType conn_type = ConnectionType::OUTBOUND, bool block_relay_only = false);
206207
bool CheckIncomingNonce(uint64_t nonce);
207208

208209
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static UniValue addnode(const JSONRPCRequest& request)
264264
if (strCommand == "onetry")
265265
{
266266
CAddress addr;
267-
node.connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, ConnectionType::MANUAL);
267+
node.connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, ConnectionType::MANUAL);
268268
return NullUniValue;
269269
}
270270

src/test/fuzz/process_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
4444
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
4545
for (int i = 0; i < num_peers_to_add; ++i) {
4646
const ServiceFlags service_flags = ServiceFlags(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
47-
const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL});
47+
const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL, ConnectionType::FEELER});
4848
const bool block_relay_only{fuzzed_data_provider.ConsumeBool()};
4949
peers.push_back(MakeUnique<CNode>(i, service_flags, 0, INVALID_SOCKET, CAddress{CService{in_addr{0x0100007f}, 7777}, NODE_NETWORK}, 0, 0, CAddress{}, std::string{}, conn_type, block_relay_only).release());
5050
CNode& p2p_node = *peers.back();

0 commit comments

Comments
 (0)