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 2,672 Lines • ▼ Show 20 Lines | PeerManagerImpl::FindTxForGetData(const CNode &peer, const TxId &txid, | ||||
return {}; | return {}; | ||||
} | } | ||||
//! Determine whether or not a peer can request a proof, and return it (or | //! Determine whether or not a peer can request a proof, and return it (or | ||||
//! nullptr if not found or not allowed). | //! nullptr if not found or not allowed). | ||||
static avalanche::ProofRef | static avalanche::ProofRef | ||||
FindProofForGetData(const CNode &peer, const avalanche::ProofId &proofid, | FindProofForGetData(const CNode &peer, const avalanche::ProofId &proofid, | ||||
const std::chrono::seconds now) { | const std::chrono::seconds now) { | ||||
avalanche::ProofRef proof = nullptr; | avalanche::ProofRef proof; | ||||
bool send_unconditionally = | bool send_unconditionally = | ||||
g_avalanche->withPeerManager([&](const avalanche::PeerManager &pm) { | g_avalanche->withPeerManager([&](const avalanche::PeerManager &pm) { | ||||
return pm.forPeer(proofid, [&](const avalanche::Peer &peer) { | return pm.forPeer(proofid, [&](const avalanche::Peer &peer) { | ||||
proof = peer.proof; | proof = peer.proof; | ||||
// If we know that proof for long enough, allow for requesting | // If we know that proof for long enough, allow for requesting | ||||
// it. | // it. | ||||
return peer.registration_time <= | return peer.registration_time <= | ||||
now - UNCONDITIONAL_RELAY_DELAY; | now - UNCONDITIONAL_RELAY_DELAY; | ||||
}); | }); | ||||
}); | }); | ||||
if (!proof) { | if (!proof) { | ||||
// Always send our local proof if it gets requested, assuming it's | // Always send our local proof if it gets requested, assuming it's | ||||
// valid. This will make it easier to bind with peers upon startup where | // valid. This will make it easier to bind with peers upon startup where | ||||
// the status of our proof is unknown pending for a block. Note that it | // the status of our proof is unknown pending for a block. Note that it | ||||
// still needs to have been announced first (presumably via an avahello | // still needs to have been announced first (presumably via an avahello | ||||
// message). | // message). | ||||
proof = g_avalanche->getLocalProof(); | proof = g_avalanche->getLocalProof(); | ||||
} | } | ||||
// We don't have this proof | // We don't have this proof | ||||
if (!proof) { | if (!proof) { | ||||
return nullptr; | return avalanche::ProofRef(); | ||||
} | } | ||||
if (send_unconditionally) { | if (send_unconditionally) { | ||||
return proof; | return proof; | ||||
} | } | ||||
// Otherwise, the proofs must have been announced recently. | // Otherwise, the proofs must have been announced recently. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (State(peer.GetId())->m_recently_announced_proofs.contains(proofid)) { | if (State(peer.GetId())->m_recently_announced_proofs.contains(proofid)) { | ||||
return proof; | return proof; | ||||
} | } | ||||
return nullptr; | return avalanche::ProofRef(); | ||||
} | } | ||||
void PeerManagerImpl::ProcessGetData( | void PeerManagerImpl::ProcessGetData( | ||||
const Config &config, CNode &pfrom, Peer &peer, | const Config &config, CNode &pfrom, Peer &peer, | ||||
const std::atomic<bool> &interruptMsgProc) { | const std::atomic<bool> &interruptMsgProc) { | ||||
AssertLockNotHeld(cs_main); | AssertLockNotHeld(cs_main); | ||||
std::deque<CInv>::iterator it = peer.m_getdata_requests.begin(); | std::deque<CInv>::iterator it = peer.m_getdata_requests.begin(); | ||||
▲ Show 20 Lines • Show All 4,311 Lines • Show Last 20 Lines |