Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 3,939 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::BLOCK) { | ||||
pfrom.nLastBlockTime = GetTime(); | pfrom.nLastBlockTime = GetTime(); | ||||
} else { | } else { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
mapBlockSource.erase(hash); | mapBlockSource.erase(hash); | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::AVAHELLO && g_avalanche && | if (msg_type == NetMsgType::AVAHELLO && g_avalanche) { | ||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
Misbehaving(pfrom, 20, "unsolicited-avahello"); | |||||
return; | |||||
} | |||||
if (!pfrom.m_avalanche_state) { | if (!pfrom.m_avalanche_state) { | ||||
pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | ||||
} | } | ||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | ||||
verifier >> delegation; | verifier >> delegation; | ||||
avalanche::Proof proof; | avalanche::Proof proof; | ||||
avalanche::DelegationState state; | avalanche::DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (!delegation.verify(state, proof, pubkey)) { | if (!delegation.verify(state, proof, pubkey)) { | ||||
Misbehaving(pfrom, 100, "invalid-delegation"); | Misbehaving(pfrom, 100, "invalid-delegation"); | ||||
return; | return; | ||||
} | } | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
verifier >> sig; | verifier >> sig; | ||||
} | } | ||||
// Ignore avalanche requests while importing | // Ignore avalanche requests while importing | ||||
if (msg_type == NetMsgType::AVAPOLL && !fImporting && !fReindex && | if (msg_type == NetMsgType::AVAPOLL && !fImporting && !fReindex && | ||||
g_avalanche && | g_avalanche) { | ||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
Misbehaving(pfrom, 20, "unsolicited-avapoll"); | |||||
return; | |||||
} | |||||
auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
int64_t cooldown = | int64_t cooldown = | ||||
gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | gArgs.GetArg("-avacooldown", AVALANCHE_DEFAULT_COOLDOWN); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
auto &node_state = State(pfrom.GetId())->m_avalanche_state; | auto &node_state = State(pfrom.GetId())->m_avalanche_state; | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVAPOLL && !fImporting && !fReindex && | ||||
// Send the query to the node. | // Send the query to the node. | ||||
g_avalanche->sendResponse( | g_avalanche->sendResponse( | ||||
&pfrom, avalanche::Response(round, cooldown, std::move(votes))); | &pfrom, avalanche::Response(round, cooldown, std::move(votes))); | ||||
return; | return; | ||||
} | } | ||||
// Ignore avalanche requests while importing | // Ignore avalanche requests while importing | ||||
if (msg_type == NetMsgType::AVARESPONSE && !fImporting && !fReindex && | if (msg_type == NetMsgType::AVARESPONSE && !fImporting && !fReindex && | ||||
g_avalanche && | g_avalanche) { | ||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
Misbehaving(pfrom, 20, "unsolicited-avaresponse"); | |||||
return; | |||||
} | |||||
// As long as QUIC is not implemented, we need to sign response and | // As long as QUIC is not implemented, we need to sign response and | ||||
// verify response's signatures in order to avoid any manipulation of | // verify response's signatures in order to avoid any manipulation of | ||||
// messages at the transport level. | // messages at the transport level. | ||||
CHashVerifier<CDataStream> verifier(&vRecv); | CHashVerifier<CDataStream> verifier(&vRecv); | ||||
avalanche::Response response; | avalanche::Response response; | ||||
verifier >> response; | verifier >> response; | ||||
if (!g_avalanche->forNode(pfrom.GetId(), [&](const avalanche::Node &n) { | if (!g_avalanche->forNode(pfrom.GetId(), [&](const avalanche::Node &n) { | ||||
▲ Show 20 Lines • Show All 1,464 Lines • Show Last 20 Lines |