20#include <xrpld/app/misc/HashRouter.h>
21#include <xrpld/core/Config.h>
28 auto iter = suppressionMap_.find(key);
30 if (iter != suppressionMap_.end())
32 suppressionMap_.touch(iter);
37 expire(suppressionMap_, setup_.holdTime);
40 std::ref(suppressionMap_.emplace(key,
Entry()).first->second),
true);
63 result.first.addPeer(peer);
64 return {result.second, result.first.relayed()};
72 auto [s, created] =
emplace(key);
88 auto& s = result.first;
99 return emplace(key).first.getFlags();
105 XRPL_ASSERT(flags,
"ripple::HashRouter::setFlags : valid input");
111 if ((s.getFlags() & flags) == flags)
124 auto& s = emplace(key).first;
126 if (!s.shouldRelay(suppressionMap_.clock().now(), setup_.relayTime))
129 return s.releasePeerSet();
138 auto const& section = config.
section(
"hashrouter");
142 if (
set(tmp,
"hold_time", section))
145 Throw<std::runtime_error>(
146 "HashRouter hold time must be at least 12 seconds (the "
147 "approximate validation time for three ledgers).");
150 if (
set(tmp,
"relay_time", section))
153 Throw<std::runtime_error>(
154 "HashRouter relay time must be at least 8 seconds (the "
155 "approximate validation time for two ledgers).");
160 Throw<std::runtime_error>(
161 "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_
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
bool shouldProcess(uint256 const &key, PeerShortID peer, int &flags, std::chrono::seconds tx_interval)
int getFlags(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 setFlags(uint256 const &key, int flags)
Set the flags on a hash.
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.