Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show All 26 Lines | |||||
#include <chrono> | #include <chrono> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
#include <unordered_set> | #include <unordered_set> | ||||
#include <vector> | #include <vector> | ||||
namespace avalanche { | namespace avalanche { | ||||
/** | |||||
* Maximum number of valid proofs the peer manager can have registered. | |||||
*/ | |||||
const constexpr uint32_t AVALANCHE_MAX_VALID_PROOFS = 4000; | |||||
class Delegation; | class Delegation; | ||||
namespace { | namespace { | ||||
struct TestPeerManager; | struct TestPeerManager; | ||||
} | } | ||||
struct Slot { | struct Slot { | ||||
private: | private: | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
enum class ProofRegistrationResult { | enum class ProofRegistrationResult { | ||||
NONE = 0, | NONE = 0, | ||||
ALREADY_REGISTERED, | ALREADY_REGISTERED, | ||||
ORPHAN, | ORPHAN, | ||||
INVALID, | INVALID, | ||||
CONFLICTING, | CONFLICTING, | ||||
REJECTED, | REJECTED, | ||||
COOLDOWN_NOT_ELAPSED, | COOLDOWN_NOT_ELAPSED, | ||||
SCORE_TOO_LOW, | |||||
}; | }; | ||||
class ProofRegistrationState : public ValidationState<ProofRegistrationResult> { | class ProofRegistrationState : public ValidationState<ProofRegistrationResult> { | ||||
}; | }; | ||||
namespace bmi = boost::multi_index; | namespace bmi = boost::multi_index; | ||||
class PeerManager { | class PeerManager { | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | public: | ||||
const ProofRadixTree &getShareableProofsSnapshot() const { | const ProofRadixTree &getShareableProofsSnapshot() const { | ||||
return shareableProofs; | return shareableProofs; | ||||
} | } | ||||
private: | private: | ||||
template <typename ProofContainer> | template <typename ProofContainer> | ||||
void moveToConflictingPool(const ProofContainer &proofs); | void moveToConflictingPool(const ProofContainer &proofs); | ||||
template <typename Callable> | |||||
void forEachConflictingProof(const ProofRef &proof, Callable &&func); | |||||
bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | bool addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid); | ||||
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); | ||||
friend struct ::avalanche::TestPeerManager; | friend struct ::avalanche::TestPeerManager; | ||||
}; | }; | ||||
/** | /** | ||||
* Internal methods that are exposed for testing purposes. | * Internal methods that are 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 |