MCPcopy Create free account
hub / github.com/ElementsProject/elements / MaybeSendPing

Method MaybeSendPing

src/net_processing.cpp:4457–4499  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4455}
4456
4457void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now)
4458{
4459 if (m_connman.ShouldRunInactivityChecks(node_to, std::chrono::duration_cast<std::chrono::seconds>(now)) &&
4460 peer.m_ping_nonce_sent &&
4461 now > peer.m_ping_start.load() + TIMEOUT_INTERVAL)
4462 {
4463 // The ping timeout is using mocktime. To disable the check during
4464 // testing, increase -peertimeout.
4465 LogPrint(BCLog::NET, "ping timeout: %fs peer=%d\n", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), peer.m_id);
4466 node_to.fDisconnect = true;
4467 return;
4468 }
4469
4470 const CNetMsgMaker msgMaker(node_to.GetCommonVersion());
4471 bool pingSend = false;
4472
4473 if (peer.m_ping_queued) {
4474 // RPC ping request by user
4475 pingSend = true;
4476 }
4477
4478 if (peer.m_ping_nonce_sent == 0 && now > peer.m_ping_start.load() + PING_INTERVAL) {
4479 // Ping automatically sent as a latency probe & keepalive.
4480 pingSend = true;
4481 }
4482
4483 if (pingSend) {
4484 uint64_t nonce = 0;
4485 while (nonce == 0) {
4486 GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
4487 }
4488 peer.m_ping_queued = false;
4489 peer.m_ping_start = now;
4490 if (node_to.GetCommonVersion() > BIP0031_VERSION) {
4491 peer.m_ping_nonce_sent = nonce;
4492 m_connman.PushMessage(&node_to, msgMaker.Make(NetMsgType::PING, nonce));
4493 } else {
4494 // Peer is too old to support ping command with nonce, pong will never arrive.
4495 peer.m_ping_nonce_sent = 0;
4496 m_connman.PushMessage(&node_to, msgMaker.Make(NetMsgType::PING));
4497 }
4498 }
4499}
4500
4501void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::microseconds current_time)
4502{

Callers

nothing calls this directly

Calls 7

count_microsecondsFunction · 0.85
GetRandBytesFunction · 0.85
GetCommonVersionMethod · 0.80
PushMessageMethod · 0.80
loadMethod · 0.45
MakeMethod · 0.45

Tested by

no test coverage detected