Bitcoin ABC  0.26.3
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
InvRequestTracker< InvId > Class Template Reference

#include <invrequest.h>

Public Member Functions

 InvRequestTracker (bool deterministic=false)
 Construct a InvRequestTracker. More...
 
 ~InvRequestTracker ()=default
 
void ReceivedInv (NodeId peer, const InvId &invid, bool preferred, std::chrono::microseconds reqtime)
 Adds a new CANDIDATE announcement. More...
 
void DisconnectedPeer (NodeId peer)
 Deletes all announcements for a given peer. More...
 
void ForgetInvId (const InvId &invid)
 Deletes all announcements for a given invid. More...
 
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. More...
 
void RequestedData (NodeId peer, const InvId &invid, std::chrono::microseconds expiry)
 Marks an inventory as requested, with a specified expiry. More...
 
void ReceivedResponse (NodeId peer, const InvId &invid)
 Converts a CANDIDATE or REQUESTED announcement to a COMPLETED one. More...
 
size_t CountInFlight (NodeId peer) const
 Count how many REQUESTED announcements a peer has. More...
 
size_t CountCandidates (NodeId peer) const
 Count how many CANDIDATE announcements a peer has. More...
 
size_t Count (NodeId peer) const
 Count how many announcements a peer has (REQUESTED, CANDIDATE, and COMPLETED combined). More...
 
size_t Size () const
 Count how many announcements are being tracked in total across all peers and inventory ids. More...
 
uint64_t ComputePriority (const InvId &invid, NodeId peer, bool preferred) const
 Access to the internal priority computation (testing only) More...
 
void SanityCheck () const
 Run internal consistency check (testing only). More...
 
void PostGetRequestableSanityCheck (std::chrono::microseconds now) const
 Run a time-dependent internal consistency check (testing only). More...
 

Private Attributes

const std::unique_ptr< InvRequestTrackerImplInterfacem_impl
 

Detailed Description

template<class InvId>
class InvRequestTracker< InvId >

Definition at line 159 of file invrequest.h.

Constructor & Destructor Documentation

◆ InvRequestTracker()

template<class InvId >
InvRequestTracker< InvId >::InvRequestTracker ( bool  deterministic = false)
inlineexplicit

Construct a InvRequestTracker.

Definition at line 171 of file invrequest.h.

◆ ~InvRequestTracker()

template<class InvId >
InvRequestTracker< InvId >::~InvRequestTracker ( )
default

Member Function Documentation

◆ ComputePriority()

template<class InvId >
uint64_t InvRequestTracker< InvId >::ComputePriority ( const InvId &  invid,
NodeId  peer,
bool  preferred 
) const
inline

Access to the internal priority computation (testing only)

Definition at line 318 of file invrequest.h.

◆ Count()

template<class InvId >
size_t InvRequestTracker< InvId >::Count ( NodeId  peer) const
inline

Count how many announcements a peer has (REQUESTED, CANDIDATE, and COMPLETED combined).

Definition at line 309 of file invrequest.h.

Here is the caller graph for this function:

◆ CountCandidates()

template<class InvId >
size_t InvRequestTracker< InvId >::CountCandidates ( NodeId  peer) const
inline

Count how many CANDIDATE announcements a peer has.

Definition at line 301 of file invrequest.h.

◆ CountInFlight()

template<class InvId >
size_t InvRequestTracker< InvId >::CountInFlight ( NodeId  peer) const
inline

Count how many REQUESTED announcements a peer has.

Definition at line 296 of file invrequest.h.

Here is the caller graph for this function:

◆ DisconnectedPeer()

template<class InvId >
void InvRequestTracker< InvId >::DisconnectedPeer ( NodeId  peer)
inline

Deletes all announcements for a given peer.

It should be called when a peer goes offline.

Definition at line 211 of file invrequest.h.

◆ ForgetInvId()

template<class InvId >
void InvRequestTracker< InvId >::ForgetInvId ( const InvId &  invid)
inline

Deletes all announcements for a given invid.

This should be called when an inventory is no longer needed. The caller should ensure that new announcements for the same invid will not trigger new ReceivedInv calls, at least in the short term after this call.

Definition at line 220 of file invrequest.h.

◆ GetRequestable()

template<class InvId >
std::vector<InvId> InvRequestTracker< InvId >::GetRequestable ( NodeId  peer,
std::chrono::microseconds  now,
std::vector< std::pair< NodeId, InvId >> *  expired 
)
inline

Find the invids to request now from peer.

It does the following:

  • Convert all REQUESTED announcements (for all invids/peers) with (expiry <= now) to COMPLETED ones. These are returned in expired, if non-nullptr.
  • Requestable announcements are selected: CANDIDATE announcements from the specified peer with (reqtime <= now) for which no existing REQUESTED announcement with the same invid from a different peer exists, and for which the specified peer is the best choice among all (reqtime <= now) CANDIDATE announcements with the same invid (subject to preferredness rules, and tiebreaking using a deterministic salted hash of peer and invid).
  • The selected announcements are returned in announcement order (even if multiple were added at the same time, or when the clock went backwards while they were being added). This is done to minimize disruption from dependent inventories being requested out of order: if multiple dependent inventories are announced simultaneously by one peer, and end up being requested from them, the requests will happen in announcement order.

Definition at line 245 of file invrequest.h.

◆ PostGetRequestableSanityCheck()

template<class InvId >
void InvRequestTracker< InvId >::PostGetRequestableSanityCheck ( std::chrono::microseconds  now) const
inline

Run a time-dependent internal consistency check (testing only).

This can only be called immediately after GetRequestable, with the same 'now' parameter.

Definition at line 332 of file invrequest.h.

◆ ReceivedInv()

template<class InvId >
void InvRequestTracker< InvId >::ReceivedInv ( NodeId  peer,
const InvId &  invid,
bool  preferred,
std::chrono::microseconds  reqtime 
)
inline

Adds a new CANDIDATE announcement.

Does nothing if one already exists for that (invid, peer) combination (whether it's CANDIDATE, REQUESTED, or COMPLETED).

Definition at line 201 of file invrequest.h.

◆ ReceivedResponse()

template<class InvId >
void InvRequestTracker< InvId >::ReceivedResponse ( NodeId  peer,
const InvId &  invid 
)
inline

Converts a CANDIDATE or REQUESTED announcement to a COMPLETED one.

If no such announcement exists for the provided peer and invid, nothing happens.

It should be called whenever an inventory or NOTFOUND was received from a peer. When the inventory is not needed entirely anymore, ForgetInvId should be called instead of, or in addition to, this call.

Definition at line 289 of file invrequest.h.

◆ RequestedData()

template<class InvId >
void InvRequestTracker< InvId >::RequestedData ( NodeId  peer,
const InvId &  invid,
std::chrono::microseconds  expiry 
)
inline

Marks an inventory as requested, with a specified expiry.

If no CANDIDATE announcement for the provided peer and invid exists, this call has no effect. Otherwise:

  • That announcement is converted to REQUESTED.
  • If any other REQUESTED announcement for the same invid already existed, it means an unexpected request was made (GetRequestable will never advise doing so). In this case it is converted to COMPLETED, as we're no longer waiting for a response to it.

Definition at line 275 of file invrequest.h.

◆ SanityCheck()

template<class InvId >
void InvRequestTracker< InvId >::SanityCheck ( ) const
inline

Run internal consistency check (testing only).

Definition at line 324 of file invrequest.h.

◆ Size()

template<class InvId >
size_t InvRequestTracker< InvId >::Size ( ) const
inline

Count how many announcements are being tracked in total across all peers and inventory ids.

Definition at line 315 of file invrequest.h.

Member Data Documentation

◆ m_impl

template<class InvId >
const std::unique_ptr<InvRequestTrackerImplInterface> InvRequestTracker< InvId >::m_impl
private

Definition at line 167 of file invrequest.h.


The documentation for this class was generated from the following file: