| 7347 | |
| 7348 | |
| 7349 | bool 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) { |