1#include <xrpld/app/misc/setup_HashRouter.h>
2#include <xrpld/core/Config.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/unit_test.h>
6#include <xrpl/core/HashRouter.h>
26 using namespace std::chrono_literals;
68 using namespace std::chrono_literals;
82 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
154 using namespace std::chrono_literals;
162 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
183 using namespace std::chrono_literals;
197 using namespace std::chrono_literals;
206 BEAST_EXPECT(peers && peers->empty());
218 BEAST_EXPECT(peers && peers->size() == 3);
229 BEAST_EXPECT(peers && peers->size() == 2);
234 BEAST_EXPECT(peers && peers->size() == 0);
241 using namespace std::chrono_literals;
260 using namespace std::chrono_literals;
265 BEAST_EXPECT(setup.holdTime == 300s);
266 BEAST_EXPECT(setup.relayTime == 30s);
271 auto& h = cfg.
section(
"hashrouter");
272 h.
set(
"hold_time",
"600");
273 h.set(
"relay_time",
"15");
275 BEAST_EXPECT(setup.holdTime == 600s);
276 BEAST_EXPECT(setup.relayTime == 15s);
281 auto& h = cfg.
section(
"hashrouter");
282 h.
set(
"hold_time",
"400");
283 h.set(
"relay_time",
"400");
285 BEAST_EXPECT(setup.holdTime == 400s);
286 BEAST_EXPECT(setup.relayTime == 400s);
291 auto& h = cfg.
section(
"hashrouter");
292 h.
set(
"hold_time",
"60");
293 h.set(
"relay_time",
"120");
302 "HashRouter relay time must be less than or equal to hold "
304 BEAST_EXPECT(e.
what() == expected);
310 auto& h = cfg.
section(
"hashrouter");
311 h.
set(
"hold_time",
"10");
312 h.set(
"relay_time",
"120");
321 "HashRouter hold time must be at least 12 seconds (the "
322 "approximate validation time for three "
324 BEAST_EXPECT(e.
what() == expected);
330 auto& h = cfg.
section(
"hashrouter");
331 h.
set(
"hold_time",
"500");
332 h.set(
"relay_time",
"6");
341 "HashRouter relay time must be at least 8 seconds (the "
342 "approximate validation time for two ledgers).";
343 BEAST_EXPECT(e.
what() == expected);
349 auto& h = cfg.
section(
"hashrouter");
350 h.
set(
"hold_time",
"alice");
351 h.set(
"relay_time",
"bob");
355 BEAST_EXPECT(setup.holdTime == 300s);
356 BEAST_EXPECT(setup.relayTime == 30s);
370 HF combined = f1 | f2;
372 BEAST_EXPECT(
static_cast<UHF
>(combined) == (
static_cast<UHF
>(f1) |
static_cast<UHF
>(f2)));
376 BEAST_EXPECT(temp == combined);
378 HF intersect = combined & f1;
379 BEAST_EXPECT(intersect == f1);
383 BEAST_EXPECT(temp2 == f1);
385 BEAST_EXPECT(
any(f1));
386 BEAST_EXPECT(
any(f2));
387 BEAST_EXPECT(
any(combined));
388 BEAST_EXPECT(!
any(HF::UNDEFINED));
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
Section & section(std::string const &name)
Returns the section with the given name.
Routing table for objects identified by hash.
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.
void addSuppression(uint256 const &key)
bool shouldProcess(uint256 const &key, PeerShortID peer, HashRouterFlags &flags, std::chrono::seconds tx_interval)
void set(std::string const &key, std::string const &value)
Set a key/value pair.
void run() override
Runs the suite.
HashRouter::Setup getSetup(std::chrono::seconds hold, std::chrono::seconds relay)
any_t const any
Returns an amount representing "any issuer".
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Stopwatch & stopwatch()
Returns an instance of a wall clock.
HashRouter::Setup setup_HashRouter(Config const &config)
Create HashRouter setup from configuration.
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.