Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 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. | ||||
#ifndef BITCOIN_AVALANCHE_PEERMANAGER_H | #ifndef BITCOIN_AVALANCHE_PEERMANAGER_H | ||||
#define BITCOIN_AVALANCHE_PEERMANAGER_H | #define BITCOIN_AVALANCHE_PEERMANAGER_H | ||||
#include <avalanche/node.h> | #include <avalanche/node.h> | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <bloom.h> | |||||
#include <coins.h> | #include <coins.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <salteduint256hasher.h> | #include <salteduint256hasher.h> | ||||
#include <boost/multi_index/composite_key.hpp> | #include <boost/multi_index/composite_key.hpp> | ||||
#include <boost/multi_index/hashed_index.hpp> | #include <boost/multi_index/hashed_index.hpp> | ||||
#include <boost/multi_index/member.hpp> | #include <boost/multi_index/member.hpp> | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | using NodeSet = boost::multi_index_container< | ||||
boost::multi_index::composite_key< | boost::multi_index::composite_key< | ||||
Node, | Node, | ||||
boost::multi_index::member<Node, PeerId, &Node::peerid>, | boost::multi_index::member<Node, PeerId, &Node::peerid>, | ||||
boost::multi_index::member<Node, TimePoint, | boost::multi_index::member<Node, TimePoint, | ||||
&Node::nextRequestTime>>>>>; | &Node::nextRequestTime>>>>>; | ||||
NodeSet nodes; | NodeSet nodes; | ||||
/** Pool of proofs using orphan UTXOs as stake */ | |||||
std::map<ProofId, Proof> orphanProofs; | |||||
/** Filter of recently rejected proofs */ | |||||
std::unique_ptr<CRollingBloomFilter> recentProofRejects; | |||||
static constexpr int SELECT_PEER_MAX_RETRY = 3; | static constexpr int SELECT_PEER_MAX_RETRY = 3; | ||||
static constexpr int SELECT_NODE_MAX_RETRY = 3; | static constexpr int SELECT_NODE_MAX_RETRY = 3; | ||||
public: | public: | ||||
PeerManager(); | |||||
/** | /** | ||||
* Node API. | * Node API. | ||||
*/ | */ | ||||
bool addNode(NodeId nodeid, const Proof &proof, | bool addNode(NodeId nodeid, const Proof &proof, | ||||
const Delegation &delegation); | const Delegation &delegation); | ||||
bool removeNode(NodeId nodeid); | bool removeNode(NodeId nodeid); | ||||
bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | bool forNode(NodeId nodeid, std::function<bool(const Node &n)> func) const; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
// Accssors. | // Accssors. | ||||
uint64_t getSlotCount() const { return slotCount; } | uint64_t getSlotCount() const { return slotCount; } | ||||
uint64_t getFragmentation() const { return fragmentation; } | uint64_t getFragmentation() const { return fragmentation; } | ||||
std::vector<Peer> getPeers() const; | std::vector<Peer> getPeers() const; | ||||
std::vector<NodeId> getNodeIdsForPeer(PeerId peerId) const; | std::vector<NodeId> getNodeIdsForPeer(PeerId peerId) const; | ||||
const Proof *getProof(const ProofId proofId) const; | |||||
bool addProof(Proof &&proof); | |||||
private: | private: | ||||
PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | PeerSet::iterator fetchOrCreatePeer(const Proof &proof); | ||||
PeerSet::iterator fetchOrCreatePeer(const Proof &proof, | |||||
ProofValidationState &state); | |||||
bool addNodeToPeer(const PeerSet::iterator &it); | bool addNodeToPeer(const PeerSet::iterator &it); | ||||
bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1); | bool removeNodeFromPeer(const PeerSet::iterator &it, uint32_t count = 1); | ||||
}; | }; | ||||
/** | /** | ||||
* This is an internal method that is exposed for testing purposes. | * This is an internal method that is exposed for testing purposes. | ||||
*/ | */ | ||||
PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | PeerId selectPeerImpl(const std::vector<Slot> &slots, const uint64_t slot, | ||||
const uint64_t max); | const uint64_t max); | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PEERMANAGER_H | #endif // BITCOIN_AVALANCHE_PEERMANAGER_H |