5#ifndef BITCOIN_INVREQUEST_H
6#define BITCOIN_INVREQUEST_H
127 static std::unique_ptr<InvRequestTrackerImplInterface>
133 const std::function<void(
const NodeId &,
const uint256 &)> &;
138 std::chrono::microseconds reqtime) = 0;
141 virtual std::vector<uint256>
146 std::chrono::microseconds expiry) = 0;
151 virtual size_t Size()
const = 0;
153 bool preferred)
const = 0;
164 static_assert(std::is_base_of<uint256, InvId>::value,
165 "InvRequestTracker inv id type should be uint256 or derived");
167 const std::unique_ptr<InvRequestTrackerImplInterface>
m_impl;
202 std::chrono::microseconds reqtime) {
203 m_impl->ReceivedInv(peer, invid, preferred, reqtime);
246 std::vector<std::pair<NodeId, InvId>> *expired) {
256 expired->emplace_back(nodeid, InvId(invid));
259 std::vector<uint256> hashes =
260 m_impl->GetRequestable(peer, now, clearExpired, emplaceExpired);
261 return std::vector<InvId>(hashes.begin(), hashes.end());
276 std::chrono::microseconds expiry) {
277 m_impl->RequestedData(peer, invid, expiry);
290 m_impl->ReceivedResponse(peer, invid);
297 return m_impl->CountInFlight(peer);
302 return m_impl->CountCandidates(peer);
319 bool preferred)
const {
320 return m_impl->ComputePriority(invid, peer, preferred);
333 m_impl->PostGetRequestableSanityCheck(now);
~InvRequestTracker()=default
std::vector< InvId > GetRequestable(NodeId peer, std::chrono::microseconds now, std::vector< std::pair< NodeId, InvId > > *expired)
Find the invids to request now from peer.
size_t Size() const
Count how many announcements are being tracked in total across all peers and inventory ids.
const std::unique_ptr< InvRequestTrackerImplInterface > m_impl
InvRequestTracker(bool deterministic=false)
Construct a InvRequestTracker.
void RequestedData(NodeId peer, const InvId &invid, std::chrono::microseconds expiry)
Marks an inventory as requested, with a specified expiry.
void ForgetInvId(const InvId &invid)
Deletes all announcements for a given invid.
void DisconnectedPeer(NodeId peer)
Deletes all announcements for a given peer.
void SanityCheck() const
Run internal consistency check (testing only).
uint64_t ComputePriority(const InvId &invid, NodeId peer, bool preferred) const
Access to the internal priority computation (testing only)
void PostGetRequestableSanityCheck(std::chrono::microseconds now) const
Run a time-dependent internal consistency check (testing only).
size_t Count(NodeId peer) const
Count how many announcements a peer has (REQUESTED, CANDIDATE, and COMPLETED combined).
size_t CountCandidates(NodeId peer) const
Count how many CANDIDATE announcements a peer has.
void ReceivedInv(NodeId peer, const InvId &invid, bool preferred, std::chrono::microseconds reqtime)
Adds a new CANDIDATE announcement.
void ReceivedResponse(NodeId peer, const InvId &invid)
Converts a CANDIDATE or REQUESTED announcement to a COMPLETED one.
size_t CountInFlight(NodeId peer) const
Count how many REQUESTED announcements a peer has.
Data structure to keep track of, and schedule, inventory downloads from peers.
virtual void ReceivedInv(NodeId peer, const uint256 &invid, bool preferred, std::chrono::microseconds reqtime)=0
static std::unique_ptr< InvRequestTrackerImplInterface > BuildImpl(bool deterministic)
virtual void RequestedData(NodeId peer, const uint256 &invid, std::chrono::microseconds expiry)=0
virtual void ForgetInvId(const uint256 &invid)=0
virtual void DisconnectedPeer(NodeId peer)=0
virtual size_t CountInFlight(NodeId peer) const =0
virtual std::vector< uint256 > GetRequestable(NodeId peer, std::chrono::microseconds now, ClearExpiredFun clearExpired, EmplaceExpiredFun emplaceExpired)=0
virtual void ReceivedResponse(NodeId peer, const uint256 &invid)=0
virtual void SanityCheck() const =0
virtual size_t Size() const =0
virtual size_t Count(NodeId peer) const =0
virtual uint64_t ComputePriority(const uint256 &invid, NodeId peer, bool preferred) const =0
virtual ~InvRequestTrackerImplInterface()=default
const std::function< void()> & ClearExpiredFun
virtual size_t CountCandidates(NodeId peer) const =0
const std::function< void(const NodeId &, const uint256 &)> & EmplaceExpiredFun
virtual void PostGetRequestableSanityCheck(std::chrono::microseconds now) const =0