Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show All 16 Lines | private: | ||||
uint64_t start; | uint64_t start; | ||||
uint32_t score; | uint32_t score; | ||||
PeerId peerid; | PeerId peerid; | ||||
public: | public: | ||||
Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn) | Slot(uint64_t startIn, uint32_t scoreIn, PeerId peeridIn) | ||||
: start(startIn), score(scoreIn), peerid(peeridIn) {} | : start(startIn), score(scoreIn), peerid(peeridIn) {} | ||||
Slot withStart(uint64_t startIn) const { | |||||
return Slot(startIn, score, peerid); | |||||
} | |||||
Slot withScore(uint64_t scoreIn) const { | Slot withScore(uint64_t scoreIn) const { | ||||
return Slot(start, scoreIn, peerid); | return Slot(start, scoreIn, peerid); | ||||
} | } | ||||
Slot withPeerId(PeerId peeridIn) const { | Slot withPeerId(PeerId peeridIn) const { | ||||
return Slot(start, score, peeridIn); | return Slot(start, score, peeridIn); | ||||
} | } | ||||
uint64_t getStart() const { return start; } | uint64_t getStart() const { return start; } | ||||
Show All 18 Lines | |||||
public: | public: | ||||
PeerId addPeer(uint32_t score) { return addPeer(nextPeerId++, score); } | PeerId addPeer(uint32_t score) { return addPeer(nextPeerId++, score); } | ||||
bool removePeer(PeerId p); | bool removePeer(PeerId p); | ||||
bool rescorePeer(PeerId p, uint32_t score); | bool rescorePeer(PeerId p, uint32_t score); | ||||
PeerId selectPeer() const; | PeerId selectPeer() const; | ||||
/** | |||||
* Trigger maintenance of internal datastructures. | |||||
* Returns how much slot space was saved after compaction. | |||||
*/ | |||||
uint64_t compact(); | |||||
/** | |||||
* Perform consistency check on internal data structures. | |||||
* Mostly useful for tests. | |||||
*/ | |||||
bool verify() const; | |||||
// 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; } | ||||
private: | private: | ||||
PeerId addPeer(PeerId peerid, uint32_t score); | PeerId addPeer(PeerId peerid, uint32_t score); | ||||
}; | }; | ||||
/** | /** | ||||
* 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); | ||||
#endif // BITCOIN_AVALANCHE_PEERMANAGER_H | #endif // BITCOIN_AVALANCHE_PEERMANAGER_H |