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 <atomic> | #include <atomic> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <vector> | #include <vector> | ||||
static constexpr size_t NO_PEER = ~size_t(0); | static constexpr size_t NO_PEER = ~size_t(0); | ||||
struct Slot { | struct Slot { | ||||
private: | private: | ||||
uint64_t start; | uint64_t start; | ||||
uint64_t stop; | uint64_t score; | ||||
public: | public: | ||||
Slot(uint64_t startIn, uint64_t stopIn) : start(startIn), stop(stopIn) {} | Slot(uint64_t startIn, uint64_t stop) | ||||
: start(startIn), score(stop - start) {} | |||||
Slot withScore(uint64_t score) { return Slot(start, start + score); } | Slot withScore(uint64_t scoreIn) { return Slot(start, start + scoreIn); } | ||||
uint64_t getStart() const { return start; } | uint64_t getStart() const { return start; } | ||||
uint64_t getStop() const { return stop; } | uint64_t getStop() const { return start + score; } | ||||
bool contains(uint64_t slot) const { return start <= slot && slot < stop; } | bool contains(uint64_t slot) const { | ||||
bool precedes(uint64_t slot) const { return slot >= stop; } | return getStart() <= slot && slot < getStop(); | ||||
bool follows(uint64_t slot) const { return start > slot; } | } | ||||
bool precedes(uint64_t slot) const { return slot >= getStop(); } | |||||
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; | ||||
public: | public: | ||||
Show All 18 Lines |