| 3267 | } |
| 3268 | |
| 3269 | bool 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 | // |