Skip to content

Commit

Permalink
Merge dashpay#5983: backport: Merge bitcoin#22138, 21939, bitcoin-cor…
Browse files Browse the repository at this point in the history
…e/gui#163, 20373,  22144, 22013, 21719, 20786

18169f4 Merge bitcoin#20786: net: [refactor] Prefer integral types in CNodeStats (MarcoFalke)
751c9e6 Merge bitcoin#21719: refactor: Add and use EnsureConnman in rpc code (MarcoFalke)
74b20eb Merge bitcoin#22013: net: ignore block-relay-only peers when skipping DNS seed (fanquake)
366ca98 Merge bitcoin#22144: Randomize message processing peer order (fanquake)
4d20cb7 Merge bitcoin#20373: refactor, net: Increase CNode data member encapsulation (MarcoFalke)
b8b3c4c Merge bitcoin-core/gui#163: Peer details: replace Direction with Connection Type (MarcoFalke)
00b828c Merge bitcoin#21939: refactor: Replace memset calls with array initialization (W. J. van der Laan)
7bcc56c Merge bitcoin#22138: script: fix spelling linter raising spuriously on "invokable" (MarcoFalke)

Pull request description:

  bitcoin backports

Top commit has no ACKs.

Tree-SHA512: 28dd3c672be847a376aaf1683a665b658b132364b4903fa360810dead7f30bd6496c231b6496e55572e09f1908febdba385d863e5e1d714cb784cc4350126be9
  • Loading branch information
PastaPastaPasta committed Apr 23, 2024
2 parents 5c240bb + 18169f4 commit 6194e45
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 171 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ BITCOIN_CORE_H = \
rpc/blockchain.h \
rpc/client.h \
rpc/mining.h \
rpc/net.h \
rpc/protocol.h \
rpc/rawtransaction_util.h \
rpc/register.h \
Expand Down
41 changes: 23 additions & 18 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ bool CNode::IsBlockRelayOnly() const {
return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || IsBlockOnlyConn();
}

