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,675 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 isAvalancheOutboundOrManual(const CNode *pnode) { | |||||
return pnode->IsAvalancheOutboundConnection() || | |||||
(pnode->IsManualConn() && (pnode->nServices & NODE_AVALANCHE)); | |||||
} | |||||
void PeerManagerImpl::AvalanchePeriodicNetworking(CScheduler &scheduler) const { | void PeerManagerImpl::AvalanchePeriodicNetworking(CScheduler &scheduler) const { | ||||
const auto now = GetTime<std::chrono::seconds>(); | const auto now = GetTime<std::chrono::seconds>(); | ||||
std::vector<NodeId> avanode_outbound_ids; | std::vector<NodeId> avanode_outbound_ids; | ||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
// Not enabled or not ready yet, retry later | // Not enabled or not ready yet, retry later | ||||
goto scheduleLater; | goto scheduleLater; | ||||
} | } | ||||
m_connman.ForEachNode([&](CNode *pnode) { | m_connman.ForEachNode([&](CNode *pnode) { | ||||
// Build a list of the avalanche manual or outbound peers nodeids | // Build a list of the avalanche manual or outbound peers nodeids | ||||
if (isAvalancheOutboundOrManual(pnode)) { | if (!pnode->IsInboundConn() && pnode->sendAvaVersion > 0) { | ||||
avanode_outbound_ids.push_back(pnode->GetId()); | avanode_outbound_ids.push_back(pnode->GetId()); | ||||
} | } | ||||
// If a proof radix tree timed out, cleanup | // If a proof radix tree timed out, cleanup | ||||
if (pnode->m_proof_relay && | if (pnode->m_proof_relay && | ||||
now > (pnode->m_proof_relay->lastSharedProofsUpdate.load() + | now > (pnode->m_proof_relay->lastSharedProofsUpdate.load() + | ||||
AVALANCHE_AVAPROOFS_TIMEOUT)) { | AVALANCHE_AVAPROOFS_TIMEOUT)) { | ||||
LogPrint(BCLog::AVALANCHE, | LogPrint(BCLog::AVALANCHE, | ||||
▲ Show 20 Lines • Show All 2,025 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERACK) { | ||||
if (g_avalanche && isAvalancheEnabled(gArgs)) { | if (g_avalanche && isAvalancheEnabled(gArgs)) { | ||||
// Notify our peer that we have avalanche enabled and can serve | // Notify our peer that we have avalanche enabled and can serve | ||||
// avalanche addresses and proofs | // avalanche addresses and proofs | ||||
if (pfrom.GetCommonVersion() >= SENDAVA_VERSION) { | if (pfrom.GetCommonVersion() >= SENDAVA_VERSION) { | ||||
m_connman.PushMessage(&pfrom, | m_connman.PushMessage(&pfrom, | ||||
msgMaker.Make(NetMsgType::SENDAVA, | msgMaker.Make(NetMsgType::SENDAVA, | ||||
AVALANCHE_SENDAVA_VERSION)); | AVALANCHE_SENDAVA_VERSION)); | ||||
} | } | ||||
if (g_avalanche->sendHello(&pfrom)) { | |||||
LogPrint(BCLog::AVALANCHE, "Send avahello to peer %d\n", | |||||
pfrom.GetId()); | |||||
auto localProof = g_avalanche->getLocalProof(); | |||||
// If we sent a hello message, we should have a proof | |||||
assert(localProof); | |||||
// Add our proof id to the list or the recently announced proof | |||||
// INVs to this peer. This is used for filtering which INV can | |||||
// be requested for download. | |||||
LOCK(cs_main); | |||||
State(pfrom.GetId()) | |||||
->m_recently_announced_proofs.insert(localProof->getId()); | |||||
} | |||||
// Send getavaaddr and getavaproofs to our avalanche outbound or | |||||
// manual connections | |||||
if (isAvalancheOutboundOrManual(&pfrom)) { | |||||
m_connman.PushMessage(&pfrom, | |||||
msgMaker.Make(NetMsgType::GETAVAADDR)); | |||||
WITH_LOCK(peer->m_addr_token_bucket_mutex, | |||||
peer->m_addr_token_bucket += GetMaxAddrToSend()); | |||||
if (pfrom.m_proof_relay && | |||||
!m_chainman.ActiveChainstate().IsInitialBlockDownload()) { | |||||
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) { | ||||
// Must have a verack message before anything else | // Must have a verack message before anything else | ||||
▲ Show 20 Lines • Show All 1,158 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::SENDAVA) { | ||||
if (version == 0) { | if (version == 0) { | ||||
Misbehaving(pfrom, 100, "invalid-sendava-version"); | Misbehaving(pfrom, 100, "invalid-sendava-version"); | ||||
return; | return; | ||||
} | } | ||||
pfrom.sendAvaVersion = version; | pfrom.sendAvaVersion = version; | ||||
if (g_avalanche->sendHello(&pfrom)) { | |||||
LogPrint(BCLog::AVALANCHE, "Send avahello to peer %d\n", | |||||
pfrom.GetId()); | |||||
auto localProof = g_avalanche->getLocalProof(); | |||||
// If we sent a hello message, we should have a proof | |||||
assert(localProof); | |||||
// Add our proof id to the list or the recently announced proof | |||||
// INVs to this peer. This is used for filtering which INV can | |||||
// be requested for download. | |||||
LOCK(cs_main); | |||||
State(pfrom.GetId()) | |||||
->m_recently_announced_proofs.insert(localProof->getId()); | |||||
} | |||||
// Send getavaaddr and getavaproofs to our avalanche outbound or | |||||
// manual connections | |||||
if (!pfrom.IsInboundConn()) { | |||||
m_connman.PushMessage(&pfrom, | |||||
msgMaker.Make(NetMsgType::GETAVAADDR)); | |||||
WITH_LOCK(peer->m_addr_token_bucket_mutex, | |||||
peer->m_addr_token_bucket += GetMaxAddrToSend()); | |||||
if (pfrom.m_proof_relay && | |||||
!m_chainman.ActiveChainstate().IsInitialBlockDownload()) { | |||||
m_connman.PushMessage(&pfrom, | |||||
msgMaker.Make(NetMsgType::GETAVAPROOFS)); | |||||
pfrom.m_proof_relay->compactproofs_requested = true; | |||||
} | |||||
} | |||||
deadalnix: The fact the message name made no sense was already a hint, but the fact all of this needs to… | |||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::AVAHELLO) { | if (msg_type == NetMsgType::AVAHELLO) { | ||||
if (pfrom.m_avalanche_state) { | if (pfrom.m_avalanche_state) { | ||||
LogPrint( | LogPrint( | ||||
BCLog::AVALANCHE, | BCLog::AVALANCHE, | ||||
"Ignoring avahello from peer %d: already in our node set\n", | "Ignoring avahello from peer %d: already in our node set\n", | ||||
▲ Show 20 Lines • Show All 2,191 Lines • Show Last 20 Lines |
The fact the message name made no sense was already a hint, but the fact all of this needs to be moved here is another. When you need to do a handshake before you do the handshake, you know you have one too many handshake.