Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | public: | ||||
bool ProcessMessages(const Config &config, CNode *pfrom, | bool ProcessMessages(const Config &config, CNode *pfrom, | ||||
std::atomic<bool> &interrupt) override; | std::atomic<bool> &interrupt) override; | ||||
bool SendMessages(const Config &config, CNode *pto) override | bool SendMessages(const Config &config, CNode *pto) override | ||||
EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing); | EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing); | ||||
/** Implement PeerManager */ | /** Implement PeerManager */ | ||||
void StartScheduledTasks(CScheduler &scheduler) override; | void StartScheduledTasks(CScheduler &scheduler) override; | ||||
void CheckForStaleTipAndEvictPeers() override; | void CheckForStaleTipAndEvictPeers() override; | ||||
bool FetchBlock(const Config &config, NodeId id, | |||||
const CBlockIndex &block_index) override; | |||||
bool GetNodeStateStats(NodeId nodeid, | bool GetNodeStateStats(NodeId nodeid, | ||||
CNodeStateStats &stats) const override; | CNodeStateStats &stats) const override; | ||||
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } | bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } | ||||
void SendPings() override; | void SendPings() override; | ||||
void RelayTransaction(const TxId &txid) override; | void RelayTransaction(const TxId &txid) override; | ||||
void RelayProof(const avalanche::ProofId &proofid) override; | void RelayProof(const avalanche::ProofId &proofid) override; | ||||
void SetBestHeight(int height) override { m_best_height = height; }; | void SetBestHeight(int height) override { m_best_height = height; }; | ||||
void Misbehaving(const NodeId pnode, const int howmuch, | void Misbehaving(const NodeId pnode, const int howmuch, | ||||
▲ Show 20 Lines • Show All 1,549 Lines • ▼ Show 20 Lines | return pindex->IsValid(BlockValidity::SCRIPTS) && | ||||
(pindexBestHeader != nullptr) && | (pindexBestHeader != nullptr) && | ||||
(pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() < | ||||
STALE_RELAY_AGE_LIMIT) && | STALE_RELAY_AGE_LIMIT) && | ||||
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, | (GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, | ||||
*pindexBestHeader, consensusParams) < | *pindexBestHeader, consensusParams) < | ||||
STALE_RELAY_AGE_LIMIT); | STALE_RELAY_AGE_LIMIT); | ||||
} | } | ||||
bool PeerManagerImpl::FetchBlock(const Config &config, NodeId id, | |||||
const CBlockIndex &block_index) { | |||||
if (fImporting || fReindex) { | |||||
return false; | |||||
} | |||||
LOCK(cs_main); | |||||
// Ensure this peer exists and hasn't been disconnected | |||||
CNodeState *state = State(id); | |||||
if (state == nullptr) { | |||||
return false; | |||||
} | |||||
// Mark block as in-flight unless it already is (for this peer). | |||||
// If a block was already in-flight for a different peer, its BLOCKTXN | |||||
// response will be dropped. | |||||
if (!BlockRequested(config, id, block_index)) { | |||||
return false; | |||||
} | |||||
// Construct message to request the block | |||||
const BlockHash &hash{block_index.GetBlockHash()}; | |||||
const std::vector<CInv> invs{CInv(MSG_BLOCK, hash)}; | |||||
// Send block request message to the peer | |||||
if (!m_connman.ForNode(id, [this, &invs](CNode *node) { | |||||
const CNetMsgMaker msgMaker(node->GetCommonVersion()); | |||||
this->m_connman.PushMessage( | |||||
node, msgMaker.Make(NetMsgType::GETDATA, invs)); | |||||
return true; | |||||
})) { | |||||
RemoveBlockRequest(hash); | |||||
LogPrint(BCLog::NET, "Failed to request block %s from peer=%d\n", | |||||
hash.ToString(), id); | |||||
return false; | |||||
} | |||||
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n", hash.ToString(), | |||||
id); | |||||
return true; | |||||
} | |||||
std::unique_ptr<PeerManager> | std::unique_ptr<PeerManager> | ||||
PeerManager::make(const CChainParams &chainparams, CConnman &connman, | PeerManager::make(const CChainParams &chainparams, CConnman &connman, | ||||
AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, | AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, | ||||
CTxMemPool &pool, bool ignore_incoming_txs) { | CTxMemPool &pool, bool ignore_incoming_txs) { | ||||
return std::make_unique<PeerManagerImpl>(chainparams, connman, addrman, | return std::make_unique<PeerManagerImpl>(chainparams, connman, addrman, | ||||
banman, chainman, pool, | banman, chainman, pool, | ||||
ignore_incoming_txs); | ignore_incoming_txs); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 5,109 Lines • Show Last 20 Lines |