diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,6 +114,7 @@ addrdb.h \ addrman.h \ attributes.h \ + avalanche/node.h \ avalanche/peermanager.h \ avalanche/processor.h \ avalanche/protocol.h \ diff --git a/src/avalanche/node.h b/src/avalanche/node.h new file mode 100644 --- /dev/null +++ b/src/avalanche/node.h @@ -0,0 +1,23 @@ +// Copyright (c) 2018-2019 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_NODE_H +#define BITCOIN_AVALANCHE_NODE_H + +#include // For NodeId +#include + +#include + +using TimePoint = std::chrono::time_point; + +struct AvalancheNode { + NodeId nodeid; + int64_t score; + + TimePoint nextRequestTime; + CPubKey pubkey; +}; + +#endif // BITCOIN_AVALANCHE_NODE_H diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -5,11 +5,11 @@ #ifndef BITCOIN_AVALANCHE_PROCESSOR_H #define BITCOIN_AVALANCHE_PROCESSOR_H +#include #include #include #include #include -#include #include #include @@ -179,18 +179,6 @@ struct query_timeout {}; class AvalancheProcessor { -public: - using TimePoint = std::chrono::time_point; - - struct Node { - NodeId nodeid; - int64_t score; - - TimePoint nextRequestTime; - CPubKey pubkey; - }; - -private: CConnman *connman; std::chrono::milliseconds queryTimeoutDuration; @@ -205,15 +193,16 @@ std::atomic round; using PeerSet = boost::multi_index_container< - Node, boost::multi_index::indexed_by< - // index by nodeid - boost::multi_index::hashed_unique< - boost::multi_index::member>, - // sorted by nextRequestTime - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::member>>>; + AvalancheNode, + boost::multi_index::indexed_by< + // index by nodeid + boost::multi_index::hashed_unique>, + // sorted by nextRequestTime + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::member>>>; RWCollection peerSet; @@ -271,7 +260,8 @@ std::vector &updates); bool addPeer(NodeId nodeid, int64_t score, CPubKey pubkey); - bool forNode(NodeId nodeid, std::function func) const; + bool forNode(NodeId nodeid, + std::function func) const; CPubKey getSessionPubKey() const { return sessionKey.GetPubKey(); } diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -233,7 +233,7 @@ auto w = peerSet.getWriteView(); auto it = w->find(nodeid); if (it != w->end()) { - w->modify(it, [&response](Node &n) { + w->modify(it, [&response](AvalancheNode &n) { // FIXME: This will override the time even when we received an // old stale message. This should check that the message is // indeed the most up to date one before updating the time. @@ -347,7 +347,7 @@ } bool AvalancheProcessor::forNode( - NodeId nodeid, std::function func) const { + NodeId nodeid, std::function func) const { auto r = peerSet.getReadView(); auto it = r->find(nodeid); return it != r->end() && func(*it); @@ -499,7 +499,7 @@ auto w = peerSet.getWriteView(); auto it = w->find(pnode->GetId()); if (it != w->end()) { - w->modify(it, [&timeout](Node &n) { + w->modify(it, [&timeout](AvalancheNode &n) { n.nextRequestTime = timeout; }); } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3630,15 +3630,14 @@ AvalancheResponse response; verifier >> response; - if (!g_avalanche->forNode( - pfrom->GetId(), [&](const AvalancheProcessor::Node &n) { - std::array sig; - vRecv >> sig; - - // Unfortunately, the verify API require a vector. - std::vector vchSig{sig.begin(), sig.end()}; - return n.pubkey.VerifySchnorr(verifier.GetHash(), vchSig); - })) { + if (!g_avalanche->forNode(pfrom->GetId(), [&](const AvalancheNode &n) { + std::array sig; + vRecv >> sig; + + // Unfortunately, the verify API require a vector. + std::vector vchSig{sig.begin(), sig.end()}; + return n.pubkey.VerifySchnorr(verifier.GetHash(), vchSig); + })) { LOCK(cs_main); Misbehaving(pfrom, 100, "invalid-ava-response-signature"); return true;