Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
// Copyright (c) 2018-2019 The Bitcoin developers | // Copyright (c) 2018-2019 The Bitcoin 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 <avalanche/processor.h> | #include <avalanche/processor.h> | ||||
#include <avalanche/delegationbuilder.h> | #include <avalanche/delegationbuilder.h> | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <key_io.h> // For DecodeSecret | #include <key_io.h> // For DecodeSecret | ||||
#include <net_processing.h> // For Misbehaving | #include <net_processing.h> // For ::PeerManager | ||||
#include <netmessagemaker.h> | #include <netmessagemaker.h> | ||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/bitmanip.h> | #include <util/bitmanip.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <chrono> | #include <chrono> | ||||
#include <tuple> | #include <tuple> | ||||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | public: | ||||
NotificationsHandler(Processor *p) : m_processor(p) {} | NotificationsHandler(Processor *p) : m_processor(p) {} | ||||
void updatedBlockTip() override { | void updatedBlockTip() override { | ||||
LOCK(m_processor->cs_peerManager); | LOCK(m_processor->cs_peerManager); | ||||
m_processor->peerManager->updatedBlockTip(); | m_processor->peerManager->updatedBlockTip(); | ||||
} | } | ||||
}; | }; | ||||
Processor::Processor(interfaces::Chain &chain, CConnman *connmanIn) | Processor::Processor(interfaces::Chain &chain, CConnman *connmanIn, | ||||
: connman(connmanIn), queryTimeoutDuration(AVALANCHE_DEFAULT_QUERY_TIMEOUT), | NodePeerManager *nodePeerManagerIn) | ||||
round(0), peerManager(std::make_unique<PeerManager>()) { | : connman(connmanIn), nodePeerManager(nodePeerManagerIn), | ||||
queryTimeoutDuration(AVALANCHE_DEFAULT_QUERY_TIMEOUT), round(0), | |||||
peerManager(std::make_unique<PeerManager>()) { | |||||
if (gArgs.IsArgSet("-avasessionkey")) { | if (gArgs.IsArgSet("-avasessionkey")) { | ||||
sessionKey = DecodeSecret(gArgs.GetArg("-avasessionkey", "")); | sessionKey = DecodeSecret(gArgs.GetArg("-avasessionkey", "")); | ||||
} else { | } else { | ||||
// Pick a random key for the session. | // Pick a random key for the session. | ||||
sessionKey.MakeNewKey(true); | sessionKey.MakeNewKey(true); | ||||
} | } | ||||
if (gArgs.IsArgSet("-avaproof")) { | if (gArgs.IsArgSet("-avaproof")) { | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | bool Processor::registerVotes(NodeId nodeid, const Response &response, | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
{ | { | ||||
// Check that the query exists. | // Check that the query exists. | ||||
auto w = queries.getWriteView(); | auto w = queries.getWriteView(); | ||||
auto it = w->find(std::make_tuple(nodeid, response.getRound())); | auto it = w->find(std::make_tuple(nodeid, response.getRound())); | ||||
if (it == w.end()) { | if (it == w.end()) { | ||||
Misbehaving(nodeid, 2, "unexpcted-ava-response"); | nodePeerManager->Misbehaving(nodeid, 2, "unexpcted-ava-response"); | ||||
return false; | return false; | ||||
} | } | ||||
invs = std::move(it->invs); | invs = std::move(it->invs); | ||||
w->erase(it); | w->erase(it); | ||||
} | } | ||||
// Verify that the request and the vote are consistent. | // Verify that the request and the vote are consistent. | ||||
const std::vector<Vote> &votes = response.GetVotes(); | const std::vector<Vote> &votes = response.GetVotes(); | ||||
size_t size = invs.size(); | size_t size = invs.size(); | ||||
if (votes.size() != size) { | if (votes.size() != size) { | ||||
Misbehaving(nodeid, 100, "invalid-ava-response-size"); | nodePeerManager->Misbehaving(nodeid, 100, "invalid-ava-response-size"); | ||||
return false; | return false; | ||||
} | } | ||||
for (size_t i = 0; i < size; i++) { | for (size_t i = 0; i < size; i++) { | ||||
if (invs[i].hash != votes[i].GetHash()) { | if (invs[i].hash != votes[i].GetHash()) { | ||||
Misbehaving(nodeid, 100, "invalid-ava-response-content"); | nodePeerManager->Misbehaving(nodeid, 100, | ||||
"invalid-ava-response-content"); | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
std::map<CBlockIndex *, Vote> responseIndex; | std::map<CBlockIndex *, Vote> responseIndex; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 263 Lines • Show Last 20 Lines |