| 5974 | |
| 5975 | |
| 5976 | bool SendMessages(CNode* pto) |
| 5977 | { |
| 5978 | const Consensus::Params& consensusParams = Params().GetConsensus(); |
| 5979 | { |
| 5980 | // Don't send anything until we get its version message |
| 5981 | if (pto->nVersion == 0) |
| 5982 | return true; |
| 5983 | |
| 5984 | // |
| 5985 | // Message: ping |
| 5986 | // |
| 5987 | bool pingSend = false; |
| 5988 | if (pto->fPingQueued) { |
| 5989 | // RPC ping request by user |
| 5990 | pingSend = true; |
| 5991 | } |
| 5992 | if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) { |
| 5993 | // Ping automatically sent as a latency probe & keepalive. |
| 5994 | pingSend = true; |
| 5995 | } |
| 5996 | if (pingSend) { |
| 5997 | uint64_t nonce = 0; |
| 5998 | while (nonce == 0) { |
| 5999 | GetRandBytes((unsigned char*)&nonce, sizeof(nonce)); |
| 6000 | } |
| 6001 | pto->fPingQueued = false; |
| 6002 | pto->nPingUsecStart = GetTimeMicros(); |
| 6003 | if (pto->nVersion > BIP0031_VERSION) { |
| 6004 | pto->nPingNonceSent = nonce; |
| 6005 | pto->PushMessage("ping", nonce); |
| 6006 | } else { |
| 6007 | // Peer is too old to support ping command with nonce, pong will never arrive. |
| 6008 | pto->nPingNonceSent = 0; |
| 6009 | pto->PushMessage("ping"); |
| 6010 | } |
| 6011 | } |
| 6012 | |
| 6013 | TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState() |
| 6014 | if (!lockMain) |
| 6015 | return true; |
| 6016 | |
| 6017 | // Address refresh broadcast |
| 6018 | int64_t nNow = GetTimeMicros(); |
| 6019 | if (!IsInitialBlockDownload() && pto->nNextLocalAddrSend < nNow) { |
| 6020 | AdvertizeLocal(pto); |
| 6021 | pto->nNextLocalAddrSend = PoissonNextSend(nNow, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL); |
| 6022 | } |
| 6023 | |
| 6024 | // |
| 6025 | // Message: addr |
| 6026 | // |
| 6027 | if (pto->nNextAddrSend < nNow) { |
| 6028 | pto->nNextAddrSend = PoissonNextSend(nNow, AVG_ADDRESS_BROADCAST_INTERVAL); |
| 6029 | vector<CAddress> vAddr; |
| 6030 | vAddr.reserve(pto->vAddrToSend.size()); |
| 6031 | BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) |
| 6032 | { |
| 6033 | if (!pto->addrKnown.contains(addr.GetKey())) |