rippled
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::HashRouter Class Reference

Routing table for objects identified by hash. More...

Collaboration diagram for ripple::HashRouter:
Collaboration graph
[legend]

Classes

class  Entry
 An entry in the routing table. More...
 

Public Types

using PeerShortID = std::uint32_t
 

Public Member Functions

 HashRouter (Stopwatch &clock, std::chrono::seconds entryHoldTimeInSeconds)
 
HashRouteroperator= (HashRouter const &)=delete
 
virtual ~HashRouter ()=default
 
void addSuppression (uint256 const &key)
 
bool addSuppressionPeer (uint256 const &key, PeerShortID peer)
 
std::pair< bool, std::optional< Stopwatch::time_point > > addSuppressionPeerWithStatus (uint256 const &key, PeerShortID peer)
 Add a suppression peer and get message's relay status. More...
 
bool addSuppressionPeer (uint256 const &key, PeerShortID peer, int &flags)
 
bool shouldProcess (uint256 const &key, PeerShortID peer, int &flags, std::chrono::seconds tx_interval)
 
bool setFlags (uint256 const &key, int flags)
 Set the flags on a hash. More...
 
int getFlags (uint256 const &key)
 
std::optional< std::set< PeerShortID > > shouldRelay (uint256 const &key)
 Determines whether the hashed item should be relayed. More...
 

Static Public Member Functions

static std::chrono::seconds getDefaultHoldTime ()
 

Private Member Functions

std::pair< Entry &, bool > emplace (uint256 const &)
 

Private Attributes

std::mutex mutex_
 
beast::aged_unordered_map< uint256, Entry, Stopwatch::clock_type, hardened_hash< strong_hash > > suppressionMap_
 
const std::chrono::seconds holdTime_
 

Detailed Description

Routing table for objects identified by hash.

This table keeps track of which hashes have been received by which peers. It is used to manage the routing and broadcasting of messages in the peer to peer overlay.

Definition at line 53 of file HashRouter.h.

Member Typedef Documentation

◆ PeerShortID

Definition at line 57 of file HashRouter.h.

Constructor & Destructor Documentation

◆ HashRouter()

ripple::HashRouter::HashRouter ( Stopwatch clock,
std::chrono::seconds  entryHoldTimeInSeconds 
)

Definition at line 146 of file HashRouter.h.

◆ ~HashRouter()

virtual ripple::HashRouter::~HashRouter ( )
virtualdefault

Member Function Documentation

◆ getDefaultHoldTime()

static std::chrono::seconds ripple::HashRouter::getDefaultHoldTime ( )
static

Definition at line 139 of file HashRouter.h.

◆ operator=()

HashRouter& ripple::HashRouter::operator= ( HashRouter const &  )
delete

◆ addSuppression()

void ripple::HashRouter::addSuppression ( uint256 const &  key)

Definition at line 43 of file HashRouter.cpp.

◆ addSuppressionPeer() [1/2]

bool ripple::HashRouter::addSuppressionPeer ( uint256 const &  key,
PeerShortID  peer 
)

Definition at line 51 of file HashRouter.cpp.

◆ addSuppressionPeerWithStatus()

std::pair< bool, std::optional< Stopwatch::time_point > > ripple::HashRouter::addSuppressionPeerWithStatus ( uint256 const &  key,
PeerShortID  peer 
)

Add a suppression peer and get message's relay status.

Return pair: element 1: true if the peer is added. element 2: optional is seated to the relay time point or is unseated if has not relayed yet.

Definition at line 57 of file HashRouter.cpp.

◆ addSuppressionPeer() [2/2]

bool ripple::HashRouter::addSuppressionPeer ( uint256 const &  key,
PeerShortID  peer,
int &  flags 
)

Definition at line 67 of file HashRouter.cpp.

◆ shouldProcess()

bool ripple::HashRouter::shouldProcess ( uint256 const &  key,
PeerShortID  peer,
int &  flags,
std::chrono::seconds  tx_interval 
)

Definition at line 78 of file HashRouter.cpp.

◆ setFlags()

bool ripple::HashRouter::setFlags ( uint256 const &  key,
int  flags 
)

Set the flags on a hash.

Returns
true if the flags were changed. false if unchanged.

Definition at line 102 of file HashRouter.cpp.

◆ getFlags()

int ripple::HashRouter::getFlags ( uint256 const &  key)

Definition at line 94 of file HashRouter.cpp.

◆ shouldRelay()

auto ripple::HashRouter::shouldRelay ( uint256 const &  key)

Determines whether the hashed item should be relayed.

Effects:

If the item should be relayed, this function will not
return `true` again until the hold time has expired.
The internal set of peers will also be reset.
Returns
A std::optional set of peers which do not need to be relayed to. If the result is uninitialized, the item should not be relayed.

Definition at line 118 of file HashRouter.cpp.

◆ emplace()

auto ripple::HashRouter::emplace ( uint256 const &  key)
private

Definition at line 25 of file HashRouter.cpp.

Member Data Documentation

◆ mutex_

std::mutex ripple::HashRouter::mutex_
mutableprivate

Definition at line 213 of file HashRouter.h.

◆ suppressionMap_

beast::aged_unordered_map< uint256, Entry, Stopwatch::clock_type, hardened_hash<strong_hash> > ripple::HashRouter::suppressionMap_
private

Definition at line 221 of file HashRouter.h.

◆ holdTime_

const std::chrono::seconds ripple::HashRouter::holdTime_
private

Definition at line 223 of file HashRouter.h.