20#include <xrpld/app/misc/HashRouter.h>
21#include <xrpld/core/Config.h>
23#include <xrpl/basics/chrono.h>
24#include <xrpl/beast/unit_test.h>
44 using namespace std::chrono_literals;
86 using namespace std::chrono_literals;
100 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
172 using namespace std::chrono_literals;
180 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
201 using namespace std::chrono_literals;
215 using namespace std::chrono_literals;
224 BEAST_EXPECT(peers && peers->empty());
236 BEAST_EXPECT(peers && peers->size() == 3);
247 BEAST_EXPECT(peers && peers->size() == 2);
252 BEAST_EXPECT(peers && peers->size() == 0);
259 using namespace std::chrono_literals;
278 using namespace std::chrono_literals;
283 BEAST_EXPECT(setup.holdTime == 300s);
284 BEAST_EXPECT(setup.relayTime == 30s);
289 auto& h = cfg.
section(
"hashrouter");
290 h.
set(
"hold_time",
"600");
291 h.set(
"relay_time",
"15");
293 BEAST_EXPECT(setup.holdTime == 600s);
294 BEAST_EXPECT(setup.relayTime == 15s);
299 auto& h = cfg.
section(
"hashrouter");
300 h.
set(
"hold_time",
"400");
301 h.set(
"relay_time",
"400");
303 BEAST_EXPECT(setup.holdTime == 400s);
304 BEAST_EXPECT(setup.relayTime == 400s);
309 auto& h = cfg.
section(
"hashrouter");
310 h.
set(
"hold_time",
"60");
311 h.set(
"relay_time",
"120");
320 "HashRouter relay time must be less than or equal to hold "
322 BEAST_EXPECT(e.
what() == expected);
328 auto& h = cfg.
section(
"hashrouter");
329 h.
set(
"hold_time",
"10");
330 h.set(
"relay_time",
"120");
339 "HashRouter hold time must be at least 12 seconds (the "
340 "approximate validation time for three "
342 BEAST_EXPECT(e.
what() == expected);
348 auto& h = cfg.
section(
"hashrouter");
349 h.
set(
"hold_time",
"500");
350 h.set(
"relay_time",
"6");
359 "HashRouter relay time must be at least 8 seconds (the "
360 "approximate validation time for two ledgers).";
361 BEAST_EXPECT(e.
what() == expected);
367 auto& h = cfg.
section(
"hashrouter");
368 h.
set(
"hold_time",
"alice");
369 h.set(
"relay_time",
"bob");
373 BEAST_EXPECT(setup.holdTime == 300s);
374 BEAST_EXPECT(setup.relayTime == 30s);
388 HF combined = f1 | f2;
391 static_cast<UHF
>(combined) ==
392 (
static_cast<UHF
>(f1) |
static_cast<UHF
>(f2)));
396 BEAST_EXPECT(temp == combined);
398 HF intersect = combined & f1;
399 BEAST_EXPECT(intersect == f1);
403 BEAST_EXPECT(temp2 == f1);
405 BEAST_EXPECT(
any(f1));
406 BEAST_EXPECT(
any(f2));
407 BEAST_EXPECT(
any(combined));
408 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.
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.
void addSuppression(uint256 const &key)
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.
HashRouter::Setup setup_HashRouter(Config const &config)
Stopwatch & stopwatch()
Returns an instance of a wall clock.
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.