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 <avalanche/proofpool.h> | #include <avalanche/proofpool.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <consensus/validation.h> | |||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <salteduint256hasher.h> | #include <salteduint256hasher.h> | ||||
#include <util/time.h> | #include <util/time.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/mem_fun.hpp> | #include <boost/multi_index/mem_fun.hpp> | ||||
#include <boost/multi_index/member.hpp> | #include <boost/multi_index/member.hpp> | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | struct PendingNode { | ||||
PendingNode(ProofId proofid_, NodeId nodeid_) | PendingNode(ProofId proofid_, NodeId nodeid_) | ||||
: proofid(proofid_), nodeid(nodeid_){}; | : proofid(proofid_), nodeid(nodeid_){}; | ||||
}; | }; | ||||
struct by_proofid; | struct by_proofid; | ||||
struct by_nodeid; | struct by_nodeid; | ||||
enum class ProofRegistrationResult { | |||||
NONE = 0, | |||||
ALREADY_REGISTERED, | |||||
ORPHAN, | |||||
INVALID, | |||||
CONFLICTING, | |||||
REJECTED, | |||||
}; | |||||
class ProofRegistrationState : public ValidationState<ProofRegistrationResult> { | |||||
}; | |||||
namespace bmi = boost::multi_index; | namespace bmi = boost::multi_index; | ||||
class PeerManager { | class PeerManager { | ||||
std::vector<Slot> slots; | std::vector<Slot> slots; | ||||
uint64_t slotCount = 0; | uint64_t slotCount = 0; | ||||
uint64_t fragmentation = 0; | uint64_t fragmentation = 0; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | public: | ||||
* and is not the best candidate. | * and is not the best candidate. | ||||
*/ | */ | ||||
enum class RegistrationMode { | enum class RegistrationMode { | ||||
DEFAULT, | DEFAULT, | ||||
FORCE_ACCEPT, | FORCE_ACCEPT, | ||||
}; | }; | ||||
bool registerProof(const ProofRef &proof, | bool registerProof(const ProofRef &proof, | ||||
ProofRegistrationState ®istrationState, | |||||
RegistrationMode mode = RegistrationMode::DEFAULT); | RegistrationMode mode = RegistrationMode::DEFAULT); | ||||
bool registerProof(const ProofRef &proof, | |||||
RegistrationMode mode = RegistrationMode::DEFAULT) { | |||||
ProofRegistrationState dummy; | |||||
return registerProof(proof, dummy, mode); | |||||
} | |||||
bool exists(const ProofId &proofid) const { | bool exists(const ProofId &proofid) const { | ||||
return getProof(proofid) != nullptr; | return getProof(proofid) != nullptr; | ||||
} | } | ||||
template <typename Callable> | template <typename Callable> | ||||
bool forPeer(const ProofId &proofid, Callable &&func) const { | bool forPeer(const ProofId &proofid, Callable &&func) const { | ||||
auto &pview = peers.get<by_proofid>(); | auto &pview = peers.get<by_proofid>(); | ||||
auto it = pview.find(proofid); | auto it = pview.find(proofid); | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |