Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <net_processing.h> | #include <net_processing.h> | ||||
#include <addrman.h> | #include <addrman.h> | ||||
#include <avalanche/processor.h> | #include <avalanche/processor.h> | ||||
#include <avalanche/proof.h> | |||||
#include <avalanche/validation.h> | |||||
#include <banman.h> | #include <banman.h> | ||||
#include <blockdb.h> | #include <blockdb.h> | ||||
#include <blockencodings.h> | #include <blockencodings.h> | ||||
#include <blockfilter.h> | #include <blockfilter.h> | ||||
#include <blockvalidity.h> | #include <blockvalidity.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
▲ Show 20 Lines • Show All 2,783 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::VERACK) { | ||||
if (pfrom.nVersion >= SENDHEADERS_VERSION) { | if (pfrom.nVersion >= SENDHEADERS_VERSION) { | ||||
// Tell our peer we prefer to receive headers rather than inv's | // Tell our peer we prefer to receive headers rather than inv's | ||||
// We send this to non-NODE NETWORK peers as well, because even | // We send this to non-NODE NETWORK peers as well, because even | ||||
// non-NODE NETWORK peers can announce blocks (such as pruning | // non-NODE NETWORK peers can announce blocks (such as pruning | ||||
// nodes) | // nodes) | ||||
m_connman.PushMessage(&pfrom, | m_connman.PushMessage(&pfrom, | ||||
msgMaker.Make(NetMsgType::SENDHEADERS)); | msgMaker.Make(NetMsgType::SENDHEADERS)); | ||||
} | } | ||||
if (pfrom.nVersion >= SHORT_IDS_BLOCKS_VERSION) { | if (pfrom.nVersion >= SHORT_IDS_BLOCKS_VERSION) { | ||||
// Tell our peer we are willing to provide version 1 or 2 | // Tell our peer we are willing to provide version 1 or 2 | ||||
// cmpctblocks. However, we do not request new block announcements | // cmpctblocks. However, we do not request new block announcements | ||||
// using cmpctblock messages. We send this to non-NODE NETWORK peers | // using cmpctblock messages. We send this to non-NODE NETWORK peers | ||||
// as well, because they may wish to request compact blocks from us. | // as well, because they may wish to request compact blocks from us. | ||||
bool fAnnounceUsingCMPCTBLOCK = false; | bool fAnnounceUsingCMPCTBLOCK = false; | ||||
uint64_t nCMPCTBLOCKVersion = 1; | uint64_t nCMPCTBLOCKVersion = 1; | ||||
m_connman.PushMessage(&pfrom, | m_connman.PushMessage(&pfrom, | ||||
msgMaker.Make(NetMsgType::SENDCMPCT, | msgMaker.Make(NetMsgType::SENDCMPCT, | ||||
fAnnounceUsingCMPCTBLOCK, | fAnnounceUsingCMPCTBLOCK, | ||||
nCMPCTBLOCKVersion)); | nCMPCTBLOCKVersion)); | ||||
} | } | ||||
if ((pfrom.nServices & NODE_AVALANCHE) && g_avalanche && | |||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | |||||
if (g_avalanche->sendHello(&pfrom)) { | |||||
LogPrint(BCLog::NET, "Send avahello to peer %d\n", | |||||
pfrom.GetId()); | |||||
} | |||||
} | |||||
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 | ||||
Misbehaving(pfrom, 10, "non-verack message before version handshake"); | Misbehaving(pfrom, 10, "non-verack message before version handshake"); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 998 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 && | |||||
gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | |||||
if (!pfrom.m_avalanche_state) { | |||||
pfrom.m_avalanche_state = std::make_unique<CNode::AvalancheState>(); | |||||
} | |||||
CHashVerifier<CDataStream> verifier(&vRecv); | |||||
avalanche::Delegation &delegation = pfrom.m_avalanche_state->delegation; | |||||
verifier >> delegation; | |||||
avalanche::Proof proof; | |||||
avalanche::DelegationState state; | |||||
CPubKey pubkey; | |||||
if (!delegation.verify(state, proof, pubkey)) { | |||||
Misbehaving(pfrom, 100, "invalid-delegation"); | |||||
return; | |||||
} | |||||
std::array<uint8_t, 64> 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)) { | gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { | ||||
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); | ||||
▲ Show 20 Lines • Show All 1,574 Lines • Show Last 20 Lines |