MCPcopy Create free account
hub / github.com/LUX-Core/lux / SendMessages

Function SendMessages

src/main.cpp:7349–7576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7347
7348
7349bool SendMessages(CNode* pto)
7350{
7351 const Consensus::Params& consensusParams = Params().GetConsensus();
7352 {
7353 // Don't send anything until we get their version message
7354 if (pto->nVersion == 0)
7355 return true;
7356
7357 //
7358 // Message: ping
7359 //
7360 bool pingSend = false;
7361 if (pto->fPingQueued) {
7362 // RPC ping request by user
7363 pingSend = true;
7364 }
7365 if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) {
7366 // Ping automatically sent as a latency probe & keepalive.
7367 pingSend = true;
7368 }
7369 if (pingSend) {
7370 uint64_t nonce = 0;
7371 while (nonce == 0) {
7372 GetRandBytes((unsigned char*)&nonce, sizeof(nonce));
7373 }
7374 pto->fPingQueued = false;
7375 pto->nPingUsecStart = GetTimeMicros();
7376 if (pto->nVersion > BIP0031_VERSION) {
7377 pto->nPingNonceSent = nonce;
7378 pto->PushMessage("ping", nonce);
7379 } else {
7380 // Peer is too old to support ping command with nonce, pong will never arrive.
7381 pto->nPingNonceSent = 0;
7382 pto->PushMessage("ping");
7383 }
7384 }
7385
7386 TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState()
7387 if (!lockMain)
7388 return true;
7389
7390 // Address refresh broadcast
7391 int64_t nNow = GetTimeMicros();
7392 if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) {
7393 AdvertizeLocal(pto);
7394 pto->nNextLocalAddrSend = nNextSend(nNow, RELAY_LOCAL_ADDRESS_INTERVAL);
7395 }
7396
7397 //
7398 // Message: addr
7399 //
7400 if (pto->nNextAddrSend < nNow) {
7401 pto->nNextAddrSend = nNextSend(nNow, RELAY_ADDRESS_INTERVAL);
7402 vector<CAddress> vAddr;
7403 vAddr.reserve(pto->vAddrToSend.size());
7404 for (const CAddress& addr : pto->vAddrToSend) {
7405 // returns true if wasn't already contained in the set
7406 if (pto->setAddrKnown.insert(addr).second) {

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 15

GetTimeMicrosFunction · 0.85
GetRandBytesFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
AdvertizeLocalFunction · 0.85
nNextSendFunction · 0.85
GetAdjustedTimeFunction · 0.85
GetRandHashFunction · 0.85
FindNextBlocksToDownloadFunction · 0.85
IsWitnessEnabledFunction · 0.85
GetFetchFlagsFunction · 0.85
MarkBlockAsInFlightFunction · 0.85
LogPrintFunction · 0.85

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68