Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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