mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
merge bitcoin#19771: Replace enum CConnMan::NumConnections with enum class ConnectionDirection
This commit is contained in:
parent
62a7311fe4
commit
5c4c7c55f8
@ -6,9 +6,10 @@
|
||||
#define BITCOIN_INTERFACES_NODE_H
|
||||
|
||||
#include <amount.h> // For CAmount
|
||||
#include <net.h> // For CConnman::NumConnections
|
||||
#include <net.h> // For NodeId
|
||||
#include <net_types.h> // For banmap_t
|
||||
#include <netaddress.h> // For Network
|
||||
#include <netbase.h> // For ConnectionDirection
|
||||
#include <support/allocators/secure.h> // For SecureString
|
||||
#include <uint256.h>
|
||||
#include <util/translation.h>
|
||||
@ -175,7 +176,7 @@ public:
|
||||
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
|
||||
|
||||
//! Get number of connections.
|
||||
virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;
|
||||
virtual size_t getNodeCount(ConnectionDirection flags) = 0;
|
||||
|
||||
//! Get stats for connected nodes.
|
||||
using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
|
||||
|
@ -1316,7 +1316,7 @@ void CDKGSession::RelayInvToParticipants(const CInv& inv) const
|
||||
logger.Batch("RelayInvToParticipants inv[%s] relayMembers[%d] GetNodeCount[%d] GetNetworkActive[%d] HasMasternodeQuorumNodes[%d] for quorumHash[%s] forMember[%s] relayMembers[%s]",
|
||||
inv.ToString(),
|
||||
relayMembers.size(),
|
||||
connman.GetNodeCount(CConnman::CONNECTIONS_ALL),
|
||||
connman.GetNodeCount(ConnectionDirection::Both),
|
||||
connman.GetNetworkActive(),
|
||||
connman.HasMasternodeQuorumNodes(params.type, m_quorum_base_block_index->GetBlockHash()),
|
||||
m_quorum_base_block_index->GetBlockHash().ToString(),
|
||||
|
@ -3790,7 +3790,7 @@ void CConnman::AddPendingProbeConnections(const std::set<uint256> &proTxHashes)
|
||||
masternodePendingProbes.insert(proTxHashes.begin(), proTxHashes.end());
|
||||
}
|
||||
|
||||
size_t CConnman::GetNodeCount(NumConnections flags)
|
||||
size_t CConnman::GetNodeCount(ConnectionDirection flags)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
|
||||
@ -3799,12 +3799,12 @@ size_t CConnman::GetNodeCount(NumConnections flags)
|
||||
if (pnode->fDisconnect) {
|
||||
continue;
|
||||
}
|
||||
if ((flags & CONNECTIONS_VERIFIED) && pnode->GetVerifiedProRegTxHash().IsNull()) {
|
||||
if ((flags & ConnectionDirection::Verified) && pnode->GetVerifiedProRegTxHash().IsNull()) {
|
||||
continue;
|
||||
}
|
||||
if (flags & (pnode->IsInboundConn() ? CONNECTIONS_IN : CONNECTIONS_OUT)) {
|
||||
if (flags & (pnode->IsInboundConn() ? ConnectionDirection::In : ConnectionDirection::Out)) {
|
||||
nNum++;
|
||||
} else if (flags == CONNECTIONS_VERIFIED) {
|
||||
} else if (flags == ConnectionDirection::Verified) {
|
||||
nNum++;
|
||||
}
|
||||
}
|
||||
|
14
src/net.h
14
src/net.h
@ -18,6 +18,7 @@
|
||||
#include <limitedmap.h>
|
||||
#include <net_permissions.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
@ -931,17 +932,6 @@ class CConnman
|
||||
{
|
||||
friend class CNode;
|
||||
public:
|
||||
|
||||
enum NumConnections {
|
||||
CONNECTIONS_NONE = 0,
|
||||
CONNECTIONS_IN = (1U << 0),
|
||||
CONNECTIONS_OUT = (1U << 1),
|
||||
CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
|
||||
CONNECTIONS_VERIFIED = (1U << 2),
|
||||
CONNECTIONS_VERIFIED_IN = (CONNECTIONS_VERIFIED | CONNECTIONS_IN),
|
||||
CONNECTIONS_VERIFIED_OUT = (CONNECTIONS_VERIFIED | CONNECTIONS_OUT),
|
||||
};
|
||||
|
||||
enum SocketEventsMode {
|
||||
SOCKETEVENTS_SELECT = 0,
|
||||
SOCKETEVENTS_POLL = 1,
|
||||
@ -1253,7 +1243,7 @@ public:
|
||||
bool IsMasternodeQuorumRelayMember(const uint256& protxHash);
|
||||
void AddPendingProbeConnections(const std::set<uint256>& proTxHashes);
|
||||
|
||||
size_t GetNodeCount(NumConnections num);
|
||||
size_t GetNodeCount(ConnectionDirection);
|
||||
size_t GetMaxOutboundNodeCount();
|
||||
void GetNodeStats(std::vector<CNodeStats>& vstats);
|
||||
bool DisconnectNode(const std::string& node);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
extern int nConnectTimeout;
|
||||
@ -29,6 +30,25 @@ static const int DEFAULT_CONNECT_TIMEOUT = 5000;
|
||||
static const int DEFAULT_NAME_LOOKUP = true;
|
||||
static const bool DEFAULT_ALLOWPRIVATENET = false;
|
||||
|
||||
enum class ConnectionDirection {
|
||||
None = 0,
|
||||
In = (1U << 0),
|
||||
Out = (1U << 1),
|
||||
Both = (In | Out),
|
||||
Verified = (1U << 2),
|
||||
VerifiedIn = (Verified | In),
|
||||
VerifiedOut = (Verified | Out),
|
||||
};
|
||||
static inline ConnectionDirection& operator|=(ConnectionDirection& a, ConnectionDirection b) {
|
||||
using underlying = typename std::underlying_type<ConnectionDirection>::type;
|
||||
a = ConnectionDirection(underlying(a) | underlying(b));
|
||||
return a;
|
||||
}
|
||||
static inline bool operator&(ConnectionDirection a, ConnectionDirection b) {
|
||||
using underlying = typename std::underlying_type<ConnectionDirection>::type;
|
||||
return (underlying(a) & underlying(b));
|
||||
}
|
||||
|
||||
class proxyType
|
||||
{
|
||||
public:
|
||||
|
@ -335,7 +335,7 @@ public:
|
||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
|
||||
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||
size_t getNodeCount(CConnman::NumConnections flags) override
|
||||
size_t getNodeCount(ConnectionDirection flags) override
|
||||
{
|
||||
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
|
||||
}
|
||||
|
@ -76,14 +76,14 @@ ClientModel::~ClientModel()
|
||||
|
||||
int ClientModel::getNumConnections(unsigned int flags) const
|
||||
{
|
||||
CConnman::NumConnections connections = CConnman::CONNECTIONS_NONE;
|
||||
ConnectionDirection connections = ConnectionDirection::None;
|
||||
|
||||
if(flags == CONNECTIONS_IN)
|
||||
connections = CConnman::CONNECTIONS_IN;
|
||||
connections = ConnectionDirection::In;
|
||||
else if (flags == CONNECTIONS_OUT)
|
||||
connections = CConnman::CONNECTIONS_OUT;
|
||||
connections = ConnectionDirection::Out;
|
||||
else if (flags == CONNECTIONS_ALL)
|
||||
connections = CConnman::CONNECTIONS_ALL;
|
||||
connections = ConnectionDirection::Both;
|
||||
|
||||
return m_node.getNodeCount(connections);
|
||||
}
|
||||
|
@ -734,7 +734,7 @@ static RPCHelpMan getblocktemplate()
|
||||
if(!node.connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
if (node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
|
||||
if (node.connman->GetNodeCount(ConnectionDirection::Both) == 0)
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
|
||||
|
||||
if (active_chainstate.IsInitialBlockDownload())
|
||||
|
@ -58,7 +58,7 @@ static RPCHelpMan getconnectioncount()
|
||||
if(!node.connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
return (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
|
||||
return (int)node.connman->GetNodeCount(ConnectionDirection::Both);
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -649,12 +649,12 @@ static RPCHelpMan getnetworkinfo()
|
||||
obj.pushKV("timeoffset", GetTimeOffset());
|
||||
if (node.connman) {
|
||||
obj.pushKV("networkactive", node.connman->GetNetworkActive());
|
||||
obj.pushKV("connections", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
|
||||
obj.pushKV("connections_in", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_IN));
|
||||
obj.pushKV("connections_out", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_OUT));
|
||||
obj.pushKV("connections_mn", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED));
|
||||
obj.pushKV("connections_mn_in", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED_IN));
|
||||
obj.pushKV("connections_mn_out", (int)node.connman->GetNodeCount(CConnman::CONNECTIONS_VERIFIED_OUT));
|
||||
obj.pushKV("connections", (int)node.connman->GetNodeCount(ConnectionDirection::Both));
|
||||
obj.pushKV("connections_in", (int)node.connman->GetNodeCount(ConnectionDirection::In));
|
||||
obj.pushKV("connections_out", (int)node.connman->GetNodeCount(ConnectionDirection::Out));
|
||||
obj.pushKV("connections_mn", (int)node.connman->GetNodeCount(ConnectionDirection::Verified));
|
||||
obj.pushKV("connections_mn_in", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedIn));
|
||||
obj.pushKV("connections_mn_out", (int)node.connman->GetNodeCount(ConnectionDirection::VerifiedOut));
|
||||
std::string strSocketEvents;
|
||||
switch (node.connman->GetSocketEventsMode()) {
|
||||
case CConnman::SOCKETEVENTS_SELECT:
|
||||
|
@ -86,7 +86,7 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
|
||||
(void)connman.GetDeterministicRandomizer(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
|
||||
},
|
||||
[&] {
|
||||
(void)connman.GetNodeCount(fuzzed_data_provider.PickValueInArray({CConnman::CONNECTIONS_NONE, CConnman::CONNECTIONS_IN, CConnman::CONNECTIONS_OUT, CConnman::CONNECTIONS_ALL}));
|
||||
(void)connman.GetNodeCount(fuzzed_data_provider.PickValueInArray({ConnectionDirection::None, ConnectionDirection::In, ConnectionDirection::Out, ConnectionDirection::Both}));
|
||||
},
|
||||
[&] {
|
||||
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
|
||||
|
Loading…
Reference in New Issue
Block a user