xrpld
Loading...
Searching...
No Matches
xrpl::HashRouter Class Reference

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

#include <HashRouter.h>

Collaboration diagram for xrpl::HashRouter:

Classes

struct  Setup
 Structure used to customize HashRouter behavior. More...
class  Entry
 An entry in the routing table. More...

Public Types

using PeerShortID = std::uint32_t

Public Member Functions

 HashRouter (Setup const &setup, Stopwatch &clock)
HashRouter & operator= (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.
bool addSuppressionPeer (UInt256 const &key, PeerShortID peer, HashRouterFlags &flags)
bool shouldProcess (UInt256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds txInterval)
bool setFlags (UInt256 const &key, HashRouterFlags flags)
 Set the flags on a hash.
bool clearFlags (UInt256 const &key, HashRouterFlags flags)
 Clear flags on a hash.
HashRouterFlags getFlags (UInt256 const &key)
std::optional< std::set< PeerShortID > > shouldRelay (UInt256 const &key)
 Determines whether the hashed item should be relayed.

Private Member Functions

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

Private Attributes

std::mutex mutex_
Setup const setup_
beast::AgedUnorderedMap< UInt256, Entry, Stopwatch::ClockType, HardenedHash< StrongHash > > suppressionMap_

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 95 of file HashRouter.h.

Member Typedef Documentation

◆ PeerShortID

Definition at line 99 of file HashRouter.h.

Constructor & Destructor Documentation

◆ HashRouter()

xrpl::HashRouter::HashRouter ( Setup const & setup,
Stopwatch & clock )

Definition at line 222 of file HashRouter.h.

◆ ~HashRouter()

virtual xrpl::HashRouter::~HashRouter ( )
virtualdefault

Member Function Documentation

◆ operator=()

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

◆ addSuppression()

void xrpl::HashRouter::addSuppression ( UInt256 const & key)

Definition at line 35 of file libxrpl/core/HashRouter.cpp.

◆ addSuppressionPeer() [1/2]

bool xrpl::HashRouter::addSuppressionPeer ( UInt256 const & key,
PeerShortID peer )

Definition at line 43 of file libxrpl/core/HashRouter.cpp.

◆ addSuppressionPeerWithStatus()

std::pair< bool, std::optional< Stopwatch::time_point > > xrpl::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 49 of file libxrpl/core/HashRouter.cpp.

◆ addSuppressionPeer() [2/2]

bool xrpl::HashRouter::addSuppressionPeer ( UInt256 const & key,
PeerShortID peer,
HashRouterFlags & flags )

Definition at line 59 of file libxrpl/core/HashRouter.cpp.

◆ shouldProcess()

bool xrpl::HashRouter::shouldProcess ( UInt256 const & key,
PeerShortID peer,
HashRouterFlags & flags,
std::chrono::seconds txInterval )

Definition at line 70 of file libxrpl/core/HashRouter.cpp.

◆ setFlags()

bool xrpl::HashRouter::setFlags ( UInt256 const & key,
HashRouterFlags flags )

Set the flags on a hash.

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

Definition at line 113 of file libxrpl/core/HashRouter.cpp.

◆ clearFlags()

bool xrpl::HashRouter::clearFlags ( UInt256 const & key,
HashRouterFlags flags )

Clear flags on a hash.

A hash without an entry is left without one, so clearing never creates or refreshes an entry.

Parameters
keyThe hash whose flags to clear.
flagsThe flags to clear.
Returns
true if at least one of the flags was set and is now clear, false if nothing changed.

Definition at line 86 of file libxrpl/core/HashRouter.cpp.

◆ getFlags()

HashRouterFlags xrpl::HashRouter::getFlags ( UInt256 const & key)

Definition at line 105 of file libxrpl/core/HashRouter.cpp.

◆ shouldRelay()

auto xrpl::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 a seated optional again until the relay 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 unseated, the item should not be relayed.

Definition at line 129 of file libxrpl/core/HashRouter.cpp.

◆ emplace()

auto xrpl::HashRouter::emplace ( UInt256 const & key)
private

Definition at line 18 of file libxrpl/core/HashRouter.cpp.

Member Data Documentation

◆ mutex_

std::mutex xrpl::HashRouter::mutex_
mutableprivate

Definition at line 306 of file HashRouter.h.

◆ setup_

Setup const xrpl::HashRouter::setup_
private

Definition at line 309 of file HashRouter.h.

◆ suppressionMap_

beast::AgedUnorderedMap<UInt256, Entry, Stopwatch::ClockType, HardenedHash<StrongHash> > xrpl::HashRouter::suppressionMap_
private

Definition at line 313 of file HashRouter.h.