MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SendMessages

Method SendMessages

src/net_processing.cpp:3269–3800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3267}
3268
3269bool PeerLogicValidation::SendMessages(CNode* pto)
3270{
3271 const Consensus::Params& consensusParams = Params().GetConsensus();
3272 {
3273 // Don't send anything until the version handshake is complete
3274 if (!pto->fSuccessfullyConnected || pto->fDisconnect)
3275 return true;
3276
3277 // If we get here, the outgoing message serialization version is set and can't change.
3278 const CNetMsgMaker msgMaker(pto->GetSendVersion());
3279
3280 //
3281 // Message: ping
3282 //
3283 bool pingSend = false;
3284 if (pto->fPingQueued) {
3285 // RPC ping request by user
3286 pingSend = true;
3287 }
3288 if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
3289 // Ping automatically sent as a latency probe & keepalive.
3290 pingSend = true;
3291 }
3292 if (pingSend) {
3293 uint64_t nonce = 0;
3294 while (nonce == 0) {
3295 GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
3296 }
3297 pto->fPingQueued = false;
3298 pto->nPingUsecStart = GetTimeMicros();
3299 if (pto->nVersion > BIP0031_VERSION) {
3300 pto->nPingNonceSent = nonce;
3301 connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING, nonce));
3302 } else {
3303 // Peer is too old to support ping command with nonce, pong will never arrive.
3304 pto->nPingNonceSent = 0;
3305 connman->PushMessage(pto, msgMaker.Make(NetMsgType::PING));
3306 }
3307 }
3308
3309 TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState()
3310 if (!lockMain)
3311 return true;
3312
3313 if (SendRejectsAndCheckIfBanned(pto, connman, m_enable_bip61))
3314 return true;
3315 CNodeState &state = *State(pto->GetId());
3316
3317 // Address refresh broadcast
3318 int64_t nNow = GetTimeMicros();
3319 if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
3320 AdvertiseLocal(pto);
3321 pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
3322 }
3323
3324 //
3325 // Message: addr
3326 //

Callers 2

ThreadMessageHandlerMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 15

GetTimeMicrosFunction · 0.85
GetRandBytesFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
AdvertiseLocalFunction · 0.85
PoissonNextSendFunction · 0.85
GetAdjustedTimeFunction · 0.85
LookupBlockIndexFunction · 0.85
ReadBlockFromDiskFunction · 0.85
GetTimeFunction · 0.85
maxFunction · 0.85
GetRandIntFunction · 0.85

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64