12#ifndef OPENVPN_TIME_DURHELPER_H
13#define OPENVPN_TIME_DURHELPER_H
21 const std::string &name,
22 const std::string &valstr,
23 const unsigned int min_value,
27 const unsigned int maxdur = ms ? 1000 * 60 * 60 * 24 : 60 * 60 * 24 * 7;
28 unsigned int value = 0;
29 const bool status = parse_number<unsigned int>(valstr, value);
31 OPENVPN_THROW_ARG1(option_error, ERR_INVALID_OPTION_VAL, name <<
": error parsing number of " << (ms ?
"milliseconds" :
"seconds"));
34 if (value == 0 || value > maxdur)
36 if (value < min_value)
38 dur = ms ? Time::Duration::milliseconds(value) : Time::Duration::seconds(value);
42 const std::string &name,
44 const unsigned int min_value,
70 const Time::Duration &default_duration,
71 const unsigned int min_value,
75 Time::Duration
ret(default_duration);
81 const Time::Duration &min,
82 const unsigned int flux_order,
85 const unsigned int range = 1 << flux_order;
86 const int delta = int(rng.
rand_get<
unsigned int>() & (range - 1)) - int(range >> 1);
87 const Time::Duration
ret = dur + delta;
const Option * get_ptr(const std::string &name) const
const std::string & get(const size_t index, const size_t max_len) const
Abstract base class for random number generators.
T rand_get()
Create a data object filled with random bytes.
#define OPENVPN_THROW_ARG1(exc, arg, stuff)
Support deferred server-side state creation when client connects.
const Option * load_duration_parm(Time::Duration &dur, const std::string &name, const OptionList &opt, const unsigned int min_value, const bool x2, const bool allow_ms)
void set_duration_parm(Time::Duration &dur, const std::string &name, const std::string &valstr, const unsigned int min_value, const bool x2, const bool ms)
Time::Duration skew_duration(const Time::Duration &dur, const Time::Duration &min, const unsigned int flux_order, RandomAPI &rng)
Time::Duration load_duration_default(const std::string &name, const OptionList &opt, const Time::Duration &default_duration, const unsigned int min_value, const bool x2, const bool allow_ms)
Implementation of the base classes for random number generators.