Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 1,763 Lines • ▼ Show 20 Lines | static bool AlreadyHaveProof(const avalanche::ProofId &proofid) { | ||||
return g_avalanche && g_avalanche->getProof(proofid); | return g_avalanche && g_avalanche->getProof(proofid); | ||||
} | } | ||||
void RelayTransaction(const TxId &txid, const CConnman &connman) { | void RelayTransaction(const TxId &txid, const CConnman &connman) { | ||||
connman.ForEachNode( | connman.ForEachNode( | ||||
[&txid](CNode *pnode) { pnode->PushTxInventory(txid); }); | [&txid](CNode *pnode) { pnode->PushTxInventory(txid); }); | ||||
} | } | ||||
void RelayProof(const avalanche::ProofId &proofid, const CConnman &connman) { | |||||
connman.ForEachNode( | |||||
[&proofid](CNode *pnode) { pnode->PushProofInventory(proofid); }); | |||||
} | |||||
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. | ||||
// Use deterministic randomness to send to the same nodes for 24 hours at a | // Use deterministic randomness to send to the same nodes for 24 hours at a | ||||
// time so the m_addr_knowns of the chosen nodes prevent repeats | // time so the m_addr_knowns of the chosen nodes prevent repeats | ||||
▲ Show 20 Lines • Show All 1,407 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::INV) { | ||||
continue; | continue; | ||||
} | } | ||||
if (inv.IsMsgProof()) { | if (inv.IsMsgProof()) { | ||||
const avalanche::ProofId proofid(inv.hash); | const avalanche::ProofId proofid(inv.hash); | ||||
const bool fAlreadyHave = AlreadyHaveProof(proofid); | const bool fAlreadyHave = AlreadyHaveProof(proofid); | ||||
logInv(inv, fAlreadyHave); | logInv(inv, fAlreadyHave); | ||||
pfrom.AddKnownProof(proofid); | |||||
if (!fAlreadyHave && g_avalanche && isAvalancheEnabled(gArgs)) { | if (!fAlreadyHave && g_avalanche && isAvalancheEnabled(gArgs)) { | ||||
const bool preferred = isPreferredDownloadPeer(pfrom); | const bool preferred = isPreferredDownloadPeer(pfrom); | ||||
LOCK(cs_proofrequest); | LOCK(cs_proofrequest); | ||||
AddProofAnnouncement(pfrom, proofid, current_time, | AddProofAnnouncement(pfrom, proofid, current_time, | ||||
preferred); | preferred); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,120 Lines • ▼ Show 20 Lines | auto addInvAndMaybeFlush = [&](uint32_t type, const uint256 &hash) { | ||||
// concern for them. | // concern for them. | ||||
next = current_time; | next = current_time; | ||||
} | } | ||||
} | } | ||||
return fSendTrickle; | return fSendTrickle; | ||||
}; | }; | ||||
// Add proofs to inventory | |||||
if (pto->m_proof_relay != nullptr) { | |||||
LOCK(pto->m_proof_relay->cs_proof_inventory); | |||||
if (computeNextInvSendTime(pto->m_proof_relay->nextInvSend)) { | |||||
auto it = pto->m_proof_relay->setInventoryProofToSend.begin(); | |||||
while (it != | |||||
pto->m_proof_relay->setInventoryProofToSend.end()) { | |||||
const avalanche::ProofId proofid = *it; | |||||
it = pto->m_proof_relay->setInventoryProofToSend.erase(it); | |||||
if (pto->m_proof_relay->filterProofKnown.contains( | |||||
proofid)) { | |||||
continue; | |||||
} | |||||
pto->m_proof_relay->filterProofKnown.insert(proofid); | |||||
addInvAndMaybeFlush(MSG_AVA_PROOF, proofid); | |||||
} | |||||
} | |||||
} | |||||
if (pto->m_tx_relay != nullptr) { | if (pto->m_tx_relay != nullptr) { | ||||
LOCK(pto->m_tx_relay->cs_tx_inventory); | LOCK(pto->m_tx_relay->cs_tx_inventory); | ||||
// Check whether periodic sends should happen | // Check whether periodic sends should happen | ||||
const bool fSendTrickle = | const bool fSendTrickle = | ||||
computeNextInvSendTime(pto->m_tx_relay->nNextInvSend); | computeNextInvSendTime(pto->m_tx_relay->nNextInvSend); | ||||
// Time to send but the peer has requested we not relay | // Time to send but the peer has requested we not relay | ||||
// transactions. | // transactions. | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |