1#include <xrpld/app/misc/HashRouter.h>
2#include <xrpld/core/Config.h>
9 auto iter = suppressionMap_.find(key);
11 if (iter != suppressionMap_.end())
13 suppressionMap_.touch(iter);
18 expire(suppressionMap_, setup_.holdTime);
43 result.first.addPeer(peer);
44 return {result.second, result.first.relayed()};
52 auto [s, created] =
emplace(key);
68 auto& s = result.first;
79 return emplace(key).first.getFlags();
85 XRPL_ASSERT(
static_cast<bool>(flags),
"xrpl::HashRouter::setFlags : valid input");
91 if ((s.getFlags() & flags) == flags)
103 auto& s = emplace(key).first;
105 if (!s.shouldRelay(suppressionMap_.clock().now(), setup_.relayTime))
108 return s.releasePeerSet();
117 auto const& section = config.
section(
"hashrouter");
121 if (
set(tmp,
"hold_time", section))
124 Throw<std::runtime_error>(
125 "HashRouter hold time must be at least 12 seconds (the "
126 "approximate validation time for three ledgers).");
129 if (
set(tmp,
"relay_time", section))
132 Throw<std::runtime_error>(
133 "HashRouter relay time must be at least 8 seconds (the "
134 "approximate validation time for two ledgers).");
139 Throw<std::runtime_error>(
"HashRouter relay time must be less than or equal to hold time");
Section & section(std::string const &name)
Returns the section with the given name.
An entry in the routing table.
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
HashRouterFlags getFlags(uint256 const &key)
bool addSuppressionPeer(uint256 const &key, PeerShortID peer)
bool setFlags(uint256 const &key, HashRouterFlags flags)
Set the flags on a hash.
std::pair< bool, std::optional< Stopwatch::time_point > > addSuppressionPeerWithStatus(uint256 const &key, PeerShortID peer)
Add a suppression peer and get message's relay status.
std::pair< Entry &, bool > emplace(uint256 const &)
beast::aged_unordered_map< uint256, Entry, Stopwatch::clock_type, hardened_hash< strong_hash > > suppressionMap_
void addSuppression(uint256 const &key)
bool shouldProcess(uint256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds tx_interval)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
HashRouter::Setup setup_HashRouter(Config const &config)
Structure used to customize HashRouter behavior.
seconds holdTime
Expiration time for a hash entry.
seconds relayTime
Amount of time required before a relayed item will be relayed again.