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);
21 std::ref(suppressionMap_.emplace(key,
Entry()).first->second),
true);
44 result.first.addPeer(peer);
45 return {result.second, result.first.relayed()};
56 auto [s, created] =
emplace(key);
72 auto& s = result.first;
83 return emplace(key).first.getFlags();
90 static_cast<bool>(flags),
"ripple::HashRouter::setFlags : valid input");
96 if ((s.getFlags() & flags) == flags)
109 auto& s = emplace(key).first;
111 if (!s.shouldRelay(suppressionMap_.clock().now(), setup_.relayTime))
114 return s.releasePeerSet();
123 auto const& section = config.
section(
"hashrouter");
127 if (
set(tmp,
"hold_time", section))
130 Throw<std::runtime_error>(
131 "HashRouter hold time must be at least 12 seconds (the "
132 "approximate validation time for three ledgers).");
135 if (
set(tmp,
"relay_time", section))
138 Throw<std::runtime_error>(
139 "HashRouter relay time must be at least 8 seconds (the "
140 "approximate validation time for two ledgers).");
145 Throw<std::runtime_error>(
146 "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.
beast::aged_unordered_map< uint256, Entry, Stopwatch::clock_type, hardened_hash< strong_hash > > suppressionMap_
HashRouterFlags getFlags(uint256 const &key)
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
bool shouldProcess(uint256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds tx_interval)
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 &)
void addSuppression(uint256 const &key)
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.