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: | |||||
uint64_t start; | uint64_t start; | ||||
uint64_t stop; | uint64_t stop; | ||||
public: | |||||
Slot(uint64_t startIn, uint64_t stopIn) : start(startIn), stop(stopIn) {} | Slot(uint64_t startIn, uint64_t stopIn) : start(startIn), stop(stopIn) {} | ||||
Slot withScore(uint64_t score) { return Slot(start, start + score); } | |||||
uint64_t getStart() const { return start; } | |||||
uint64_t getStop() const { return stop; } | |||||
bool contains(uint64_t slot) const { return start <= slot && slot < stop; } | bool contains(uint64_t slot) const { return start <= slot && slot < stop; } | ||||
bool precedes(uint64_t slot) const { return slot >= stop; } | bool precedes(uint64_t slot) const { return slot >= stop; } | ||||
bool follows(uint64_t slot) const { return start > slot; } | bool follows(uint64_t slot) const { return start > slot; } | ||||
}; | }; | ||||
class PeerManager { | class PeerManager { | ||||
std::vector<Slot> slots; | std::vector<Slot> slots; | ||||
uint64_t slotCount = 0; | uint64_t slotCount = 0; | ||||
Show All 21 Lines |