Skip to content

Commit 6194e45

Browse files
Merge dashpay#5983: backport: Merge bitcoin#22138, 21939, bitcoin-core/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
2 parents 5c240bb + 18169f4 commit 6194e45

16 files changed

+201
-171
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ BITCOIN_CORE_H = \
286286
rpc/blockchain.h \
287287
rpc/client.h \
288288
rpc/mining.h \
289+
rpc/net.h \
289290
rpc/protocol.h \
290291
rpc/rawtransaction_util.h \
291292
rpc/register.h \

src/net.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ bool CNode::IsBlockRelayOnly() const {
588588
return (ignores_incoming_txs && !HasPermission(NetPermissionFlags::Relay)) || IsBlockOnlyConn();
589589
}
590590

591-
std::string CNode::ConnectionTypeAsString() const
591+
std::string ConnectionTypeAsString(ConnectionType conn_type)
592592
{
593-
switch (m_conn_type) {
593+
switch (conn_type) {
594594
case ConnectionType::INBOUND:
595595
return "inbound";
596596
case ConnectionType::MANUAL:
@@ -700,7 +700,7 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
700700
X(verifiedPubKeyHash);
701701
}
702702
X(m_masternode_connection);
703-
stats.m_conn_type_string = ConnectionTypeAsString();
703+
X(m_conn_type);
704704
}
705705
#undef X
706706

@@ -2169,7 +2169,7 @@ void CConnman::ThreadDNSAddressSeed()
21692169
{
21702170
LOCK(cs_vNodes);
21712171
for (const CNode* pnode : vNodes) {
2172-
if (pnode->fSuccessfullyConnected && !pnode->IsOutboundOrBlockRelayConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
2172+
if (pnode->fSuccessfullyConnected && !pnode->IsFullOutboundConn() && !pnode->m_masternode_probe_connection) ++nRelevant;
21732173
}
21742174
}
21752175
if (nRelevant >= 2) {
@@ -2256,7 +2256,7 @@ void CConnman::ProcessAddrFetch()
22562256
}
22572257
}
22582258

2259-
bool CConnman::GetTryNewOutboundPeer()
2259+
bool CConnman::GetTryNewOutboundPeer() const
22602260
{
22612261
return m_try_another_outbound_peer;
22622262
}
@@ -2273,7 +2273,7 @@ void CConnman::SetTryNewOutboundPeer(bool flag)
22732273
// Also exclude peers that haven't finished initial connection handshake yet
22742274
// (so that we don't decide we're over our desired connection limit, and then
22752275
// evict some peer that has finished the handshake)
2276-
int CConnman::GetExtraFullOutboundCount()
2276+
int CConnman::GetExtraFullOutboundCount() const
22772277
{
22782278
int full_outbound_peers = 0;
22792279
{
@@ -2291,7 +2291,7 @@ int CConnman::GetExtraFullOutboundCount()
22912291
return std::max(full_outbound_peers - m_max_outbound_full_relay, 0);
22922292
}
22932293

2294-
int CConnman::GetExtraBlockRelayCount()
2294+
int CConnman::GetExtraBlockRelayCount() const
22952295
{
22962296
int block_relay_peers = 0;
22972297
{
@@ -2619,7 +2619,7 @@ std::vector<CAddress> CConnman::GetCurrentBlockRelayOnlyConns() const
26192619
return ret;
26202620
}
26212621

2622-
std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
2622+
std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() const
26232623
{
26242624
std::vector<AddedNodeInfo> ret;
26252625

@@ -2965,6 +2965,7 @@ void CConnman::ThreadMessageHandler()
29652965
{
29662966
int64_t nLastSendMessagesTimeMasternodes = 0;
29672967

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

29802985
for (CNode* pnode : vNodesCopy)
29812986
{
@@ -3616,7 +3621,7 @@ CConnman::~CConnman()
36163621
Stop();
36173622
}
36183623

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

3840-
size_t CConnman::GetNodeCount(ConnectionDirection flags)
3845+
size_t CConnman::GetNodeCount(ConnectionDirection flags) const
38413846
{
38423847
LOCK(cs_vNodes);
38433848

@@ -3864,7 +3869,7 @@ size_t CConnman::GetMaxOutboundNodeCount()
38643869
return m_max_outbound;
38653870
}
38663871

3867-
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
3872+
void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
38683873
{
38693874
vstats.clear();
38703875
LOCK(cs_vNodes);
@@ -4003,18 +4008,18 @@ void CConnman::RecordBytesSent(uint64_t bytes)
40034008
nMaxOutboundTotalBytesSentInCycle += bytes;
40044009
}
40054010

4006-
uint64_t CConnman::GetMaxOutboundTarget()
4011+
uint64_t CConnman::GetMaxOutboundTarget() const
40074012
{
40084013
LOCK(cs_totalBytesSent);
40094014
return nMaxOutboundLimit;
40104015
}
40114016

4012-
std::chrono::seconds CConnman::GetMaxOutboundTimeframe()
4017+
std::chrono::seconds CConnman::GetMaxOutboundTimeframe() const
40134018
{
40144019
return MAX_UPLOAD_TIMEFRAME;
40154020
}
40164021

4017-
std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle()
4022+
std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle() const
40184023
{
40194024
LOCK(cs_totalBytesSent);
40204025
if (nMaxOutboundLimit == 0)
@@ -4028,7 +4033,7 @@ std::chrono::seconds CConnman::GetMaxOutboundTimeLeftInCycle()
40284033
return (cycleEndTime < now) ? 0s : cycleEndTime - now;
40294034
}
40304035

4031-
bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit)
4036+
bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit) const
40324037
{
40334038
LOCK(cs_totalBytesSent);
40344039
if (nMaxOutboundLimit == 0)
@@ -4048,7 +4053,7 @@ bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit)
40484053
return false;
40494054
}
40504055

4051-
uint64_t CConnman::GetOutboundTargetBytesLeft()
4056+
uint64_t CConnman::GetOutboundTargetBytesLeft() const
40524057
{
40534058
LOCK(cs_totalBytesSent);
40544059
if (nMaxOutboundLimit == 0)
@@ -4057,13 +4062,13 @@ uint64_t CConnman::GetOutboundTargetBytesLeft()
40574062
return (nMaxOutboundTotalBytesSentInCycle >= nMaxOutboundLimit) ? 0 : nMaxOutboundLimit - nMaxOutboundTotalBytesSentInCycle;
40584063
}
40594064

4060-
uint64_t CConnman::GetTotalBytesRecv()
4065+
uint64_t CConnman::GetTotalBytesRecv() const
40614066
{
40624067
LOCK(cs_totalBytesRecv);
40634068
return nTotalBytesRecv;
40644069
}
40654070

4066-
uint64_t CConnman::GetTotalBytesSent()
4071+
uint64_t CConnman::GetTotalBytesSent() const
40674072
{
40684073
LOCK(cs_totalBytesSent);
40694074
return nTotalBytesSent;

0 commit comments

Comments
 (0)