std::string CNode::ConnectionTypeAsString() const
std::string ConnectionTypeAsString(ConnectionType conn_type)
{
switch (m_conn_type) {
switch (conn_type) {
case ConnectionType::INBOUND:
return "inbound";
case ConnectionType::MANUAL:
Expand Down Expand Up @@ -700,7 +700,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
X(verifiedPubKeyHash);
}
X(m_masternode_connection);
stats.m_conn_type_string = ConnectionTypeAsString();
X(m_conn_type);
}
#undef X

Expand Down Expand Up @@ -2169,7 +2169,7 @@ void CConnman::ThreadDNSAddressSeed()
{
LOCK(cs_vNodes);
for (const CNode* pnode : vNodes) {
if (pnode->fSuccessfullyConnected && !pnode->IsOutboundOrBlockRelayConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
if (pnode->fSuccessfullyConnected && !pnode->IsFullOutboundConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
}
}
if (nRelevant >= 2) {
Expand Down Expand Up @@ -2256,7 +2256,7 @@ void CConnman::ProcessAddrFetch()
}
}

bool CConnman::GetTryNewOutboundPeer()
bool CConnman::GetTryNewOutboundPeer() const
{
return m_try_another_outbound_peer;
}
Expand All @@ -2273,7 +2273,7 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
// Also exclude peers that haven't finished initial connection handshake yet
// (so that we don't decide we're over our desired connection limit, and then
// evict some peer that has finished the handshake)
int CConnman::GetExtraFullOutboundCount()
int CConnman::GetExtraFullOutboundCount() const
{
int full_outbound_peers = 0;
{
Expand All @@ -2291,7 +2291,7 @@ int CConnman::GetExtraFullOutboundCount()
return std::max(full_outbound_peers - m_max_outbound_full_relay, 0);
}

int CConnman::GetExtraBlockRelayCount()
int CConnman::GetExtraBlockRelayCount() const
{
int block_relay_peers = 0;
{
Expand Down Expand Up @@ -2619,7 +2619,7 @@ std::vector<CAddress> CConnman::GetCurrentBlockRelayOnlyConns() const
return ret;
}

std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
{
std::vector<AddedNodeInfo> ret;

Expand Down Expand Up @@ -2965,6 +2965,7 @@ void CConnman::ThreadMessageHandler()
{
int64_t nLastSendMessagesTimeMasternodes = 0;

FastRandomContext rng;
while (!flagInterruptMsgProc)
{
std::vector<CNode*> vNodesCopy = CopyNodeVector();
Expand All @@ -2976,6 +2977,10 @@ void CConnman::ThreadMessageHandler()
fSkipSendMessagesForMasternodes = false;
nLastSendMessagesTimeMasternodes = GetTimeMillis();
}
// Randomize the order in which we process messages from/to our peers.
// This prevents attacks in which an attacker exploits having multiple
// consecutive connections in the vNodes list.
Shuffle(vNodesCopy.begin(), vNodesCopy.end(), rng);

for (CNode* pnode : vNodesCopy)
{
Expand Down Expand Up @@ -3616,7 +3621,7 @@ CConnman::~CConnman()
Stop();
}

std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network)
std::vector<CAddress> CConnman::GetAddresses(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
{
std::vector<CAddress> addresses = addrman.GetAddr(max_addresses, max_pct, network);
if (m_banman) {
Expand Down Expand Up @@ -3837,7 +3842,7 @@ void CConnman::AddPendingProbeConnections(const std::set<uint256> &proTxHashes)
masternodePendingProbes.insert(proTxHashes.begin(), proTxHashes.end());
}

size_t CConnman::GetNodeCount(ConnectionDirection flags)
size_t CConnman::GetNodeCount(ConnectionDirection flags) const
{
LOCK(cs_vNodes);

Expand All @@ -3864,7 +3869,7 @@ size_t CConnman::GetMaxOutboundNodeCount()
return m_max_outbound;
}

void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
{
vstats.clear();
LOCK(cs_vNodes);
Expand Down Expand Up @@ -4003,18 +4008,18 @@ void CConnman::RecordBytesSent(uint64_t bytes)
nMaxOutboundTotalBytesSentInCycle += bytes;
}

uint64_t CConnman::GetMaxOutboundTarget()
uint64_t CConnman::GetMaxOutboundTarget() const
{
LOCK(cs_totalBytesSent);
return nMaxOutboundLimit;
}

std::chrono::seconds CConnman::GetMaxOutboundTimeframe()
std::chrono::seconds CConnman::GetMaxOutboundTimeframe() const
{
return MAX_UPLOAD_TIMEFRAME;
}

std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle()
std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle() const
{
LOCK(cs_totalBytesSent);
if (nMaxOutboundLimit == 0)
Expand All @@ -4028,7 +4033,7 @@ std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle()
return (cycleEndTime < now) ? 0s : cycleEndTime - now;
}

bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit)
bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit) const
{
LOCK(cs_totalBytesSent);
if (nMaxOutboundLimit == 0)
Expand All @@ -4048,7 +4053,7 @@ bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit)
return false;
}

uint64_t CConnman::GetOutboundTargetBytesLeft()
uint64_t CConnman::GetOutboundTargetBytesLeft() const
{
LOCK(cs_totalBytesSent);
if (nMaxOutboundLimit == 0)
Expand All @@ -4057,13 +4062,13 @@ uint64_t CConnman::GetOutboundTargetBytesLeft()
return (nMaxOutboundTotalBytesSentInCycle >= nMaxOutboundLimit) ? 0 : nMaxOutboundLimit - nMaxOutboundTotalBytesSentInCycle;
}

uint64_t CConnman::GetTotalBytesRecv()
uint64_t CConnman::GetTotalBytesRecv() const
{
LOCK(cs_totalBytesRecv);
return nTotalBytesRecv;
}

uint64_t CConnman::GetTotalBytesSent()
uint64_t CConnman::GetTotalBytesSent() const
{
LOCK(cs_totalBytesSent);
return nTotalBytesSent;
Expand Down
Loading

0 comments on commit 6194e45

Please sign in to comment.