0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

scripted-diff: rename ping members

-BEGIN VERIFY SCRIPT-
sed -i 's/fPingQueued/m_ping_queued/g' src/net_processing.cpp
sed -i 's/nMinPingUsecTime/m_min_ping_time/g' src/net.* src/net_processing.cpp src/test/net_tests.cpp
sed -i 's/nPingNonceSent/m_ping_nonce_sent/g' src/net_processing.cpp
sed -i 's/nPingUsecTime/m_last_ping_time/g' src/net.*
-END VERIFY SCRIPT-
This commit is contained in:
John Newbery 2020-07-11 18:20:10 +01:00
parent 45dcf22661
commit a5e15ae45c
4 changed files with 26 additions and 26 deletions

View file

@ -601,8 +601,8 @@ void CNode::copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap)
stats.minFeeFilter = 0;
}
stats.m_ping_usec = nPingUsecTime;
stats.m_min_ping_usec = nMinPingUsecTime;
stats.m_ping_usec = m_last_ping_time;
stats.m_min_ping_usec = m_min_ping_time;
// Leave string empty if addrLocal invalid (not filled in yet)
CService addrLocalUnlocked = GetAddrLocal();
@ -824,7 +824,7 @@ size_t CConnman::SocketSendData(CNode& node) const
static bool ReverseCompareNodeMinPingTime(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
{
return a.nMinPingUsecTime > b.nMinPingUsecTime;
return a.m_min_ping_time > b.m_min_ping_time;
}
static bool ReverseCompareNodeTimeConnected(const NodeEvictionCandidate &a, const NodeEvictionCandidate &b)
@ -979,7 +979,7 @@ bool CConnman::AttemptToEvictConnection()
peer_relay_txes = node->m_tx_relay->fRelayTxes;
peer_filter_not_null = node->m_tx_relay->pfilter != nullptr;
}
NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->nMinPingUsecTime,
NodeEvictionCandidate candidate = {node->GetId(), node->nTimeConnected, node->m_min_ping_time,
node->nLastBlockTime, node->nLastTXTime,
HasAllDesirableServiceFlags(node->nServices),
peer_relay_txes, peer_filter_not_null, node->nKeyedNetGroup,

View file

@ -591,11 +591,11 @@ public:
std::atomic<int64_t> nLastTXTime{0};
/** Last measured round-trip time. Used only for RPC/GUI stats/debugging.*/
std::atomic<int64_t> nPingUsecTime{0};
std::atomic<int64_t> m_last_ping_time{0};
/** Lowest measured round-trip time. Used as an inbound peer eviction
* criterium in CConnman::AttemptToEvictConnection. */
std::atomic<int64_t> nMinPingUsecTime{std::numeric_limits<int64_t>::max()};
std::atomic<int64_t> m_min_ping_time{std::numeric_limits<int64_t>::max()};
CNode(NodeId id, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion);
~CNode();
@ -717,8 +717,8 @@ public:
/** A ping-pong round trip has completed successfully. Update latest and minimum ping times. */
void PongReceived(std::chrono::microseconds ping_time) {
nPingUsecTime = count_microseconds(ping_time);
nMinPingUsecTime = std::min(nMinPingUsecTime.load(), count_microseconds(ping_time));
m_last_ping_time = count_microseconds(ping_time);
m_min_ping_time = std::min(m_min_ping_time.load(), count_microseconds(ping_time));
}
private:
@ -1253,7 +1253,7 @@ struct NodeEvictionCandidate
{
NodeId id;
int64_t nTimeConnected;
int64_t nMinPingUsecTime;
int64_t m_min_ping_time;
int64_t nLastBlockTime;
int64_t nLastTXTime;
bool fRelevantServices;

View file

@ -220,11 +220,11 @@ struct Peer {
std::atomic<int> m_starting_height{-1};
/** The pong reply we're expecting, or 0 if no pong expected. */
std::atomic<uint64_t> nPingNonceSent{0};
std::atomic<uint64_t> m_ping_nonce_sent{0};
/** When the last ping was sent, or 0 if no ping was ever sent */
std::atomic<std::chrono::microseconds> m_ping_start{0us};
/** Whether a ping has been requested by the user */
std::atomic<bool> fPingQueued{false};
std::atomic<bool> m_ping_queued{false};
/** Set of txids to reconsider once their parent transactions have been accepted **/
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);
@ -1108,7 +1108,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
// So, if a ping is taking an unusually long time in flight,
// the caller can immediately detect that this is happening.
std::chrono::microseconds ping_wait{0};
if ((0 != peer->nPingNonceSent) && (0 != peer->m_ping_start.load().count())) {
if ((0 != peer->m_ping_nonce_sent) && (0 != peer->m_ping_start.load().count())) {
ping_wait = GetTime<std::chrono::microseconds>() - peer->m_ping_start.load();
}
@ -1655,7 +1655,7 @@ bool static AlreadyHaveBlock(const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED
void PeerManagerImpl::SendPings()
{
LOCK(m_peer_mutex);
for(auto& it : m_peer_map) it.second->fPingQueued = true;
for(auto& it : m_peer_map) it.second->m_ping_queued = true;
}
void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman)
@ -3868,8 +3868,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
vRecv >> nonce;
// Only process pong message if there is an outstanding ping (old ping without nonce should never pong)
if (peer->nPingNonceSent != 0) {
if (nonce == peer->nPingNonceSent) {
if (peer->m_ping_nonce_sent != 0) {
if (nonce == peer->m_ping_nonce_sent) {
// Matching pong received, this ping is no longer outstanding
bPingFinished = true;
const auto ping_time = ping_end - peer->m_ping_start.load();
@ -3902,12 +3902,12 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LogPrint(BCLog::NET, "pong peer=%d: %s, %x expected, %x received, %u bytes\n",
pfrom.GetId(),
sProblem,
peer->nPingNonceSent,
peer->m_ping_nonce_sent,
nonce,
nAvail);
}
if (bPingFinished) {
peer->nPingNonceSent = 0;
peer->m_ping_nonce_sent = 0;
}
return;
}
@ -4327,7 +4327,7 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer)
// This means that setmocktime may cause pings to time out.
auto now = GetTime<std::chrono::microseconds>();
if (m_connman.RunInactivityChecks(node_to) && peer.nPingNonceSent &&
if (m_connman.RunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
now > peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL}) {
LogPrint(BCLog::NET, "ping timeout: %fs peer=%d\n", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), peer.m_id);
node_to.fDisconnect = true;
@ -4337,12 +4337,12 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer)
const CNetMsgMaker msgMaker(node_to.GetCommonVersion());
bool pingSend = false;
if (peer.fPingQueued) {
if (peer.m_ping_queued) {
// RPC ping request by user
pingSend = true;
}
if (peer.nPingNonceSent == 0 && now > peer.m_ping_start.load() + PING_INTERVAL) {
if (peer.m_ping_nonce_sent == 0 && now > peer.m_ping_start.load() + PING_INTERVAL) {
// Ping automatically sent as a latency probe & keepalive.
pingSend = true;
}
@ -4352,14 +4352,14 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer)
while (nonce == 0) {
GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
}
peer.fPingQueued = false;
peer.m_ping_queued = false;
peer.m_ping_start = now;
if (node_to.GetCommonVersion() > BIP0031_VERSION) {
peer.nPingNonceSent = nonce;
peer.m_ping_nonce_sent = nonce;
m_connman.PushMessage(&node_to, msgMaker.Make(NetMsgType::PING, nonce));
} else {
// Peer is too old to support ping command with nonce, pong will never arrive.
peer.nPingNonceSent = 0;
peer.m_ping_nonce_sent = 0;
m_connman.PushMessage(&node_to, msgMaker.Make(NetMsgType::PING));
}
}

View file

@ -794,7 +794,7 @@ std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(const int n_c
candidates.push_back({
/* id */ id,
/* nTimeConnected */ static_cast<int64_t>(random_context.randrange(100)),
/* nMinPingUsecTime */ static_cast<int64_t>(random_context.randrange(100)),
/* m_min_ping_time */ static_cast<int64_t>(random_context.randrange(100)),
/* nLastBlockTime */ static_cast<int64_t>(random_context.randrange(100)),
/* nLastTXTime */ static_cast<int64_t>(random_context.randrange(100)),
/* fRelevantServices */ random_context.randbool(),
@ -854,7 +854,7 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
// from eviction.
BOOST_CHECK(!IsEvicted(
number_of_nodes, [](NodeEvictionCandidate& candidate) {
candidate.nMinPingUsecTime = candidate.id;
candidate.m_min_ping_time = candidate.id;
},
{0, 1, 2, 3, 4, 5, 6, 7}, random_context));
@ -901,7 +901,7 @@ BOOST_AUTO_TEST_CASE(node_eviction_test)
BOOST_CHECK(!IsEvicted(
number_of_nodes, [number_of_nodes](NodeEvictionCandidate& candidate) {
candidate.nKeyedNetGroup = number_of_nodes - candidate.id; // 4 protected
candidate.nMinPingUsecTime = candidate.id; // 8 protected
candidate.m_min_ping_time = candidate.id; // 8 protected
candidate.nLastTXTime = number_of_nodes - candidate.id; // 4 protected
candidate.nLastBlockTime = number_of_nodes - candidate.id; // 4 protected
},