Skip to content

Commit 442abae

Browse files
committed
[net/refactor] Add AddrFetch connections to ConnectionType enum
- AddrFetch connections are short lived connections used to getaddr from a peer - previously called "one shot" connections
1 parent af59feb commit 442abae

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/net.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ void CConnman::ProcessAddrFetch()
17311731
CAddress addr;
17321732
CSemaphoreGrant grant(*semOutbound, true);
17331733
if (grant) {
1734-
OpenNetworkConnection(addr, false, &grant, strDest.c_str(), true);
1734+
OpenNetworkConnection(addr, false, &grant, strDest.c_str(), ConnectionType::ADDR_FETCH);
17351735
}
17361736
}
17371737

@@ -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, ConnectionType::MANUAL);
1780+
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), ConnectionType::MANUAL);
17811781
for (int i = 0; i < 10 && i < nLoop; i++)
17821782
{
17831783
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
@@ -1948,7 +1948,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
19481948
conn_type = ConnectionType::OUTBOUND;
19491949
}
19501950

1951-
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, conn_type);
1951+
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, conn_type);
19521952
}
19531953
}
19541954
}
@@ -2023,7 +2023,7 @@ void CConnman::ThreadOpenAddedConnections()
20232023
}
20242024
tried = true;
20252025
CAddress addr(CService(), NODE_NONE);
2026-
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), false, ConnectionType::MANUAL);
2026+
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), ConnectionType::MANUAL);
20272027
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
20282028
return;
20292029
}
@@ -2035,7 +2035,7 @@ void CConnman::ThreadOpenAddedConnections()
20352035
}
20362036

20372037
// if successful, this moves the passed grant to the constructed node
2038-
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, ConnectionType conn_type)
2038+
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, ConnectionType conn_type)
20392039
{
20402040
assert(conn_type != ConnectionType::INBOUND);
20412041

@@ -2062,8 +2062,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
20622062
return;
20632063
if (grantOutbound)
20642064
grantOutbound->MoveTo(pnode->grantOutbound);
2065-
if (m_addr_fetch)
2066-
pnode->m_addr_fetch = true;
20672065

20682066
m_msgproc->InitializeNode(pnode);
20692067
{
@@ -2742,6 +2740,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
27422740
addr(addrIn),
27432741
addrBind(addrBindIn),
27442742
fFeeler(conn_type_in == ConnectionType::FEELER),
2743+
m_addr_fetch(conn_type_in == ConnectionType::ADDR_FETCH),
27452744
m_manual_connection(conn_type_in == ConnectionType::MANUAL),
27462745
fInbound(conn_type_in == ConnectionType::INBOUND),
27472746
nKeyedNetGroup(nKeyedNetGroupIn),

src/net.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ enum class ConnectionType {
119119
MANUAL,
120120
FEELER,
121121
BLOCK_RELAY,
122+
ADDR_FETCH,
122123
};
123124

124125
class NetEventsInterface;
@@ -204,7 +205,7 @@ class CConnman
204205
bool GetNetworkActive() const { return fNetworkActive; };
205206
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
206207
void SetNetworkActive(bool active);
207-
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, bool m_addr_fetch = false, ConnectionType conn_type = ConnectionType::OUTBOUND);
208+
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = nullptr, const char *strDest = nullptr, ConnectionType conn_type = ConnectionType::OUTBOUND);
208209
bool CheckIncomingNonce(uint64_t nonce);
209210

210211
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, ConnectionType::MANUAL);
267+
node.connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), 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, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY});
47+
const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH});
4848
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).release());
4949
CNode& p2p_node = *peers.back();
5050

0 commit comments

Comments
 (0)