diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -24,6 +24,8 @@ namespace avalanche { +class Delegation; + struct Slot { private: uint64_t start; @@ -143,7 +145,8 @@ /** * Node API. */ - bool addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); + bool addNode(NodeId nodeid, const Proof &proof, + const Delegation &delegation); bool removeNode(NodeId nodeid); NodeId selectNode(); diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include #include // For ChainstateActive() @@ -109,21 +109,27 @@ } bool PeerManager::addNode(NodeId nodeid, const Proof &proof, - const CPubKey &pubkey) { + const Delegation &delegation) { const PeerId peerid = getPeer(proof); if (peerid == NO_PEER) { return false; } + DelegationState state; + CPubKey pubkey; + if (!delegation.verify(state, proof, pubkey)) { + return false; + } + auto nit = nodes.find(nodeid); if (nit == nodes.end()) { - return nodes.emplace(nodeid, peerid, pubkey).second; + return nodes.emplace(nodeid, peerid, std::move(pubkey)).second; } // We actually have this node already, we need to update it. return nodes.modify(nit, [&](Node &n) { n.peerid = peerid; - n.pubkey = pubkey; + n.pubkey = std::move(pubkey); }); } diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -61,6 +61,7 @@ namespace avalanche { +class Delegation; class PeerManager; class Proof; @@ -265,7 +266,8 @@ bool registerVotes(NodeId nodeid, const Response &response, std::vector &updates); - bool addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); + bool addNode(NodeId nodeid, const Proof &proof, + const Delegation &delegation); 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 @@ -353,9 +353,9 @@ } bool Processor::addNode(NodeId nodeid, const Proof &proof, - const CPubKey &pubkey) { + const Delegation &delegation) { LOCK(cs_peerManager); - return peerManager->addNode(nodeid, proof, pubkey); + return peerManager->addNode(nodeid, proof, delegation); } bool Processor::forNode(NodeId nodeid, diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -2,11 +2,12 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include +#include #include