Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 2,068 Lines • ▼ Show 20 Lines | CTransactionRef static 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 std::shared_ptr<avalanche::Proof> | static std::shared_ptr<avalanche::Proof> | ||||
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) { | ||||
auto proof = g_avalanche->getProof(proofid); | std::shared_ptr<avalanche::Proof> proof = nullptr; | ||||
bool send_unconditionally = | |||||
g_avalanche->withPeerManager([&](const avalanche::PeerManager &pm) { | |||||
return pm.forPeer(proofid, [&](const avalanche::Peer &peer) { | |||||
proof = peer.proof; | |||||
// If we know that proof for long enough, allow for requesting | |||||
// it. | |||||
return peer.registration_time <= | |||||
now - UNCONDITIONAL_RELAY_DELAY; | |||||
}); | |||||
}); | |||||
// We don't have this proof | // We don't have this proof | ||||
if (!proof) { | if (!proof) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
auto proofRegistrationTime = g_avalanche->getProofRegistrationTime(proofid); | if (send_unconditionally) { | ||||
// If we know that proof for long enough, allow for requesting it | |||||
if (proofRegistrationTime <= now - UNCONDITIONAL_RELAY_DELAY) { | |||||
return proof; | return proof; | ||||
} | } | ||||
{ | |||||
LOCK(cs_main); | |||||
// Otherwise, the proofs must have been announced recently. | // Otherwise, the proofs must have been announced recently. | ||||
if (State(peer.GetId()) | LOCK(cs_main); | ||||
->m_recently_announced_proofs.contains(proofid)) { | if (State(peer.GetId())->m_recently_announced_proofs.contains(proofid)) { | ||||
return proof; | return proof; | ||||
} | } | ||||
} | |||||
return nullptr; | return nullptr; | ||||
} | } | ||||
static void ProcessGetData(const Config &config, CNode &pfrom, | static void ProcessGetData(const Config &config, CNode &pfrom, | ||||
CConnman &connman, CTxMemPool &mempool, | CConnman &connman, CTxMemPool &mempool, | ||||
const std::atomic<bool> &interruptMsgProc) | const std::atomic<bool> &interruptMsgProc) | ||||
LOCKS_EXCLUDED(cs_main) { | LOCKS_EXCLUDED(cs_main) { | ||||
▲ Show 20 Lines • Show All 3,755 Lines • Show Last 20 Lines |