Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.h
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public: | ||||
bool follows(uint64_t slot) const { return getStart() > slot; } | bool follows(uint64_t slot) const { return getStart() > slot; } | ||||
}; | }; | ||||
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; | ||||
/** | |||||
* Several nodes can make an avalanche peer. In this case, all nodes are | |||||
* considered interchangeable parts of the same peer. | |||||
*/ | |||||
struct Peer { | |||||
uint32_t score; | |||||
uint32_t index; | |||||
Peer(uint32_t score_, uint32_t index_) : score(score_), index(index_) {} | |||||
}; | |||||
PeerId nextPeerId = 0; | PeerId nextPeerId = 0; | ||||
std::unordered_map<PeerId, uint32_t> peerIndices; | std::unordered_map<PeerId, Peer> peers; | ||||
static constexpr int SELECT_PEER_MAX_RETRY = 3; | static constexpr int SELECT_PEER_MAX_RETRY = 3; | ||||
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); | ||||
Show All 29 Lines |