diff --git a/src/avalanche/node.h b/src/avalanche/node.h --- a/src/avalanche/node.h +++ b/src/avalanche/node.h @@ -9,15 +9,23 @@ #include #include +#include + +using PeerId = uint32_t; +static constexpr PeerId NO_PEER = -1; using TimePoint = std::chrono::time_point; struct AvalancheNode { NodeId nodeid; - int64_t score; - + PeerId peerid; TimePoint nextRequestTime; CPubKey pubkey; + + AvalancheNode(NodeId nodeid_, PeerId peerid_, CPubKey pubkey_) + : nodeid(nodeid_), peerid(peerid_), + nextRequestTime(std::chrono::steady_clock::now()), + pubkey(std::move(pubkey_)) {} }; #endif // BITCOIN_AVALANCHE_NODE_H diff --git a/src/avalanche/peermanager.h b/src/avalanche/peermanager.h --- a/src/avalanche/peermanager.h +++ b/src/avalanche/peermanager.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_AVALANCHE_PEERMANAGER_H #define BITCOIN_AVALANCHE_PEERMANAGER_H +#include #include #include @@ -19,9 +20,6 @@ #include #include -using PeerId = uint32_t; -static constexpr PeerId NO_PEER = -1; - struct Slot { private: uint64_t start; @@ -75,34 +73,22 @@ PeerId nextPeerId = 0; std::unordered_map peers; - using TimePoint = std::chrono::time_point; - - struct Node { - NodeId nodeid; - PeerId peerid; - TimePoint nextRequestTime; - CPubKey pubkey; - - Node(NodeId nodeid_, PeerId peerid_, CPubKey pubkey_) - : nodeid(nodeid_), peerid(peerid_), - nextRequestTime(std::chrono::steady_clock::now()), - pubkey(std::move(pubkey_)) {} - }; - using NodeSet = boost::multi_index_container< - Node, + AvalancheNode, boost::multi_index::indexed_by< // index by nodeid - boost::multi_index::hashed_unique< - boost::multi_index::member>, + boost::multi_index::hashed_unique>, // sorted by peerid/nextRequestTime boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::composite_key< - Node, - boost::multi_index::member, - boost::multi_index::member>>>>; + AvalancheNode, + boost::multi_index::member, + boost::multi_index::member< + AvalancheNode, TimePoint, + &AvalancheNode::nextRequestTime>>>>>; NodeSet nodes; diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -102,7 +102,7 @@ } // We actually have this node already, we need to update it. - return nodes.modify(nit, [&](Node &n) { + return nodes.modify(nit, [&](AvalancheNode &n) { n.peerid = peerid; n.pubkey = std::move(pubkey); }); @@ -118,7 +118,8 @@ return false; } - return nodes.modify(it, [&](Node &n) { n.nextRequestTime = timeout; }); + return nodes.modify(it, + [&](AvalancheNode &n) { n.nextRequestTime = timeout; }); } NodeId PeerManager::getSuitableNodeToQuery() { diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -341,8 +341,7 @@ bool AvalancheProcessor::addPeer(NodeId nodeid, int64_t score, CPubKey pubkey) { return peerSet.getWriteView() - ->insert({nodeid, score, std::chrono::steady_clock::now(), - std::move(pubkey)}) + ->insert({nodeid, /* peerid is unused here */ 0, std::move(pubkey)}) .second; }