MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessGetHeadersMessage

Function ProcessGetHeadersMessage

src/p2p/chainmessage.cpp:512–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510}
511
512bool ProcessGetHeadersMessage(CNode *pFrom, CDataStream &vRecv) {
513 CBlockLocator locator;
514 uint256 hashStop;
515 vRecv >> locator >> hashStop;
516
517 LOCK(cs_main);
518
519 CBlockIndex *pIndex = nullptr;
520 if (locator.IsNull()) {
521 // If locator is null, return the hashStop block
522 map<uint256, CBlockIndex *>::iterator mi = mapBlockIndex.find(hashStop);
523 if (mi == mapBlockIndex.end())
524 return true;
525
526 pIndex = (*mi).second;
527 } else {
528 // Find the last block the caller has in the main chain
529 pIndex = chainActive.FindFork(mapBlockIndex, locator);
530 if (pIndex)
531 pIndex = chainActive.Next(pIndex);
532 }
533
534 // We must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end
535 vector<CBlock> vHeaders;
536 int32_t nLimit = 2000;
537 LogPrint(BCLog::NET, "getheaders %d to %s from peer %s\n", (pIndex ? pIndex->height : -1), hashStop.ToString(),
538 pFrom->addr.ToString());
539
540 for (; pIndex; pIndex = chainActive.Next(pIndex)) {
541 CBlockHeader blockHeader;
542 if (!GetBlockHeader(pIndex, blockHeader))
543 return ERRORMSG("get block=%s index failed", pIndex->GetIdString());
544 vHeaders.push_back(blockHeader);
545
546 if (--nLimit <= 0 || pIndex->GetBlockHash() == hashStop)
547 break;
548 }
549 pFrom->PushMessage("headers", vHeaders);
550
551 return false;
552}
553
554void ProcessGetBlocksMessage(CNode *pFrom, CDataStream &vRecv) {
555 CBlockLocator locator;

Callers 1

ProcessMessageFunction · 0.85

Calls 11

GetBlockHeaderFunction · 0.85
FindForkMethod · 0.80
GetIdStringMethod · 0.80
push_backMethod · 0.80
PushMessageMethod · 0.80
IsNullMethod · 0.45
findMethod · 0.45
endMethod · 0.45
NextMethod · 0.45
ToStringMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected