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 1,667 Lines • ▼ Show 20 Lines | |||||
void PeerManagerImpl::UpdateAvalancheStatistics() const { | void PeerManagerImpl::UpdateAvalancheStatistics() const { | ||||
m_connman.ForEachNode([](CNode *pnode) { | m_connman.ForEachNode([](CNode *pnode) { | ||||
if (pnode->m_avalanche_state) { | if (pnode->m_avalanche_state) { | ||||
pnode->m_avalanche_state->updateAvailabilityScore(); | pnode->m_avalanche_state->updateAvailabilityScore(); | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
static bool shouldSendGetAvaAddr(const CNode *pnode) { | static bool isAvalancheOutboundOrManual(const CNode *pnode) { | ||||
return pnode->IsAvalancheOutboundConnection() || | return pnode->IsAvalancheOutboundConnection() || | ||||
(pnode->IsManualConn() && (pnode->nServices & NODE_AVALANCHE)); | (pnode->IsManualConn() && (pnode->nServices & NODE_AVALANCHE)); | ||||
} | } | ||||
void PeerManagerImpl::MaybeRequestAvalancheNodes(CScheduler &scheduler) const { | void PeerManagerImpl::MaybeRequestAvalancheNodes(CScheduler &scheduler) const { | ||||
if (g_avalanche && | if (g_avalanche && | ||||
(!g_avalanche->isQuorumEstablished() || | (!g_avalanche->isQuorumEstablished() || | ||||
g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { | ||||
return pm.shouldRequestMoreNodes(); | return pm.shouldRequestMoreNodes(); | ||||
}))) { | }))) { | ||||
std::vector<NodeId> avanode_outbound_ids; | std::vector<NodeId> avanode_outbound_ids; | ||||
m_connman.ForEachNode([&](CNode *pnode) { | m_connman.ForEachNode([&](CNode *pnode) { | ||||
if (shouldSendGetAvaAddr(pnode)) { | if (isAvalancheOutboundOrManual(pnode)) { | ||||
avanode_outbound_ids.push_back(pnode->GetId()); | avanode_outbound_ids.push_back(pnode->GetId()); | ||||
} | } | ||||
}); | }); | ||||
// Randomly select an avalanche outbound peer to send the getavaaddr | // Randomly select an avalanche outbound peer to send the getavaaddr | ||||
// message to | // message to | ||||
if (!avanode_outbound_ids.empty()) { | if (!avanode_outbound_ids.empty()) { | ||||
Shuffle(avanode_outbound_ids.begin(), avanode_outbound_ids.end(), | Shuffle(avanode_outbound_ids.begin(), avanode_outbound_ids.end(), | ||||
▲ Show 20 Lines • Show All 1,982 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERACK) { | ||||
// Add our proof id to the list or the recently announced proof | // Add our proof id to the list or the recently announced proof | ||||
// INVs to this peer. This is used for filtering which INV can | // INVs to this peer. This is used for filtering which INV can | ||||
// be requested for download. | // be requested for download. | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
State(pfrom.GetId()) | State(pfrom.GetId()) | ||||
->m_recently_announced_proofs.insert(localProof->getId()); | ->m_recently_announced_proofs.insert(localProof->getId()); | ||||
} | } | ||||
// Send getavaaddr to our avalanche outbound connections | // Send getavaaddr and getavaproofs to our avalanche outbound or | ||||
if (shouldSendGetAvaAddr(&pfrom)) { | // manual connections | ||||
if (isAvalancheOutboundOrManual(&pfrom)) { | |||||
m_connman.PushMessage(&pfrom, | m_connman.PushMessage(&pfrom, | ||||
msgMaker.Make(NetMsgType::GETAVAADDR)); | msgMaker.Make(NetMsgType::GETAVAADDR)); | ||||
WITH_LOCK(peer->m_addr_token_bucket_mutex, | WITH_LOCK(peer->m_addr_token_bucket_mutex, | ||||
peer->m_addr_token_bucket += GetMaxAddrToSend()); | peer->m_addr_token_bucket += GetMaxAddrToSend()); | ||||
if (pfrom.m_proof_relay) { | |||||
m_connman.PushMessage( | |||||
&pfrom, msgMaker.Make(NetMsgType::GETAVAPROOFS)); | |||||
pfrom.m_proof_relay->compactproofs_requested = true; | |||||
} | |||||
} | } | ||||
} | } | ||||
pfrom.fSuccessfullyConnected = true; | pfrom.fSuccessfullyConnected = true; | ||||
return; | return; | ||||
} | } | ||||
if (!pfrom.fSuccessfullyConnected) { | if (!pfrom.fSuccessfullyConnected) { | ||||
▲ Show 20 Lines • Show All 3,211 Lines • Show Last 20 Lines |