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

Function ProcessGetData

src/p2p/chainmessage.cpp:74–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void ProcessGetData(CNode *pFrom) {
75 deque<CInv>::iterator it = pFrom->vRecvGetData.begin();
76
77 vector<CInv> vNotFound;
78
79 LOCK(cs_main);
80
81 while (it != pFrom->vRecvGetData.end()) {
82 // Don't bother if send buffer is too full to respond anyway
83 if (pFrom->nSendSize >= SendBufferSize()) {
84 LogPrint(BCLog::NET, "send buffer size: %d full for peer: %s\n", pFrom->nSendSize, pFrom->addr.ToString());
85 break;
86 }
87
88 const CInv &inv = *it;
89 {
90 boost::this_thread::interruption_point();
91 it++;
92
93 if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) {
94 auto mi = mapBlockIndex.find(inv.hash);
95 if (mi == mapBlockIndex.end()) {
96 LogPrint(BCLog::NET, "block %s not found\n", inv.hash.GetHex());
97
98 } else { // Load block from disk and send it
99 CBlock block;
100 ReadBlockFromDisk((*mi).second, block);
101 if (inv.type == MSG_BLOCK) {
102 LogPrint(BCLog::NET, "send block[%u]: %s to peer %s\n", block.GetHeight(), block.GetHash().GetHex(),
103 pFrom->addr.ToString());
104
105 pFrom->PushMessage(NetMsgType::BLOCK, block);
106
107 } else {// MSG_FILTERED_BLOCK)
108 LOCK(pFrom->cs_filter);
109 if (pFrom->pFilter) {
110 CMerkleBlock merkleBlock(block, *pFrom->pFilter);
111 pFrom->PushMessage("merkleblock", merkleBlock);
112 // CMerkleBlock just contains hashes, so also push any transactions in the block the client
113 // did not see This avoids hurting performance by pointlessly requiring a round-trip Note
114 // that there is currently no way for a node to request any single transactions we didnt
115 // send here - they must either disconnect and retry or request the full block. Thus, the
116 // protocol spec specified allows for us to provide duplicate txn here, however we MUST
117 // always provide at least what the remote peer needs
118 for (auto &pair : merkleBlock.vMatchedTxn)
119 if (!pFrom->setInventoryKnown.count(CInv(MSG_TX, pair.second)))
120 pFrom->PushMessage(NetMsgType::TX, block.vptx[pair.first]);
121 }
122 // else
123 // no response
124 }
125
126 // Trigger them to send a getblocks request for the next batch of inventory
127 if (inv.hash == pFrom->hashContinue) {
128 // Bypass PushInventory, this must send even if redundant,
129 // and we want it right after the last block so they don't
130 // wait for other stuff first.
131 vector<CInv> vInv;

Callers 3

ProcessMessagesFunction · 0.85
ProcessGetDataMessageFunction · 0.85
ProcessDataMethod · 0.85

Calls 15

SendBufferSizeFunction · 0.85
ReadBlockFromDiskFunction · 0.85
PushMessageMethod · 0.80
push_backMethod · 0.80
TipMethod · 0.80
IsKnownTypeMethod · 0.80
GetCommandMethod · 0.80
IsRelayForbiddenMethod · 0.80
reserveMethod · 0.80
CInvClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected