xrpld
Loading...
Searching...
No Matches
setup_HashRouter.cpp
1#include <xrpld/app/misc/setup_HashRouter.h>
2
3#include <xrpld/core/Config.h>
4
5#include <xrpl/basics/contract.h>
6#include <xrpl/config/BasicConfig.h>
7#include <xrpl/config/Constants.h>
8#include <xrpl/core/HashRouter.h>
9
10#include <chrono>
11#include <cstdint>
12#include <stdexcept>
13
14namespace xrpl {
15
17setupHashRouter(Config const& config)
18{
19 using namespace std::chrono;
20
22 auto const& section = config.section(Sections::kHashrouter);
23
24 std::int32_t tmp{};
25
26 if (set(tmp, Keys::kHoldTime, section))
27 {
28 if (tmp < 12)
29 {
31 "HashRouter hold time must be at least 12 seconds (the "
32 "approximate validation time for three ledgers).");
33 }
34 setup.holdTime = seconds(tmp);
35 }
36 if (set(tmp, Keys::kRelayTime, section))
37 {
38 if (tmp < 8)
39 {
41 "HashRouter relay time must be at least 8 seconds (the "
42 "approximate validation time for two ledgers).");
43 }
44 setup.relayTime = seconds(tmp);
45 }
46 if (setup.relayTime > setup.holdTime)
47 {
48 Throw<std::runtime_error>("HashRouter relay time must be less than or equal to hold time");
49 }
50
51 return setup;
52}
53
54} // namespace xrpl
Section & section(std::string const &name)
Returns the section with the given name.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
HashRouter::Setup setupHashRouter(Config const &config)
Create HashRouter setup from configuration.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49
Structure used to customize HashRouter behavior.
Definition HashRouter.h:91
seconds holdTime
Expiration time for a hash entry.
Definition HashRouter.h:99
seconds relayTime
Amount of time required before a relayed item will be relayed again.
Definition HashRouter.h:103
static constexpr auto kRelayTime
Definition Constants.h:147
static constexpr auto kHoldTime
Definition Constants.h:112
static constexpr auto kHashrouter
Definition Constants.h:19