mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-21 22:31:21 +02:00
[net/refactor] Add feeler connections to ConnectionType enum
This commit is contained in:
parent
1521c47438
commit
0e52a659a2
12
src/net.cpp
12
src/net.cpp
@ -1777,7 +1777,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||||||
for (const std::string& strAddr : connect)
|
for (const std::string& strAddr : connect)
|
||||||
{
|
{
|
||||||
CAddress addr(CService(), NODE_NONE);
|
CAddress addr(CService(), NODE_NONE);
|
||||||
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, false, ConnectionType::MANUAL);
|
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, ConnectionType::MANUAL);
|
||||||
for (int i = 0; i < 10 && i < nLoop; i++)
|
for (int i = 0; i < 10 && i < nLoop; i++)
|
||||||
{
|
{
|
||||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||||
@ -1943,7 +1943,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||||||
// well for sanity.)
|
// well for sanity.)
|
||||||
bool block_relay_only = nOutboundBlockRelay < m_max_outbound_block_relay && !fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay;
|
bool block_relay_only = nOutboundBlockRelay < m_max_outbound_block_relay && !fFeeler && nOutboundFullRelay >= m_max_outbound_full_relay;
|
||||||
|
|
||||||
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, fFeeler, ConnectionType::OUTBOUND, block_relay_only);
|
ConnectionType conn_type = (fFeeler ? ConnectionType::FEELER : ConnectionType::OUTBOUND);
|
||||||
|
OpenNetworkConnection(addrConnect, (int)setConnected.size() >= std::min(nMaxConnections - 1, 2), &grant, nullptr, false, conn_type, block_relay_only);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2018,7 +2019,7 @@ void CConnman::ThreadOpenAddedConnections()
|
|||||||
}
|
}
|
||||||
tried = true;
|
tried = true;
|
||||||
CAddress addr(CService(), NODE_NONE);
|
CAddress addr(CService(), NODE_NONE);
|
||||||
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), false, false, ConnectionType::MANUAL);
|
OpenNetworkConnection(addr, false, &grant, info.strAddedNode.c_str(), false, ConnectionType::MANUAL);
|
||||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2030,7 +2031,7 @@ void CConnman::ThreadOpenAddedConnections()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if successful, this moves the passed grant to the constructed node
|
// if successful, this moves the passed grant to the constructed node
|
||||||
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)
|
void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound, const char *pszDest, bool m_addr_fetch, ConnectionType conn_type, bool block_relay_only)
|
||||||
{
|
{
|
||||||
assert(conn_type != ConnectionType::INBOUND);
|
assert(conn_type != ConnectionType::INBOUND);
|
||||||
|
|
||||||
@ -2059,8 +2060,6 @@ void CConnman::OpenNetworkConnection(const CAddress& addrConnect, bool fCountFai
|
|||||||
grantOutbound->MoveTo(pnode->grantOutbound);
|
grantOutbound->MoveTo(pnode->grantOutbound);
|
||||||
if (m_addr_fetch)
|
if (m_addr_fetch)
|
||||||
pnode->m_addr_fetch = true;
|
pnode->m_addr_fetch = true;
|
||||||
if (fFeeler)
|
|
||||||
pnode->fFeeler = true;
|
|
||||||
|
|
||||||
m_msgproc->InitializeNode(pnode);
|
m_msgproc->InitializeNode(pnode);
|
||||||
{
|
{
|
||||||
@ -2738,6 +2737,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
|
|||||||
: nTimeConnected(GetSystemTimeInSeconds()),
|
: nTimeConnected(GetSystemTimeInSeconds()),
|
||||||
addr(addrIn),
|
addr(addrIn),
|
||||||
addrBind(addrBindIn),
|
addrBind(addrBindIn),
|
||||||
|
fFeeler(conn_type_in == ConnectionType::FEELER),
|
||||||
m_manual_connection(conn_type_in == ConnectionType::MANUAL),
|
m_manual_connection(conn_type_in == ConnectionType::MANUAL),
|
||||||
fInbound(conn_type_in == ConnectionType::INBOUND),
|
fInbound(conn_type_in == ConnectionType::INBOUND),
|
||||||
nKeyedNetGroup(nKeyedNetGroupIn),
|
nKeyedNetGroup(nKeyedNetGroupIn),
|
||||||
|
@ -117,6 +117,7 @@ enum class ConnectionType {
|
|||||||
INBOUND,
|
INBOUND,
|
||||||
OUTBOUND,
|
OUTBOUND,
|
||||||
MANUAL,
|
MANUAL,
|
||||||
|
FEELER,
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetEventsInterface;
|
class NetEventsInterface;
|
||||||
@ -202,7 +203,7 @@ public:
|
|||||||
bool GetNetworkActive() const { return fNetworkActive; };
|
bool GetNetworkActive() const { return fNetworkActive; };
|
||||||
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
|
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
|
||||||
void SetNetworkActive(bool active);
|
void SetNetworkActive(bool active);
|
||||||
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);
|
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);
|
||||||
bool CheckIncomingNonce(uint64_t nonce);
|
bool CheckIncomingNonce(uint64_t nonce);
|
||||||
|
|
||||||
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
|
bool ForNode(NodeId id, std::function<bool(CNode* pnode)> func);
|
||||||
|
@ -264,7 +264,7 @@ static UniValue addnode(const JSONRPCRequest& request)
|
|||||||
if (strCommand == "onetry")
|
if (strCommand == "onetry")
|
||||||
{
|
{
|
||||||
CAddress addr;
|
CAddress addr;
|
||||||
node.connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, ConnectionType::MANUAL);
|
node.connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, ConnectionType::MANUAL);
|
||||||
return NullUniValue;
|
return NullUniValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||||||
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
||||||
for (int i = 0; i < num_peers_to_add; ++i) {
|
for (int i = 0; i < num_peers_to_add; ++i) {
|
||||||
const ServiceFlags service_flags = ServiceFlags(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
const ServiceFlags service_flags = ServiceFlags(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||||
const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL});
|
const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND, ConnectionType::MANUAL, ConnectionType::FEELER});
|
||||||
const bool block_relay_only{fuzzed_data_provider.ConsumeBool()};
|
const bool block_relay_only{fuzzed_data_provider.ConsumeBool()};
|
||||||
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());
|
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());
|
||||||
CNode& p2p_node = *peers.back();
|
CNode& p2p_node = *peers.back();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user