MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MaybeSendPing

Method MaybeSendPing

src/net_processing.cpp:5443–5484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5441}
5442
5443void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, NodeClock::time_point now)
5444{
5445 if (m_connman.ShouldRunInactivityChecks(node_to, now) &&
5446 peer.m_ping_nonce_sent &&
5447 now > peer.m_ping_start.load() + TIMEOUT_INTERVAL)
5448 {
5449 // The ping timeout is using mocktime. To disable the check during
5450 // testing, increase -peertimeout.
5451 LogDebug(BCLog::NET, "ping timeout: %fs, %s", Ticks<SecondsDouble>(now - peer.m_ping_start.load()), node_to.DisconnectMsg());
5452 node_to.fDisconnect = true;
5453 return;
5454 }
5455
5456 bool pingSend = false;
5457
5458 if (peer.m_ping_queued) {
5459 // RPC ping request by user
5460 pingSend = true;
5461 }
5462
5463 if (peer.m_ping_nonce_sent == 0 && now > peer.m_ping_start.load() + PING_INTERVAL) {
5464 // Ping automatically sent as a latency probe & keepalive.
5465 pingSend = true;
5466 }
5467
5468 if (pingSend) {
5469 uint64_t nonce;
5470 do {
5471 nonce = FastRandomContext().rand64();
5472 } while (nonce == 0);
5473 peer.m_ping_queued = false;
5474 peer.m_ping_start = now;
5475 if (node_to.GetCommonVersion() > BIP0031_VERSION) {
5476 peer.m_ping_nonce_sent = nonce;
5477 MakeAndPushMessage(node_to, NetMsgType::PING, nonce);
5478 } else {
5479 // Peer is too old to support ping message type with nonce, pong will never arrive.
5480 peer.m_ping_nonce_sent = 0;
5481 MakeAndPushMessage(node_to, NetMsgType::PING);
5482 }
5483 }
5484}
5485
5486void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::microseconds current_time)
5487{

Callers

nothing calls this directly

Calls 6

DisconnectMsgMethod · 0.80
GetCommonVersionMethod · 0.80
FastRandomContextClass · 0.70
loadMethod · 0.45
rand64Method · 0.45

Tested by

no test coverage detected