1#include <xrpld/app/misc/HashRouter.h>
2#include <xrpld/core/Config.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/unit_test.h>
25 using namespace std::chrono_literals;
67 using namespace std::chrono_literals;
81 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
153 using namespace std::chrono_literals;
161 BEAST_EXPECT(key1 != key2 && key2 != key3 && key3 != key4);
182 using namespace std::chrono_literals;
196 using namespace std::chrono_literals;
205 BEAST_EXPECT(peers && peers->empty());
217 BEAST_EXPECT(peers && peers->size() == 3);
228 BEAST_EXPECT(peers && peers->size() == 2);
233 BEAST_EXPECT(peers && peers->size() == 0);
240 using namespace std::chrono_literals;
259 using namespace std::chrono_literals;
264 BEAST_EXPECT(setup.holdTime == 300s);
265 BEAST_EXPECT(setup.relayTime == 30s);
270 auto& h = cfg.
section(
"hashrouter");
271 h.
set(
"hold_time",
"600");
272 h.set(
"relay_time",
"15");
274 BEAST_EXPECT(setup.holdTime == 600s);
275 BEAST_EXPECT(setup.relayTime == 15s);
280 auto& h = cfg.
section(
"hashrouter");
281 h.
set(
"hold_time",
"400");
282 h.set(
"relay_time",
"400");
284 BEAST_EXPECT(setup.holdTime == 400s);
285 BEAST_EXPECT(setup.relayTime == 400s);
290 auto& h = cfg.
section(
"hashrouter");
291 h.
set(
"hold_time",
"60");
292 h.set(
"relay_time",
"120");
301 "HashRouter relay time must be less than or equal to hold "
303 BEAST_EXPECT(e.
what() == expected);
309 auto& h = cfg.
section(
"hashrouter");
310 h.
set(
"hold_time",
"10");
311 h.set(
"relay_time",
"120");
320 "HashRouter hold time must be at least 12 seconds (the "
321 "approximate validation time for three "
323 BEAST_EXPECT(e.
what() == expected);
329 auto& h = cfg.
section(
"hashrouter");
330 h.
set(
"hold_time",
"500");
331 h.set(
"relay_time",
"6");
340 "HashRouter relay time must be at least 8 seconds (the "
341 "approximate validation time for two ledgers).";
342 BEAST_EXPECT(e.
what() == expected);
348 auto& h = cfg.
section(
"hashrouter");
349 h.
set(
"hold_time",
"alice");
350 h.set(
"relay_time",
"bob");
354 BEAST_EXPECT(setup.holdTime == 300s);
355 BEAST_EXPECT(setup.relayTime == 30s);
369 HF combined = f1 | f2;
372 static_cast<UHF
>(combined) ==
373 (
static_cast<UHF
>(f1) |
static_cast<UHF
>(f2)));
377 BEAST_EXPECT(temp == combined);
379 HF intersect = combined & f1;
380 BEAST_EXPECT(intersect == f1);
384 BEAST_EXPECT(temp2 == f1);
386 BEAST_EXPECT(
any(f1));
387 BEAST_EXPECT(
any(f2));
388 BEAST_EXPECT(
any(combined));
389 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.