Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,742 Lines • ▼ Show 20 Lines | switch (inv.type) { | ||||
case MSG_BLOCK: | case MSG_BLOCK: | ||||
return LookupBlockIndex(BlockHash(inv.hash)) != nullptr; | return LookupBlockIndex(BlockHash(inv.hash)) != nullptr; | ||||
} | } | ||||
// Don't know what it is, just say we already got one | // Don't know what it is, just say we already got one | ||||
return true; | return true; | ||||
} | } | ||||
void RelayTransaction(const TxId &txid, const CConnman &connman) { | void RelayTransaction(const TxId &txid, const CConnman &connman) { | ||||
CInv inv(MSG_TX, txid); | connman.ForEachNode( | ||||
connman.ForEachNode([&inv](CNode *pnode) { pnode->PushInventory(inv); }); | [&txid](CNode *pnode) { pnode->PushTxInventory(txid); }); | ||||
} | } | ||||
static void RelayAddress(const CAddress &addr, bool fReachable, | static void RelayAddress(const CAddress &addr, bool fReachable, | ||||
const CConnman &connman) { | const CConnman &connman) { | ||||
// Limited relaying of addresses outside our network(s) | // Limited relaying of addresses outside our network(s) | ||||
unsigned int nRelayNodes = fReachable ? 2 : 1; | unsigned int nRelayNodes = fReachable ? 2 : 1; | ||||
// Relay to a limited number of other nodes. | // Relay to a limited number of other nodes. | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | if (send && pindex->nStatus.hasData()) { | ||||
&pfrom, | &pfrom, | ||||
msgMaker.Make(nSendFlags, NetMsgType::BLOCK, *pblock)); | msgMaker.Make(nSendFlags, NetMsgType::BLOCK, *pblock)); | ||||
} | } | ||||
} | } | ||||
// Trigger the peer node to send a getblocks request for the next batch | // Trigger the peer node to send a getblocks request for the next batch | ||||
// of inventory. | // of inventory. | ||||
if (hash == pfrom.hashContinue) { | if (hash == pfrom.hashContinue) { | ||||
// Bypass PushInventory, this must send even if redundant, and we | // Bypass PushBlockInventory, this must send even if redundant, and | ||||
// want it right after the last block so they don't wait for other | // we want it right after the last block so they don't wait for | ||||
// stuff first. | // other stuff first. | ||||
std::vector<CInv> vInv; | std::vector<CInv> vInv; | ||||
vInv.push_back( | vInv.push_back( | ||||
CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); | CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); | ||||
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); | ||||
pfrom.hashContinue = BlockHash(); | pfrom.hashContinue = BlockHash(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,203 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::GETBLOCKS) { | ||||
pindex->nHeight <= ::ChainActive().Tip()->nHeight - | pindex->nHeight <= ::ChainActive().Tip()->nHeight - | ||||
nPrunedBlocksLikelyToHave)) { | nPrunedBlocksLikelyToHave)) { | ||||
LogPrint( | LogPrint( | ||||
BCLog::NET, | BCLog::NET, | ||||
" getblocks stopping, pruned or too old block at %d %s\n", | " getblocks stopping, pruned or too old block at %d %s\n", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString()); | pindex->nHeight, pindex->GetBlockHash().ToString()); | ||||
break; | break; | ||||
} | } | ||||
pfrom.PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); | pfrom.PushBlockInventory(pindex->GetBlockHash()); | ||||
if (--nLimit <= 0) { | if (--nLimit <= 0) { | ||||
// When this block is requested, we'll send an inv that'll | // When this block is requested, we'll send an inv that'll | ||||
// trigger the peer to getblocks the next batch of inventory. | // trigger the peer to getblocks the next batch of inventory. | ||||
LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", | LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString()); | pindex->nHeight, pindex->GetBlockHash().ToString()); | ||||
pfrom.hashContinue = pindex->GetBlockHash(); | pfrom.hashContinue = pindex->GetBlockHash(); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,881 Lines • ▼ Show 20 Lines | if (pingSend) { | ||||
BCLog::NET, | BCLog::NET, | ||||
"Announcing block %s not on main chain (tip=%s)\n", | "Announcing block %s not on main chain (tip=%s)\n", | ||||
hashToAnnounce.ToString(), | hashToAnnounce.ToString(), | ||||
::ChainActive().Tip()->GetBlockHash().ToString()); | ::ChainActive().Tip()->GetBlockHash().ToString()); | ||||
} | } | ||||
// If the peer's chain has this block, don't inv it back. | // If the peer's chain has this block, don't inv it back. | ||||
if (!PeerHasHeader(&state, pindex)) { | if (!PeerHasHeader(&state, pindex)) { | ||||
pto->PushInventory(CInv(MSG_BLOCK, hashToAnnounce)); | pto->PushBlockInventory(hashToAnnounce); | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"%s: sending inv peer=%d hash=%s\n", __func__, | "%s: sending inv peer=%d hash=%s\n", __func__, | ||||
pto->GetId(), hashToAnnounce.ToString()); | pto->GetId(), hashToAnnounce.ToString()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
pto->vBlockHashesToAnnounce.clear(); | pto->vBlockHashesToAnnounce.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 434 Lines • Show Last 20 Lines |