| 552 | } |
| 553 | |
| 554 | void ProcessGetBlocksMessage(CNode *pFrom, CDataStream &vRecv) { |
| 555 | CBlockLocator locator; |
| 556 | uint256 hashStop; |
| 557 | vRecv >> locator >> hashStop; |
| 558 | |
| 559 | LOCK(cs_main); |
| 560 | |
| 561 | // Find the last block the caller has in the main chain |
| 562 | auto *pStartIndex = chainActive.FindFork(mapBlockIndex, locator); |
| 563 | |
| 564 | // Send the rest of the chain |
| 565 | if (pStartIndex) |
| 566 | pStartIndex = chainActive.Next(pStartIndex); |
| 567 | |
| 568 | int32_t nLimit = 500; |
| 569 | LogPrint(BCLog::NET, "recv getblocks msg! start_block=%s, end_block=%s, tip_block=%s, limit=%d, peer=%s\n", |
| 570 | (pStartIndex ? pStartIndex->GetIdString() : ""), hashStop.ToString(), |
| 571 | chainActive.Tip()->GetIdString(), nLimit, pFrom->addrName); |
| 572 | |
| 573 | CBlockIndex *pIndex = pStartIndex; |
| 574 | for (; pIndex; pIndex = chainActive.Next(pIndex)) { |
| 575 | if (pIndex->GetBlockHash() == hashStop) { |
| 576 | LogPrint(BCLog::NET, "[%d] stoped by hash_end! end_block=%s, peer=%s\n", pIndex->height, |
| 577 | pIndex->GetIdString(), pFrom->addrName); |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | // bool forced = false; |
| 582 | // if (pIndex == pStartIndex || pIndex->pprev == pStartIndex) |
| 583 | // forced = true; |
| 584 | // pFrom->PushInventory(CInv(MSG_BLOCK, pIndex->GetBlockHash()), forced); |
| 585 | bool force_to_send_again = false; |
| 586 | if (pIndex == pStartIndex || pIndex->pprev == pStartIndex) |
| 587 | force_to_send_again = true; |
| 588 | |
| 589 | pFrom->PushInventory(CInv(MSG_BLOCK, pIndex->GetBlockHash()), force_to_send_again); |
| 590 | |
| 591 | if (--nLimit <= 0) { |
| 592 | // When this block is requested, we'll send an inv that'll make them |
| 593 | // getblocks the next batch of inventory. |
| 594 | LogPrint(BCLog::NET, "processing getblocks stopped by limit! end_block=%s, limit=%d, peer=%s\n", |
| 595 | pIndex->GetIdString(), 500, pFrom->addrName); |
| 596 | |
| 597 | pFrom->hashContinue = pIndex->GetBlockHash(); |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | bool ProcessInvMessage(CNode *pFrom, CDataStream &vRecv) { |
| 604 | vector<CInv> vInv; |
no test coverage detected