Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 3,122 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::GETDATA) { | ||||
if (vInv.size() > 0) { | if (vInv.size() > 0) { | ||||
LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", | LogPrint(BCLog::NET, "received getdata for: %s peer=%d\n", | ||||
vInv[0].ToString(), pfrom.GetId()); | vInv[0].ToString(), pfrom.GetId()); | ||||
} | } | ||||
pfrom.vRecvGetData.insert(pfrom.vRecvGetData.end(), vInv.begin(), | pfrom.vRecvGetData.insert(pfrom.vRecvGetData.end(), vInv.begin(), | ||||
vInv.end()); | vInv.end()); | ||||
ProcessGetData(config, pfrom, m_connman, m_mempool, interruptMsgProc); | ProcessGetData(config, pfrom, m_connman, m_mempool, interruptMsgProc); | ||||
// TODO: implement MSG_AVALANCHE_PROOF: send a proof in an AVAPROOF | |||||
// message | |||||
return; | return; | ||||
} | } | ||||
if (msg_type == NetMsgType::GETBLOCKS) { | if (msg_type == NetMsgType::GETBLOCKS) { | ||||
CBlockLocator locator; | CBlockLocator locator; | ||||
uint256 hashStop; | uint256 hashStop; | ||||
vRecv >> locator >> hashStop; | vRecv >> locator >> hashStop; | ||||
▲ Show 20 Lines • Show All 810 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::AVAHELLO && g_avalanche) { | ||||
if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
Misbehaving(pfrom, 20, "unsolicited-avahello"); | Misbehaving(pfrom, 20, "unsolicited-avahello"); | ||||
return; | 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>(); | ||||
} | } | ||||
// Store the delegation and signature for later verification. | |||||
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; | ||||
SchnorrSig &sig = pfrom.m_avalanche_state->sig; | |||||
verifier >> sig; | |||||
// Ask for the proof. | |||||
std::vector<CInv> vGetData; | |||||
vGetData.emplace_back( | |||||
CInv(MSG_AVALANCHE_PROOF, delegation.getProofId())); | |||||
m_connman.PushMessage(&pfrom, | |||||
msgMaker.Make(NetMsgType::GETDATA, vGetData)); | |||||
} | |||||
if (msg_type == NetMsgType::AVAPROOF && g_avalanche) { | |||||
// Read the proof. | |||||
avalanche::Proof proof; | avalanche::Proof proof; | ||||
vRecv >> proof; | |||||
// Verify the delegation is internally consistent. | |||||
avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | |||||
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; | // Use the delegated pubkey to verify the signature received | ||||
verifier >> sig; | // in the avahello message. | ||||
SchnorrSig &sig = pfrom.m_avalanche_state->sig; | |||||
CHashWriter hasher(SER_GETHASH, 0); | |||||
hasher << delegation.getId(); | |||||
hasher << pfrom.nRemoteHostNonce; | |||||
hasher << pfrom.GetLocalNonce(); | |||||
hasher << pfrom.nRemoteExtraEntropy; | |||||
hasher << pfrom.GetLocalExtraEntropy(); | |||||
const uint256 hash = hasher.GetHash(); | |||||
bool success; | |||||
success = pubkey.VerifySchnorr(hash, sig); | |||||
if (!success) { | |||||
Misbehaving(pfrom, 100, "invalid-avalanche-handshake"); | |||||
return; | |||||
} | |||||
// Add the node the avalanche peers. | |||||
success = g_avalanche->addNode(pfrom.GetId(), proof, delegation); | |||||
if (success) { | |||||
LogPrint(BCLog::NET, "added avalanche node=%d\n", pfrom.GetId()); | |||||
} else { | |||||
LogPrint(BCLog::NET, "failed to add avalanche node=%d\n", | |||||
pfrom.GetId()); | |||||
} | |||||
} | } | ||||
// 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) { | ||||
if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
Misbehaving(pfrom, 20, "unsolicited-avapoll"); | Misbehaving(pfrom, 20, "unsolicited-avapoll"); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 1,586 Lines • Show Last 20 Lines |