Changeset View
Changeset View
Standalone View
Standalone View
src/txrequest.h
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
* Complexity: | * Complexity: | ||||
* - Memory usage is proportional to the total number of tracked announcements | * - Memory usage is proportional to the total number of tracked announcements | ||||
* (Size()) plus the number of peers with a nonzero number of tracked | * (Size()) plus the number of peers with a nonzero number of tracked | ||||
* announcements. | * announcements. | ||||
* - CPU usage is generally logarithmic in the total number of tracked | * - CPU usage is generally logarithmic in the total number of tracked | ||||
* announcements, plus the number of announcements affected by an operation | * announcements, plus the number of announcements affected by an operation | ||||
* (amortized O(1) per announcement). | * (amortized O(1) per announcement). | ||||
*/ | */ | ||||
class TxRequestTracker { | |||||
// Avoid littering this header file with implementation details. | // Avoid littering this header file with implementation details. | ||||
class Impl; | class InvRequestTrackerImplInterface { | ||||
const std::unique_ptr<Impl> m_impl; | friend class TxRequestTracker; | ||||
// The base class is responsible for building the child implementation. | |||||
// This is a hack that allows for hiding the concrete implementation details | |||||
// from the callsite. | |||||
static std::unique_ptr<InvRequestTrackerImplInterface> | |||||
BuildImpl(bool deterministic); | |||||
public: | |||||
using ClearExpiredFun = const std::function<void()> &; | |||||
using EmplaceExpiredFun = | |||||
const std::function<void(const NodeId &, const uint256 &)> &; | |||||
virtual ~InvRequestTrackerImplInterface() = default; | |||||
virtual void ReceivedInv(NodeId peer, const uint256 &txid, bool preferred, | |||||
std::chrono::microseconds reqtime) = 0; | |||||
virtual void DisconnectedPeer(NodeId peer) = 0; | |||||
virtual void ForgetTxId(const uint256 &txid) = 0; | |||||
virtual std::vector<uint256> | |||||
GetRequestable(NodeId peer, std::chrono::microseconds now, | |||||
ClearExpiredFun clearExpired, | |||||
EmplaceExpiredFun emplaceExpired) = 0; | |||||
virtual void RequestedTx(NodeId peer, const uint256 &txid, | |||||
std::chrono::microseconds expiry) = 0; | |||||
virtual void ReceivedResponse(NodeId peer, const uint256 &txid) = 0; | |||||
virtual size_t CountInFlight(NodeId peer) const = 0; | |||||
virtual size_t CountCandidates(NodeId peer) const = 0; | |||||
virtual size_t Count(NodeId peer) const = 0; | |||||
virtual size_t Size() const = 0; | |||||
virtual uint64_t ComputePriority(const uint256 &txid, NodeId peer, | |||||
bool preferred) const = 0; | |||||
virtual void SanityCheck() const = 0; | |||||
virtual void | |||||
PostGetRequestableSanityCheck(std::chrono::microseconds now) const = 0; | |||||
}; | |||||
class TxRequestTracker { | |||||
const std::unique_ptr<InvRequestTrackerImplInterface> m_impl; | |||||
public: | public: | ||||
//! Construct a TxRequestTracker. | //! Construct a TxRequestTracker. | ||||
explicit TxRequestTracker(bool deterministic = false); | explicit TxRequestTracker(bool deterministic = false); | ||||
~TxRequestTracker(); | ~TxRequestTracker(); | ||||
// Conceptually, the data structure consists of a collection of | // Conceptually, the data structure consists of a collection of | ||||
// "announcements", one for each peer/txid combination: | // "announcements", one for each peer/txid combination: | ||||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |